Quick Start: Invoking a long-lived process using the web service API

The following C# code example invokes the FirstAppSolution/PreLoanProcess process.

???/** 
    * Ensure that you create a .NET project that uses  
    * MS Visual Studio 2008 and version 3.5 of the .NET 
    * framework. This is required to invoke a  
    * LiveCycle service using MTOM. 
    *  
    * For information, see "Invoking LiveCycle using MTOM" in Programming with LiveCycle.   
    */ 
 
using System; 
using System.Collections; 
using System.Configuration; 
using System.Data; 
using System.Linq; 
using System.Web; 
using System.ServiceModel; 
using System.Web.Security; 
using System.Web.UI; 
using System.Web.UI.HtmlControls; 
using System.Web.UI.WebControls; 
using System.Web.UI.WebControls.WebParts; 
using System.Xml.Linq; 
using System.Xml; 
using System.IO; 
 
//A reference to FirstAppSolution/PreLoanProcess 
using InvokePreLoanProcess.PreLoanProcess; 
 
//A reference to JobManager service 
using InvokePreLoanProcess.JobManager; 
 
 
namespace InvokePreLoanProcess 
{ 
       public partial class _Default : System.Web.UI.Page 
       { 
           //This method is called when the Submit Application button is  
           //Clicked 
           protected void Button1_Click(object sender, EventArgs e) 
           { 
               //Create a FirstAppSolution_PreLoanProcessClient object 
               FirstAppSolution_PreLoanProcessClient mortgageClient = new FirstAppSolution_PreLoanProcessClient(); 
               mortgageClient.Endpoint.Address = new System.ServiceModel.EndpointAddress("http://hiro-xp:8080/soap/services/FirstAppSolution/PreLoanProcess?blob=mtom"); 
 
               //Enable BASIC HTTP authentication 
               BasicHttpBinding b = (BasicHttpBinding)mortgageClient.Endpoint.Binding; 
               b.MessageEncoding = WSMessageEncoding.Mtom; 
               mortgageClient.ClientCredentials.UserName.UserName = "administrator"; 
               mortgageClient.ClientCredentials.UserName.Password = "password"; 
               b.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic; 
               b.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly; 
               b.MaxReceivedMessageSize = 2000000; 
               b.MaxBufferSize = 2000000; 
               b.ReaderQuotas.MaxArrayLength = 2000000; 
     
               //Retrieve values that user entered into the web page 
               String userName = TextBoxName.Text; 
               String phone = TextBoxPhone.Text; 
               String amount = TextBoxAmount.Text; 
 
               //Create the XML to pass to the FirstAppSolution/PreLoanProcess process 
               XmlDocument myXML = CreateXML(userName, phone, amount); 
     
               StringWriter sw = new StringWriter(); 
               XmlTextWriter xw = new XmlTextWriter(sw); 
               myXML.WriteTo(xw); 
 
               InvokePreLoanProcess.PreLoanProcess.XML inXML = new XML(); 
               inXML.document = sw.ToString();  
 
               //INvoke the FirstAppSolution/PreLoanProcess process 
               String invocationID =  mortgageClient.invoke_Async(inXML); 
 
               //Create a JobManagerClient object to obtain the status of the long-lived operation 
               JobManagerClient jobManager = new JobManagerClient(); 
               jobManager.Endpoint.Address = new System.ServiceModel.EndpointAddress("http://hiro-xp:8080/soap/services/JobManager?blob=mtom"); 
 
               //Enable BASIC HTTP authentication 
               BasicHttpBinding b1 = (BasicHttpBinding)jobManager.Endpoint.Binding; 
               b1.MessageEncoding = WSMessageEncoding.Mtom; 
               jobManager.ClientCredentials.UserName.UserName = "administrator"; 
               jobManager.ClientCredentials.UserName.Password = "password"; 
               b1.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic; 
               b1.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly; 
               b1.MaxReceivedMessageSize = 2000000; 
               b1.MaxBufferSize = 2000000; 
               b1.ReaderQuotas.MaxArrayLength = 2000000; 
 
 
               //Create a JobID object that represents the status of the  
               //long-lived operation 
               JobId jobId = new JobId(); 
               jobId.id = invocationID; 
               jobId.persistent = true; 
               JobStatus jobStatus = jobManager.getStatus(jobId); 
               System.Int16 val2 = jobStatus.statusCode; 
               LabelJobID.Text = "The job status identifier value is " + invocationID;   
               LabelStatus.Text = "The status of the long-lived operation is " + getJobDescription(val2);  
     
           } 
 
           private static XmlDocument CreateXML(String name, String phone, String amount) 
           { 
               //This method dynamically creates a DDX document  
               //to pass to the FirstAppSolution/PreLoanProcess process 
               XmlDocument xmlDoc = new XmlDocument(); 
 
               //Create the root element and append it to the XML DOM         
               System.Xml.XmlElement root = xmlDoc.CreateElement("LoanApp"); 
               xmlDoc.AppendChild(root); 
 
               //Create the Name element 
               XmlElement nameElement = xmlDoc.CreateElement("Name"); 
               nameElement.AppendChild(xmlDoc.CreateTextNode(name)); 
               root.AppendChild(nameElement); 
 
               //Create the LoanAmount element 
               XmlElement LoanAmount = xmlDoc.CreateElement("LoanAmount"); 
               LoanAmount.AppendChild(xmlDoc.CreateTextNode(amount)); 
               root.AppendChild(LoanAmount); 
 
               //Create the PhoneOrEmail element 
               XmlElement PhoneOrEmail = xmlDoc.CreateElement("PhoneOrEmail"); 
               PhoneOrEmail.AppendChild(xmlDoc.CreateTextNode(phone)); 
               root.AppendChild(PhoneOrEmail); 
 
               //Create the ApprovalStatus element 
               XmlElement ApprovalStatus = xmlDoc.CreateElement("ApprovalStatus"); 
               ApprovalStatus.AppendChild(xmlDoc.CreateTextNode("PENDING APPROVAL")); 
               root.AppendChild(ApprovalStatus); 
 
               //Return the XmlElement instance 
               return xmlDoc; 
           } 
 
 
           //Returns the String value of the Job Manager status code 
           private String getJobDescription(int val) 
           { 
               switch(val) 
               { 
                   case 0: 
                       return "JOB_STATUS_UNKNOWN"; 
     
                   case 1:  
                       return "JOB_STATUS_QUEUED"; 
 
                   case 2:  
                       return "JOB_STATUS_RUNNING"; 
 
                   case 3:  
                       return "JOB_STATUS_COMPLETED";   
     
                   case 4:  
                       return "JOB_STATUS_FAILED";  
 
                    case 5:  
                       return "JOB_STATUS_COMPLETED";  
     
                   case 6:  
                       return "JOB_STATUS_SUSPENDED"; 
     
                   case 7:  
                       return "JOB_STATUS_COMPLETE_REQUESTED"; 
     
                   case 8:  
                       return "JOB_STATUS_TERMINATE_REQUESTED"; 
 
                    case 9:  
                       return "JOB_STATUS_SUSPEND_REQUESTED"; 
 
                      case 10:  
                       return "JOB_STATUS_RESUME_REQUESTED"; 
               } 
 
               return ""; 
           } 
      } 
} 
注意: The values located in the getJobDescription user-defined method correspond to values returned by the Job Manager service. (See Retrieving the Status of a LiveCycle Job.)