Dot-Net
已超出傳入郵件的最大郵件大小配額 (65536)
我對 WCF 服務有以下配置。
即使我增加了 maxReceivedMessageSize ,服務仍然會引發錯誤:
已超出傳入郵件 (65536) 的最大郵件大小配額。要增加配額,請在適當的綁定元素上使用 MaxReceivedMessageSize 屬性。`" 例外。
如何解決?
<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
如果這是服務配置,您應該查看客戶端配置並將 maxReceivedMessageSize 與伺服器消息大小相匹配。該消息來自您的客戶。
您需要增加客戶端配置中的最大消息大小。預設值為 65536,加倍可能足以滿足您的需求。
如果您以程式方式配置端點,以下程式碼片段可能會有所幫助:
BasicHttpBinding binding = new BasicHttpBinding() { MaxReceivedMessageSize = 131072 };然後,在實例化您的服務客戶端時,將此綁定對像傳遞給建構子。例如:
MyServiceClient client = new MyServiceClient(binding, "http://www.mysite.com/MyService/");