关于WCF小小总结

来源:互联网 发布:蚁群算法的c 实现 编辑:程序博客网 时间:2024/04/29 07:00

关于WCF内部调用WCF(webhttpbind)如何处理

1、需要在调用地方使用以下代码来限定调用的wcf(webhttpbind)的方法VerifyCredit在给定的客户端环境中使用
LoginService.LoginServiceClient Client = new LoginService.LoginServiceClient();//被调用的wcf(webhttpbind)客户端对象
 using (new OperationContextScope(Client.InnerChannel))
{
   LRet= Client.VerifyCredit(CreditString);//wcf(webhttpbind)的方法
}


关于WCF配置文件学习

WCF服务器端的配置
1、配置节<system.serviceModel>主要包含“服务扩展配置”、“服务运行环境配置”、“对应于每个服务的配置项”、
“每种绑定的运行配置(可被其他节引用)”、“每种行为(终结点行为、服务行为)的配置(可被其他节引用)”

2、“对应于每个服务的配置项”<service>节中至少要包含两种终结点<endpoint>“服务元数据终结点”和“服务运行终结点”;
承载服务的计算机信息 <host>,在<host>中包含了访问服务的基址信息;<service>节的“name”属性必须被设置为服务实现的类

3、<endpoint>节的三个属性“adress”、“binding”、“contract”必须得设定;该处的“contract”协定指的是服务的“接口”

4、可以在<endpoint>节中增加子节<header>来强制客户端在向服务器发送数据时,通过不同的标识头来区别不同的客户端

5、启用了“会话模式”的WCF默认只支持10个并发访问,若要改变该默认设置,可以通过定义<serviceThrottling>行为的
“maxConcurrentSessions”属性来改变;该处比较关键

关于WCF服务的“配置信息”可以在MSDN中通过“索引”-->“WCF”-->"基本编程"-->"配置服务"找到相关信息

“索引”-->“WCF”-->"基本编程"-->"wcf疑难解答快速入门"中介绍了如何配置ssl



WCF服务客户端(asp.net后台)的配置
1、当通过“添加服务引用”添加服务后自动生成如“ServiceReference1.svcmap”文件中包含了访问的协定信息

2、一般情况下在网站的Web.config文件中会自动生成<system.serviceModel><client><endpoint></client></system.serviceModel>,在
<endpoint>节中指定要访问的目标地址;似乎当服务为自承载的情况下,VS自带工具不会自动生成该节内容,得手动添加,同时可能得需要在生成的
代理文件Reference.cs的接口对象添加接口的[System.ServiceModel.Web.WebGet(BodyStyle = System.ServiceModel.Web.WebMessageBodyStyle.Wrapped)]
属性,从而支持多个参数的传递.

3、<endpoint>节的例子“<endpoint address="http://192.168.1.178:8081/LoginService" binding="webHttpBinding"
contract="ServiceReference1.ILoginService"/>”中的contract的属性内容“ServiceReference1”必须为添加引用时所起的名字


关于WCF以Https发布的配置

1、配置文件中需要配置<security mode="Transport">和<serviceMetadata httpsGetEnabled="true" />


关于以应用程序为客户端调用wcf的注意事项

1、首先要在客户端的配置文件中增加以下节:
 <system.serviceModel>
    <behaviors>
      <endpointBehaviors>
        <behavior name="webBehavior">
          <webHttp/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <bindings>
      <webHttpBinding>
        <binding name="webBinding" allowCookies="true">
          <security mode="None">
            <transport clientCredentialType="None"/>
          </security>
        </binding>
      </webHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://192.168.1.178:8081/LoginService" behaviorConfiguration="webBehavior" binding="webHttpBinding" bindingConfiguration="webBinding" contract="LoginService.ILoginService" name="webBinding"/>
    </client>
  </system.serviceModel>
2、给Service References文件夹中自动生成的代理文件Reference.cs的接口添加上以下声明属性
 [System.ServiceModel.Web.WebGet(BodyStyle = System.ServiceModel.Web.WebMessageBodyStyle.Wrapped)]

0 0