Accessing the Dedicated Server API with .Net

Customers using an ASP.NET Framework Client will need to do the following steps in order to call the .Net Dedicated Servers API’s services (its functions).
 
General Information
 
  • The Dedicated Server API uses SOAP to communicate.
 
Set Up Steps to Use the API Services (the functions)
 
  1. Add a “service reference” to the client application that will be calling the API functions
          Namespace is: DedicatedServerApi
  1. Add entries to the to the client application’s web.config file.
          See the Client application’s web.config file  section below.
  1. Reference the following: svcutil.exe http://api.reliablesite.net/dedicated-servers.svc?wsdl to review the function calls of the API service.
 
Demonstration on How to Code a Call to an API Function
 
Calling the “User Management” service's “validate a user login” functionality.
 
Function to be called along with the required parameters:
     UsersValidateLogin(keyToAccessApi, passwordToAccessApi, userName, userPassword)
 
The function results and user object (the user details) are passed back to the calling client.
 
The reseller either passed or did not pass API security.
The reseller’s user passed its validation or did not.
 
1) Using the .Net language - VB.NET, creating the subroutine that can be called. 
  Sub ProcessValidateLogin(ByVal keyToAccedssApi as String, ByVal passwordToAccessApi as String, ByVal userName as String, ByVal userPassword as String )
         Dim strMessage As String = “”
         Dim userDetailsInfoResult As New DedicatedServerApi.UserDetailsInfoResult

        ‘ Step 1: Create an instance of the WCF proxy.
        Dim proxyClient As New DedicatedServerApi.UserClient()

        Try
            ‘ Step 2: Call the API function.
            userDetailsInfoResult = proxyClient.UsersValidateLogin(keyToAccessApi, passwordToAccessApi, userName, userPassword)

          ‘ Show the results.
            Console.WriteLine("")
            Console.WriteLine("Message:       " & userDetailsInfoResult.Message)
            Console.WriteLine("Call Result:    " & userDetailsInfoResult.Result.ToString())
            Console.WriteLine("Result Code:  " & userDetailsInfoResult.Result_Code.ToString())
            Console.WriteLine("")
            Console.WriteLine("User object:")
            Console.WriteLine("  Name:         " & userDetailsInfoResult.UserDetails.User_Name)
            Console.WriteLine("  Password:   " & userDetailsInfoResult.UserDetails.User_Password)
            Console.WriteLine("  Email:         " & userDetailsInfoResult.UserDetails.Email_Address)
            Console.WriteLine("  Whmcs:       " & userDetailsInfoResult.UserDetails.Whmcs_Client_Id)   
            Console.WriteLine("")   

           ‘ Step 3: Closing the client gracefully closes the connection and cleans up resources.
           proxyClient.Close()                  
          Catch timeout As TimeoutException
             Console.WriteLine("Critical Error - from API web service(UsersValidateLogin) - at timeout. Contact ReliableSite, do not continue. " & timeout.ToString())
             strMessage = "Critical Error - from API web service(UsersValidateLogin) - at timeout”
         Catch ex As Exception
            Console.WriteLine("Critical Error - from API web service(UsersValidateLogin). Contact ReliableSite, do not continue. " & ex.Message)
            StrMessage = "Critical Error - from API web service(UsersValidateLogin)”
         Finally
           If InStr(strMessage, "Critical Error") > 0 Then
               proxyClient.Abort()
           End If
        End Try
    End Sub
 
