views:

6424

answers:

5

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?

A: 

I believe you are going to have to tranfer the file as a byte array to WCF. You will need to handle the post from SWFUpload and convert to a byte array before sending to your service.

JasonS
+2  A: 

@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

aku
+1  A: 

Maybe going through this article would help: http://kjellsj.blogspot.com/2007/02/wcf-streaming-upload-files-over-http.html

Vaibhav
+1  A: 

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.

Philippe
A: 

Thanks all for the suggestions. I have referred to kjellsj blog, have tried streaming and buffered, have set messageEncoding to Mtom and Text.

I still can't get past the "ProtocalException" error (The client and service bindings may be mismatched). It seems so trivial but the error persists.

I think the service drops the connection when it detects the protocol error

weird and frustrating.

jdiaz