How to make a call to my WCF service asynchronous?

限于喜欢 提交于 2019-11-26 05:27:29

问题


I have a WCF service that I call from a windows service.

The WCF service runs a SSIS package, and that package can take a while to complete and I don\'t want my windows service to have to wait around for it to finish.

How can I make my WCF service call asynchronous? (or is it asynchronous by default?)


回答1:


All your needs will be satisfied in the following articles from MSDN:

Implementing an Async Service Operation

Calling WCF Service Async

Designing Service Contracts




回答2:


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.




回答3:


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);
}



回答4:


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.



来源:https://stackoverflow.com/questions/400798/how-to-make-a-call-to-my-wcf-service-asynchronous

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!