Friday, October 1, 2010

Start to develop web service - part 2

step 1. download standard binary distribution.
if your OS is vista, select control panel - system - Advanced system settings, go to 'advanced' tab and click 'Environment  Variables...'
set AXIS2_HOME as the axis2 installation folder for the binary distribution.
Note: this step can not be skipped.

step 2. run this command in windows command window
C:\Users\andy>%AXIS2_HOME%\bin\wsdl2java -uri http://localhost:8080/axis2/services/SimpleService?wsdl -p client -s -o stub
-p: package name
-o: root folder for client source code
in my computer, the response message is as follows.
Using AXIS2_HOME:   E:\axis2-1.4.1
Using JAVA_HOME:    C:\jdk1.6.0_13
Retrieving document at 'http://localhost:8080/axis2/services/SimpleService?wsdl'
so you can find client source code C:\Users\andy\stub\src\client\SimpleServiceStub.java
I will not list the source code for this class. it's a little long and complicated.

Step 3. create a client class to call above SimpleServiceStub.java.
StubClient.java
package client;

public class StubClient {

 public static void main(String[] args) throws Exception {
  SimpleServiceStub stub = new SimpleServiceStub();
  SimpleServiceStub.GetGreeting gp = new SimpleServiceStub.GetGreeting();
  gp.setName("bill gates");
  System.out.println(stub.getGreeting(gp).get_return());
  System.out.println(stub.getPrice().get_return());
 }
}

run this class, you will see the result returned from web service.

No comments:

Post a Comment