You can define asynchronous behavior for your service class by passing the following values along with the ServiceBehavior attribute:
InstanceContextMode = InstanceContextMode.Single ,ConcurrencyMode = ConcurrencyMode.Multiple .
The resulting code may look like this:
[ServiceContract] [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Multiple)] public class MyService { [WebInvoke(UriTemplate = "*", Method = "*")] public Message HandleRequest() { var webContext = WebOperationContext.Current; var webClient = new WebClient(); return webContext.CreateStreamResponse(webClient.OpenRead("http://site.com"), "text/html"); } }
source share