using System; using System.Collections.Generic; using System.Text; using System.Xml; using WebserviceConsumptionExampleApplication.Connection; using WebserviceConsumptionExampleApplication.Ticket; /** * WebserviceConsumptionExample.cs * * Uses the WS implementation to create a ticket * * This is part of an example implementation for connecting to the * IssueCentre WebService APIs for version 2.0 of IssueCentre and should * not be relied upon to be production worthy code. * * This application consume the webservices for IssueCentre using * the "generate web reference" feature of Visual Studio #. * It uses the getContracts method of Connection,to list the contracts, uses the first * contract returned to login to IssueCentreby calling generateKey then uses the key to log a * ticket into IssueCentre by calling the createTicket method of the Ticket webservice. * */ namespace WebserviceConsumptionExampleApplication { class WebserviceConsumptionExample { public static String username = "yourIssueCentreUserName"; public static String password = "yourIssueCentrePassword"; static void Main(string[] args) { //Setup the webservice objects ConnectionService connection = new Connection.ConnectionService(); connection.Url = "http://YouIssueCentreServer/issuecentre/Connection"; TicketsService ticket = new Ticket.TicketsService(); ticket.Url = "http://YouIssueCentreServer/issuecentre/Ticket"; try { //Create the object which contains the parameters getContracts getContactsRequestParams = new getContracts(); //Setup the object's parameters (numerical order matching the method signature) getContactsRequestParams.arg0 = username; getContactsRequestParams.arg1 = password; //Call the method and get the @return parameter (Containing the response) String xml = connection.getContracts(getContactsRequestParams).@return; //Parse the string as XML XmlDocument xd = new XmlDocument(); xd.LoadXml(xml); //If there are no problems then continue if (xd.DocumentElement.Attributes["error"].Value == "0") { //Select out the first contract from the xml returned and get its ID int contractId = Int32.Parse(xd.DocumentElement.SelectNodes("contracts")[0].SelectNodes("contract")[0].Attributes.GetNamedItem("id").Value); //Create the object which contains the parameters for the generate key method generateKey generateKeyRequestParams = new generateKey(); //Setup the object's parameters (numerical order matching the method signature) generateKeyRequestParams.arg0 = username; generateKeyRequestParams.arg1 = password; generateKeyRequestParams.arg2 = contractId; //Call the method and get the @return parameter (Containing the response) xml = connection.generateKey(generateKeyRequestParams).@return; //Parse the string as XML xd.LoadXml(xml); //If there are no problems then continue if (xd.DocumentElement.Attributes["error"].Value == "0") { //Select out the root elements innerText (contains the key) String key = xd.DocumentElement.InnerText; //setup the parameters for the new ticket int company = 0; //Company code (Customers.getCompanies()) int contact = 0; //Contact code (Customers.getContacts()) int product = 0; //Product code (Contracts.getProducts()) int productVersion = 0; //Product Version code (Contracts.getProducts()) int ticketStatus = 0; //Ticket Status code (Contracts.getStatusTypes()) int priority = 0; //Priority code (Contracts.getPriorities()) int platform = 0; //Platform code (Contracts.getProducts()) int platformVersion = 0; //Platform version code (Contracts.getProducts()) int errorType = 0; //Error type code (Contracts.getErrorTypes()) int receivedBy = 0; //received by method (Contracts.getReceivedByMethods()) int timeSpent = 0; //Number of seconds spent recording this ticket (For reporting) String supplierRef = ""; //Stored in the supplier reference field String clientRef = ""; //Stored in the client reference field String internalNotes = ""; //Agent only visible notes String issue = ""; //Issue description String summary = ""; //Short summary of issue //Create the object which contains the parameters for the createTicket method createTicket createTicketParams = new createTicket(); //Setup the object's parameters (numerical order matching the method signature) createTicketParams.arg0 = key; createTicketParams.arg1 = company; createTicketParams.arg2 = contact; createTicketParams.arg3 = product; createTicketParams.arg4 = productVersion; createTicketParams.arg5 = ticketStatus; createTicketParams.arg6 = priority; createTicketParams.arg7 = supplierRef; createTicketParams.arg8 = clientRef; createTicketParams.arg9 = internalNotes; createTicketParams.arg10 = platform; createTicketParams.arg11 = platformVersion; createTicketParams.arg12 = errorType; createTicketParams.arg13 = receivedBy; createTicketParams.arg14 = issue; createTicketParams.arg15 = timeSpent; createTicketParams.arg16 = summary; //Call the createTicket method with the object xml = ticket.createTicket(createTicketParams).@return; //Parse the xml response. xd.LoadXml(xml); } else { Console.WriteLine(xd.DocumentElement.Value); } } else { Console.WriteLine(xd.DocumentElement.Value); } } finally { } } } }