BWS with VisualStudio and C#

event_note November 20, 2012

Here comes a sample of how you can access the BioID Web Service (BWS) from a VisualStudio project in C#.

Add a Service Reference (NOT a Web Reference) to the project from which you want to access the BWS

  • Enter the address and click Go
  • Select the IBioIDWebService service contract
  • Use a namespace like BWSor whatever you prefer
  • Click OK to create the required files (Service References/BWS/Reference.csandapp.config/web.config)

You should now open your app.config or web.config (depends on the type of project you are currently working on) and review the generated settings. Especially ensure that the address of the endpoint is set to the BWS Server Host you want to talk to, e.g. (You can also apply other settings according to the sample configuration file ).

That's it. Here is some sample code showing how to use the BWS:

using BWS; // in case you used the namespace BWS
    // create the BWS client
    BioIDWebServiceClient bws = new BioIDWebServiceClient();
    // set your client certificate to be used for client authentication: 
    // ("D5E1EF3C0B7A196AE5506F57CE32801A78EA5BA3" must be replaced with your thumbprint)
        StoreLocation.CurrentUser, StoreName.My,
        X509FindType.FindByThumbprint, "D5E1EF3C0B7A196AE5506F57CE32801A78EA5BA3");
    // test the BWS by fetching the status:
    string message;
    bool success = bws.Status(out message);
    Console.WriteLine("The service is up and running: {0}", success);
    // do some enrollment for the face trait with 3 samples 
    // (you could simultaneously also enroll voice samples if required)
    // the Biometric Class ID is made up of your Storage (bws), your Partition (789)
    // and a ClassID managed by you (Note: this is a unique ID and all the data associated
    // with your Storage/Partition can only be accessed with your certificate)
    BiometricClassID bcid =
        new BiometricClassID { Storage = "bws", Partition = 789, ClassID = 12345 };
    // for demonstration we simply load the three face samples from disk
    // (real applications would us a grabber to capture live images)
    Sample[] enrollsamples = new Sample[3];
    enrollsamples[0] = new Sample { Trait = Trait.Face, Data = System.IO.File.ReadAllBytes(@"\user01.png") };
    enrollsamples[1] = new Sample { Trait = Trait.Face, Data = System.IO.File.ReadAllBytes(@"\user02.png") };
    enrollsamples[2] = new Sample { Trait = Trait.Face, Data = System.IO.File.ReadAllBytes(@"\user03.png") };
    // now go for enrollment (with livedetection enabled)
    success = bws.Enroll(out message, bcid, enrollsamples, EnrollmentFlags.LiveFaceDetection);
    Console.WriteLine("Enrollment succeeded: {0}", success);
    // let's do a verification of the user we currently trained
    Sample[] verifysamples = new Sample[1];
    verifysamples[0] = new Sample { Trait = Trait.Face, Data = System.IO.File.ReadAllBytes(@"\user04.png") };
    success = bws.Verify(out message, bcid, verifysamples, ClassificationFlags.None);
    Console.WriteLine("Verification succeeded: {0}", success);
    // as this was just a test we immediately remove the currently enrolled user
// don't forget to do some error handling
catch (System.ServiceModel.FaultException<BioIDWebServiceFault> bioidFault)
    // errors that are generated by the BWS, following the BWS fault contract
    Console.WriteLine("BioIDWebServiceFault {0}:", bioidFault.Detail.Code);
catch (Exception e)
    // any other errors
    Console.WriteLine("Exception caught:");

Please also refer to the description of the BWS Web API.