Chapter 9 .NET Client Support


Client setup

These steps require a .NET framework SDK, which you can download from the Microsoft .NET SDK download Web site :

  1. Copy the DotNETSample.wsdl interface file and DotNETSampleImpl.wsdl implementation file from the server machine to the .NET client machine.
  2. Run .NET's wsdl.exe command or a batch file to create the client proxy. You must supply the full path to the DotNETSampleImpl.wsdl and DotNETSample.wsdl files as arguments to wsdl.exe.

    Windows batch file, run.bat:

    wsdl c:\DotNETSampleImpl.wsdl  c:\DotNETSample.wsdl
    


    This creates the proxy file which contains the source code, including the same methods that are exposed in the Web service created in EAServer--it is the proxy for the Web service. Some things to keep in mind when running wsdl:

  3. Create the client executable program by writing a Client.cs program and compiling it using csc.exe in .NET. See "The client.cs file".

    Supply both the Client.cs and GreetingService.cs files as command line arguments when compiling:

    csc.exe Client.cs GreetingService.cs
    


    csc.exe is the C# compiler that comes with the .NET framework SDK. The result of running the csc command above is an executable program called Client.exe.

    Although the proxy file name is GreetingService.cs, the name of the proxy class is dotNETSampleGreetingService. If you open GreetingService.cs, you see:

    public class dotNETSampleGreetingService
    


    which is the same as the wsdl:service value minus the "/":

    <wsdl:service name= "dotNETSample/GreetingService">
    


    When the client creates an instance of the proxy, the proxy class name is used, not the proxy file name. In this case, dotNETSampleGreetingService is used, not GreetingService
  4. Run the client application:

    Client.exe
    


    The client uses GreetingService.cs to invoke the Web service by sending a SOAP request to the SOAP servlet identified by the http://<hostname:<portnumber>/WEBSERVICES/SOAP URL contained in the GreetingService.cs file, where hostname is the name of the machine where EAServer resides and portnumber is EAServer's HTTP port. The default HTTP port number is 8080. The host name is set by the JAGUAR_HOST_NAME setting in the /bin/setenv.bat (setenv.sh on UNIX machines) file located in the EAServer installation directory.

The client.cs file

This is the listing of the client.cs file:

using System;
using System.Drawing;
using  System.Collections;
using System.ComponentModel;
using  System.Windows.Forms;
using System.Data;

public  class Client 
{ 
    static void  Main(String[] args) 
    { 
        if  (args.Length == 0)
        {
    Console.WriteLine("usage:  client <name>");
            return;    
        }
        dotNETSampleGreetingService  srv = new dotNETSampleGreetingService();
        String  str = srv.sayHello(args[0]);
        Console.WriteLine(str);
    }
}

The GreetingService.cs proxy file

This is the listing of the GreetingService.cs proxy file

//------------------------------------------------------------------------
// <autogenerated>
//      This code was generated by a tool.
//      Runtime Version: 1.0.3705.0
//
//      Changes to this file may cause incorrect behavior and will be  lost if 
//     the code is regenerated.
// </autogenerated>
//---------------------------------------------------------------------------

//
// This  source code was auto-generated by wsdl, Version=1.0.3705.0.
// 
using  System.Diagnostics;
using System.Xml.Serialization;
using  System;
using System.Web.Services.Protocols;
using  System.ComponentModel;
using System.Web.Services;


/// <remarks/>
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Web.Services.WebServiceBindingAttribute(Name="dotNETSample/GreetingServiceBinding", Namespace="http://www.com.sybase.webservices/DotNETSampleImpl")]
public  class dotNETSampleGreetingService : System.Web.Services.Protocols.SoapHttpClientProtocol {
     
    /// <remarks/>
     public dotNETSampleGreetingService() {
         this.Url = "http://localhost:8080/WEBSERVICES/SOAP";
     }
    
    /// <remarks/>
     [System.Web.Services.Protocols.SoapRpcMethodAttribute("dotNETSample/Greeting.ejbCreate  return,void,return", RequestNamespace="", ResponseNamespace="")]
     [return: System.Xml.Serialization.SoapElementAttribute("return")]
     public string ejbCreate() {
        object[] results = this.Invoke("ejbCreate",  new object[0]);
        return ((string)(results[0]));
     }
    
