Search code examples
javajakarta-eesoapwsdlapache-axis

How does client and server connect in Axis2 Web service?


I am new to Axis2 Web services, and I tried to implement Axis2 from some simple tutorials. My code runs well in JavaEE with Tomcat server 7.0+, however I still haven't fully understood how client and server connect together. For that reason, I have a several general questions regarding to Axis2:

  1. What is the functions of the Stub.java file that is automatically generated in client side? I don't know how it functions, but it seems to handle the requests of the client side. Here is the code I need to implement to run from the client side:

    public static String getData(int code) throws RemoteException, MylittleShopParserConfigurationExceptionException, MylittleShopIOExceptionException, MylittleShopSAXExceptionException  {
    //When creating client web service, importing http://localhost:8080/Server/services/MylittleShop?wsdl (this is the xml file for
    //describing server-web service, it will tell the client how to compose a web service request and the interface that is
    // provided by the server ,all of thing contained in MylittleShopStub class.
    MylittleShopStub ser = new MylittleShopStub();
    GetData setCode =  new GetData();
    setCode.setCode(code);
    GetData1Response getCode = null;
    getCode = ser.getData1(setCode);
    return getCode.get_return();
    

    }

My service is simply to send a code (id) to the server to retrieve a dataset from the database.

  1. What I need to write in the client side is the function that is auto-generated based on the function I have in the server side. However, I only need to pass the necessary parameters then send back to the server to get the response. So how do the parameters in client side are handled uppon sending requests to the server?
  2. Do client and server communicate via HTTP?

Thank you in advance!


Solution

    1. MylittleShopStub.java is a java client model of the service. Practically what it does is what is mentioned in point 2. It converts the Java objects that model the client request to the appropriate XML, sends them to the server endpoint defined. Then receives the server response in XML format, creates the server response java object and returns it to the caller. The following quote might also help.

    Using the service is simply a matter of creating and populating the appropriate type of request using the names defined in the WSDL file, and then using the stub to actually send the request to the appropriate method.

    Axis 2 Creating Clients

    1. A WSDL Service understands and responds to XML documents that are submitted to the server. These XML should follow a specific XSD. At first the client encodes all the parameters in XML,and sends them to the server. Then the server parses the XML, it performs the defined operations and returns an XML to the client. The java client parses the XML and returns the result as a java object.

    2. Client and server can communicate over HTTP and HTTPS. Normally since you follow simple tutorials you use HTTP.

    About WSDL services WSDL (Web Services Description Language) is an XML language for describing Web services. So by definition WSDL web services are the web services that are describe and conform to the WSDL standard. A web service is in a sense a remote procedure call. A client program asks a server program to do "something" and (in most cases) return a result. WSDL defines an XML format that is used by client and server to communicate in a neutral, programming language independent, format. So basically the client and server programs send back and forth XML documents that describe the customer request and server response.