大WCF Web服务请求与(400)HTTP错误的请求失败 [英] Large WCF web service request failing with (400) HTTP Bad Request

查看:505
本文介绍了大WCF Web服务请求与(400)HTTP错误的请求失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到这个显然是普遍的问题,一直未能解决。

I've encountered this apparently common problem and have been unable to resolve it.

如果我打电话给我的WCF Web服务使用数量相对较少的数组中的参数项(我测试过多达50个)的,一切都很好。

但是,如果我调用Web服务与500个项目,我得到了错误的请求错误。

有趣的是,我已经运行 Wireshark的在服务器上,看来,请求甚至没有触及服务器 - 400被在客户端生成的错误。

Interestingly, I've run Wireshark on the server and it appears that the request isn't even hitting the server - the 400 error is being generated on the client side.

的例外是:

System.ServiceModel.ProtocolException: The remote server returned an unexpected response: (400) Bad Request. ---> System.Net.WebException: The remote server returned an error: (400) Bad Request.

我的客户端配置文件的 system.serviceModel 部分:

The system.serviceModel section of my client config file is:

<system.serviceModel>
    <bindings>
        <wsHttpBinding>
            <binding name="WSHttpBinding_IMyService" closeTimeout="00:01:00"
                openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647"
                messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
                allowCookies="false">
                <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="2147483647"
                    maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                <reliableSession ordered="true" inactivityTimeout="00:10:00"
                    enabled="false" />
                <security mode="None">
                    <transport clientCredentialType="Windows" proxyCredentialType="None"
                        realm="" />
                    <message clientCredentialType="Windows" negotiateServiceCredential="true"
                        establishSecurityContext="true" />
                </security>
            </binding>
        </wsHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://serviceserver/MyService.svc"
            binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IMyService"
            contract="SmsSendingService.IMyService" name="WSHttpBinding_IMyService" />
    </client>
</system.serviceModel>

在服务器端,我的web.config文件中有如下的 system.serviceModel 部分:

On the server side, my web.config file has the following system.serviceModel section:

<system.serviceModel>
    <services>
        <service name="MyService.MyService" behaviorConfiguration="MyService.MyServiceBehaviour" >
            <endpoint address="" binding="wsHttpBinding" bindingConfiguration="MyService.MyServiceBinding" contract="MyService.IMyService">
            </endpoint>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
        </service>
    </services>
    <bindings>
      <wsHttpBinding>
        <binding name="MyService.MyServiceBinding">
          <security mode="None"></security>
        </binding>
      </wsHttpBinding>
    </bindings>
    <behaviors>
        <serviceBehaviors>
            <behavior name="MyService.MyServiceBehaviour">
                <!-- 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="true"/>
            </behavior>
        </serviceBehaviors>
    </behaviors>
</system.serviceModel>

我有<一个href="http://stackoverflow.com/questions/740039/c-wcf-wcf-service-returning-a-404-bad-request-when-sending-an-array-of-items">looked在一个<一个href="http://stackoverflow.com/questions/323551/http-bad-request-error-when-requesting-a-wcf-service-contract">fairly大 <一href="http://rajaramtechtalk.word$p$pss.com/2008/05/29/systemservicemodelprotocolexception-the-remote-server-returned-an-unexpected-response-400-bad-request/">number的<一个href="http://www.stonejunction.com/post/2008/12/01/WCF-Call-gives-400-Bad-Request-response.aspx">answers到<一个href="http://www.experts-exchange.com/Programming/Languages/.NET/Web%5FServices/Q%5F24002313.html">this问题与没有成功

谁能帮助我?

推荐答案

尝试设置maxReceivedMessageSize在服务器上也是如此,例如,为4MB:

Try setting maxReceivedMessageSize on the server too, e.g. to 4MB:

    <binding name="MyService.MyServiceBinding" 
           maxReceivedMessageSize="4194304">

主要原因默认(65535我相信)是如此之低,是减少拒绝服务(DoS)攻击的风险。需要设置它比服务器上的最大请求大小,并在客户端上的最大响应大小更大。如果你是在Intranet环境,DoS攻击的风险的攻击,可能是低的,所以它可能是安全使用的值比预期需要的要高得多。

The main reason the default (65535 I believe) is so low is to reduce the risk of Denial of Service (DoS) attacks. You need to set it bigger than the maximum request size on the server, and the maximum response size on the client. If you're in an Intranet environment, the risk of DoS attacks is probably low, so it's probably safe to use a value much higher than you expect to need.

顺便说一对连接到WCF服务,故障排除提示:

By the way a couple of tips for troubleshooting problems connecting to WCF services:

使用一个HTTP调试工具,如提琴手在客户端上,以检查HTTP流量。

Use an HTTP debugging tool such as Fiddler on the client to inspect the HTTP traffic.

这篇关于大WCF Web服务请求与(400)HTTP错误的请求失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