    /// <remarks/>
     public System.IAsyncResult BeginejbCreate(System.AsyncCallback  callback, object asyncState) {
        return  this.BeginInvoke("ejbCreate", new object[0], callback, asyncState);
     }
    
    /// <remarks/>
     public string EndejbCreate(System.IAsyncResult asyncResult) {
         object[] results = this.EndInvoke(asyncResult);
         return ((string)(results[0]));
     }
    
    /// <remarks/>
     [System.Web.Services.Protocols.SoapRpcMethodAttribute("dotNETSample/Greeting.ejbActivate  return,void,return", RequestNamespace="", ResponseNamespace="")]
     [return: System.Xml.Serialization.SoapElementAttribute("return")]
     public string ejbActivate() {
        object[] results = this.Invoke("ejbActivate",  new object[0]);
        return ((string)(results[0]));
     }
    
    /// <remarks/>
     public System.IAsyncResult BeginejbActivate(System.AsyncCallback  callback, object asyncState) {
        return  this.BeginInvoke("ejbActivate", new object[0],  callback, asyncState);
    }
  
     /// <remarks/>
     public string EndejbActivate(System.IAsyncResult asyncResult) {
         object[] results = this.EndInvoke(asyncResult);
         return ((string)(results[0]));
     }
    
    /// <remarks/>
     [System.Web.Services.Protocols.SoapRpcMethodAttribute("dotNETSample/Greeting.ejbPassivate  return,void,return", RequestNamespace="", ResponseNamespace="")]
     [return: System.Xml.Serialization.SoapElementAttribute("return")]
     public string ejbPassivate() {
        object[] results = this.Invoke("ejbPassivate",  new object[0]);
        return ((string)(results[0]));
     }
    
    /// <remarks/>
     public System.IAsyncResult BeginejbPassivate(System.AsyncCallback  callback, object asyncState) {
        return  this.BeginInvoke("ejbPassivate", new object[0],  callback, asyncState);
    }
    
     /// <remarks/>
     public string EndejbPassivate(System.IAsyncResult asyncResult) {
         object[] results = this.EndInvoke(asyncResult);
         return ((string)(results[0]));
     }
    
    /// <remarks/>
     [System.Web.Services.Protocols.SoapRpcMethodAttribute("dotNETSample/Greeting.ejbRemove  return,void,return", RequestNamespace="", ResponseNamespace="")]
     [return: System.Xml.Serialization.SoapElementAttribute("return")]
     public string ejbRemove() {
        object[] results = this.Invoke("ejbRemove",  new object[0]);
        return ((string)(results[0]));
     }
    
    /// <remarks/>
     public System.IAsyncResult BeginejbRemove(System.AsyncCallback  callback, object asyncState) {
        return  this.BeginInvoke("ejbRemove", new object[0], callback, asyncState);
     }
    
    /// <remarks/>
     public string EndejbRemove(System.IAsyncResult asyncResult) {
         object[] results = this.EndInvoke(asyncResult);
         return ((string)(results[0]));
     }
    
    /// <remarks/>
     [System.Web.Services.Protocols.SoapRpcMethodAttribute("dotNETSample/Greeting.sayHello  return,java.lang.String,return in,java.lang.String" +
",p0",  RequestNamespace="", ResponseNamespace="")]
     [return: System.Xml.Serialization.SoapElementAttribute("return")]
     public string sayHello(string p0) {
         object[] results = this.Invoke("sayHello",  new object[] {
                     p0});
        return ((string)(results[0]));
     }
    
    /// <remarks/>
     public System.IAsyncResult BeginsayHello(string p0, System.AsyncCallback callback,  object asyncState) {
        return this.BeginInvoke("sayHello",  new object[] {
                     p0}, callback, asyncState);
    }
     
    /// <remarks/>
     public string EndsayHello(System.IAsyncResult asyncResult) {
         object[] results = this.EndInvoke(asyncResult);
         return ((string)(results[0]));
     }
}

 


Copyright © 2002 Sybase, Inc. All rights reserved.