Last post Oct 16, 2012 11:57 PM by Steven Cheng - MSFT
Oct 15, 2012 02:43 PM|pdassnyc|LINK
I have a web application which is going to allow users to upload files, can someone provide me with a working example on how to do this with C#, I'm new to WCF so not too familiar with how to do this. I've been using BasicHTTPBinding for all my other work
so far, if that matters. I've seen that's it's possible with the application using Byte, but those examples do not sure WCF, we are being asked to force the application to upload via WCF, which is hosted on another machine. the file will then be stored
in the database, so it needs to be able to send and retrieve, if anyone knows of a tutorial/example I can study to learn how please let me know.
Oct 15, 2012 04:10 PM|N_EvilScott|LINK
Use the following link:
WCF uses streaming for uploading. You basically make handler calls sending 4096 bytes at a time until the file is completely sent.
Oct 16, 2012 11:57 PM|Steven Cheng - MSFT|LINK
As you mentioned that you need a WCF service which allow client to upload some file data (binary stream), correct?
If so, here are some possible options:
1) You can build a standard SOAP based WCF service (basicHttpBinding or other) and expose an operation which take a byte type parameter. then the client-side supply the file data(binary data) through this byte parameter. In such case, the SOAP formatter
will convert binary data(byte) into base64 format string which will cause large message size.
2) Another option is building a REST style WCF service (with webHttpBinding). WCF REST endpoint allows client to directly send arbitrary format data (text, binary or even hybrid such as multipart form). And your client can directly send the file content
via raw binary stream (bytes). Here are some reference about WCF REST programming:
#WCF Web HTTP Programming Model
#How to: Create a Service That Accepts Arbitrary Data using the WCF REST Programming Model
and some examples about uploading file through WCF REST service:
#Using WCF to stream data to a REST service.
#Uploading File to server from ASP.Net client using WCF REST Service
BTW, if WCF is not forced, it would be simpler to build an ASP.NET http handler or page for file uploading. that would be much more simple and straightforward:)