问题描述
我遇到以下错误的问题:已超过传入消息的最大消息大小配额 (65536).要增加配额,请在适当的绑定元素上使用 MaxReceivedMessageSize 属性."
所以我做了一些研究,发现我需要增加缓冲区和消息大小,这是我的 WCF 服务配置文件:
<绑定><wsHttpBinding><binding name="default" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"/></wsHttpBinding></绑定><服务><服务名称="WCF.Service.Service"><endpoint address="ws" name="ws" bindingConfiguration="default" binding="wsHttpBinding" contract="WCF.Service.Contracts.IService"/><endpoint address="mex" binding="mexHttpBinding" name="mex" contract="IMetadataExchange"/></服务></服务><行为><服务行为><行为><!-- 为避免泄露元数据信息,将下面的值设置为 false 并在部署之前删除上面的元数据端点 --><serviceMetadata httpGetEnabled="True"/><!-- 接收故障中的异常详细信息以进行调试,将下面的值设置为 true.部署前设置为false避免泄露异常信息--><serviceDebug includeExceptionDetailInFaults="True"/></行为></serviceBehaviors></行为></system.serviceModel>
当我在 WCF 测试客户端中运行服务并查看生成的客户端配置文件时,它没有绑定:
<system.serviceModel><绑定><wsHttpBinding><绑定名称="ws" 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"/><reliableSessionordered="true" inactivityTimeout="00:10:00"启用=假"/><安全模式=消息"><传输 clientCredentialType="Windows" proxyCredentialType="None"领域=""/><message clientCredentialType="Windows"negotiationServiceCredential="true"algorithmSuite="默认"/></安全></binding></wsHttpBinding></绑定><客户><端点地址="http://localhost:37444/Service.svc/ws" binding="wsHttpBinding"bindingConfiguration="ws" contract="IService" name="ws"><身份><userPrincipalName value="username@domain"/></身份></端点></客户端></system.serviceModel>我不明白为什么我的绑定配置没有得到应用!?WCF 测试客户端也设置为始终重新生成配置.我还尝试在消费前端应用程序中更新服务引用,但它也没有获得更新的绑定配置.任何建议将不胜感激.谢谢!
WCF 不会从您的服务器导入所有设置.也没有开关可以打开它.虽然在许多情况下可能有意义,但将所有设置从服务器端复制到客户端并不总是一个好主意.
因此,在您的情况下,您需要做的是将该绑定配置也添加到您的客户端代理,并从您的客户端端点引用它.
如果您控制连线的两端,您可以稍微轻松一点:将绑定配置外部化到一个单独的文件中并引用它.
因此创建一个文件 bindings.config
,其中包含:
<绑定><wsHttpBinding><绑定名称=默认"maxBufferPoolSize="2147483647"maxReceivedMessageSize="2147483647"/></wsHttpBinding></绑定>
然后您可以将该文件复制到服务器和客户端项目中,并从您的服务和客户端配置中引用它:
<bindings configSource="bindings.config"/><服务><服务名称="WCF.Service.Service"><endpoint address="ws" name="ws" bindingConfiguration="default" binding="wsHttpBinding" contract="WCF.Service.Contracts.IService"/><endpoint address="mex" binding="mexHttpBinding" name="mex" contract="IMetadataExchange"/></服务></服务>
在您的客户端:
<bindings configSource="bindings.config"/><客户><端点名称=ws"地址="http://localhost:37444/Service.svc/ws"绑定=wsHttpBinding"bindingConfiguration="默认"合同=IService"><身份><userPrincipalName value="username@domain"/></身份></端点></客户端></system.serviceModel>
这样,您可以一次性完成绑定配置,并在两个地方使用.
I have the problem with the following error: "The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element."
So I did some research and found that I needed to increase the buffer and message size, here's my WCF Service config file:
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="default" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"/>
</wsHttpBinding>
</bindings>
<services>
<service name="WCF.Service.Service">
<endpoint address="ws" name="ws" bindingConfiguration="default" binding="wsHttpBinding" contract="WCF.Service.Contracts.IService" />
<endpoint address="mex" binding="mexHttpBinding" name="mex" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- 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>
When I run the service in the WCF Test Client and look at the generated client config file it doesn't have my binding:
<configuration>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="ws" 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="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:37444/Service.svc/ws" binding="wsHttpBinding"
bindingConfiguration="ws" contract="IService" name="ws">
<identity>
<userPrincipalName value="username@domain" />
</identity>
</endpoint>
</client>
</system.serviceModel>
I'm lost to as why my binding configuration is NOT getting applied!? The WCF Test Client is set to always regenerate the config as well. I've also tried updating the service reference in a consuming front end application, but it does not get the updated binding configuration either. Any suggestions would be greatly appreciated. Thanks!
WCF does not import all settings from your server. There's no switch to turn that on, either. While it might make sense in many cases, it wouldn't always be a good idea to just duplicate all settings from the server-side to the client.
So in your case, what you need to do is add that binding configuration to your client side proxy, too, and reference it from your client endpoint.
If you control both ends of the wire, you can ease your work a bit: externalize the binding configuration into a separate file and reference it.
So create a file bindings.config
that contains:
<?
and then you can copy that file both into the server and the client project, and reference it from within your service and client config:
<system.serviceModel>
<bindings configSource="bindings.config" />
<services>
<service name="WCF.Service.Service">
<endpoint address="ws" name="ws" bindingConfiguration="default" binding="wsHttpBinding" contract="WCF.Service.Contracts.IService" />
<endpoint address="mex" binding="mexHttpBinding" name="mex" contract="IMetadataExchange" />
</service>
</services>
and on your client side:
<system.serviceModel>
<bindings configSource="bindings.config" />
<client>
<endpoint name="ws"
address="http://localhost:37444/Service.svc/ws"
binding="wsHttpBinding"
bindingConfiguration="default"
contract="IService">
<identity>
<userPrincipalName value="username@domain" />
</identity>
</endpoint>
</client>
</system.serviceModel>
That way, you can have your configuration for the bindings done once, and used in both places.
这篇关于为什么我的 WCF 服务没有加载我的绑定配置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!