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

Using the IBM webMethods add-in for Microsoft Visual Studio, you can connect to a running Integration Server and generate an object from an integration service. This sample uses the concat service.

To create a C# file from the concat service

Procedure

  1. Open Visual Studio .NET.
  2. Open a new .NET project using the Console Application template.
  3. On the Tools menu, click IBM webMethods Add-In for Microsoft Visual Studio.
    Note: If this menu item is not visible, make sure you have installed the add-in. For information on installing the add-in, see the IBM webMethods Package for Microsoft .NET Installation and User's Guide.
  4. In the IBM webMethods Add-In for Microsoft Visual Studio dialog box, provide the following information about the instance of Integration Server to which to connect:
    In this field... Type this...
    IBM webMethods Integration Server Integration Server host name and port in the format host:port.
    UserID Name of a valid user account on this Integration Server.
    Password Password for the user account. Passwords are case-sensitive.
  5. Click Connect. The IBM webMethods add-in for Microsoft Visual Studio window is displayed. This window contains a tree view of packages and services on the Integration Server to which you are connected.
    Tip: The add-in opens as a floating window. You can dock the window by dragging it to the Visual Studio .NET toolbar.
  6. In the Solution Explorer, select the Project under which you want to create the C# client code. If the Solution Explorer is not already open, in the View menu, click Solution Explorer.
  7. In the tree view of packages, go to the WmPublic.pub.string:concat service.
  8. Right-click the concat service and, click Generate Code, and then click C# Code.
  9. If the Solution Explorer is not already open, in the View menu, click Solution Explorer. The concat.cs file should be visible in the Solution Explorer panel.
  10. Add the references by doing the following:
    1. In the Solution Explorer panel, right-click the References node, and then click Add Reference.
    2. Click Browse tab and go to the default add-in directory for Visual Studio, where the IBM webMethods Add-In for Microsoft Visual Studio is installed.

      Typically, the IBM webMethods Add-In for Microsoft Visual Studio is installed in the directory C:\Documents and Settings\All Users\Application Data\Microsoft\MSEnvShared\Addins\

    3. Select CGUTIL.dll and wmClientAPI.dll.
    4. Click OK. The two DLLs should now appear under the References node in the Solution Explorer panel.

Results

The following sections provide brief descriptions of the sample code as they relate to Generating Microsoft .NET Clients:

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

The following sample shows the all of the C# code used in Generating a C# Client Code in Visual Studio but does not attempt to depict the end-to-end actions needed to create an executable:
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;  
  
    }  
  
  }  
}