2011-08-29 117 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

相關問題