简体   繁体   English

使用C#异步调用WCF?

[英]Async call to WCF with C#?

In C#, how do I make an async call to a WCF Web Service? 在C#中,如何对WCF Web服务进行异步调用? I have a Service Reference set up to generate async. 我有一个服务参考设置来生成异步。 I also modified my calls to use { WebServiceObject.Begin* () } but there are two parameters at the end, 'AsyncCallback' and 'object asyncState'. 我还修改了我使用{WebServiceObject.Begin *()}的调用,但最后有两个参数,'AsyncCallback'和'object asyncState'。 What are these and how do I use them? 这些是什么以及如何使用它们?

Thanks, 谢谢,

你可能还想看看没有痛苦的Async

See MSDN here; 在这里查看MSDN; http://msdn.microsoft.com/en-us/library/system.asynccallback.aspx http://msdn.microsoft.com/en-us/library/system.asynccallback.aspx

here; 这里; http://msdn.microsoft.com/en-us/library/ms228969.aspx http://msdn.microsoft.com/en-us/library/ms228969.aspx

here; 这里; http://msdn.microsoft.com/en-us/library/ms228975.aspx http://msdn.microsoft.com/en-us/library/ms228975.aspx

and here; 和这里; http://msdn.microsoft.com/en-us/library/86wf6409.aspx http://msdn.microsoft.com/en-us/library/86wf6409.aspx

Basicly in Begin* you set an callback, that callback is called when the operation has completed. 基本上在Begin *中设置回调,操作完成后调用回调。 There you call End* to retrieve the appropriate data. 在那里你调用End *来检索适当的数据。

Callback is called when operation is completed, so you can call End* and grab return value or exception if any. 操作完成后调用回调,因此您可以调用End *并获取返回值或异常(如果有)。 asyncState is just a value for matching in callback if you use same callback method in several places. 如果在多个地方使用相同的回调方法,asyncState只是回调中匹配的值。 Here is a description of Async design pattern - http://msdn.microsoft.com/en-us/library/aa719595(VS.71).aspx 以下是异步设计模式的说明 - http://msdn.microsoft.com/en-us/library/aa719595(VS.71).aspx

If you are creating GUI application, consider using another version - *Async method which is generated for each operation as well. 如果要创建GUI应用程序,请考虑使用另一个版本 - * Async方法,该方法也是为每个操作生成的。 It provides thread synchronization. 它提供线程同步。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM