//***************************************************************************** //* * //* "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 WebServiceClient.MyBFMAccess; using Microsoft.Web.Services2.Security.Tokens; using System.Xml; using System.Xml.Serialization; namespace WebServiceClient { public partial class Form3 : Form { // modified constructor (added 3 parameters) public Form3(BFMWSService passedService, UsernameToken passedToken, String passedPiid) { InitializeComponent(); myService = passedService; myToken = passedToken; myPiid = passedPiid; myInit(); } // receive process instance values from server & render values private void button1_Click(object sender, EventArgs e) { // do immediate refreshes to see elapsed times myVal2.Text = " ... computing ..."; this.Refresh(); myVal3.Text = " ... computing ..."; this.Refresh(); try { // get running state myVal2.Text = getProcessState(myPiid); this.Refresh(); if (myVal2.Text == "STATE_RUNNING") { myVal3.Text = "(not available yet)"; this.Refresh(); } else { // get output value myVal3.Text = getOutputData(myPiid); this.Refresh(); } } catch (Exception exc) { // Whenever an error occurred, let the user know the details: MessageBox.Show(exc.Message, "Error displaying process details", MessageBoxButtons.OK, MessageBoxIcon.Error); } } /* * * instance variables needed * * */ private UsernameToken myToken = null; private BFMWSService myService = null; private String myPiid = null; // create output labels dynamically private Label myKey1 = new Label(); private Label myVal1 = new Label(); private Label myKey2 = new Label(); private Label myVal2 = new Label(); private Label myKey3 = new Label(); private Label myVal3 = new Label(); /* * * Auxiliary functions used * * */ // initialize the controls in this form private void myInit() { // initialize the static labels myKey1.Text = "Internal name:"; myKey2.Text = "Process state:"; myKey3.Text = "Output:"; // for computed labels, use 3 times default size myVal1.Width *= 3; myVal2.Width *= 3; myVal3.Width *= 3; // initialize the computed labels myVal1.Text = myPiid; myVal2.Text = "[press Refresh to compute]"; myVal3.Text = "[press Refresh to compute]"; // arrange the labels in the table tableLayoutPanel1.Controls.Add(myKey1, 0, 0); tableLayoutPanel1.Controls.Add(myVal1, 1, 0); tableLayoutPanel1.Controls.Add(myKey2, 0, 1); tableLayoutPanel1.Controls.Add(myVal2, 1, 1); tableLayoutPanel1.Controls.Add(myKey3, 0, 2); tableLayoutPanel1.Controls.Add(myVal3, 1, 2); // adjust layout: border, alignment tableLayoutPanel1.CellBorderStyle = TableLayoutPanelCellBorderStyle.Inset; tableLayoutPanel1.AutoSize = true; tableLayoutPanel1.AutoSizeMode = AutoSizeMode.GrowAndShrink; if (tableLayoutPanel1.Parent.Width < tableLayoutPanel1.Width) { // table bigger than window, truncate rhs part of table tableLayoutPanel1.Left = 0; } else { // center table in window tableLayoutPanel1.Left = (tableLayoutPanel1.Parent.Width - tableLayoutPanel1.Width) / 2; } } // get running state of process instance private String getProcessState(String piid) { // assemble request for getting the process object getProcessInstance myGetPIRequest = new getProcessInstance(); myGetPIRequest.piid = piid; // request instance object and return running state getProcessInstanceResponse myPIResponse = myService.getProcessInstance(myGetPIRequest); return myPIResponse.processInstance.executionState; } // get output of process instance private String getOutputData(String piid) { // assemble request for getting output message getOutputMessageForProcessInstance myGetOMRequest = new getOutputMessageForProcessInstance(); myGetOMRequest.piid = piid; // request output message XmlElement myGetOMResponse = myService.getOutputMessageForProcessInstance(myGetOMRequest); operation1Response myResult = xml2operation1Response(myGetOMResponse); return myResult.isEligible.ToString(); } // parse XML structure into instance of generated helper class protected operation1Response xml2operation1Response(XmlElement myXmlElement) { // make use of the objects defined in // BO_Customer_BO_Address_advertiseProcessInterface.cs: operation1Response myResponse = new operation1Response(); XmlSerializer mySerializer = new XmlSerializer(myResponse.GetType()); XmlReader myXmlReader = new XmlNodeReader(myXmlElement); myResponse = (operation1Response)(mySerializer.Deserialize(myXmlReader)); return myResponse; } } }