WCF将大图像上传为wsHttpBinding [英] WCF upload large images as wsHttpBinding
问题描述
我创建了WCF服务来上传图片.对于图像< 50KB左右,但我收到远程服务器返回错误:(400)错误的请求."具有较大的图像. 我一直在寻找年龄,并尝试了许多不同的方法,包括设置maxRequestLength和其他一些设置.
在客户端,web.config将其作为basicHttpBinding接收,而我则是wsHttpBinding(以获取最新功能集).如果我将绑定类型手动更改为wsHttpBinding并更改了相应的选项,则会收到不支持的媒体类型"错误. 在WCF测试客户端中,它也将该服务显示为basicHttpBinding.
所以我的问题确实是双重的.
- 我该怎么做才能使我的服务处理大于50KB的文件?
- 要使服务被识别为wsHttp而不是basicHttp,我需要更改什么?
很抱歉,如果有人回答这些问题,我已经搜寻了stackoverflow并尝试了一些建议,但很可能我错过了!
像往常一样,我现在通过解决服务web.config并将端点手动更改为wsHttpBinding来解决了wsHttpBinding问题.不过,仍然会出现较大的上传文件大小问题.
您将需要在web.config中更新绑定
例如这就是我在wcf宁静服务中所做的事情.我相信您的情况也会很相似
<bindings>
<webHttpBinding>
<!-- buffer: 64KB; max size: 64MB -->
<binding name="StreamedBinding" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00" transferMode="Streamed"
maxBufferPoolSize="67108864" maxBufferSize="65536" maxReceivedMessageSize="67108864">
</binding>
</webHttpBinding>
</bindings>
<service name="WCFRestFul.ApiRestful">
<endpoint address="" binding="webHttpBinding"
bindingConfiguration="StreamedBinding" bindingName="StreamedBinding"
contract="WCFRestFul.IApiRestful" behaviorConfiguration="web" />
</service>
I've created a WCF Service to upload images. It works fine with images < 50KB or so but I get "The remote server returned an error: (400) Bad Request." with larger images. I've been looking for ages and tried lots of different things, including setting the maxRequestLength and several other settings.
On the client-side of things the web.config is picking it up as a basicHttpBinding and I'm after a wsHttpBinding (for the more up-to-date feature-set). If I manually change the the binding type to wsHttpBinding and change the corresponding options, I get a Unsupported Media Type error. Lookingin the WCF Test Client it shows the service as a basicHttpBinding too.
So my question is two-fold really.
- What do I need to do to allow my service to handle files > 50KB?
- What do I need to change for my service to be recognised as wsHttp instead of basicHttp?
Apologies if there is a question answering these - I have scoured stackoverflow and tried a few suggestions but it is possible I've missed it!
EDIT: As is always the way, I've managed to solve the wsHttpBinding issue now by fiddling around with the service web.config and manually changing the endpoint to wsHttpBinding. Still getting the large upload filesize issue though.
you will need to update your bindings in you web.config
e.g. this is how i did in my wcf restful service. i believe it will be very similar in your case as well
<bindings>
<webHttpBinding>
<!-- buffer: 64KB; max size: 64MB -->
<binding name="StreamedBinding" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00" transferMode="Streamed"
maxBufferPoolSize="67108864" maxBufferSize="65536" maxReceivedMessageSize="67108864">
</binding>
</webHttpBinding>
</bindings>
<service name="WCFRestFul.ApiRestful">
<endpoint address="" binding="webHttpBinding"
bindingConfiguration="StreamedBinding" bindingName="StreamedBinding"
contract="WCFRestFul.IApiRestful" behaviorConfiguration="web" />
</service>
这篇关于WCF将大图像上传为wsHttpBinding的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!