【问题标题】:WCF Service: The remote server returned an unexpected response: (400) Bad RequestWCF 服务:远程服务器返回意外响应:(400)错误请求
【发布时间】:2014-07-15 16:36:12
【问题描述】:

我有一个 WCF 服务,当必须通过网络传输小数据时,该服务效果很好。当我将数据增加到更大的大小时,出现以下错误:

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

我知道这个问题已经被其他用户多次问过。但是,我已经尝试了所有这些方法来解决这个问题。没有什么对我有用。你能看看我的配置内容,如果我遗漏了什么,请告诉我。以下是我的服务的配置文件。

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" />
  </system.web>
  <!-- When deploying the service library project, the content of the config file must be added to the host's 
  app.config file. System.Configuration does not support config files for libraries. -->
  <system.serviceModel>
    <services>
      <service name="RecieveValidationResultHubServiceLibrary.ReceiveValidationResultHubService">
        <endpoint address="" binding="basicHttpBinding" contract="RecieveValidationResultHubServiceLibrary.IReceiveValidationResultHubService">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8735/Design_Time_Addresses/RecieveValidationResultHubServiceLibrary/ReceiveValidationResultHubService/" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, 
          set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="True" httpsGetEnabled="True"/>
          <!-- To receive exception details in faults for debugging purposes, 
          set the value below to true.  Set to false before deployment 
          to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="False" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

以下是服务参考配置:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
    <add key="MaxParallelThreads" value="300"/>
  </appSettings>
  <system.web>
    <compilation debug="true" />
  </system.web>
  <!-- When deploying the service library project, the content of the config file must be added to the host's 
  app.config file. System.Configuration does not support config files for libraries. -->
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IReceiveValidationResultHubService" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" transferMode="Streamed"/>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost:8735/Design_Time_Addresses/RecieveValidationResultHubServiceLibrary/ReceiveValidationResultHubService/"
        binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IReceiveValidationResultHubService"
        contract="ReceiveValidationServiceReference.IReceiveValidationResultHubService"
        name="BasicHttpBinding_IReceiveValidationResultHubService" />
    </client>
    <services>
      <service name="StartValidationClientServiceLibrary.StartValidationClientService">
        <endpoint address="" binding="basicHttpBinding" contract="StartValidationClientServiceLibrary.IStartValidationClientService">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8734/Design_Time_Addresses/StartValidationClientServiceLibrary/StartValidationClientService/" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, 
          set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="True" httpsGetEnabled="True"/>
          <!-- To receive exception details in faults for debugging purposes, 
          set the value below to true.  Set to false before deployment 
          to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="False" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

【问题讨论】:

  • 了解您尝试过哪些“修复”会很有帮助,这样我们就不会陷入同样的​​困境。
  • 您可能需要按照here 的说明扩大邮件大小配额。
  • 我已经尝试过:maxBufferPoolSize="2000000" maxReceivedMessageSize="2000000" maxStringContentLength="2000000" maxArrayLength="2000000" 在两个配置中。但是,对我不起作用。
  • 请确保您在 WCF 服务层和客户端消费者层具有通用配置,并且提到的第二件事请检查配额是否相同并增加到最大值
  • 记得更改客户端和服务器中的 max(params)...

标签: c# wcf


【解决方案1】:

如果错误与最大读者配额有关,请在您的绑定下的 web.config 中进行更改。看看它是否有效。

<binding maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
      <readerQuotas maxDepth="32" maxStringContentLength="2147483647"
        maxArrayLength="16348" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
</binding>

【讨论】:

  • 我当前客户端的配置文件如下所示: 我仍然不确定将这些最大参数放在我的服务配置文件的什么位置.
  • 在你的 web.config 文件中,有 标签,里面有 标签。在 标记中使用此代码。
猜你喜欢
  • 2019-08-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-01-13
  • 2014-11-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多