2011-08-29 113 views
9

我对WCF服务有以下配置。传入邮件的最大邮件大小限额(65536)已被超出

即使我增加了maxReceivedMessageSize,服务还是抛出一个错误:

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.`" exception.

这又如何解决呢?

<system.serviceModel> 
    <services> 
     <service name="MyService" behaviorConfiguration="MyServiceTypeBehaviors"> 
     <endpoint address="http://localhost:22230/MyService.svc" 
       binding="basicHttpBinding" 
       bindingConfiguration="MyServiceBinding" 
       contract="IMyService" /> 

     <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" /> 
     </service> 
    </services> 

    <behaviors> 
     <serviceBehaviors> 
     <behavior name="MyServiceTypeBehaviors" > 
      <serviceMetadata httpGetEnabled="true" /> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 

    <bindings> 
     <basicHttpBinding> 
     <binding name="MyServiceBinding" 
       hostNameComparisonMode="StrongWildcard" 
       receiveTimeout="00:10:00" 
       sendTimeout="00:10:00" 
       openTimeout="00:10:00" 
       closeTimeout="00:10:00" 
       maxReceivedMessageSize="6553600" 
       maxBufferSize="6553600" 
       maxBufferPoolSize="524288" 
       transferMode="Buffered" 
       messageEncoding="Text" 
       textEncoding="utf-8" 
       bypassProxyOnLocal="false" 
       useDefaultWebProxy="true" > 
      <security mode="None" /> 
     </binding> 
     </basicHttpBinding> 
    </bindings> 
    </system.serviceModel 
+0

我的理论是,你的客户端配置不正确配置。 – ChaosPandion

+0

所以你说,这是正确的,应该工作?我的客户现在是WCFTestClient。 – DarthVader

+0

在[此线程](http://social.msdn.microsoft.com/forums/en-US/wcf/thread/f1ad96bf-c5a0-4e6f-a357-0957d32cf2e5)中有一些想法,其中一些不适用不适用(例如,你已经增加了maxBufferSize),但可能更值得仔细观察。 – ewall

回答

15

如果这是服务配置,您应该查看您的客户端配置并将maxReceivedMessageSize与服务器消息大小相匹配。该消息来自您的客户。

+0

我的客户现在是WCFTestClient。 – DarthVader

+2

然后,您必须更改WCFTestClient的配置(转至工具和选项)或将更少的数据发送到WCFTestClient。 – Peter

+2

更改wcf测试客户端(FW 4.0在我的情况下)的配置 你应该右键点击config左边文件树列表中的最低文件。 选择“使用SvcConfigEditor编辑”,然后选择“绑定”。在绑定元素里面找到这里标出的3个家伙。 将其设置为2MB为合理大小。 http://i.imgur.com/eBdguoy.png – arik

4

您需要增加客户端配置中的最大消息大小。默认值是65536,加倍可能足以满足您的需求。

如果以编程方式配置您的端点,下面的代码片段可以帮助:

BasicHttpBinding binding = new BasicHttpBinding() { MaxReceivedMessageSize = 131072 }; 

然后,实例化服务客户端时,通过在此绑定对象的构造函数。例如:

MyServiceClient client = new MyServiceClient(binding, "http://www.mysite.com/MyService/"); 
0

确保您复制新的App.config

相关问题