简体   繁体   English

单向操作与异步调用

[英]One-Way operations vs Asynchronous calls

As stated in the first section of this article (.chm file - see note below) 本文第一部分所述 (.chm文件 - 请参阅下面的注释)

One-way calls do not equate to asynchronous calls. 单向调用不等同于异步调用。 When one-way calls reach the service, they may not be dispatched all at once and may be queued up on the service side to be dispatched one at a time... If the number of queued messages has exceeded the queue's capacity, then the client will block, even when issuing a one-way call. 当单向呼叫到达服务时,它们可能不会立即全部调度,并且可能在服务端排队等待一次调度一次......如果排队消息的数量超过了队列的容量,那么即使发出单向呼叫,客户端也会阻止。

If a one-way call is invoked, when does it return control to the caller? 如果调用单向调用,它何时将控制权返回给调用者? The introduction of the same article states that one-way calls are used for fire-and-forget operations , thereby simulating a kind of asynchronous call. 同一篇文章的介绍表明, 单向调用用于“即发即弃”操作 ,从而模拟一种异步调用。 If a sessionful WCF service has a Login() one-way method which starts the session, when does this method return control to the caller? 如果会话WCF服务具有启动会话的Login()单向方法,此方法何时将控制权返回给调用者? Does it return before the method is actually executed on the service? 在方法实际执行服务之前它是否返回? If so, how can I be sure that the method was performed on service? 如果是这样,我怎么能确定该方法是在服务上执行的?

If I wanted the service to return to the client the possible errors that occur during the login procedure, would be an asynchronous call the only way to achieve a fire-and-forget behaviour? 如果我希望服务返回到客户端登录过程中可能发生的错误,那么异步调用是实现“即发即弃”行为的唯一方法吗?


Note: The quote above is taken from an article called WCF Essentials - What You Need To Know About One-Way Calls, Callbacks, And Events by Juval Lowy, and can be found in the October 2006 issue of MSDN magazine. 注意:上面的引用来自一篇名为WCF Essentials的文章- 你需要了解的关于单向调用,回调和事件的内容,由Juval Lowy提供,可以在2006年10月的MSDN杂志中找到。 The link above is to a help file (.chm) format on MSDN. 上面的链接是MSDN上的帮助文件(.chm)格式。 If you can't get the linked CHM file to work (I couldn't) you can open it with 7zip. 如果您无法使链接的CHM文件起作用(我不能),您可以使用7zip打开它。

If a sessionful WCF service has a Login one-way method which starts the session, when does this method return control to the caller? 如果会话WCF服务具有启动会话的Login单向方法,此方法何时将控制权返回给调用者?

For OneWay calls: The caller will continue to execute as soon as the service call is dispatched or queued. 对于OneWay呼叫:一旦调度或排队服务呼叫,呼叫者将继续执行。 Basically as soon as the service successfully receives the call. 基本上,只要服务成功接收到呼叫。

how can I be sure that the method was performed on service? 我怎么能确定该方法是在服务上执行的?

If the client does not get an exception, the service call was (or will be) performed. 如果客户端没有获得异常,则执行(或将要)服务调用。 When the service call actual runs or whether it succeeded or threw an exception is unknown to the client. 当服务调用实际运行或者是否成功或抛出异常时,客户端都不知道。

If I wanted the service to return to the client the possible errors that occur during the login procedure, would be an asynchronous call the only way to achieve a fire-and-forget behaviour? 如果我希望服务返回到客户端登录过程中可能发生的错误,那么异步调用是实现“即发即弃”行为的唯一方法吗?

This does not make sense. 这根本不符合逻辑。 Fire-and-forget by definition means forget the result. 根据定义,“一劳永逸”意味着忘记结果。 It does not return any values or errors to the client. 没有任何价值或错误返回给客户端。 However an asynchronous call is not fire-and-forget and would return errors. 但是,异步调用不会发送,并且会返回错误。

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

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