How can I make my WCF Image Upload Service asynchronous instead of synchronous. My SaveImage
function is called directly from a asynchronous javascript call.
The Contract (IImageWCFService.cs):
[ServiceContract(Namespace = "MyServices.org")]
public interface IImageWCFService
{
[OperationContract(AsyncPattern = true)]
[WebInvoke(Method = "POST", ResponseFormat=WebMessageFormat.Json, UriTemplate="SaveImage")]
void SaveImage(Stream stream);
}
The Service (ImageWCFService.svc.cs) :
public void SaveImage(Stream stream)
{
// long running task up manipulating the image
// some lines of code contains image upload to Amazon S3 functions
}
I return void because this should be a one way call, the user don't need to get any result from the function or whether it was succeeded or not.
Right now when this WCF service run, it will consume the main thread. I want it to run asynchronously. I've read that the recommended way is to use:
[OperationContract(AsyncPattern = true)]
or Task-based asynchronous pattern for WCF.
I've read many articles but still am very confused how to implement it in my function. I need a code example that will show the implementation of my Image Upload function.
Note: A good source about the differences between various async implementations in this question - which says that the best way to implement it is using Task-based asynchronous pattern for WCF.
Again, the call is made from the JavaScript directly, but I have no problem create a webservice (asmx) one the save server that will call the WCF service on the server side if that's what it need, but again, I am confused about all this.
Thanks.