API Guide

S5. Sample Code

// Sample Code – Container.ContainerInfo

using System;
using System.IO;
using System.Net;
using System.Web;
using System.Xml;

namespace TEST {

   class ConsoleApp {

      static void Main(string[] args) {
         ContainerContainerInfo();
      }

      static void ContainerContainerInfo () {
         // Service Connection and Security Settings
         string serviceEndpointUrl = "https://ws.mxvm.net/XDocSystemService.ashx";
         string methodSignature = "Container.ContainerInfo";
         string securityContext = "cst122";
         bool   xwsSuccess = false;

         // method parameters
         string projectId = "1000";
         string containerKey = "201001";
         int dataIncludeFlags = 1 | 2;

         // Construct the base service URL endpoint
         string url = String.Concat(
           serviceEndpointUrl,
           "?XM=",  HttpUtility.UrlEncode(methodSignature),
           "&XSC=", HttpUtility.UrlEncode(securityContext),

           // Add the method specific parameters
           "&ProjectId=", HttpUtility.UrlEncode(projectId), 
           "&ContainerKey=", HttpUtility.UrlEncode(containerKey), 
           "&DataIncludeFlags=", dataIncludeFlags.ToString()
         );

         Console.WriteLine("URL: " + url);

         // Create a web request and get the response.
         try {
            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
            webRequest.Method = WebRequestMethods.Http.Get;
            webRequest.Timeout = 60 * 3 * 1000;  // 3 minutes in milliseconds

            // get and inspect the response
            using (HttpWebResponse webResponse = webRequest.GetResponse()) {
               // Check the service response for success using the HTTP headers
               xwsSuccess = (webResponse.Headers["XwsSuccess"] == "1");

               // Example of getting other service response headers 
               string xwsRequestId = webResponse.Headers["XwsRequestId"];
               int xwsResultCode = Int32.Parse(webResponse.Headers["XwsResultCode"]);
               string xwsResultInfo = webResponse.Headers["XwsResultInfo"];
               int xwsErrorCode = Int32.Parse(webResponse.Headers["XwsErrorCode"]);
               string xwsErrorInfo = webResponse.Headers["XwsErrorInfo"];

               // Read the service response xml data if you need the ResponseData, 
               // or want to inspect the error trace in case of an error.
               XmlDocument responseXml = new XmlDocument();

               // Get the response XML payload if you care about it
               using (Stream responseStream = webResponse.GetResponseStream()) {
                  using (StreamReader reader = new StreamReader(responseStream)) {
                     responseXml.Load(reader);
                  }
               }

               // Inspect the Response XML Payload if you care about it.
               XmlElement responseNode = (XmlElement)responseXml.SelectSingleNode("//ServiceResponse");

               if (responseNode != null) {
                  // Another way to inspect for success from the XML payload.
                  // Typically, this is not used since success can be inspected from the Response Header.
                  xwsSuccess = (responseNode.GetAttribute("Success") == "1");
                  Console.WriteLine("Success=" + xwsSuccess);
                  Console.WriteLine("ResultCode=" + responseNode.GetAttribute("ResultCode"));
                  Console.WriteLine("ResultInfo=" + responseNode.GetAttribute("ResultInfo"));

                  if (xwsSuccess) {
                     // inspect the Container Node
                     XmlElement containerNode = (XmlElement)responseNode.SelectSingleNode("//Container");
                     if (containerNode != null) {
                        Console.WriteLine("ContainerId=" + messageNode.GetAttribute("ContainerId"));
                        Console.WriteLine("TotalDocumentCount=" + messageNode.GetAttribute("TotalDocumentCount"));
                     }
                  }
               }
            }
         } catch (Exception e) {
            Console.WriteLine("ERROR: " + e.ToString());
         }

         // Processing compete
         Console.WriteLine("...");
      }
   }
}