wcf – 远程服务器返回了意外响应:(400)错误请求

调用我的WCF服务方法时,我没有收到任何错误.

这个名为SaveTemplate()的特殊方法接受byte []的输入.

我正在使用大小为byte [806803]的文件测试此方法,
但以错误结束:

WCF – The remote server returned an unexpected response: (400) Bad Request.*

我已经在Google上找到了几个搜索结果,并根据这些在app.config中进行了一些更改,但仍然收到错误:-(

这是我的WCF服务库的App.Config文件:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.web>
    <compilation debug="true" />
  </system.web>

  <system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding name="wsHttp" maxReceivedMessageSize="50000000" maxBufferPoolSize="50000000"
        messageEncoding="Mtom" >
          <readerQuotas maxDepth="500000000" maxStringContentLength="500000000" maxArrayLength="500000000"
          maxBytesPerRead="500000000" maxNameTableCharCount="500000000" />
          <security mode="None"></security>
        </binding>
      </wsHttpBinding>
    </bindings>

    <services>
      <service behaviorConfiguration="ReportingComponentLibrary.TemplateServiceBehavior"
        name="ReportingComponentLibrary.TemplateService">
        <endpoint address="" binding="wsHttpBinding" contract="ReportingComponentLibrary.ITemplateService" bindingConfiguration="wsHttp" >
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" ></endpoint>
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8080/ReportingComponentLibrary/TemplateService/" />
          </baseAddresses>
        </host>
      </service>

      <service behaviorConfiguration="ReportingComponentLibrary.TemplateServiceBehavior"
        name="ReportingComponentLibrary.TemplateReportService">
        <endpoint address="" binding="wsHttpBinding" contract="ReportingComponentLibrary.ITemplateReportService" bindingConfiguration="wsHttp" >
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8080/ReportingComponentLibrary/TemplateReportService/" />
          </baseAddresses>
        </host>
      </service>

    </services>

    <behaviors>
      <serviceBehaviors>
        <behavior name="ReportingComponentLibrary.TemplateServiceBehavior">
          <serviceMetadata httpGetEnabled="True"/>
          <serviceDebug includeExceptionDetailInFaults="True" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>
最佳答案
由于您似乎是在IIS中的ASP.NET内部托管,因此除了WCF的各种设置之外,还需要确保ASP.NET允许的请求长度.对于ASP.NET,您正在寻找的设置是the httpRuntime element上的maxRequestLength.此设置的默认值仅为4MB,这样就可以解释您遇到问题的原因.

对于512MB maxLength,这看起来有点像这样:

<system.web>
    <httpRuntime maxRequestLength="524288" />

    <!-- rest of your config here -->
</system.web>

转载注明原文:wcf – 远程服务器返回了意外响应:(400)错误请求 - 代码日志