Building SOAP API Client Applications with Microsoft Visual Studio IDE

This section provides steps to build a SOAP web services application using Microsoft Visual Studio IDE.

You must generate the classes required to consume OpenAir SOAP web services (SOAP API) from the OpenAir WSDL before you can build client applications using Visual Studio languages. These classes serve as proxies for their server-side counterparts.

After you have imported the OpenAir WSDL definition into your development platform, you can walk through the following sample code to create a simple client application. See C# Sample Code — Read (SOAP API).

Note:

These steps are provided for illustration purposes only. For detailed instructions about setting up, and building applications using Visual Studio IDE or other development platforms, refer to the Visual Studio documentation.

To use Microsoft Visual Studio IDE with OpenAir SOAP web services:

  1. In Microsoft Visual Studio, create a new project and give it a name, for example SoapClientApplication.

  2. Go to Project > Add Service Reference > Advanced > Add Web Reference.

    The Add Web Reference window appears.

  3. In the URL box, enter the URL for the OpenAir WSDL. For example, if you are using the generic WSDL for production accounts, the URL is https://app.openair.com/wsdl.pl.

  4. Click Go to retrieve information about OpenAir SOAP Web Services.

  5. In the Web reference name box, rename the web reference as OpenAir, for example.

  6. Click Add Reference.

    Visual Studio retrieves the service description and generates the proxy classes to interface between your application and OpenAir SOAP web services.

  7. Implement your application by writing your business logic using the generated proxy classes.

    1. Add a using directive to the OpenAir SOAP web service reference. Replace SoapClientApplication.OpenAir with the name of your project and the web reference name for OpenAir SOAP web services MyProjectName.MyReferenceName.

                          using System;
      using SoapClientApplication.OpenAir;
      
      namespace SoapClientApplication 
      
                        
    2. Get an instance of the OpenAir SOAP web services proxy class.

                          {
         class GettingStartedWithOaSoapApi
            {
               private static OAirServiceHandlerService m_svc;
               m_svc = new OAirServiceHandlerService(); 
      
                        
    3. Authenticate by populating the LoginParams object and then invoking the login() operation.

                                   private static bool Login()
                  {
                     OpenAir.LoginParams lp = new OpenAir.LoginParams();
                     lp.api_namespace = "<Your_API_Namespace>";
                     lp.api_key = "<Your_API_Key>";
                     lp.company = "<Your_Company_ID>";
                     lp.user = "<Your_User_ID>";
                     lp.password = "<Your_Password>";
      
                     LoginResult loginResult;
                     loginResult = m_svc.login(lp); 
      
                        

      Replace <Your_API_Namespace>, <Your_API_Key>, <Your_Company_ID>, <Your_User_ID>, and <Your_Password> with your API namespace, API key, and OpenAir company ID, user ID and password.

      The login() command creates a session and returns a session ID which you can use in the SOAP header to provide authentication for API calls implementing your business logic.

    4. Set up the SOAP header to include the session ID.

                                         SessionHeader header = new SessionHeader();
                     header.sessionId = loginResult.sessionId;
                     m_svc.SessionHeaderValue = header;
                  } 
      
                        
    5. Implement your business logic. For example, create a new customer in OpenAir.

                                   private static void AddCustomer()
                  {
                     oaCustomer customer = new oaCustomer();
                     customer.name = "XYZ Inc";
                     try
                        {
                           // Add the customer and output any errors encountered
                           UpdateResult result = m_svc.add(customer);
                           if (result.errors != null)
                              {
                                 foreach (oaError err in result.errors)
                                    {
                                       oaError err = (oaError)base;
                                       Console.WriteLine("Error "+err.code + ": " + err.comment + "\t" + err.text);
                                    }  
                              }
                            if (result.status == "A") Console.WriteLine("Customer added");
                        }
                  } 
      
                        
    6. Add an application entry point, perform operations if the authentication is successful and sign out to invalidate the current session.

                                   static void Main(string[] args)
                  {
                     if (Login())
                       {
                          AddCustomer();
                          // end the session
                          m_svc.logout();
                       }
                   }
            }
      }