Invoking a Service using Visual Studio
Using IBM webMethods Add-In for Microsoft Visual Studio
Using the IBM webMethods add-in for Microsoft Visual Studio, you can select a service from a running Integration Server and generate a C# or Visual Basic class, as shown in Generating a C# Client Code in Visual Studio. This sample shows how you would go about creating a console application, but does not attempt to depict the end-to-end actions needed to create an executable.
This sample requires that you add two references to the .NET project, which you can find in the IBM webMethods Add-In for Microsoft Visual Studio installation directory.
The files are CGUTIL.dll and wmClientAPI.dll.
This sample is based on the WmPublic.pub:concat service delivered with Integration Server.
Generating a C# Client Code in Visual Studio
About this task
To create a C# file from the concat service
Procedure
Results
The following sections provide brief descriptions of the sample code as they relate to Generating Microsoft .NET Clients:
- List Packages to be Used (Generated Code)
- Class Declaration (Generated Code)
- Connect to Integration Server (Generated Code)
- Invoke the Service and Retrieve the Output (Generated Code)
- Disconnect from Integration Server (Generated Code)
You can find the complete code sample in Complete Generated Code Sample.
List Packages to be Used (Generated Code)
The first stage of the code sample contains using statements that specify the .NET packages
to use:
using System;
using webMethods.ClientAPI;
Class Declaration (Generated Code)
The second stage of the code creates the context in which the client operates:
namespace Pub.String
{
/// <summary>
/// Sample client demonstrating invocation of the 'concat' Integration ///
Service using an object generated by the webMethods Visual
/// Studio Add-in.
/// </summary>
class ClientSample2
Connect to Integration Server (Generated Code)
The third stage creates the connection to Integration Server:
{
String returnString = null;
// create our connection context with the Integration Server
Context serverContext = new Context();
// connect to the server
try
{
serverContext.connect( "localhost:5555", "Administrator", "manage" );
}
catch( Exception ex )
{
Console.WriteLine("Connection to server failed, reason=" + ex );
return null;
}
Populate the Service Inputs (Generated Code)
The fourth stage of the code creates input data variables:
// create the Concat service object
//(created by the Add-in for the pub.string:concat service)
Concat concatService = new Concat();
// populate the inputs
concatService.in_inString1 = string1;
concatService.in_inString2 = string2;
Invoke the Service and Retrieve the Output (Generated Code)
The fifth and sixth stages are to invoke the service and retrieve the output:
// invoke the service
concatService.invoke( serverContext );
// extract the output
returnString = concatService.out_value;
Disconnect from Integration Server (Generated Code)
The seventh stage is to disconnect from Integration Server:
// disconnect from the server
serverContext.disconnect();
Complete Generated Code Sample
using System;
using webMethods.ClientAPI;
namespace Pub.String
{
/// <summary>
/// Sample client demonstrating invocation of the 'concat' Integration ///
Service using an object generated by the webMethods Visual
/// Studio Add-in.
/// </summary>
class ClientSample2
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
// execute the generated service object
String result = concatStrings( "testString1", "testString2" );
Console.WriteLine( "concat=" + result );
}
/**
* Concatentate strings using the Add-in generated class for the
* pub.strings:concat service
*/
public static String concatStrings( String string1, String string2 )
{
String returnString = null;
// create our connection context with the Integration Server
Context serverContext = new Context();
// connect to the server
try
{
serverContext.connect( "localhost:5555", "Administrator", "manage" );
}
catch( Exception ex )
{
Console.WriteLine("Connection to server failed, reason=" + ex );
return null;
}
// create the Concat service object
//(created by the Add-in for the pub.string:concat service)
Concat concatService = new Concat();
// populate the inputs
concatService.in_inString1 = string1;
concatService.in_inString2 = string2;
// invoke the service
concatService.invoke( serverContext );
// extract the output
returnString = concatService.out_value;
// disconnect from the server
serverContext.disconnect();
return returnString;
}
}
}