2010-01-13 84 views
2

我必须建立一个API,它是一个WCF服务。在web.config中的服务,我指定了自定义bindong看起来像这样:WCF服务绑定回吐默认值,​​而不是自定义值

<bindings> 
    <wsHttpBinding> 
    <binding name="FxBinding" 
     maxBufferPoolSize="2147483647" 
     maxReceivedMessageSize="2147483647" 
     closeTimeout="00:20:00" 
     openTimeout="00:20:00" 
     receiveTimeout="00:20:00" 
     sendTimeout="00:20:00" 
     messageEncoding="Mtom"> 
       <readerQuotas 
     maxDepth="64" 
     maxStringContentLength="2147483647" 
     maxArrayLength="2147483647" 
     maxBytesPerRead="4096" 
     maxNameTableCharCount="16384" /> 
     <security mode="None"></security> 
    </binding> 
    </wsHttpBinding> 
</bindings> 

告诉配置使用我已经在端点标签设置“名称”属性指定的绑定:

<services> 
    <service name="Dba.Admanager.Api.ListingServiceContract" behaviorConfiguration="Dba.Admanager.Api.ListingServiceContractBehavior"> 
    <endpoint address="" binding="wsHttpBinding" name="FxBinding" contract="Dba.Admanager.ApplicationController.Api.IListingServiceContract"> 
     <identity> 
     <dns value="localhost"/> 
     </identity> 
    </endpoint> 
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> 
    </service> 
</services> 

见。当我在VS2008中创建对Web服务的Web引用时,会生成一个app.config。 在这个app.config中使用的绑定应该是上面指定的绑定。但在app.config中是一个默认绑定,例如“maxArrayLength”中的默认值。

<bindings> 
     <wsHttpBinding> 
      <binding name="FxBinding" closeTimeout="00:01:00" openTimeout="00:01:00" 
       receiveTimeout="00:10: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="Windows" proxyCredentialType="None" 
         realm=""> 
         <extendedProtectionPolicy policyEnforcement="Never" /> 
        </transport> 
        <message clientCredentialType="Windows" negotiateServiceCredential="true" 
         algorithmSuite="Default" establishSecurityContext="true" /> 
       </security> 
      </binding> 
     </wsHttpBinding> 
    </bindings> 
    <client> 
     <endpoint address="http://l-aar-00424012.corp.ebay.com/Admanager.Api/ListingServiceContract.svc" 
      binding="wsHttpBinding" bindingConfiguration="FxBinding" contract="WCFListingServiceContract.IListingServiceContract" 
      name="FxBinding"> 
      <identity> 
       <dns value="localhost" /> 
      </identity> 
     </endpoint> 
    </client> 

我可以看到,客户端使用的FxBinding配置,但为什么地球上所有的值都是默认的,我不明白。可以通过anubody提供有关如何自定义绑定值并使其反映在“客户端”部分的线索?

如果我改变价值观manualle在App.config我得到预期的效果,而每次Web引用更新时,VS只是增加了使用默认值的新结合。

回答

4

信息如maxArrayLength不是WSDL的一部分,所以客户端不能推断它,只是需要默认值。

2

正如达林已经提到的 - 因为这些结合参数不是服务和客户端之间的互操作的元数据的一部分,他们不能被自动的客户端,当你创建一个新的客户端代理回升。

你可以做的是这样的:

  • 在一个单独的配置文件和参考定义绑定配置的服务器上 - 即把里面的东西<bindings>bindings.config,然后从你的服务器端Web引用它的.config或app.config中:

    <system.serviceModel> 
        <bindings configSource="bindings.config" /> 
    </system.serviceModel> 
    
  • 然后复制bindings.config到你的客户端和做同样的事情出现在你的app.config。

注:是的,Visual Studio将抱怨的“configSource”没有被定义,所有 - 但是这只是在VS智能感知配置文件的一个漏洞。相信我 - 它的工作原理 - 我每天都在生产系统中使用它! .NET中的每个配置部分都有一个“configSource”属性!

使用这种方法,您可以创建一个文件,该文件包含系统的结合配置,你可以用它在服务器和客户端上都。

+0

Thancs marc_s。这是很有价值的信息,并使配置更具可读性。 Plus:它可以节省配置同步的麻烦。 – esbenr