远程服务器返回意外响应:(400) Bad Request

Posted

技术标签:

【中文标题】远程服务器返回意外响应:(400) Bad Request【英文标题】:The remote server returned an unexpected response: (400) Bad Request 【发布时间】:2011-02-20 10:46:50 【问题描述】:

我收到异常“远程服务器返回意外响应:(400) 错误请求”,但我不知道为什么。

web.config 看起来不错 - 但也许我没有看到问题

<configuration>

  <system.web>
      <compilation debug="true" targetFramework="4.0" />
      <httpRuntime maxRequestLength="524288" />
  </system.web>

 <system.serviceModel>
   <services>
      <service name="ServiceLibrary.ServiceProxy"                                              behaviorConfiguration="ServiceBehavior">

    <endpoint address="" binding="wsHttpBinding" contract="ServiceLibrary.IServiceProxy">
      <identity>
        <dns value="localhost"/>
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
  </service>
</services>  


<behaviors>
  <serviceBehaviors>
    <behavior name="ServiceBehavior">
      <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
      <serviceMetadata httpGetEnabled="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>

<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />

代码(服务器)

[ServiceContract]
public interface IServiceProxy

    [OperationContract]   
    ImageData GetImgInfo( byte[] analyzingTargetBitmap );   


[DataContract]
public class ImageData  ... 

客户端代码

<system.serviceModel>
    <bindings>
        <wsHttpBinding>
            <binding name="WSHttpBinding_IServiceProxy" closeTimeout="00:15:00"
                openTimeout="00:15:00" receiveTimeout="00:10:00" sendTimeout="00:15:00"
                bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
                allowCookies="false">
                <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                    maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                <reliableSession ordered="true" inactivityTimeout="00:15:00"
                    enabled="false" />
                <security mode="Message">
                    <transport clientCredentialType="Windows" proxyCredentialType="None"
                        realm="" />
                    <message clientCredentialType="Windows" negotiateServiceCredential="true"
                        algorithmSuite="Default" />
                </security>
            </binding>
        </wsHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://localhost:50025/ServiceProxy.svc" binding="wsHttpBinding"
            bindingConfiguration="WSHttpBinding_IServiceProxy" contract="ServiceReference1.IServiceProxy"
            name="WSHttpBinding_IServiceProxy">
            <identity>
                <dns value="localhost" />
            </identity>
        </endpoint>
    </client>
</system.serviceModel>

【问题讨论】:

你在做什么?? 如何您尝试访问您的服务?给我们看一些代码!!我们不可能仅仅从你的配置中猜出你在做什么..... 您仍未向我们展示如何您如何调用此服务! 【参考方案1】:

WCF 错误确实不能解释问题,但我遇到了类似的问题。可能是您发送的对象太大或数组中的项目太多。

您必须更改配置以接受更大的消息。

【讨论】:

顺便说一句,可能导致这种情况的另一件事是意外地在服务和客户端上配置了不匹配的绑定。例如,您使用 basicHttpBinding 设置客户端,使用 netTcpBinding 设置服务

以上是关于远程服务器返回意外响应:(400) Bad Request的主要内容,如果未能解决你的问题,请参考以下文章

远程服务器返回了意外响应:(400) Bad Request WCF REST

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

“远程服务器返回意外响应:(400)错误请求”

WCF LIST 传输大数据,远程服务器返回了意外响应 400

HttpWebRequest-远程服务器返回错误:(400) Bad Request

Oauth2:远程服务器返回错误:(400) Bad Request