Client Example in Microsoft .NET Home | KEA

CXL

Cmap Web Service

Layout Web Service

Client Example

This page demonstrates:
  • How to generate a client stub in Microsoft Visual C# 2005 from the WSDL of the Cmap Web Service and Layout Web Service
  • How to use the generated stub.
The source code for this example can be found at Client.zip. After downloading and extracting the Zip file, you should open the project file Client.csproj.

The source code for a more complete example can be found at CmapWSClient.zip with a tutorial. After downloading and extracting the Zip file, you should open the project file CmapWSClient.csproj.

The steps involved are:
  1. Create a project
  2. Generate the stub
  3. Use the stub
    1. Browse for a Cmap
    2. Get the Cmap, Lay it out and Save it back to the server

Create a project

Open Microsoft Visual C# 2005 and in the File menu, select the option "New Project...":



In our example we will create a simple console application called "Client". Select the template "Console Application" and type "Client" for the name of the project in the textbox labeled "Name" and click the "OK" button:



Your Microsoft Visual C# 2005 application will look as follows:


Generate the stub

In the Solution Explorer Frame, right click over the Client Project and select the option "Add Web Reference...":



A window will pop up. Enter "http://cmap.ihmc.us/xml/CmapTools.disco" in the text field labeled "URL" and click "Go":



The list of services defined in the Disco File will appear. Next, in the textbox labeled "Web reference name", enter a label for the namespace that you want to assign to the generated stub (in our example, we chose the label "CmapWS"). Then click the button "Add Reference":



In the Solution Explorer you should now see the reference to the Web Service:

Use the stub

In the Program.cs code window, add a using line to reference the stub namespace (in our case Client.CmapWS).

 
using Client.CmapWS;
 

In the main method of the same window declare and create an object of type CmapWebServiceBinding, which is the service stub for the Cmap Web Service, and an object of type LayoutWebServiceBinding, which is the service stub for the Layout Web Service, and set the appropriate URL to each of the services (replace the <server-address> with the address of the server where the services are hosted):

 
CmapWebServiceBinding cmapWs = new CmapWebServiceBinding();
cmapWs.Url = "http://<server-address>/services/CmapWebService";
 
LayoutWebServiceBinding layoutWs = new LayoutWebServiceBinding();
cmapWs.Url = "http://<server-address>/services/LayoutWebService";
 

Create an account list for using as credentials when calling the methods in the Cmap Web Service (replace the <user-id> and <password> with an user-id and password of an user with write permissions over the root folder, because we are going to write back a Cmap in that folder):

 
account acc = new account();
acc.userid = "<user-id>";
acc.password = "<password>";
 
account[] accountList = new account[] {acc};
 

Browse for a Cmap

Get the list of resources in the root folder:

 
resmetalist rootResMetaList = cmapWS.cmapWs.getRootResourceMetaList(accountList);
 

Iterate through the list to find a Cmap:

 
resmeta cmapResMeta = null;
foreach (resmeta rm in cmapResMeta.resmeta)
{
if (rm.format.Text[0] == "x-cmap/x-cxl")
{
cmapResMeta = rm;
break;
}
}
 

Get the Cmap, Lay it out and Save it back to the server

Now if a Cmap was found, retrieve it from the server, then lay it out with the Layout Web Service, and finally save it back to the server:

 
if (cmapResMeta != null)
{
cmap map = cmapWs.getCmap (cmapResMeta.identifier.Text[0], accountList);
layoutWs.layout(ref map);
cmapWs.saveCmap(cmapResMeta.identifier.Text[0], map, accountList);
}