How to upload a file to a WCF Service?

I've build a WCF Service to accept a file and write it to disk. The front-end consists of a page with SWFUpload which is handling the upload on the client side. Apparently, SWFUpload posts the data with a Content Type of: multipart/form-data.

I would think this ok but on the Service side I get an error. The error is "ProtocolException" expecting text/xml. I've tried different message encodings in the bindings but nothing seems to work.

How can I get this file uploaded using multipart/form-data?


@jdiaz,

@JasonS is right, to upload file you need to transfer it as a byte stream. You need to use WCF streaming. For example on how to upload file via WCF see an article from http://kjellsj.blogspot.com


What you want to use is probably MTOM, if you want it to be standard. Using this, you can have MIME multiparts messages.

You then have to read the file as a stream and stuff it into one of the parameters of the request.


It might be that your WCF service targets .NET Framework 3.5 and your IIS is running on .NET Framework 4.0. In this case (framework mismatch) you need to modify your service.

链接地址: http://www.djcxy.com/p/48624.html

上一篇: Python REST(Web服务)框架的建议?

下一篇: 如何将文件上传到WCF服务?