Async CTP - How can I use async/await to call a wcf service?

后端 未结 6 1955

If I call a WCF service method I would do something like this:

proxy.DoSomethingAsync();
proxy.DoSomethingAsyncCompleted += OnDoSomethingAsyncCompleted;
         


        
6条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-08 17:01

    As mentioned by Matt, there is a TaskFactory.FromAsync method that allows you to create a Task from a Begin/End pair. You need to enable asynchronous endpoints when you add your WCF reference, and then you can wrap them up yourself using extension methods.

    As mentioned by Amadeo, there is a sample of this in the Async CTP, under the (C# WCF) Stock Quotes directory.

    Also in that directory, there is a TaskWsdlImportExtension project. Add a reference to that dll and modify your .config as such:

    
     
      
       
        
         
        
       
      
     
    
    

    Then you don't have to do your own wrapping at all; the TaskWsdlImportExtension will do it for you.

提交回复
热议问题