views:

88

answers:

1

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?

+3  A: 

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.

Jojo Sardez