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...
    }
  • 相关阅读:
    变量定义和声明的差别(整理)
    堆栈指针理解
    HDU 4349 Xiao Ming&#39;s Hope
    iOS 8中CLLocationManager及MKMapView showUserLocation失败的解决的方法
    Ant命令行操作
    linux awk命令详细使用方法
    mysql 修改[取消]timestamp的自动更新
    cocos2d-x 3.0游戏实例学习笔记《卡牌塔防》第六步---炮台&amp;点击炮台加入英雄&amp;英雄升级
    SendMessage、PostMessage原理
    poj 2104 K-th Number 主席树+超级详细解释
  • 原文地址:https://www.cnblogs.com/yipeng-yu/p/2848405.html
Copyright © 2011-2022 走看看