我遇到了這個我試圖處理的瘋狂問題。我知道,當我們獲取大量數據時,我們必須增加客戶端.config文件的配額,但是如果我的客戶端正在向WCF服務器發送大量數據,我該怎麼辦?傳入消息的最大消息大小配額(65536)....要提高配額,請使用MaxReceivedMessageSize屬性
當我發送小尺寸輸入參數時,它完美正常工作。不幸的是,當輸入變大時,它就會崩潰。
調試器,它說:
錯誤的請求,400;
上跟蹤文件,它是:
傳入的消息(65536)的最大消息大小配額 被超過。要增加配額,請在適當的綁定元素上使用MaxReceivedMessageSize 屬性。
有什麼方法可以增加服務器端數據傳輸的配額嗎?如果是這樣,怎麼樣?
這裏是我的示例配置相關的部分:
<bindings>
<basicHttpBinding>
<binding name="MyBasicHttpBinding"
closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00"
sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false"
hostNameComparisonMode="StrongWildcard" maxBufferSize="2147483647"
maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="64" maxStringContentLength="2147483647" maxArrayLength="2147483647"
maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service name="MyWcfService">
<endpoint address="http://myservice..."
binding="basicHttpBinding" bindingConfiguration="MyBasicHttpBinding"
name="MyBasicHttpBinding" contract="IMyContract" />
</service>
</services>
,這裏是我的客戶端代碼(我動態創建一個):
var binding = new BasicHttpBinding();
binding.MaxBufferPoolSize = 2147483647;
binding.MaxBufferSize = 2147483647;
binding.MaxReceivedMessageSize = 2147483647;
binding.ReaderQuotas.MaxStringContentLength = 2147483647;
binding.ReaderQuotas.MaxArrayLength = 2147483647;
binding.ReaderQuotas.MaxDepth = 2147483647;
binding.ReaderQuotas.MaxBytesPerRead = 2147483647;
var address = new EndpointAddress("http://mylocalservice..");
ChannelFactory<IMyContract> factory = new ChannelFactory<IMyContract>(binding, address);
foreach (OperationDescription op in factory.Endpoint.Contract.Operations)
{
DataContractSerializerOperationBehavior dataContractBehavior =
op.Behaviors.Find<DataContractSerializerOperationBehavior>()
as DataContractSerializerOperationBehavior;
if (dataContractBehavior != null)
{
dataContractBehavior.MaxItemsInObjectGraph = 2147483646;
}
}
public IMyContract MyClientObject = factory.CreateChannel();
我通過上述[這裏]的步驟解決了這個問題[1] [1]:HTTP://計算器。COM /問題/ 7476853/WCF的錯誤最大數的項,也就是說,可以待連載 - 或反序列化功能於一/ 8656402#8656402 – Ram
在您的客戶端代碼要設置通過代碼readerquotas所以下面的是設置他們的方法: XmlDictionaryReaderQuotas myReaderQuotas =新XmlDictionaryReaderQuotas(); myReaderQuotas.MaxStringContentLength = 2147483647; myReaderQuotas.MaxArrayLength = 2147483647; myReaderQuotas.MaxBytesPerRead = 2147483647; myReaderQuotas.MaxDepth = 64; myReaderQuotas.MaxNameTableCharCount = 2147483647; binding.GetType()的getProperty( 「ReaderQuotas」)的SetValue(結合,myReaderQuotas,空)。; – Rajesh