远程服务器返回了意外的响应:(400)错误的请求(The remote server returne

2019-09-02 18:05发布

调用除了在一个我的WCF服务的方法时,我没有得到任何错误。

这称为SaveTemplate()特定方法以字节[]的输入。

我与大小字节[806803]的文件测试这种方法,但在一个错误结尾:

WCF - 远程服务器返回了意外的响应:(400)错误的请求*。

我已经通过几个搜索结果中消失了我已经在谷歌找到并根据这些做出的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>

Answer 1:

既然你出现在IIS可托管ASP.NET的里面,你需要确保该请求长度ASP.NET允许除了WCF的各种设置也设置。 对于ASP.NET你正在寻找的设置maxRequestLength上的httpRuntime元素 。 此设置的默认值是只有4MB,这样可以解释为什么您遇到的问题。

这看起来有点像这样一个512MB的最大长度:

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

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


Answer 2:

感谢所有帮助!

这是我的无知造成我拿这么多的时间来解决这个问题。

我的失败与新的绑定配置更新我的Windows服务的配置文件。 相反,我只是在复制Windows服务目录中的一个单独的配置文件。



Answer 3:

我的50美分:所述httpRuntime元素的maxRequestLength属性的从65536的值更改为2147483647。



文章来源: The remote server returned an unexpected response: (400) Bad Request
标签: wcf service