Code – Sonus in C# – Part 01 of 05

This post is part 1 of a series of 5 on writing C# applications using Sonus API.

I used Microsoft Visual Studio Community 2015 running Windows 10 and targeted Windows Desktop Application to .NET Framework 4.6.1.

The REST APIs are provided for developers who want to programmatically integrate the Sonus SBC 1000/2000 into their application, and for administrators who want to script interactions with the Sonus SBC 1000/2000 gateway.

Sonus SBC 1000/2000’s REST APIs provide access to resources via URI paths. To use a REST API, your application makes HTTPs requests and parses the responses. Currently, the only supported response format is XML. Methods used by developers are standard HTTP methods such as GET, PUT, POST, and DELETE to communication resources.

In the App.config nothing special, just reference to .NET Framework 4.6.1.


Also in Program.cs nothing special, just launching the Form1. The code is intended for illustrating the Sonus API concepts, therefor quite old-style monolithic.


Applications based upon Sonus API need authentication information based upon user and password. The user used for the REST sessions must be in Sonus defined for the REST access level. This user must be created from the WebUI prior to using the REST API. The REST client must remember cookies that are returned from the Sonus SBC System and supply those same cookies back to the REST gateway with Cookie: headers on subsequent requests. All requests will be authenticated against that session cookie. If a valid session cookie is not found, the REST client will receive an HTTP 401 status code in the response.

We need to provide for every session border controller the parameters for REST user and password, the user interface therefor provides text boxes to enter these and as well as a ‘Safe profile’ button to save them for later retrieval. The profiles are stored in XML files located in the same directory as the executable, below a sample altered with dummy data.


Below a screenshot of the user interface of the main screen. The top section is for entering authentication and define logging level. The middle section allows to logon and view the session identifier and sample configuration data retrieved such as serial number. The lower section will be used later for performing other REST functions and logout.

Finally the code of the Form where everything happens. The code is quite self explaining, I am use httpClient with async and await to have a responsive application supporting the GET, POST, PUT and DELETE requests. Sonus currently supports only XML hence the reference using System.Xml. I also initialise the combo boxes with frequently used URI supported by the Sonus API.


There is also some code providing logging to ListBox and Disk, and functionality to save the configuration information such as FQDN of the session border controller and REST user and REST password for later retrieval.


In the next blog article we will handle the Logon and Logout and start implementing the the REST capabilities with GET, POST, PUT and DELETE using Sonus API.