Developing a .NET 1 or 2 client for WebSphere transport for SOAP using Microsoft Visual Studio 2012

Develop an .NET 1 or 2 web service client to run using the IBM MQ transport for SOAP.


Before you begin

Important: .NET Framework 2.0 is a prerequisite for this task, therefore make sure that we have it installed before you begin.

We can start the development of a .NET 1 or 2 client in a number of different ways:

  1. Use amqwdeployWMQService to generate client stubs from a web service and import them into Microsoft Visual Studio.
  2. Use java2wsdl to generate WSDL from a Java implementation of a web service, and then use wsdl.exe, which is shipped with .NET, to generate client stubs.
  3. Generate WSDL from a .NET .asmx implementation of the service using amqswsdl, and then use wsdl.exe.
  4. If we have developed and deployed the service for HTTP, use the Add Web reference... wizard in Microsoft Visual Studio to configure the client to access the HTTP service. Alter the URL refer to the service deployed to IBM MQ transport for SOAP.

The task uses the service developed in Developing a .NET 1 or 2 service for IBM MQ transport for SOAP using Microsoft Visual Studio 2012.


About this task

Follow these steps to create a .NET 1 or 2 Client for HTTP and IBM MQ transport for SOAP.


Procedure

  1. Create the client console application and modify it to invoke the StockQuote HTTP web service.
    1. Right click Solution 'StockQuoteDotNet' in the Solution Explorer > Add... > New Project. Select the C# Project Type, .NET Framework 2.0, and Console Application. Name the project StockQuoteClientDotNet > OK
    2. Right click Solution 'StockQuoteDotNet' in the Solution Explorer > Add... > New Project. Select the C# Project Type, .NET Framework 2.0, and Console Application. Name the project StockQuoteClientDotNet > OK
    3. Right-click StockQuoteClientDotNet > Set as Startup project.
    4. Right-click StockQuoteClientDotNet > Add Web Reference... > Browse to web services in this solution > Select StockQuote > Add Reference. Notice we have added a Web reference to local host and a new configuration file app.config.
    5. In the Solution Explorer, change the name of the console application from Program.cs to StockQuoteClientDotNet.cs > Click OK to changing all the usages of Program.cs to StockQuoteClientDotNet.cs.
    6. Replace the contents of StockQuoteClientDotNet.cs with the code inFigure 1.
      Figure 1. HTTP StockQuoteClientDotNet program
      using System;
      using StockQuoteClientDotNet.localhost;
      namespace StockQuoteClientDotNet {
        class StockQuoteClientDotNet {
          static void Main(string[] args) {
            try { 
              StockQuote stockobj = new StockQuote();
              Console.WriteLine("http reply is: " 
                + stockobj.getNonInlineQuote("http request");
            }
            catch (System.Exception e) {
              Console.WriteLine("Exception thrown: " + e.ToString());
            }
            Console.ReadLine();
          }
        }
      }
      
    7. Launch StockQuoteClientDotNet to test against the StockQuote.asmx service:
      1. Press F5, click the green arrow in the action bar, or Debug > Start Debugging (F5).

        If the StockQuoteDOtNet project is in the same solution, it starts automatically. Otherwise you need to start the service first.

        The command window with the results opens behind the workspace. The Console.ReadLine(); statement prevents it from closing until you press Enter.

      Tip: Make sure StockQuote.asmx is the Start page in the StockQuoteDotNet project.
  2. Modify StockQuoteClientDotNet to call the StockQuote.asmx service using IBM MQ transport for SOAP.
    1. Add the lines shown in bold to the client.
      Figure 2. Modified StockQuoteClientDotNet program
      using System;
      using StockQuoteClientDotNet.localhost;
      namespace StockQuoteClientDotNet {
        class StockQuoteClientDotNet {
          static void Main(string[] args) {
            try { 
              IBM.WMQSOAP.Register.Extension(); 
              StockQuote stockobj = new StockQuote();
              Console.WriteLine("http reply is: " 
                + stockobj.getNonInlineQuote("http request");
              stockobj.Url = "jms:/queue?"
                + "initialContextFactory=com.ibm.mq.jms.Nojndi"
                + "&connectionFactory=()&destination=REQUESTDOTNET@QM1"
                + "&targetService=StockQuote.asmx";         
              Console.WriteLine("jms reply is: " 
                + stockobj.getNonInlineQuote("jms request"));
            }
            catch (System.Exception e) {
              Console.WriteLine("Exception thrown: " + e.ToString());
            }
            Console.ReadLine();
          }
        }
      }
      

      Alternatively, modify the default URL. Open StockQuoteClientDotNet > Properties > Settings.settings and change the value of the StockQuoteClientDotNet_localhost_StockQuote property to the IBM MQ transport for SOAP URL.

    2. Add a reference to amqsoap.dll
      1. In the StockQuoteClientDotNet project in the Solution Explorer, right-click References > Add Reference... > Click the Browse tab > browse to MQ_INSTALLATION_PATH\bin > Select amqsoap.dll > OK. MQ_INSTALLATION_PATH is the directory where IBM MQ is installed.
  3. Test the client with the StockQuote.asmx service using IBM MQ transport for SOAP.
    1. Open a command window in the StockQuoteDotNet project directory: .\StockQuoteDotNet\StockQuoteDotNet > Verify that .bin\StockQuoteDotNet.dll exists. If it does not, rebuild the solution.
    2. Type the command amqwRegisterdotNet. You need only run amqwRegisterdotNet once per installation.
    3. If we have run amqwdeployWMQServer with the genAsmxWMQBits, run the .NET SOAP Listener: generated\server\startWMQNListener
    4. Alternatively run the listener directly:
      amqwSOAPNETListener -u "jms:/queue?
      destination=REQUESTDOTNET@QM1
      &connectionFactory=()&initialContextFactory=com.ibm.mq.jms.Nojndi
      &targetService=StockQuote.asmx&replyDestination=SYSTEM.SOAP.RESPONSE.QUEUE"
      -w C:\IBM\ID\StockQuoteDotNet\StockQuoteDotNet -n 10
      
  4. In Visual Studio 2012, press F5 to run StockQuoteClientDotNet.


.NET Framework 1 and .NET Framework 2 web service clients

The sample .NET clients provided with the IBM MQ transport for SOAP use generated stubs to call the sample Axis and .NET services.

For .NET Framework 1 and .NET Framework 2 clients, IBM MQ provides access to web services using .NET clients. The amqwdeployWMQService command has an option, genProxiestoDotNet, that generates .NET Framework 1 or .NET Framework 2 client stubs for a web service. We can also use client stubs generated by the .NET wsdl tool, or by Microsoft Visual Studio 2012.

The sample .NET Framework 1 and .NET web service clients are installed in MQ_INSTALLATION_PATH \tools\soap\samples\dotnet. MQ_INSTALLATION_PATH is the directory where IBM MQ is installed.

    SQVB2Axis.vb
    SQVB2Axis.vb,Figure 3, is the Visual Basic client to call the StockQuoteAxisService service.

    SQVB2DotNet.vb
    QVB2DotNet.vb,Figure 4, is the Visual Basic client to call the StockQuoteDotNet service.

    SQCS2Axis.cs
    SQCS2Axis.cs,Figure 5, is the C# client to call the StockQuoteAxisService service. We can override the URL of the service by providing a URL on the command line.

    SQCS2DotNet.cs
    SQCS2DotNet.cs,Figure 6, is the C# client to call the StockQuoteDotNet service. We can override the URL of the service by providing a URL on the command line.

Figure 3. SQVB2Axis
Module SQVB2Axis
   Function Main(ByVal CmdArgs() As String) As Integer
      IBM.WMQSOAP.Register.Extension()
      Dim obj As New StockQuoteAxisService()
      Dim res As Single = obj.getQuote("fromcs")
      System.Console.WriteLine("SQVB2Axis: reply is: '{0}'", res)
   End Function
End Module
Figure 4. SQVB2DotNet
Module SQVB2DotNet
   Function Main(ByVal CmdArgs() As String) As Integer
      IBM.WMQSOAP.Register.Extension()
      Dim obj as new StockQuoteDotNet()
      Dim res as Single = obj.getQuote("fromcs")
      System.Console.WriteLine("SQVB2DotNet: reply is: '{0}'", res)
   End Function
End Module
Figure 5. SQCS2Axis
using System;
class SQCS2Axis {
   [STAThread]
   static void Main(string[] args) {
      try {
         IBM.WMQSOAP.Register.Extension();
         StockQuoteAxisService stockobj = new StockQuoteAxisService();
         if (args.GetLength(0) >= 1) 
            stockobj.Url = args[0];
         System.Single res = stockobj.getQuote("XXX");
         Console.WriteLine("SQCS2Axis RPC reply is: " + res);
      }
      catch (System.Exception e) {
         Console.WriteLine("\n>>> EXCEPTION WHILE RUNNING SQCS2Axis DEMO <<<\n"
            + e.ToString());
      }
   }
}
Figure 6. SQCS2DotNet
using System;
class SQCS2DotNet {
   [STAThread]
   static void Main(string[] args) {
      try {
         IBM.WMQSOAP.Register.Extension();
         StockQuoteDotNet stockobj = new StockQuoteDotNet();
         if (args.GetLength(0) >= 1) 
            stockobj.Url = args[0];
         System.Single res = stockobj.getQuote("XXX");
         Console.WriteLine("RPC reply is: " + res);
         if (args.GetLength(0) == 0) {
            res = stockobj.getQuoteDOC("XXX");
            Console.WriteLine("DOC reply is: " + res);
      }
      catch (System.Exception e) {
         Console.WriteLine("\n>>> EXCEPTION WHILE RUNNING SQCS2DotNet DEMO <<<\n"
            + e.ToString());
      }
   }
}