zoukankan      html  css  js  c++  java
  • WCF web.config 一般配置

    新建一个DeskTopService的Wcf服务

    web.config配置如下:(测试可以用)

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <connectionStrings>
        <add name="TestConnectionString" connectionString="Data Source=.;Database=test;Uid=test;Pwd=test;" providerName="System.Data.SqlClient" />
      </connectionStrings>
      <system.web>
        <compilation debug="true" targetFramework="4.0" />
      </system.web>
      <system.serviceModel>
        <services>
          <service behaviorConfiguration="DeskTopService.DeskTopServiceBehavior" name="DeskTopService.DeskTopService">
            <endpoint address="" binding="basicHttpBinding" contract="DeskTopService.IDeskTopService" />
            <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
          </service>
        </services>
        <behaviors>
          <serviceBehaviors>
            <behavior name="DeskTopService.DeskTopServiceBehavior">
              <!-- 为避免泄漏元数据信息,请在部署前将以下值设置为 false 并删除上面的元数据终结点 -->
              <serviceMetadata httpGetEnabled="true"/>
              <!-- 要接收故障异常详细信息以进行调试,请将以下值设置为 true。在部署前设置为 false 以避免泄漏异常信息 -->
              <serviceDebug includeExceptionDetailInFaults="false"/>
            </behavior>
          </serviceBehaviors>
        </behaviors>
        <serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
      </system.serviceModel>
    </configuration>

    客户端 添加服务应用的Wcf地址 如:http://desktopservice.xxxxxx.com/DeskTopService.svc (最好是配置在IIS中,方便测试调用)

    客户端web.config配置示例:(这里我只贴上 ServiceModel 节点,实际上也只需要配置这个节点)

    <system.serviceModel>
        <bindings>
          <basicHttpBinding>
            <binding name="basicBinding" maxReceivedMessageSize="6553600">
              <readerQuotas maxStringContentLength="6553600" />
            </binding>
            <binding name="BasicHttpBinding_IDeskTopService" closeTimeout="00:01:00"
              openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
              allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
              maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
              messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
              useDefaultWebProxy="true">
              <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                maxBytesPerRead="4096" maxNameTableCharCount="16384" />
              <security mode="None">
                <transport clientCredentialType="None" proxyCredentialType="None"
                  realm="" />
                <message clientCredentialType="UserName" algorithmSuite="Default" />
              </security>
            </binding>
          </basicHttpBinding>
          <netTcpBinding>
            <binding name="netTcpBinding" maxReceivedMessageSize="6553600">
              <readerQuotas maxStringContentLength="6553600" />
            </binding>
          </netTcpBinding>
        </bindings>
        <client>
          <endpoint address="http://desktopservice.xxxxxx.com/DeskTopService.svc"
            binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IDeskTopService"
            contract="DeskTopService.IDeskTopService" name="BasicHttpBinding_IDeskTopService" />
        </client>
      </system.serviceModel>

    然后就可以在客户端进行引用了

    class Test
    {
        static void Main()
        {
            DeskTopServiceClient client = new DeskTopServiceClient();
    
            // 使用 "client" 变量在服务上调用操作。
    
            // 始终关闭客户端。
            client.Close();
        }
    }

    完成!!

  • 相关阅读:
    DPK880 打印机 驱动正确安装不反应。
    VB6.0 获取N位有效数字方法
    Asp.Net开发小技巧汇总
    Microsoft SqlServer生成表数据Insert语句
    dell 服务器重装
    编程应该注意
    FIRST
    SharedObject使用:在FluorineFx.net与Flex中使用共享对象维护在线用户列表实例
    Flex与As3学习笔记之:Part 3 函数参数、字符串处理、日期与时间类型
    Flex与As3学习笔记之:Part 1 Flex语言基础
  • 原文地址:https://www.cnblogs.com/wangbogo/p/2586470.html
Copyright © 2011-2022 走看看