zoukankan      html  css  js  c++  java
  • WCF 基础

    ServiceModel 配置元素

    Binding 配置元素:

    客户端Web.config:

    <?xml version="1.0" encoding="utf-8"?>

    <configuration>

    <system.serviceModel>

    <!-- 描述咋样通信,如:编码、传输协议、安全-->
    <bindings>
    <basicHttpBinding>
    <binding name="BasicHttpBinding_IUser" 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>
    </bindings>

    <!--设定匹配端点-->
    <client>
    <endpoint address="http://localhost/User.svc" binding="basicHttpBinding"
    bindingConfiguration="BasicHttpBinding_IUser" contract="WCFService.IUser"
    name="BasicHttpBinding_IUser" />
    </client>
    </system.serviceModel>
    </configuration>

    服务端Web.config代码

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>

    <system.serviceModel>
    <behaviors>
    <serviceBehaviors>
    <behavior>
    <!-- 为避免泄漏元数据信息,请在部署前将以下值设置为 false 并删除上面的元数据终结点 -->
    <serviceMetadata httpGetEnabled="true"/>
    <!-- 要接收故障异常详细信息以进行调试,请将以下值设置为 true。在部署前设置为 false 以避免泄漏异常信息 -->
    <serviceDebug includeExceptionDetailInFaults="false"/>
    </behavior>
    </serviceBehaviors>
    </behaviors>

    <!--匹配所有相同端点的客户端请求:就是A,B,C必须一致-->

    <services>
    <service name="WCFService">
    <endpoint address="http://localhost/User.svc" binding="basicHttpBinding"
    contract="WCFService.IUser" />
    </service>
    </services>

    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
    </system.serviceModel>
    <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    </system.webServer>

    </configuration>

    //客户端使用

    using (ChannelFactory<Ixxx> channelFactory = new ChannelFactory<IEmployees>(endpointConfigName))
    {
                   
                   Ixxx proxy = channelFactory.CreateChannel();
             //dosomething...
    }
  • 相关阅读:
    架构与思维:设计容量,到底有多重要 ?
    MySQL全面瓦解25:构建高性能索引(案例分析篇)
    MySQL全面瓦解24:构建高性能索引(策略篇)
    MySQL全面瓦解23:MySQL索引实现和使用
    MySQL全面瓦解22:索引的介绍和原理分析
    C#9.0:Records
    C#9.0:Improved Pattern Matching
    C#9.0:Top-Level Programs
    C#9.0:Init
    MySQL全面瓦解21(番外):一次深夜优化亿级数据分页的奇妙经历
  • 原文地址:https://www.cnblogs.com/yipeng-yu/p/2848405.html
Copyright © 2011-2022 走看看