How to Connect to CA Mobile Device Management (MDM) Web Services in C#

Document ID : KB000028789
Last Modified Date : 14/02/2018
Show Technical Document Details

Title: How to Connect to CA Mobile Device Management (MDM) Web Services in C#

 

Description:

The documentation found on http://wiki.ca.com for CA MDM describes the API Services.  This document describes and provides some sample code to connect using Visual Studio 2010 C# console application. This is provided as a sample only and is not supported.

 

Please reference the API Services documentation for CA MDM at http://wiki.ca.com/

This document provides two examples.

1- Connect to the "Server" service and pull back a list of MDM servers

2- Connect to the "Tenant" service and pull back a list of Tenants

This document does not provide all of the code to do something useful, but enough to get a programmer started.

 

Requirements:

  • CA MDM 14.3 or later release
  • C# or similar development language knowledge
  • Visual Studio 2010 or later release installed 

 

Enable API Services Logging:

Please see the Reference Guide for your release of CA MDM for the steps.

CA MDM 14.3:  https://wiki.ca.com/display/CMDM143/Enable+API+Services+Logging

 

Add MDM Service VS Project:

1. Start Visual Studio (VS) and create a working project in C#. For this H2G, we will be using the 

Windows Forms Application.

2. Create a New Windows Forms Application (File > New Project > Windows Forms Application)

Capture.JPG

3. In the 'Solution Explorer' panel, right click on ‚References? and select ‚Add Service Reference…?

Capture2.JPG

4. On the popup console input the services URLs that we will be using for this example.

Give the service a meaningful name so it is easy to understand.

Capture3.JPG

Click on ‚OK? once all the information has been input. The end result should be something 

like the screen shot below. This example will be using the Tenant and Server Services.

You may also choose to add Policy or other services if needed.  Please see the product documentation wiki.ca.com for the list of services available.

Below are the ones used in this example:

http://CAMDMSERVER:7980/AfariaService/Server?wsdl, 

http://CAMDMSERVER:7980/AfariaService/Tenant?wsdl).

 

In your Visual Studio "Solution Explorer", you should have a list of Services References similar to the following:

Capture4.JPG

 

 

Get Server and Farm ID Context:

1- The "Server ID" can be found manually in the DBMS by selecting the column from the A_SERVER table. 

For example:

Capture9.JPG

2- To look up the farm id manually, we can check the registry key:

HKLM\SOFTWARE\Afaria\Afaria\ApiService\Setup\Farm\FarmName

Capture6.JPG

 

3- For the API Process, we will be making calls to the CA MDM Api Service to retrieve this information.

First, we will need to establish a connection to the CA MDM environment to get the Server / Farm ID.

            Server.ServerServiceClient svc1 = new Server.ServerServiceClient("NetNamedPipeBinding_IServerService");

            svc1.ClientCredentials.Windows.ClientCredential.Domain = "myMDMServerHostname";

            svc1.ClientCredentials.Windows.ClientCredential.UserName = "myMDMuser";

            svc1.ClientCredentials.Windows.ClientCredential.Password = "myPassword";

 

On the initial connection, we have 3 possible endpoint connection types for each of the services that we are planning on using.  Please take note of the naming convention here used for the service. The Service Name is embedded into the name as shown below. Note: "Server" after the capital "I":

WSHttpBinding_IServerService

NetTcpBinding_IServerService

NetNamedPipeBinding_IServerService

The next 3 lines of code set the domain, user and password for the credentials.

After the connection to the service is made, we can start making request calls to obtain the data.

First, we will initialize the context.

Server.ContextInfo myCtx1 = svc1.InitContext(_guid);

Next, let's get the Server and Farm ID

Server.ServerDescription[] tmp = svc1.GetServerList();

Server.ServerDescription _serverDesc = tmp[2];

string _myServerIDContext = _serverDesc.ServerId;

string _myFarmIDContext = myCtx1.FarmId;

            Console.WriteLine("guid = " + _guid);

            Console.WriteLine("_myServerIDContext = " + _myServerIDContext);

 

            Console.WriteLine("_myFarmIDContext = " + _myFarmIDContext);

 

Get Tenant ID Context:

1- To look up the tenant ID manually, we can look at the database table: A_TENANT.

Capture5.JPG

 

2- For the API Service, we will be making a call to the API service to retrieve the information. Note the code is very similar to what we used against the Server Service above.

TenantServer.TenantServiceClient svc2 =

            new TenantServer.TenantServiceClient("NetNamedPipeBinding_ITenantService");

           

svc2.ClientCredentials.Windows.ClientCredential.Domain = "myMDMServer";

            svc2.ClientCredentials.Windows.ClientCredential.UserName = "myMDMUser";

            svc2.ClientCredentials.Windows.ClientCredential.Password = "myMDMPassword";

            TenantServer.ContextInfo myCtx2 = svc2.InitContext(_guid);

            TenantServer.TenantInfo[] _tenantList = svc2.GetTenantList();

            TenantServer.TenantInfo _tenant0 = _tenantList[0];

            Console.WriteLine("_tenant0 Name = " + _tenant0.Name);

            Console.WriteLine("_tenant0 Description = " + _tenant0.Description);

            TenantServer.TenantInfo _tenant1 = _tenantList[1];

            Console.WriteLine("_tenant1 Name = " + _tenant1.Name);

            Console.WriteLine("_tenant1 Description = " + _tenant1.Description);

            TenantServer.TenantInfo _tenant2 = _tenantList[2];

            Console.WriteLine("_tenant2 Name = " + _tenant2.Name);

            Console.WriteLine("_tenant2 Description = " + _tenant2.Description);

            TenantServer.TenantInfo _tenant3 = _tenantList[3];

            Console.WriteLine("_tenant3 Name = " + _tenant3.Name);

            Console.WriteLine("_tenant3 Description = " + _tenant3.Description);

            Console.ReadLine();

 

 

Handling Fault and Exceptions:

As with making any Web Services calls, it is best to handle the exceptions as something can go wrong by using "try-catch" blocks.

Capture8.JPG