How to make a call to my WCF service asynchronous?
the WCF Proxy inside of your client (Windows Service?) needs to be specified at creation that you wish to have Asynchronous operations available.
You can modify an existing WCF Proxy by right clicking on it and choosing 'Configure Service Reference' From here you just need to check the tick box next to 'Generate asynchronous operations'
Ok so that is the WCF Proxy side of things taken care of. Now you need to use APM (Asynchronous Programming Model) with the Proxy inside of your client.
Service side:
[ServiceContract]
public interface IMyService
{
[OperationContract]
bool DoWork(int i);
}
Client side:
[ServiceContract(Name = nameof(IMyService))]
public interface IMyServiceClient : IMyService
{
[OperationContract]
Task<bool> DoWorkAsync(int i);
}
All your needs will be satisfied in the following articles from MSDN:
Implementing an Async Service Operation
Calling WCF Service Async
Designing Service Contracts
On Visual Studio 2010, on the Add Service Reference > click Advanced button > check the Generate Asynchronous Operations
checkbox.
After doing so, the Async operations will be added and be available for your use.