我有一个简单的WCF服务需要处理大型数据流,所以我有很多配置值超过了默认值。我最近一直在将所有代码转移到一个新的重组解决方案中,我刚刚转移了这项服务。但是,当我尝试生成客户端代理(在VS2008中使用WCFTestClient.exe或“添加服务引用”时,客户端代理配置中的值与我为服务设置的值不匹配。
这是服务器配置 - 注意maxBufferSize,maxReceivedMessageSize,maxStringContentLength和MaxArrayLength的增加值
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="default" maxBufferSize="5000000" maxReceivedMessageSize="5000000">
<readerQuotas maxStringContentLength="5000000" maxArrayLength="5000000" />
<!-- turn this setting on to require SSL/https -->
<!-- <security mode="Transport" /> -->
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="Consent.Service.SubjectConsentServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="Consent.Service.SubjectConsentServiceBehavior"
name="Consent.Service.SubjectConsentService">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="default"
contract="Consent.Service.ISubjectConsentService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
这是VS2008使用“添加服务引用”生成的代理
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_ISubjectConsentService" 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://server/Consent/services/SubjectConsent.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ISubjectConsentService"
contract="ServiceReference1.ISubjectConsentService" name="BasicHttpBinding_ISubjectConsentService" />
</client>
</system.serviceModel>
客户端代理将这4个值设置为默认值。
客户端使用默认值的任何想法?
答案 0 :(得分:5)
服务器配置文件中设置的值不会作为Web服务元数据的一部分公开(因为它们与传输层有关,而不是服务本身),因此客户端(或者,在本例中为“添加服务参考“功能”无法自动查找它们。 (所有“添加服务引用”都要求输入WSDL并生成相应的类;它无法访问配置文件中与传输相关的设置。)
因此,您需要在客户端和服务器上覆盖它们。