在我的 Silverlight 4 项目中,我调用了通过包装服务访问的 WCF 服务。这只是一个 WCF 服务应用程序,其中包含对我的其他 WCF 的服务引用。我收到以下异常:
“已超出传入消息 (65536) 的最大消息大小配额。要增加配额,请在适当的绑定元素上使用 MaxReceivedMessageSize 属性。”。
调试时我看到:
用户代码未处理 ProtocolException -- 远程服务器返回意外响应:(400) 错误请求。
在 Silverlight 中,即使服务发送不同的错误代码,也可能会报告 404 响应代码。
我正在使用 Silverlight 4 和 .NET 4.0。
我可以在 WCF 测试客户端中将 maxBufferSize 和 maxReceivedMessageSize 更改为 524288 以查看我的预期结果。
如何更改这些值以便实际使用它们而不是 WCF 默认设置?
包装服务 web.config:
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IMyService" closeTimeout="00:02:00"
openTimeout="00:02:00" receiveTimeout="00:10:00" sendTimeout="00:02:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="524288" maxBufferPoolSize="524288" maxReceivedMessageSize="524288"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="524288" maxStringContentLength="524288" maxArrayLength="524288"
maxBytesPerRead="524288" maxNameTableCharCount="524288" />
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://internal:51505/SvcApp/MySvc_MyService.svc"
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IMyService"
contract="WCFServiceRef.IMyService"
name="BasicHttpBinding_IMyService" />
</client>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
Web 项目 web.config:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpsBinding_IMyWrapperService" maxBufferSize="524288"
maxReceivedMessageSize="524288">
<security mode="Transport" />
</binding>
<binding name="BasicHttpBinding_IMyWrapperService" closeTimeout="00:02:00"
openTimeout="00:02:00" receiveTimeout="00:10:00" sendTimeout="00:02:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="524288" maxBufferPoolSize="524288" maxReceivedMessageSize="524288"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="524288" maxStringContentLength="524288" maxArrayLength="524288"
maxBytesPerRead="524288" maxNameTableCharCount="524288" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://internal/mysvc/MyWrapperService.svc"
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IMyWrapperService"
contract="WrapperServiceServiceRef.IMyWrapperService"
name="BasicHttpBinding_IMyWrapperService" />
</client>
</system.serviceModel>
我已经看到了命名我的 serviceBehavior 并添加 maxItemsInObjectGraph 的建议。
我尝试添加“LargeEndpointBehavior”,但这似乎没有做任何事情。
<client>
<endpoint address="http://internal:51505/SvcApp/MySvc_MyService.svc"
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IMyService"
contract="WCFServiceRef.IMyService"
name="BasicHttpBinding_IMyService"
behaviorConfiguration="LargeEndpointBehavior" />
</client>
<behaviors>
<serviceBehaviors>
<behavior name="LargeEndpointBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</serviceBehaviors>
</behaviors>
我只需要修复我的服务包装器 web.config 吗?
我通过包装器调用的服务、我的ServiceReferences.ClientConfig
Silverlight 项目和托管我的 xap 文件的 Web 应用程序的所有值都已达到最大值。
有什么建议么?