//***************************************************************************** //* * //* "This sample program is provided AS IS and may be used, executed, copied * //* and modified without royalty payment by customer * //* (a) for its own instruction and study, * //* (b) in order to develop applications designed to run with an * //* IBM WebSphere product, either for customer's own internal use or for * //* redistribution by customer, as part of such an application, in * //* customer's own products." * //* * //* Product 5655-FLW, * //* (C) COPYRIGHT International Business Machines Corp., 2006, 2007 * //* All Rights Reserved * Licensed Materials - Property of IBM * //* * //***************************************************************************** //* * //* DISCLAIMER * //* * //* This material contains programming source code for your consideration. * //* These examples have not been thoroughly tested under all conditions. * //* IBM, therefore, cannot guarantee or imply reliability, serviceability, * //* or function of these programs. * //* ALL PROGRAMS CONTAINED HEREIN ARE PROVIDED TO YOU "AS IS", WITHOUT ANY * //* WARRANTIES (EXPRESS OR IMPLIED) OR SUPPORT WHATSOEVER, INCLUDING BUT * //* NOT LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS * //* FOR A PARTICULAR PURPOSE. * //* * //***************************************************************************** /* * This sample shows the usage of the BFM Web Service API. * */ using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Xml; using WebServiceClient.MyBFMAccess; using Microsoft.Web.Services2.Security.Tokens; using System.IO; using System.Xml.Serialization; namespace WebServiceClient { public partial class Form2 : Form { private UsernameToken myToken = null; private BFMWSService myService = null; protected XmlElement serialize2Xml(object obj) { if (obj != null) { if (obj is XmlElement) { // XmlElement return obj as XmlElement; } else if (obj is XmlNode) { // XmlNode return obj as XmlElement; } else { // other XmlDocument myDocument = new XmlDocument(); MemoryStream myMemoryStream = new MemoryStream(); XmlWriter myTextWriter = new XmlTextWriter(myMemoryStream, null); XmlSerializer myXmlSerializer = new XmlSerializer(obj.GetType()); myXmlSerializer.Serialize(myTextWriter, obj); myMemoryStream.Position = 0; myDocument.Load(myMemoryStream); return myDocument.DocumentElement; } } return null; } public Form2(BFMWSService passedService, UsernameToken passedToken) { InitializeComponent(); myService = passedService; myToken = passedToken; } private void button1_Click(object sender, EventArgs e) { String myPiid = ""; try { // Verify process template exists // Use UsernameToken myService.RequestSoapContext.Security.Tokens.Clear(); myService.RequestSoapContext.Security.Tokens.Add(myToken); // Create input object and run the query queryProcessTemplates queryInput = new queryProcessTemplates(); queryInput.whereClause = "PROCESS_TEMPLATE.NAME = 'advertiseProcess'"; ProcessTemplateType[] templateTypes = myService.queryProcessTemplates(queryInput); if (templateTypes.Length == 0) { // catch most frequent problem: template not found MessageBox.Show("Process Template 'advertiseProcess' not found on server", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // Process interface settings, see interface editor String myOperationName = "operation1"; String myPortTypeName = "advertiseProcessInterface"; String myNamespace = "http://WSApiModule/advertiseProcessInterface"; String myProcessTemplateName = "advertiseProcess"; // assemble the SOAP message using data received from form BO_Customer myCustomer = new BO_Customer(); myCustomer.firstName = textBoxFName.Text; // first name myCustomer.lastName = textBoxLName.Text; // last name BO_Address myAddress = new BO_Address(); myAddress.street = textBoxSName.Text; // street name myAddress.city = textBoxCName.Text; // city name myCustomer.address = myAddress; operation1 myOp1 = new operation1(); myOp1.customer = myCustomer; // create the message used to start long-running process sendMessage mySendmsg = new sendMessage(); mySendmsg.Any = serialize2Xml(myOp1); mySendmsg.portType = new XmlQualifiedName(myPortTypeName, myNamespace); mySendmsg.operation = myOperationName; mySendmsg.processTemplateName = myProcessTemplateName; // send the message, this starts the process sendMessageResponse mySendmsgResp = myService.sendMessage(mySendmsg); // from the response, extract the PIID String myPiid = mySendmsgResp.pIID; // now we open a new form to watch the status and to display the result Form3 f3 = new Form3(myService, myToken, myPiid); f3.Show(); } catch (Exception exc) { // Whenever an error occurred, let the user know the details: MessageBox.Show(exc.Message, "Error running advanced sample", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }