轮询设备的 WCF 异步回调设置

发布于 2024-08-24 11:57:39 字数 790 浏览 1 评论 0原文

我有一个 WCF 服务设置来从我们的 .Net 应用程序控制 USB 指纹读取器。这工作正常,我可以要求它注册用户等等。

阅读器允许识别(它告诉您特定用户已经出示了他们的手指,而不是要求它验证特定用户的手指是否存在),但在识别模式下必须不断轮询设备以了解其状态 - 当用户检测到状态变化。

我想要的是感兴趣的应用程序通知服务它想知道何时识别用户,并提供在发生这种情况时触发的回调。 WCF 服务将立即返回并在后台生成一个线程来持续轮询设备。如果没有人尝试登录,这种轮询可能会持续几个小时。

实现这一目标的最佳方法是什么?我的服务协定当前定义如下:

[ServiceContract (CallbackContract=typeof(IBiometricCallback))]
public interface IBiometricWcfService
{
    ...
    [OperationContract (IsOneWay = true)]
    void BeginIdentification();
    ...
}

public interface IBiometricCallback
{
    ...
    [OperationContract(IsOneWay = true)]
    void IdentificationFinished(int aUserId, string aMessage, bool aSuccess);
    ...
}

在我的 BeginIdentification() 方法中,我可以轻松地生成一个工作线程来轮询设备,还是更容易使 WCF 服务异步?

I have a WCF service setup to control a USB fingerprint reader from our .Net applications. This works fine and I can ask it to enroll users and so on.

The reader allows identification (it tells you that a particular user has presented their finger, as opposed to asking it to verify that a particular user's finger is present), but the device must be constantly polled while in identification mode for its status - when a user is detected the status changes.

What I want is for an interested application to notify the service that it wants to know when a user is identified, and provide a callback that gets triggered when this happens. The WCF service will return immediately and spawn a thread in the background to continuously poll the device. This polling could go on for hours at a time if no one tries to log in.

What's the best way to acheive this? My service contract is currently defined as follows:

[ServiceContract (CallbackContract=typeof(IBiometricCallback))]
public interface IBiometricWcfService
{
    ...
    [OperationContract (IsOneWay = true)]
    void BeginIdentification();
    ...
}

public interface IBiometricCallback
{
    ...
    [OperationContract(IsOneWay = true)]
    void IdentificationFinished(int aUserId, string aMessage, bool aSuccess);
    ...
}

In my BeginIdentification() method can I easily spawn a worker thread to poll the device, or is it easier to make the WCF service asynchronous?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一场春暖 2024-08-31 11:57:39

我认为将WCF服务操作异步化要好得多。此 MSDN 文章介绍了如何执行此操作:http://msdn.microsoft.com /en-us/library/ms730059.aspx

I think it is much better to make the WCF service operation asynchronously. This MSDN article shows how to do it:http://msdn.microsoft.com/en-us/library/ms730059.aspx.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文