2) Using the .Net language - C#, creating the subroutine that can be called.
  public void ProcessValidateLogin(string keyToAccessApi, string passwordToAccessApi, string userName, string userPassword)
       {
           string strMessage = "";
          DedicatedServerApi.UserDetailsInfoResult userDetailsInfoResult = new DedicatedServerApi.UserDetailsInfoResult();

          // Step 1: Create an instance of the WCF proxy.
          DedicatedServerApi.UserClient proxyClient = new DedicatedServerApi.UserClient();
          try
            {
              // Step 2: Call the API function.
             userDetailsInfoResult = proxyClient.UsersValidateLogin(keyToAccessApi, passwordToAccessApi, userName, userPassword);
           
            // Show the results.
            Console.WriteLine("");
            Console.WriteLine("Message:         " + userDetailsInfoResult.Message);
            Console.WriteLine("Call Result:      " + userDetailsInfoResult.Result.ToString());
            Console.WriteLine("Result Code:    " + userDetailsInfoResult.Result_Code.ToString());
            Console.WriteLine("");
            Console.WriteLine("User object:");
            Console.WriteLine("  Name:           " + userDetailsInfoResult.UserDetails.User_Name);
            Console.WriteLine("  Password:     " + userDetailsInfoResult.UserDetails.User_Password);
            Console.WriteLine("  Email:           " + userDetailsInfoResult.UserDetails.Email_Address);
            Console.WriteLine("  Whmcs:        " + userDetailsInfoResult.UserDetails.Whmcs_Client_Id);
            Console.WriteLine("");

           // Step 3: Closing the client gracefully closes the connection and cleans up resources.
           proxyClient.Close();
          }
        catch (TimeoutException timeout)
          {
            Console.WriteLine("Critical Error - from API web service(UsersValidateLogin) - at timeout. Contact ReliableSite, do not continue. " + timeout.ToString());
           strMessage = "Critical Error - from API web service(UsersValidateLogin) - at timeout";
          }
        catch (Exception ex)
         {
           Console.WriteLine("Critical Error - from API web service(UsersValidateLogin). Contact ReliableSite, do not continue. " + ex.Message);
           strMessage = "Critical Error - from API web service(UsersValidateLogin)";
         }
       finally
       {
          if (Strings.InStr(strMessage, "Critical Error") > 0)
             {
                proxyClient.Abort();
             }
      }
}
 
Client application’s web.config file.
 
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.web>
    <compilation debug="true" strict="false" explicit="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
  </system.web>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_User" />
        <binding name="BasicHttpBinding_Server" />
        <binding name="BasicHttpBinding_IPBlock" />
        <binding name="BasicHttpBinding_NullRoute" />
        <binding name="BasicHttpBinding_ResellerOptions" />
        <binding name="BasicHttpBinding_Bandwidth" />
        <binding name="BasicHttpBinding_DDoSAttacks" />
        <binding name="BasicHttpBinding_Backup" />
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://api.reliablesite.net/dedicated-servers.svc/User"
        binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_User"
        contract="DedicatedServerApi.User" name="BasicHttpBinding_User" />
      <endpoint address="http://api.reliablesite.net/dedicated-servers.svc/Server"
        binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_Server"
        contract="DedicatedServerApi.Server" name="BasicHttpBinding_Server" />
      <endpoint address="http://api.reliablesite.net/dedicated-servers.svc/IPBlock"
        binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IPBlock"
        contract="DedicatedServerApi.IPBlock" name="BasicHttpBinding_IPBlock" />
      <endpoint address="http://api.reliablesite.net/dedicated-servers.svc/NullRoute"
        binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_NullRoute"
        contract="DedicatedServerApi.NullRoute" name="BasicHttpBinding_NullRoute" />
      <endpoint address="http://api.reliablesite.net/dedicated-servers.svc/ResellerOptions"
        binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ResellerOptions"
        contract="DedicatedServerApi.ResellerOptions" name="BasicHttpBinding_ResellerOptions" />
      <endpoint address="http://api.reliablesite.net/dedicated-servers.svc/Bandwidth"
        binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_Bandwidth"
        contract="DedicatedServerApi.Bandwidth" name="BasicHttpBinding_Bandwidth" />
      <endpoint address="http://api.reliablesite.net/dedicated-servers.svc/DDoSAttacks"
        binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_DDoSAttacks"
        contract="DedicatedServerApi.DDoSAttacks" name="BasicHttpBinding_DDoSAttacks" />
      <endpoint address="http://api.reliablesite.net/dedicated-servers.svc/Backup"
        binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_Backup"
        contract="DedicatedServerApi.Backup" name="BasicHttpBinding_Backup" />
    </client>
    <diagnostics wmiProviderEnabled="true">
      <messageLogging logEntireMessage="false" logMalformedMessages="false" logMessagesAtTransportLevel="false" logMessagesAtServiceLevel="false"/>
    </diagnostics>
  </system.serviceModel>
</configuration>

Add Feedback