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

后端 未结 6 1954

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

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


        
6条回答
  •  生来不讨喜
    2020-12-08 17:17

    In the CTP there are factory methods that do the work of turning regular APM functions (Begin/End) into ones that are compatible with the new async keyword, for instance:

    Stream s = new FileStream("C:\test.txt", FileMode.CreateNew);
    byte []buffer = new byte[100];
    int numBytesRead = await Task.Factory.FromAsync(s.BeginRead, s.EndRead, buffer, 0, buffer.Length, null);
    

    So in your case you can do the equivalent and then you'd then call it like so:

    async proxy.DoSomethingTaskAsync()
    

    See this thread on the CTP discussion group for more info

提交回复
热议问题