在设置WCF客户端和服务器时,配置文件必须同步如何?

Ale*_*lex 14 .net wcf configuration-files

大多数WCF示例都向您展示了如何配置WCF客户端和服务器.现在,如果您在它们之间稍微改变配置会发生什么?我的意思是,谁有最终决定权?

我们以此客户端配置为例:

<configuration>
<system.serviceModel>
    <bindings>
        <wsHttpBinding>
            <binding name="WSHttpBinding_ISampleService" closeTimeout="00:01:00"
                openTimeout="00:01:00" receiveTimeout="00:01:00" sendTimeout="00:01:00"
                bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
                allowCookies="false">
                <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                    maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                <reliableSession ordered="true" inactivityTimeout="00:10:00"
                    enabled="false" />
                <security mode="Message">
                    <transport clientCredentialType="None" proxyCredentialType="None"
                        realm="" />
                    <message clientCredentialType="Windows" negotiateServiceCredential="true"
                        algorithmSuite="Default" establishSecurityContext="true" />
                </security>
            </binding>
        </wsHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://localhost:8080/SampleService" binding="wsHttpBinding"
            bindingConfiguration="WSHttpBinding_ISampleService" contract="ISampleService"
            name="WSHttpBinding_ISampleService">
        </endpoint>
    </client>
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)

通常,服务器端将在其公开的服务器上配置完全相同的绑定.

但是,如果在服务器端使用openTimeout = 00:00:30定义,现在会发生什么.什么是超时?谁赢?我为所有其他参数做同样的问题.

对于配置的每个元素(绑定,客户端,服务,行为等)及其所有细节,需要哪些参数以及在哪一方(客户端或服务器),整个事情看起来都是一团糟,你怎么知道呢?

看起来您可以在服务器端定义整个绑定以及所有超时参数,并且在客户端简单地放置所需的最小配置,以便接受来自服务器的所有参数.但是现在,考虑到服务器具有更深入的配置,客户端上所需的最低参数是多少?

使用WCF配置客户端和服务器时,关于配置的每个元素的参数有哪些最佳实践:绑定,服务,客户端/端点和行为?

在客户端和服务器之间定义冲突参数时,WCF如何处理它?

mar*_*c_s 14

为了在您对我之前的答案的最后评论中解决您的请求,我尝试了解我如何为任何给定服务创建(和修改)服务器端和客户端配置的方法.这是基于我阅读的理论(书籍,博客),我在Juval Lowy中学到的东西WCF Master Class,以及几个大型服务实施项目的相当多的实践经验 - 这不是在一个地方,在网络上提供或者在书中....所以在这里:

我会从头开始.首先考虑您的服务:

  • 您的服务住在哪个地址?
  • 你想支持哪些绑定?

最简单的场景:单个服务,单个端点,basicHttpBinding,所有默认值

服务配置:

<system.serviceModel>
   <services>
      <service name="YourNamespace.YourServiceClass">
         <endpoint name="Default"
             address="http://YourServer/SomeVirtualDirectory/YourService.svc"
             binding="basicHttpBinding"
             contract="YourNamespace.IYourServiceContract" />
      </service>
   </services>
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)

对应的客户端配置:

<system.serviceModel>
   <client name="Default">
      <endpoint name="Default"
          address="http://YourServer/SomeVirtualDirectory/YourService.svc"
          binding="basicHttpBinding"
          contract="YourClientProxyNamespace.IYourServiceContract" />
   </client>
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)

然后,如果你真的必须改变一些东西!最重要的是:永远不要让Visual Studio(添加服务参考)或svcutil.exe搞砸你的配置!保护它像你的眼睛苹果!

然后:如果您的数据传输需要的时间超过默认的1分钟超时允许时间,请更改服务端和客户端的单个设置.通过定义自定义绑定配置并从端点引用该配置来实现此目的 - 但仅更改 - 而不是更多!使用默认值保留其他所有内容.除非你绝对必须(并且知道你在做什么以及为什么要这样做),否则不要改变任何东西.

请注意:sendTimeout客户端(在发送整个消息之前允许的时间)将对应于receiveTimeout服务器上 - 整个消息允许进入的时间(请参阅此优秀博客文章和此MSDN论坛帖子以获取更多信息) )

服务配置:

 <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="ExtendedTimeout"
                 receiveTimeout="00:05:00" />
      </basicHttpBinding>
    </bindings>
    <services>
      <service name="YourNamespace.YourServiceClass">
        <endpoint name="Default"
            address="http://YourServer/SomeVirtualDirectory/YourService.svc"
            binding="basicHttpBinding"
            bindingConfiguration="ExtendedTimeout"
            contract="YourNamespace.IYourServiceContract" />
      </service>
    </services>
  </system.serviceModel>
Run Code Online (Sandbox Code Playgroud)

对应的客户端配置:

<system.serviceModel>
   <bindings>
      <basicHttpBinding>
         <binding name="ExtendedTimeout"
                  sendTimeout="00:05:00" />
      </basicHttpBinding>
   </bindings>
   <client name="Default">
      <endpoint name="Default"
          address="http://YourServer/SomeVirtualDirectory/YourService.svc"
          binding="basicHttpBinding"
          bindingConfiguration="ExtendedTimeout"
          contract="YourClientProxyNamespace.IYourServiceContract" />
   </client>
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)

由于您需要其他更改,例如服务端的多个端点,或本地设置,例如bypassProxyOnLocal- 调整您的配置,请仔细,一步一步,手动执行,并认为您的配置是整个服务中非常重要的一部分 - 处理它,把它放在版本控制等.