A. Configure Axis 2 in eclipse
Configure Axis 2 Runtime
1. Go to Windows - Preferences - Web services - Axis2 Preferences
2. Browse the location of Axis 2 API folder (for ex. axis2-1.4.1) in section Axis2 Runtime.
3. Check if the Axis2 runtime loaded successfully.
4. Click Apply and OK.
Configure web server
1. Go to Windows - Preferences - Server - Installed Runtimes
2. Click Add and choose server (for ex. Tomcat 5.5)
3. Browse the location of folder where server installed (for ex. apache-tomcat-5.5.25)
4. Configure installed JREs and select JRE to use.
5. Click Finish and OK.
Configure server and runtime for Web service
1. Go to Windows - Preferences - Web services - Server and Runtime
2. Select server (for ex. Tomcat 5x)
3. Select Web service Runtime (for ex. Apache Axis 2)
4. Click Apply and OK.
B. Generate stub code
1. Create a new project (Java or Web project)
2. Create a folder named "wsdl" in the web application and put your WSDL inside it.
3. Right click on WSDL file and choose Web services - Generate client
4. Check the configuration -
Server (for ex. Tomcat 5x)
Web service runtime (for ex. Apache Axis 2)
5. Click Next and at last, click Finish.
6. Check if the service Stub code is auto-generated.
Note: Axis 2 generates following classes in stubs :
a. Binding stub - For ex. Hello_BindingStub.java
b. Port type - For ex. Hello_PortType.java
c. Service Locator - For ex. Hello_ServiceLocator.java
d. Service - For ex. Hello_Service.java
C. Write client code
Write code in a separate class to call the web service.
STEPS :
a. Create an object of Service locator.
b. Create object of Binding stub by passing endpoint URL of service and service locator object.
c. Call web service method and get the result.
Example :
Hello_ServiceLocator locator = new Hello_ServiceLocator();
Hello_BindingStub stub = new Hello_BindingStub(
new URL(
"http//localhost:8081/HelloServer/services/Hello_Service"),
locator);
String result = stub.sayHello("SHAAN");
No comments:
Post a Comment
Note: only a member of this blog may post a comment.