Skip to main content
Omnitracs Knowledge Base

Visual Studio 2010 Example

Install certificate

Surf to https://services.omnitracs.com/portalWeb/jsp/login.jsp  using IE. Click the "lock" (security report) next to the address bar, then click "view certificates". Click "install certificate" and follow the wizard.  

viewCerts.JPG

Create a project

Start Microsoft Visual Studio 2010 and generate a new WPF Application Project. For this example we will be creating a simple application that calls getCounts in Vehicle Management and displays the returned data. 

New Project.JPG

Adding or Updating the Service Reference

Right click the References folder in the Solution Explorer and select "Add Service Reference". Then add the address of the WSDL you wish to reference and click "Go". Change the Namespace, then click "Ok". 

For this example we will be using the following: 

WSDL: https://services.omnitracs.com/qtracsWebWS/services/QTWebSvcs/wsdl/QTWebSvcs.wsdl

Namespace: QTWebService

Add Ser Ref.JPG

You should now see the service reference in the Solution Explorer. 

ser ref in sol explore.JPG

Right click the service, then click "Update Service Reference" to update the service reference.

Invoking a Web Service Method

After adding a service reference, Visual Studio automatically creates classes containing the methods and data types defined in the WSDL. 

For this example we will invoke the getCounts method in Vehicle Management. 

The getCounts methods takes a coverage identifier (optional) as a parameter. getCount returns a Counts object that contains several totals that are important for vehicle management.

The follow code will invoke the getCounts method.

QTWebService.QTWebSvcsClient QTClient = new QTWebService.QTWebSvcsClient();

QTWebService.Counts ct = new QTWebService.Counts();

ct = QTClient.getCounts("");

Editing the app.config file 

Add the following custom headers element to each endpoint element. Note: You will need to change USER, COMPANY, and PASSWORD to the appropriate values.

<headers>

  <wsse:Security mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">

    <wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">

      <wsse:Username>USER@COMPANY</wsse:Username>

      <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">PASSWORD</wsse:Password>

    </wsse:UsernameToken>

  </wsse:Security>

</headers>

Add the following identity element to each endpoint element.

<identity>

  <certificateReference storeLocation="CurrentUser" x509FindType="FindBySubjectName"

                        findValue="services.omnitracs.com" isChainIncluded="false" />

</identity>

For this example the app.config file should look like this:

<?xml version="1.0" encoding="utf-8" ?>

<configuration>

    <system.serviceModel>

        <bindings>

            <basicHttpBinding>

                <binding name="QTWebSvcsSoapBinding" closeTimeout="00:01:00"

                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"

                    allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"

                    maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"

                    messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"

                    useDefaultWebProxy="true">

                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"

                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />

                    <security mode="Transport">

                        <transport clientCredentialType="None" proxyCredentialType="None"

                            realm="" />

                        <message clientCredentialType="UserName" algorithmSuite="Default" />

                    </security>

                </binding>

            </basicHttpBinding>

        </bindings>

        <client>

            <endpoint address="https://services.omnitracs.com:443/qtracsWebWS/services/QTWebSvcs"

                binding="basicHttpBinding" bindingConfiguration="QTWebSvcsSoapBinding"

                contract="QTWebService.QTWebSvcs" name="QTWebSvcs">

                <headers>

                    <wsse:Security mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">

                        <wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">

                            <wsse:Username>USER@COMPANY</wsse:Username>

                            <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">PASSWORD</wsse:Password>

                        </wsse:UsernameToken>

                    </wsse:Security>

                </headers>

                <identity>

                  <certificateReference storeLocation="CurrentUser" x509FindType="FindBySubjectName"

                      findValue="services.omnitracs.com" isChainIncluded="false" />

                </identity>

            </endpoint>

        </client>

    </system.serviceModel>

</configuration>

Download example 

  • Was this article helpful?