未从配置读取WCF maxReceivedMessageSize
对于WCF服务,我在以下服务器端app.config中有一个配置文件:未从配置读取WCF maxReceivedMessageSize,wcf,wcf-binding,Wcf,Wcf Binding,对于WCF服务,我在以下服务器端app.config中有一个配置文件: <system.serviceModel> <bindings> <wsHttpBinding> <binding name="default" maxReceivedMessageSize="5000000"> <readerQuotas maxStringContentLength="5000000" max
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="default" maxReceivedMessageSize="5000000">
<readerQuotas maxStringContentLength="5000000" maxArrayLength="5000000" />
</binding>
</wsHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="Core.TOAService.Service1Behavior"
name="Core.TOAService.TOAService">
<endpoint address="" binding="wsHttpBinding" contract="Core.TOAService.ITOAService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8732/Design_Time_Addresses/Core.TOAService/TOAService/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="Core.TOAService.Service1Behavior">
<!-- To avoid disclosing metadata information,
set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="True"/>
<!-- To receive exception details in faults for debugging purposes,
set the value below to true. Set to false before deployment
to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
当我尝试向此服务传递一个较大的文件(仅约250KB)时,我在svclog文件中记录了一个异常:
的最大邮件大小配额
已收到传入消息(65536)
超过。要增加配额,请使用
上的MaxReceivedMessageSize属性
适当的绑定元素
从配置顶部的binding部分可以看到,我尝试将maxReceivedMessageSize设置为5000000,但服务仍然认为它设置为默认的65536。关于什么是错误的,或者哪个是“适当的”绑定元素,有什么想法吗?还有更多设置:-)请尝试
标记上的“maxBufferPoolSize”和“maxBufferSize”
但最大的问题是:您的端点没有引用该绑定配置
<endpoint address=""
binding="wsHttpBinding" contract="Core.TOAService.ITOAService">
您需要添加对它的引用,以便它变得有用-仅将其称为“default”不起作用
<endpoint address=""
binding="wsHttpBinding"
bindingConfiguration="default"
contract="Core.TOAService.ITOAService">
你走在时代的前列;-)在WCF 4中(使用.NET 4.0-今年晚些时候,2009),您将能够定义“默认绑定配置”,而不必显式命名和引用它们-但现在,您需要在端点及其绑定和任何绑定(或行为)配置之间创建链接
Marc有几个地方需要设置大小。在您的情况下,我认为您需要添加读取配额。以下是一个例子:
<basicHttpBinding>
<binding name="httpBasicBinding_Service" closeTimeout="00:03:00"
openTimeout="00:03:00" receiveTimeout="00:10:00" sendTimeout="00:03:00"
maxBufferSize="2000001"
maxBufferPoolSize="2000001" maxReceivedMessageSize="2000001">
<readerQuotas maxDepth="2000001" maxStringContentLength="2000001"
maxArrayLength="2000001" maxBytesPerRead="2000001" maxNameTableCharCount="2000001" />
</binding>
</basicHttpBinding>
如果在使用WCF测试客户端时仍然收到此错误消息,那是因为客户端有一个单独的MaxBufferSize设置 要更正此问题:
注意:自动生成的代理客户端也默认将MaxBufferSize设置为65536 是的,您必须引用绑定配置。缓冲区的改变可能是不必要的。如果真的需要三个缓冲区中的哪一个以及是否真的需要缓冲区的改变永远都不太清楚——尝试一下,看看会有帮助。关于如何调整这些设置,没有很好的、全面的文档和解释,不幸的是……Doh,我认为使用VS2010构建3.5服务是正确的!非常感谢,已经修好了。