Download wcf file

I will create WCF to upload a file, such as images or PDF files, to the server. How to create a service that can handle this function? I tried to work on this, but in most articles I was asked to use Stream as a service parameter. But I want to use byte [] (array) for the contents of the file. because this service not only accesses the .nte framework, but also uses other technologies like php, java, objective-c, etc.

does anyone help?

+7
source share
3 answers

Streaming seems to be your only option. See [MSDN Example]

See this question: How to upload a file to the WCF service?

You may check this article: http://blogs.msdn.com/b/carlosfigueira/archive/2008/04/17/wcf-raw-programming-model-receiving-arbitrary-data.aspx

It talks about setting up a WCF service to receive arbitrary data, and you can receive POST from any client (php, java, etc.)

+5
source

Create a WCF service method that takes byte[] as a parameter:

 [OperationContract] public void ReceiveByteArray(byte[] byteArray) { ... } 
+4
source

Create a WCF service method that accepts a file stream.

1) using the file upload control you can perform the task 2) create a Temp folder on the client site.

here is the code ...

string fileextension = null, FileName = null;

  try { if (FileUpload1.HasFile) { ITransferFile clientUpload = new TransferFileClient(); RemoteFileInfo uploadRequestInfo = new RemoteFileInfo(); fileextension = Path.GetExtension(FileUpload1.PostedFile.FileName); FileUpload1.PostedFile.SaveAs(Server.MapPath(Path.Combine("~/TempFolder/", FileName + fileextension))); System.IO.FileInfo fileInfo = new System.IO.FileInfo(Server.MapPath("~/TempFolder/") + FileName + fileextension); using (System.IO.FileStream stream = new System.IO.FileStream(fileInfo.FullName, System.IO.FileMode.Open, System.IO.FileAccess.Read)) { uploadRequestInfo.FileName = FileUpload1.PostedFile.FileName; uploadRequestInfo.Length = fileInfo.Length; uploadRequestInfo.FileByteStream = stream; clientUpload.UploadFile(uploadRequestInfo); } } } catch (Exception ex) { System.Web.HttpContext.Current.Response.Write("Error : " + ex.Message); } finally { if (File.Exists(Server.MapPath("~/TempFolder/") + FileName + fileextension)) { File.Delete(Server.MapPath("~/TempFolder/") + FileName + fileextension); } } 
0
source

All Articles