且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

大型 WCF Web 服务请求因 (400) HTTP 错误请求而失败

更新时间:2021-06-26 22:18:31

也尝试在服务器上设置 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:

在客户端使用诸如 Fiddler 之类的 HTTP 调试工具来检查 HTTP交通.

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