Максимальная длина запроса превышена в WCF
Я в настоящее время использую приложение Wcf и получаю вышеупомянутую ошибку в Trace Log.
Ниже приводится Web.Config для службы Wcf.
<bindings>
<wsHttpBinding>
<binding name="NewBinding0" closeTimeout="00:50:00" openTimeout="00:50:00" sendTimeout="00:50:00" receiveTimeout="00:50:00" maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<reliableSession enabled="true" />
<security mode="None">
<transport clientCredentialType="None" />
<message clientCredentialType="Windows" negotiateServiceCredential="true" establishSecurityContext="false" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<diagnostics wmiProviderEnabled="true">
<messageLogging logEntireMessage="true" logMalformedMessages="true" logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true" />
</diagnostics>
<services>
<service behaviorConfiguration="DBSyncWcfService.Service1Behavior" name="DBSyncWcfService.DBSyncService">
<endpoint binding="wsHttpBinding" bindingConfiguration="NewBinding0" name="ABC" contract="DBSyncWcfService.IDBSyncContract" address="http://192.168.5.170:9999/" />
<host>
<baseAddresses>
Ниже приведена конфигурация на стороне клиента.
WSHttpBinding binding = new WSHttpBinding();
//binding.ReaderQuotas.MaxArrayLength = 10485760;
//binding.MaxReceivedMessageSize = 10485760;
binding.Security.Mode = SecurityMode.None;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
binding.Security.Message.ClientCredentialType = MessageCredentialType.Windows;
binding.Security.Message.EstablishSecurityContext = false;
//binding.Security.Message.NegotiateServiceCredential = true;
binding.ReliableSession.Enabled = true;
binding.ReaderQuotas.MaxArrayLength = 2147483647;
binding.ReaderQuotas.MaxDepth = 2147483647;
binding.ReaderQuotas.MaxNameTableCharCount = 2147483647;
binding.ReaderQuotas.MaxBytesPerRead = 2147483647;
//binding.MaxReceivedMessageSize = 20000000;2147483647
binding.MaxReceivedMessageSize = 2147483647;
//binding.MaxReceivedMessageSize = Int32.MaxValue;
binding.ReaderQuotas.MaxStringContentLength = 2147483647;
//binding.MaxBufferPoolSize = 20000000;
binding.MaxBufferPoolSize = 2147483647;
//binding.MaxBufferPoolSize = Int32.MaxValue;
binding.ReaderQuotas.MaxArrayLength = 2147483647;
binding.ReaderQuotas.MaxDepth = 2147483647;
binding.SendTimeout = TimeSpan.FromMinutes(50);
binding.CloseTimeout = TimeSpan.FromMinutes(50);
binding.OpenTimeout = TimeSpan.FromMinutes(50);
binding.ReceiveTimeout = TimeSpan.FromMinutes(50);
2 ответа
Решение
Возможно, вам придется установить readerQuotas для привязки, как показано ниже:
WSHttpBinding binding1 = new WSHttpBinding();
binding1.MaxBufferPoolSize = 2147483647;
binding1.MaxReceivedMessageSize = 2147483647;
var myReaderQuotas1 = new XmlDictionaryReaderQuotas();
myReaderQuotas1.MaxStringContentLength = 2147483647;
myReaderQuotas1.MaxDepth = 2147483647;
myReaderQuotas1.MaxArrayLength = 2147483647;
myReaderQuotas1.MaxBytesPerRead = 2147483647;
myReaderQuotas1.MaxNameTableCharCount = 2147483647;
binding1.GetType().GetProperty("ReaderQuotas").SetValue(binding1, myReaderQuotas1, null);
Причина в том, что установка квот для уже созданной привязки не имеет никакого эффекта.
Также вам следует рассмотреть возможность увеличения значения "MaxItemsInObjectGraph" объекта DataContractSerializer на клиенте и сервере до большого значения.
Измените следующий параметр в web.config
<configuration>
<system.web>
<httpRuntime maxRequestLength="xxxx" />
</system.web>
</configuration>
xxxx - это значение в килобайтах, которое вы хотите установить.