Chapter 5: .NET Client for COM

You need to do the tutorials in this book in the order shown by the Tutorials Map.

You need Microsoft Visual Studio installed to do this session. We assume you are familiar with using Microsoft Visual Studio.

Overview

In this chapter you use a supplied C# client to call the COM object you deployed in the chapter Deploying a Service. Using Visual Studio, the chapter shows you how the client interfaces to the COM object.

You import the COM object into Visual Studio. Visual Studio generates a proxy program that invokes the COM object. A client application calls this proxy.

Preparation

Make sure the cmapserv service is deployed and registered under Windows, and the executable files of the COBOL application, Book.int and (for debugging) Book.idy, are in a folder on COBDIR, as described in the chapter Deploying a Service.

Import the COM Object

After opening CMapClient.sln in Visual Studio, you import the cmapserv.dll COM object you deployed in the chapter Deploying a Service. (If this tutorial has been run previously, delete the old cmapserv.dll from Visual Studio before importing the new one).

  1. Start Visual Studio, and load the source of the supplied sample program Examples\Net Express IDE\Mapdemo\Client\Microsoft.NET\COMClient\CMapClient.sln.
  2. Click Project > Add Reference to import the COM object into Visual Studio.
  3. Click the COM tab.
  4. Select cmapserv from the listbox, or browse to it at Examples\Net Express IDE\Mapdemo\REPOS\cmapserv.deploy\cmapserv.dll.
  5. Click OK.

The Client Source

This section shows you how the COM object is invoked from the client.

The file cmapclient.cs visible in the solution is the source code of the client application. Double-click cmapclient.cs to see the application source code.

In the supplied application, the following line invokes the COM object:

cmapserv comproxy = new comproxy(); 

and the following line calls the Next operation:

comproxy.Next(out fileStatus, 
              out title
              out type, 
              out author, 
              ref stockno, 
              out retail, 
              out onhand, 
              out sold, 
              );

Make the Data Files Accessible

The client and the service both run in the folder where the client application starts, so copying the data files to this folder will enable the service to find them:

  1. Copy bookfile.dat and bookfile.idx from Examples\Net Express IDE\Mapdemo to Examples\Net Express IDE\Mapdemo\Client\Microsoft.NET\COMClient\bin\debug.

    Visual Studio created the latter folder and put the executable file of the client there. The .dat and .idx files are the data and index parts of the indexed file that was supplied with the demo, and which you added one record to at the start of the chapter Creating a Service.

Run the Client

To run the client:

  1. In Visual Studio, click Debug > Run.
  2. Type 1111 as the stock number, leave the other fields blank, and click Read.

    After a few moments, the client displays the data from the requested record. It has successfully called the Web service, which has looked up the record in the file and returned the data.

    Try a few more operations. Recall from the chapter Creating a Service that the file as supplied contains records 1111 and 2222, and you may have added a record yourself - number 4444 if you used the example data suggested in that chapter.

  3. When you've finished, exit the application using its button.

Before Continuing...

This is the end of this path through the tutorials. To continue to another tutorial, go to the topic Tutorials and Demos.


Copyright © 2006 Micro Focus (IP) Ltd. All rights reserved.