将数据放入 WCF RESTful 服务时出现 HTTP 400 错误请求 - 最大请求大小较低?
我有一个 WCF 方法,它接受任意二进制数据,该服务会将这些数据保存到文件系统上的文件中。这是 WCF 方法:
[OperationContract]
[WebInvoke( Method="PUT", UriTemplate="/products/{productId}/resources/{resourceName}")]
public void PutResource(String productId, String resourceName, Stream resource)
但是,每当我的客户端(WinForms HttpWebRequest 装置)尝试发出此请求时,系统(IIS 或 WCF 或链中的某些东西)都会以空正文(内容长度为无论如何都设置为零)。我在 WCF 方法上设置了一个断点,但该方法从未被调用,事实上,当我调用相同的 URI 并完全注释掉该方法时,我会得到相同的错误。
我在 IErrorHandler 类的 ProvideFault 方法中设置了另一个断点,但从未调用该断点,这表明在调用 WCF 之前出现了问题。
我刚刚再次尝试了该方法,但是使用较小的请求资源(文本流,3 字节长)并且实际上工作得很好,似乎每当我使用任何大于几千字节的内容时,它都会失败。
我想不出要改变什么才能让它发挥作用 - 有什么建议吗?
编辑:我正在使用 WCF REST Starter Kit 2,它在底层使用 CustomBinding,但似乎没有使用 MaxReceivedMessageSize 属性(默认值为 65536,但我的方法因请求超过几 KB 而失败)。
EDIT2:在重建我的项目并测试各种文件后,似乎限制实际上是 64KB。现在找出 64KB 限制是在哪里指定的......
I have a WCF method that accepts arbitrary binary data which the service will save to a file on the filesystem. Here is the WCF method:
[OperationContract]
[WebInvoke( Method="PUT", UriTemplate="/products/{productId}/resources/{resourceName}")]
public void PutResource(String productId, String resourceName, Stream resource)
However whenever my clients (a WinForms HttpWebRequest contraption) attempt to make this request the system (either IIS or WCF or something in the chain) responds with HTTP 400 Bad Request with an empty body (the content-length is set to zero anyway). I set a breakpoint on my WCF method and the method is never called, in fact I get the same error when I call the same URI with the method commented out entirely.
I set another breakpoint in my ProvideFault method in my IErrorHandler class, but that is never called, which suggests something is going wrong before WCF is invoked.
I just tried the method again, but with a smaller request resource (a text stream, 3 bytes long) and that actually worked fine, it seems whenever I use anything larger than a few kilobytes it fails.
I can't think of what to change to get this to work - any suggestions?
EDIT: I'm using the WCF REST Starter Kit 2, which uses CustomBinding under the hood which doesn't seem to use the MaxReceivedMessageSize property (and the default to that is 65536, but my method fails with requests over a few KB).
EDIT2: It seems after rebuilding my project and testing a variety of files, that the limit is actually 64KB. Now to find out where that 64KB limit is being specified...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我解决了。以下是我添加到 WebServiceHost2 子类中以解决该问题的代码:
I solved it. Here's the code I added to my WebServiceHost2 subclass to fix the problem: