To upload a photo, you can use the Webinvoke annotation, which allows you to create WCF endpoints in REST format. Follow the code passage to the explanatory:
[WebInvoke(UriTemplate = "UploadPhoto/{fileName}/{description}", Method = "POST")]
public void UploadPhoto(string fileName, string description, Stream fileContents)
{
byte[] buffer = new byte[32768];
MemoryStream ms = new MemoryStream();
int bytesRead, totalBytesRead = 0;
do
{
bytesRead = fileContents.Read(buffer, 0, buffer.Length);
totalBytesRead += bytesRead;
ms.Write(buffer, 0, bytesRead);
} while (bytesRead > 0);
// Save the photo on database.
using (DataAcess data = new DataAcess())
{
var photo = new Photo() { Name = fileName, Description = description, Data = ms.ToArray(), DateTime = DateTime.UtcNow };
data.InsertPhoto(photo);
}
ms.Close();
Console.WriteLine("Uploaded file {0} with {1} bytes", fileName, totalBytesRead);
}
This excerpt comes from a complete example with Client and Server for image upload MSDN.
Perhaps a similar implementation with WEB API is more comfortable. See more details on WEB API on the Asp.net website.
If you implement the webservice (WCF or WEB API) using REST, it will be easier to send data regardless of the source language
Hello @Whallas and welcome to [pt.so]. I recommend a visit to [help] and a reading on [Ask]. Reinforce your question with an example of code you’ve done, or something for other Ops to help you with what you’ve already done.
– Caputo