【问题标题】:WCF Error 400 Bad Request when sending message bigger than 100mb发送大于 100mb 的消息时 WCF 错误 400 错误请求
【发布时间】:2019-01-15 13:41:02
【问题描述】:

我创建了我的第一个 WCF 服务,用于接收我必须处理的数据。当我一次发送大量数据时会出现问题,即 100mb 的肥皂消息,我收到回复 Error 400 Bad Request。

我尝试设置其他问题中引用的 maxReceivedMessageSize、maxBufferSize、maxAllowedContentLength、readerQuotas,但似乎没有任何效果或只是使服务根本无法工作。

这些是我的 web.config 中的当前设置

<services>
  <service name="RMQServices.RMQ_WS1" behaviorConfiguration="MyServiceTypeBehaviors">
        <endpoint address="webHttp" contract="RMQServices.RMQService" binding="basicHttpBinding" bindingConfiguration="myBasic" />
    </service>
</services>

<bindings>
    <basicHttpBinding>
        <binding name="myBasic" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" sendTimeout="00:30:00">
            <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" maxArrayLength="2147483647"/>
            <security mode="TransportCredentialOnly">
                <transport clientCredentialType="Windows" />
            </security>
        </binding>
    </basicHttpBinding>
</bindings>

<requestFiltering>          
    <requestLimits maxAllowedContentLength="2147483647" />
</requestFiltering>

我是否仍然缺少配置中的某些内容以使其正常工作并接受更大的请求?

编辑: 如果我通过服务引用发送数据,那么它甚至可以接受 1GB 的肥皂消息。但是,如果我尝试使用预构建的 SOAP XML 通过 HttpWebRequest 发送它,那么它仍然会返回一个错误请求。所以问题似乎在于我如何发送数据。

【问题讨论】:

    标签: wcf soap web-config


    【解决方案1】:

    确保您的客户端配置也具有这些值

    <client>
          <endpoint address="[address]" binding="basicHttpBinding" bindingConfiguration="myBasic" contract="" name="Name" />
    </client>
    

    然后加上

    <bindings>
    
    
        <basicHttpBinding>
            <binding name="myBasic" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" sendTimeout="00:30:00">
                <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" maxArrayLength="2147483647"/>
                <security mode="TransportCredentialOnly">
                    <transport clientCredentialType="Windows" />
                </security>
            </binding>
        </basicHttpBinding>
    </bindings>
    

    如果这不起作用,请从绑定中删除安全性,然后验证

    【讨论】:

    • 经过进一步测试,客户端有问题。如果我向服务添加服务引用,它会接受任何内容。但是当我通过 HttpWebRequest 发送一个预构建的肥皂 XML 时,它仍然返回一个错误的请求。
    【解决方案2】:

    请尝试添加以下代码sn-ps。

        <behaviors>
          <serviceBehaviors>
            <behavior name="mybehavior">
              <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
              <serviceDebug includeExceptionDetailInFaults="false"/>
              <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
            </behavior>
          </serviceBehaviors>
        </behaviors>
      </system.serviceModel>
      <system.web>
        <httpRuntime maxRequestLength="2147483647" executionTimeout="3600" />
      </system.web>
    </configuration>
    

    另外,不要忘记在客户端和服务器端之间应用配置(您还应该在客户端和服务器端端点上添加此配置)。
    如果问题仍然存在,请随时告诉我。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-26
      • 1970-01-01
      • 2018-05-09
      • 2011-01-10
      相关资源
      最近更新 更多