我有我用来调用异步方法,像这样一个WCF客户端代理:如何关闭客户端代理与异步调用WCF
var prox = new DoSomethingServiceClient("BasicHttpBinding_IDoSomethingService");
prox.DoSomethingCompleted += new EventHandler<AsyncCompletedEventArgs>(svcref_DoSomethingCompleted);
prox.DoSomethingAsync(0, Guid.NewGuid());
我什么时候关闭/中止代理?
我在svcref_DoSomethingCompleted
的第一行使用sender对象吗?
我在MS文档中看到他们在主线程中关闭代理,而不是在回调中。这是不错的做法吗?看来我错了:
http://msdn.microsoft.com/en-us/library/ms730059(v=vs.110).aspx
我也发现了这一点,使用基于任务的异步这表明你关闭代理在委托的回调,这是我最好样的期待:
http://fun-with-blackhawk.blogspot.com/2010/03/wcf-exception-handling-in-asynchronous.html
我猜的样本工程,因为有一个堵'到Console.ReadLine()''之前客户端.Close()'。如果它不在那里,它可能会在通话完成之前关闭客户端。 –