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

时间:2011-02-20 10:46:51

标签: wcf

我得到异常“远程服务器返回了意外的响应:(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 个答案:

答案 0 :(得分:3)

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

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