Additional Blogs by SAP
Showing results for 
Search instead for 
Did you mean: 
Former Member


In the below given example I am going to explain how to use Afaria API service using NET Pipe. Below are the components used to expose Device Related information

Afaria API Service


Afaria API services help third-party developers to develop solutions for their enterprises. Afaria API services are implemented using Windows Communication Foundation (WCF) for .NET Framework 4.0. The services are installed on the Afaria Administrator services and are available as "Afaria API Service" in the Add/Remove program list, and as "Afaria API" in the Service management console.

Connection Methods

Clients connect to Afaria API services using bindings.Abinding defines the transport, such as HTTP or TCP, and the encoding used.

Afaria API services support these bindings:

•Net named pipes (fastest) – provides transport-level security for .NET systems.
This is
valid only for on-server communication.

•Net TCP – provides message-level security for .NET systems. The default port is 7982.

•HTTP (slowest) – provides message-level security for .NET systems. The default port is 7980.

API Service Authorization

Access to Afaria API services is granted only to users who have the same login credentials as specified
during Afaria API service installation. The system denies access to API services if
credentials do not match.

API Service References

Afaria API provides application access to various services and their respective methods. The metadata (for example, XSD, WSDL) for each service is available online.

to use a specific service in your application, add the service reference to your development environment. You can retrieve the metadata for a service by specifying the WSDL URL.


For example:

• URL to retrieve "Devices" service metadata:


In the below given example we will create console Application by adding service reference for device

Firstly we will create new c# console solution, then we add service reference for device

http://<Your Afaria Server IP>:7980/AfariaService/Devices

1) AfariaApiService.cs : In this class,I use connectToDevice static method which will  manage device related information.

public static AfariaDevicesService.DevicesServiceClient connectToDevice()


     AfariaDevicesService.DevicesServiceClient svc = null;


           svc = new AfariaDevicesService.DevicesServiceClient ("NetTcpBinding_IDevicesService");

           svc.ClientCredentials.Windows.ClientCredential.UserName = <Your User Name>;

           svc.ClientCredentials.Windows.ClientCredential.Password = <Your Password>;


           String guid = Guid.NewGuid().ToString();

           AfariaDevicesService.ContextInfo ci1 = svc.InitContext(guid);

           AfariaDevicesService.ContextInfo ci2 = svc.GetContextInfo();


           catch (Exception ex)




return svc;


  1. Program.cs : This class will contain Main Method and displayOnConsole(AfariaDevicesService.ContextInfo ctxInfo)

        static void Main(string[] args)


            string pwd = <Password>;

            string uName = <UserName>;

            AfariaDevicesService.DevicesServiceClient svc = AfariaApiService.connectDevice();

          if (svc == null)


              Console.WriteLine("Failed to Connect to Afaria Server...");





             AfariaDevicesService.ContextInfo ctxInfo = svc.GetContextInfo();





          //Wait for user to read the Console message



//This Method display results on console.

     private static void displayOnConsole(AfariaDevicesService.ContextInfo ctxInfo)


       Console.WriteLine("Start Displaying information from Afaria Service");


       Console.WriteLine("ContextInfo:ContextID \t" + ctxInfo.ContextId);

       Console.WriteLine("ContextInfo:Authorized \t" + ctxInfo.Authorized);

       Console.WriteLine("ContextInfo:UserIdentity \t" + ctxInfo.UserIdentity);

       Console.WriteLine("ContextInfo:Afaria Service Version \t" + ctxInfo.Version);


       Console.WriteLine("Done Displaying information from Afaria Service");


       Console.WriteLine("Hit Enter to continue....");