我遇到了众所周知的 WCF 错误:
已超出传入消息的最大消息大小配额 (65536)。要增加配额,请使用相应绑定元素上的 MaxReceivedMessageSize 属性。
在阅读了此错误的前五个 Google 结果后,我仍然不知道我的服务/客户端的配置可能有什么问题。
我尝试过的:
Setting maxReceivedMessageSize http://social.msdn.microsoft.com/Forums/silverlight/en-US/5cd76441-6452-4114-98e3-5be7b3074404/the-maximum-message-size-quota-for-incoming-messages-65536-has-been-exceeded-to-increase-the?forum=silverlightdevtools.
Setting maxBufferSize and maxBufferPoolSize https://stackoverflow.com/a/5459751/240613.
Adding readerQuotas https://stackoverflow.com/a/19564171/240613.
确保客户端和服务器的值相同。 https://stackoverflow.com/a/18430650/240613.
确保绑定配置是按名称指定的。 https://stackoverflow.com/a/16266316/240613
在服务名称中包含命名空间。 https://stackoverflow.com/a/7809555/240613
注意:
小消息可以正确传输,但是当客户端向服务器发送大消息时,就会出现上述错误。
太大的消息包含约 350 KB 字节数组(假设 WCF 配置为将二进制数据编码为 Base64)。
这是一种 (1) 双向通信,(2) 使用网络 TCP 绑定,(3) 可靠会话和 (4) 启用排序(这四点与我见过的搜索错误的每个示例不同)。
该服务由随 Visual Studio 2012 安装的 IIS Express 托管。
这是我的配置。有什么提示吗?
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true" />
<bindings>
<netTcpBinding>
<binding name="netTcpEndpoint"
receiveTimeout="00:10:00"
sendTimeout="00:10:00"
maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647"
maxBufferPoolSize="2147483647">
<readerQuotas maxDepth="2147483647"
maxArrayLength="2147483647"
maxStringContentLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647"/>
<reliableSession ordered="true"
inactivityTimeout="00:10:00"
enabled="false" />
<security mode="None">
<message clientCredentialType="None" />
</security>
</binding>
</netTcpBinding>
</bindings>
<services>
<service behaviorConfiguration="DebugOrientedBehavior"
name="DemoNamespace.PipeService">
<endpoint address="Default.svc"
binding="netHttpBinding"
name="TransportLayerServiceEndpoint"
contract="DemoNamespace.IPipeService" />
<host>
<baseAddresses>
<add baseAddress="http://example.com/Default.svc" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="DebugOrientedBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
客户端配置是这样的:
<bindings>
<netHttpBinding>
<binding name="TransportLayerServiceEndpoint"
receiveTimeout="00:10:00"
sendTimeout="00:10:00"
maxBufferPoolSize="2147483647"
maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="2147483647"
maxArrayLength="2147483647"
maxStringContentLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647"/>
<reliableSession ordered="true"
enabled="false" />
<webSocketSettings transportUsage="Always" />
</binding>
</netHttpBinding>
</bindings>
<client>
<endpoint address="ws://example.com/Default.svc/Default.svc"
binding="netHttpBinding"
bindingConfiguration="TransportLayerServiceEndpoint"
contract="PipeServiceReference.IPipeService"
name="TransportLayerServiceEndpoint" />
</client>
您的服务配置似乎有问题 - 您指定netHttpBinding
对于没有绑定配置的服务端点,并且您定义了一个配置netTcpBinding
(但显然没有使用)。您的配置的相关服务部分位于此处:
<endpoint address="Default.svc"
binding="netHttpBinding"
name="TransportLayerServiceEndpoint"
contract="DemoNamespace.IPipeService" />
请注意,没有bindingConfiguration
值设定。我建议将客户端中定义的绑定配置添加到您的服务配置中,然后更新服务端点以使用该绑定:
<endpoint address="Default.svc"
binding="netHttpBinding"
bindingConfiguration="TransportLayerServiceEndpoint"
name="TransportLayerServiceEndpoint"
contract="DemoNamespace.IPipeService" />
目前您的服务正在使用默认值netHttpBinding
,这可能是您仍然收到错误的原因。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)