需要示例触发并忘记对 WCF 服务的异步调用 [英] Need sample fire and forget async call to WCF service

查看:39
本文介绍了需要示例触发并忘记对 WCF 服务的异步调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在预定的时间间隔内,我需要调用一个 WCF 服务异步调用另一个 WCF 服务.安排对我制定的 WCF 服务的调用.

On a scheduled interval I need to call a WCF service call another WCF Service asyncronously. Scheduling a call to a WCF service I have worked out.

我认为我需要什么,并且我已经在 stackoverflow 上读到过,有必要……(本质上)准备或更改 WCF 服务的代码,以便能够处理对它们的异步调用.如果是这样,那么一个简单的例子会是什么样的?(也许是一个之前和之后的例子)在 .Net 3.5 中还有必要吗?

What I think I need and I have read about here on stackoverflow that it is necessary to.., (in essence) prepare or change the code of your WCF services as to be able to handle an async call to them. If so what would a simple example of that look like?(Maybe a before and after example) Also is it still necessary in .Net 3.5?

其次,我使用来自 WCF 服务的代理来调用下一个 WCF 服务,如果它看起来与典型的 BeginEnvoke 和 EndEnvoke 的典型异步示例有任何不同,则需要一个对 WCF 服务的异步调用示例.

Second I am using a proxy from the WCF Service doing the call to the next WCF Service and need a sample of an async call to a WCF service if it looks any different than what is typical with BeginEnvoke and EndEnvoke with typical async examples.

如果我完全偏离我的问题,我会相信它,并且希望得到任何更正以建立更好的问题.

I would believe it if I am completely off on my question and would appreciate any correction to establish a better question as well.

推荐答案

设置 IsOneWay 属性的 OperationContract 属性为 true 在您调用的 WCF 方法上.这告诉 WCF 调用只对一个方向有影响,客户端不会等待方法完成执行.

Set the IsOneWay property of the OperationContract attribute to true on the WCF method that you are calling to. This tells WCF that the call only matters for one direction and the client won't hang around for the method to finish executing.

即使在调用 BeginInvoke 时,您的客户端代码仍将挂起等待服务器方法完成执行,但它将在线程池线程上执行.

Even when calling BeginInvoke your client code will still hang-out waiting for the server method to finish executing but it will do it on a threadpool thread.

[ServiceContract]
interface IWCFContract
{
   [OperationContract(IsOneWay = true)]
   void CallMe()
}

另一种方法是让 WCF 服务将其工作转移到后台线程上并立即返回.

The other way to do what you want is to have the WCF service spin its work off onto a background thread and return immediately.

这篇关于需要示例触发并忘记对 WCF 服务的异步调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