OnTime API Documentation
In This Topic
    OnTime SOAP API ASP.NET Guide
    In This Topic

    The following is a guide for using the OnTime SOAP API in an ASP.NET project using C#. This walkthrough sample demonstrates how to retrieve an order with a specific tracking number, update the description of that order, and save the changes using the OnTime SOAP API.

    1. Start Visual Studio.

    2. Create a new ASP.NET Web Application project for Visual C#. If prompted, ensure that Web Forms is selected as the project type.

    3. In Solution Explorer, right-click the project name node and select Add > Service Reference.

    4. In the Address box, enter the URL for the OnTime SOAP API for the account you would like to connect with. This is normally a URL that ends with: /ws/soap_v1.svc.

    5. Click the button labeled Go to resolve the URL, If successful, "soap_v1" should appear in the Services list.

    6. Enter a name for the service under the Namespace textbox. The default is: ServiceReference1.

    7. Click OK to add the service reference to the project.

    8. In Solution Explorer, right-click the project name node and select Add > Web Form.

    9. Name the web form and click OK to add the page to the project.

    10. In Solution Explorer right-click the web form just created and choose View Markup.

    11. Add the following HTML to the body of the page:

    HTML
    Copy Code
    <h1>Tracking# 4787</h1> 
    <br /> 
    <asp:label id="lblStatus" runat="server" text="Label">Adding "Customer Reference# 614852" to the order description. Please wait.</asp:label>

    12. In Solution Explorer, right click the web form just created and choose View Code.

    13. Ensure that the following Using directions appear at the top of the code file:

    Using
    Copy Code
    using System.Net;
    using System.ServiceModel;
    using System.ServiceModel.Channels;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    14. Add the following code to the page class:

    Page Class
    Copy Code
    private string _apiKey = "YOUR_API_KEY_HERE"; 
     
    protected void Page_Load(object sender, EventArgs e) 
    { 
         this.LoadComplete += (s, eventArgs) => 
          { 
               try 
               { 
                    // Create a new instance of the service reference. 
                    var service = new ServiceReference.Isoap_v1Client(); 
                    var operationContextScope = new OperationContextScope(service.InnerChannel); 
     
                    // Add the API to the authorization of the request if the account does not allow anonymous access. 
                    var header = MessageHeader.CreateHeader("Authorization", "", _apiKey); 
                    OperationContext.Current.OutgoingMessageHeaders.Add(header); 
     
                    // Query the service for the ID of an order with the tracking number 4787. 
                    var orders = service.GetOrderListWhere(ServiceReference.OrderColumn.TrackingNumber, "4787"); 
                    if (orders.Length > 0) 
                    { 
                         // Query the service for the order object. 
                         var order = service.GetOrder(orders[0]); 
                         if (order != null) 
                         { 
                              // Append a value to the order's description. 
                              order.Description += "Customer Reference# 614852"; 
     
                              // Update the order. 
                              service.UpdateOrder(order); 
                              lblStatus.Text = "Successfully updated the order!"; 
                         } 
                         else 
                         { 
                              lblStatus.Text = "An error has occurred: No order with tracking number 4787."; 
                         } 
                    } 
                    else 
                    { 
                         lblStatus.Text = "An error has occurred: No order with tracking number 4787."; 
                    } 
               } 
               catch (WebException wex) 
               { 
                    lblStatus.Text = "A web exception has occurred: " + wex.Message; 
               } 
               catch (Exception ex) 
               {
                    lblStatus.Text = "An exception has occurred: " + ex.Message; 
               } 
         }; 
    }

    15. Finally, ensure that you enter an API Key associated with the OnTime account in the first line of the previous code, and verify that the name of the Service Reference matches the name of the object on line 10 of the previous code.