Skip to main content
Omnitracs Knowledge Base

.Net Client Authentication using WCF

.Net Client Authentication using WCF

Programmers using .Net 2.0 and Visual Studio 2005 were required to download and install "Web Services Enhancements (WSE) for Microsoft .NET" to be able to authenticate.

Since the release of .Net 3.0 and Visual Studio 2008 that is no longer required because the environment now supports Windows Communication Foundation (WCF).

Using WCF, once you add a Service Reference to your project, you can authenticate using code similar to that found below.

void CallOmnitracsDriver_VerifyAccess()  
  // Verify Access the most basic Omnitracs QHOS Web Service method.  
  // It's used to verify user credentials.  
  // Of your SOAP reqeust is formatted correctly, and you supplied valid credentails  
  // it will return true;  
  string endpointUri = @"";  
  var endpoint = new System.ServiceModel.EndpointAddress(endpointUri);  
  // Create binding using HTTPS  
  var securityElement = System.ServiceModel.Channels.SecurityBindingElement.CreateUserNameOverTransportBindingElement();  
  var encodingElement = new System.ServiceModel.Channels.TextMessageEncodingBindingElement(System.ServiceModel.Channels.MessageVersion.Soap12, System.Text.Encoding.UTF8);  
  var transportElement = new System.ServiceModel.Channels.HttpsTransportBindingElement();  
  var binding = new System.ServiceModel.Channels.CustomBinding(securityElement, encodingElement, transportElement);  
  // Create driver client (service reference must be added to create this.)  
  // OmniTracsQHOSDriverReference is the name of the Service Reference in this example  
  var driverClient = new OmniTracsQHOSDriverReference.DriverSoapClient(binding, endpoint);  
  // Your credentials will vary  
  string companyLoginId = "TestCompany";  
  string userName = "IntegrationUser";  
  string password = "Password";  
  // Omnitracs uses "@"for the separator.  
  // The username is first for Omnitracs.  
  driverClient.ClientCredentials.UserName.UserName = userName + "@" + companyLoginId;  
  driverClient.ClientCredentials.UserName.Password = password;  
       // Call the Verify Access method.  
       bool success = driverClient.VerifyAccess();  
       // Now display the results in a popup window  
       String displayString = "The Web Service returned: true";  
       MessageBox.Show(displayString, "Web Service Call Results");  
  catch (Exception e)  
       // Now display the results in a popup window  
       String displayString = "The Web Service returned: false";  
       MessageBox.Show(displayString, "Web Service Call Results");  
  • Was this article helpful?