我遇到了这个明显常见的问题,并且一直无法解决它。
如果我在数组参数中使用相对较少的项目来调用web服务(我已经测试了多达50个),那么一切都很好。
但是,如果我调用包含500个项目的web服务,则会收到错误的请求错误。
有趣的是,我在服务器上运行了Wireshark,看起来请求甚至没有命中服务器-- 400错误是在客户端生成的。
例外是:
System.ServiceModel.ProtocolException:远程服务器返回意外响应:(400)错误请求。-> System.Net.WebException:远程服务器返回错误:(400)错误请求。
我的客户端配置文件的system.serviceModel
部分是:
<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>
<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>
I‘’ve looked at a fairly large number of answers to this question with no success.
有人能帮我吗?
发布于 2009-04-24 06:00:16
尝试在服务器上也设置maxReceivedMessageSize,例如设置为4MB:
<binding name="MyService.MyServiceBinding" maxReceivedMessageSize="4194304">
默认值(我认为是65535)如此之低的主要原因是为了降低拒绝服务(DoS)攻击的风险。您需要将其设置为大于服务器端的最大请求大小和客户端的最大响应大小。如果您在内部网环境中,DoS攻击的风险可能很低,因此使用比您预期需要的值高得多的值可能是安全的。
顺便说一句,这里有几个用于解决连接到WCF服务问题的技巧:
如this MSDN article.中所述,
发布于 2010-11-12 19:58:28
我也遇到了这个问题,但是上面的方法对我都不起作用,因为我使用了一个自定义绑定(用于BinaryXML),经过很长时间的挖掘,我在这里找到了答案:Sending large XML from Silverlight to WCF
因为我使用的是绑定,所以必须在web.config中的customBinding元素下的httpTransport元素上设置maxReceivedMessageSize:
<httpsTransport maxReceivedMessageSize="4194304" />
发布于 2011-01-27 02:39:26
值得注意的是,使用.NET 4.0时的另一个注意事项是,如果在您的配置中找不到有效的端点,则将自动创建并使用默认端点。
默认端点将使用所有默认值,因此,如果您认为您有一个有效的服务配置,并且maxReceivedMessageSize等的值很大,但该配置存在错误,您仍然会得到400 Bad Request,因为将创建并使用一个默认端点。
这是静默完成的,因此很难被检测到。您将看到有关此效果的消息(例如'No Endpoint found for Service,creating Default Endpoint‘或类似),如果您在服务器上打开跟踪,但没有其他指示(据我所知)。
https://stackoverflow.com/questions/784606
复制相似问题