You can choose between two versions of the client application:
The paragraphs in this chapter describe the steps to build a most simple Microsoft® .NET® client application which uses the secured Web Services API delivered with WebSphere Process Server.
To develop the client application, we will use Microsoft Visual Studio® .NET 2005 and Microsoft Web Services Enhancements (WSE) 2.0 SP3.
In detail, the following steps are described:
Note: During this sample, we restrict ourselves to the Business Flow Manager API (BFM API) which can be used to interact with the BPEContainer. If you rather want to use the Human Task Manager API (HTM API) which can be used to interact with the TaskContainer, all steps are conceptually similar, but you will export the WSDL files from the TaskContainer application instead.
In this section, we determine the URL for the Web Services Description file (WSDL). We need this URL to access the WSDL file which is necessary to use the Web services interface.
The most simple case is when the following three conditions are met:
In this case, the URL is
. After starting the server, you can use this URL in a Web Browser to display the WSDL file. Then proceed to the next
section Create a new application project.
In the more general case, this is the URL:
http://yourhost:yourport/bpeContextRoot/sca/com/ibm/bpe/api/sca/BFMWS/wsdl
.
Note: Replace yourhost
with your server's internet address and yourport
with the port of your server's HTTP transport.
Use the following steps to find out bpeContextRoot
(the context root of the Web services interface for the BPE container application):
The context root is listed with a leading slash.
Make sure the server is started and verify in a Web Browser that the URL you determined can be used to display a WSDL file before you proceed to the next section.
We will create a simple .NET client application which uses the Web services interface. To do this, we first create the Visual C# Windows Application project named WebServiceClient. Follow these steps:
WebServiceClient
.In this section, we access the Web Services Description file (WSDL) for which we previously determined the URL. Using this WSDL file, we then generate a C# proxy that allows to access the Web services operations as C# methods. Next, we modify the proxy to enable Web services security. Later on, we will use C# methods in our client code which is translated to Web service calls by this proxy.
First, we access the WSDL file. Do the following steps:
Note: If you want to run the .NET client application and WebSphere Process Server on different machines, you may want to use the server's unique internet address rather than "localhost". As well, you can use "localhost" for the moment and change the service endpoint later.
MyBFMAccess
and click Add Reference.Now a C# proxy is created in the file Reference.cs.
Note: For the steps in this section, the installation of the WSE component (Web Services Enhancements) is a prerequisite. See the Introduction chapter of this sample for information how to get the WSE component.
In this section we modify the proxy so the proxy can support secure Web services. Do the following steps:
Microsoft.Web.Services2.WebServicesClientProtocol
This code change alters the superclass of the proxy; the new class is part of the Microsoft WSE component and allows to call the method RequestSoapContext(...) which we will use in the implementation below.
Note: The change described in this section must be repeated whenever the proxy code is newly generated. Be aware that this code generation may happen automatically, for example, when you change the Web Reference URL via Solution Explorer > WebServiceClient > Web References > MyBFMAccess > Properties.
In this section, we create a tiny application, consisting of a single window which allows to display process templates.
Complete the following steps:
textBoxUserid
.textBoxPassword
.List Process Templates
.In this section, we program the push button so it takes the userid and password values and makes the C# proxy call the WebSphere Process Server. Complete the following steps:
using WebServiceClient.MyBFMAccess;
using Microsoft.Web.Services2.Security.Tokens;
These statements allows to use the short names rather than fully qualified names for several classes (BFMWSService, ProcessTemplateType, UsernameToken, PasswordOption) in the following lines of code.
try
{ // Get userid and password values and wrap it as UsernameToken:
UsernameToken token = new UsernameToken(textBoxUserid.Text, textBoxPassword.Text, PasswordOption.SendPlainText);
// Instantiate the proxy and attach the UsernameToken to the instance
BFMWSService myService = new BFMWSService();
myService.RequestSoapContext.Security.Tokens.Clear();
myService.RequestSoapContext.Security.Tokens.Add(token);
// Create an empty input object and run the query
queryProcessTemplates queryInput = new queryProcessTemplates();
richTextBox1.Text = " ... computing ..."; this.Refresh();
ProcessTemplateType[] templateTypes = myService.queryProcessTemplates(queryInput);
// Render the result: for each template, show three properties
richTextBox1.Clear();
if (0 == templateTypes.Length)
richTextBox1.Text = "No process templates found on server.";
for (int i = 0; i < templateTypes.Length; i++)
{
richTextBox1.AppendText("Name: " + templateTypes[i].name +
", Auto-delete: " + templateTypes[i].autoDelete +
", Long running: " + templateTypes[i].executionMode +
"\n");
}
}
catch (Exception exc)
{ // Whenever an error occurred, let the user know the details
MessageBox.Show(exc.Message, "Error running sample",
MessageBoxButtons.OK, MessageBoxIcon.Error);
richTextBox1.Text = " ... sample failed with exception: " + exc.GetType();
}
This code creates a UsernameToken from the values in the text boxes for userid and password.
Then it uses the proxy to query all process templates.
Finally, it displays some of the properties.
To keep the code simple, all potential runtime errors are mapped to one small code snippet.
The top of your editor window will now look similar to this:
Click on this link to see the complete source code of Form1.cs.
You have now finished the implementation of the simple client application. Optionally, you can now use
Then proceed to the next chapter Run the sample to work with the application.
As well, you can upgrade the simple client application and let the client application do more advanced Web Service operations, by following the instructions in the Advanced Version chapter.