wcf - WCF 中超出最大请求长度

标签 wcf wcf-binding wshttpbinding

我目前正在使用 Wcf 应用程序并在跟踪日志中遇到上述错误。

下面是 Wcf 服务的 Web.Config。

<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);

最佳答案

在 web.config 中更改以下设置

 <configuration> 
    <system.web> 
        <httpRuntime maxRequestLength="xxxx" /> 
    </system.web> 
</configuration> 

xxxx 是您要设置为 KB 的值。

关于wcf - WCF 中超出最大请求长度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12951763/

相关文章:

WCF 在客户端和服务器上都有证书(消息安全和 wsHttpBinding)

c# - 将数组传递给 WCF 服务

c# - WCF Rest api - [WebGet] 工作,但未找到 [WebInvoke(...GET...)] 的端点

wcf - 以 WCF Web 服务作为数据源的 Crystal Reports

WCF IIS 托管服务由单个服务实现的多个服务契约(Contract) - 如何通过配置在端点之间共享 uri

c# - 通过 Console/WinForms 中的 ServiceHost 托管 WCF 服务

c# - WCF 中的 mex 绑定(bind)错误

wcf - 无法处理该消息,因为操作 'http://docs.oasis-open.org/ws-sx/ws-trust/200512/RST/SCT' 无效或无法识别。

WCF 托管、配置和连接地址/端口问题(包括 Delphi 7 客户端)

c# - WCF:无法满足对安全 token 的请求,因为身份验证失败