wcfdebuggingwindows-servicesasynchronous-wcf-call

Async call for WCF service hosted in windows service


I have hosted a WCF service in windows service. I have console app for which I added a WCF service reference and generated Client for it.

I can make Sync call to the service,but Async call doesn't seem to work. If i attach server process it doesn't hit the service at all.

client= new ServiceClient();
client.DoSomething();//Works fine

client.DoSomethingAsync()//Doesnot work

Is this a known problem?


Solution

  • The asynccall will probably be started in a background workerthread. So what could be happening is that your async thread is dieing out because the foreground thread has finished it's processing.

    Unless you have some logic after you make this call to wait for the reponse, or continue with some other work on your main thread, the background thread may not have the time to get created before the application exits.

    This can be easily tested by adding Thread.Sleep after the async call.

    client.DoSomethingAsync();
    Thread.Sleep(1000);
    

    A symptom of this happening is that your service starts / stops unexpectedly and windows throws an error.