Excerpt |
---|
SystemAPI .NET Tool is a program written in C# allowing developers to manage VoipNow accounts and view information about calls. Download. |
Table of Contents | ||
---|---|---|
|
...
How To Install It
System Requirements
...
STEP 1: Please download the example archive and extract the files to a location of your choice.files from our GitHub repository:
Code Block |
---|
git clone https://github.com/4psa/systemapi-example-net.git |
STEP 2: Start Visual Studio 2010 and create a new Visual C# Console Application project.
...
You can find the schemas in your VoipNow installation server at this location:
Code Block |
---|
/usr/local/voipnow/admin/htdocs/soap2/schema/latest/3.0.x |
STEP 4: Right-click on the voipnowservice.wsdl
file and then pick WSCF.blue → blue → Generate Web Service Code, using the following option:
...
Tip |
---|
You can now use the recently created classes to write applications that interact with your VoipNow SystemAPI. |
How To Use It
The The SystemAPI .NET Tool contains tests that simulates the following operations:
- add a Service Provider Account,
- add an Organization Account,
- add a User Account,
- add an Extension Account,
- get the Call Costs for a User Account.
...
Before running the tests you have to specify the the oauth token of of the account you want to use. In order to achieve this you will update the the accessToken variable of the Main method from the Program class (Program.cs
file) with a valid oauth token.
Code Block | ||||
---|---|---|---|---|
| ||||
class Program { static void Main(string[] args) { // Change this with the oauth token of the account you want to use. string accessToken = "CHANGEME"; // Tests Tests.AddRelatedAccounts(accessToken); // Other tests... } } |
The The outh token token is used later when a a userCredentials
object object is created before calling any method of the VoipNow SystemAPI Client-side Proxy.
Code Block | ||||
---|---|---|---|---|
| ||||
//... userCredentials credentials = new userCredentials() { accessToken = accessToken }; //... ServiceProviderClient serviceProviderClient = new ServiceProviderClient("ServiceProviderPort"); //... serviceProviderClient.AddServiceProvider(credentials, request, out response); |
Note |
---|
All the test use the the 4PSA demo demo server located at at https://voipnow3demo.4psa.com/:. |
Examples
Add Related Accounts
...
In order to run the above test, the the oauth token must be provided. The The test can be found in the file: <PATH_TO_SYSTEMAPI_TOOL>\Operations\Tests.cs
.
...
The below code snippet shows how to add a Service Provider Account. The test can be found inside the file file <PATH_TO_SYSTEMAPI_TOOL>\Operations\Tests.cs
.
...
In order to run this test, the the oauth token must be provided.
The next code snippet shows how the Client-side Proxy is used in order to call a VoipNow SystemAPI operation for adding a Service Provider Account.
...
The below code snippet shows how to add an an Organization Account. The The test can be found inside the file file <PATH_TO_SYSTEMAPI_TOOL>\Operations\Tests.cs.
...
In order to run this test, the the oauth token must must be provided (i.e. accessToken parameter). Also, you must change the value of the serviceProviderId
variable from "CHANGEME" to a valid Service Provider Account Id.
The next code snippet shows how the Client-side Proxy is used in order to call a VoipNow SystemAPI operation for adding an Organization Account Organization Account.
Code Block | ||||
---|---|---|---|---|
| ||||
public static string AddOrganizationAccount(string accessToken, string parentServiceProviderID) { if (string.IsNullOrEmpty(parentServiceProviderID)) { Console.WriteLine("The parentServiceProviderID parameter cannot be null or empty"); return null; } if (string.IsNullOrEmpty(accessToken)) { Console.WriteLine("The access token cannot be null or empty!"); return null; } ServicePointManager.ServerCertificateValidationCallback += delegate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; }; ServicePointManager.Expect100Continue = false; userCredentials credentials = new userCredentials() { accessToken = accessToken }; AddOrganization request = CreateOrganizationRequest(new Random(), parentServiceProviderID); AddOrganizationResponse response = new AddOrganizationResponse(); OrganizationClient organizationClient = new OrganizationClient("OrganizationPort"); Console.WriteLine("Adding an Organization"); try { organizationClient.AddOrganization(credentials, request, out response); } catch (Exception e) { //exception found, so we check the stack trc String trace = e.StackTrace; //write the stack trace to the console Console.WriteLine("{0} Exception caught.", e); //wait for the user to press a key before closing the console Console.Read(); } finally { Console.WriteLine("The operation response:"); foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(response)) { string name = descriptor.Name; object value = descriptor.GetValue(response); Console.WriteLine("\t{0}={1}", name, value); } Console.WriteLine(); } return response.ID; } |
...
The below code snippet shows how to get the call costs for a a User Account. The The test can be found inside the file file <PATH_TO_SYSTEMAPI_TOOL>\Operations\Tests.cs
.
...
In order to run this test, the the oauth token must must be provided (i.e. accessToken parameter). Also, you must change the value of the the userId
variable from "CHANGEME" to a valid User Account Id.
The next code snippet shows how the Client-side Proxy is used in order to call a VoipNow SystemAPI operation for getting the call costs for a a User Account.
Code Block | ||||
---|---|---|---|---|
| ||||
public static void GetCallCosts(string accessToken, string userID) { if (string.IsNullOrEmpty(userID)) { Console.WriteLine("The userID parameter cannot be null or empty"); return; } if (string.IsNullOrEmpty(accessToken)) { Console.WriteLine("The access token cannot be null or empty!"); return; } ServicePointManager.ServerCertificateValidationCallback += delegate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; }; ServicePointManager.Expect100Continue = false; userCredentials credentials = new userCredentials() { accessToken = accessToken }; CallCosts request = CreateCallCostsRequest(userID); CallCostsResponse response = new CallCostsResponse(); ReportClient reportClient = new ReportClient("ReportPort"); Console.WriteLine("Getting the call costs for the user with the id = {0}", userID); try { reportClient.CallCosts(credentials, request, out response); } catch (Exception e) { //exception found, so we check the stack trc String trace = e.StackTrace; //write the stack trace to the console Console.WriteLine("{0} Exception caught.", e); //wait for the user to press a key before closing the console Console.Read(); } finally { Console.WriteLine("The operation response:"); foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(response)) { string name = descriptor.Name; object value = descriptor.GetValue(response); Console.WriteLine("\t{0}={1}", name, value); } Console.WriteLine(); } } |
Except where otherwise noted, content in this space is licensed under a Creative Commons Attribution 4.0 International.