Code – Sonus in C# – Part 02 of 05

In previous post Code – Sonus in C# – Part 01 of 05 we made a basis for using Sonus API in C#.

In this post we will extend our prototype with logon and logout, providing the basics for our first GET. In the staring sample we just want to retrieve the serial number of our Sonus session border controller.

The button Logon will attempt authentication via /rest/login, and needs in the POST the REST user and password information as defined in the Sonus session border controller. If successful the HTTP response HEADER will carry the session token in a cookie. REST clients need to lookup this cookie in the response header and cache it to use it for subsequent REST calls by setting the cookie back in the HTTP request header. We will use the variable restCookie to store this session token for subsequent REST functions on Sonus API.

It is recommended that an explicit POST is done on logout resource to cleanup session specific resources the Sonus SBC 1000/2000 node. This is implemented by the code below.

Off course prior to performing logout, we should perform our GET, POST, PUT and DELETE operations using the session token obtained during the login process. Here is off course where the actual power of the Sonus API is available at your disposal. In the sample below we perform a GET to the URL that is selected from the textBox_URL. For your convenience I populated a comboBox_Url with frequently used GET resources. In the code below we assume the textBox_URL.Text has value “system”.

In order to follow the XML response during prototyping, I also added in the user interface an XML browser display.