Vous êtes sur la page 1sur 4

WEB Service application using AXIS 2 (using HTTP and SOAP protocol)

Step to create Web service application Step1 Open eclipse window->preferences->web service->Axis2 preferences Browse and give the path of Axis bin folder which downloaded before Step2 Create an Dynamic web project For example Test project Step3 Right click on Test project select project facet option And check the axis 2 web services Click apply->ok. Step4 Create an package in src on Test Exa Step5 Create an simple java class like Converter.java
package pckg; public class Converter { public float celsiusToFarenheit(float celsius) { return (celsius*9/5)+32; } public float farenheitToCelsius(float farenheit) {

pkg our package name.

return (farenheit-32)*5/9; } }

Step6 Now we need to create service.xml file Right click on project New->other->web services->web service file->next I) II) Choose web service type from new window Bottom up or Top down Service Implementation Browse select our class which is we created above Exa III) Converter.java

check Configuration server : Tomcat web service runtime : Apache axis 2 service project : Test (our project name)

then click on NEXT button Step7 We will see Axis 2 web service java bean configuration Select Generate default service.xml file Click on next button Step8 Start service window Click on start server

Step9 Now select default all check box displayed on new window Click on finish button Step10 Now run this project Run on Server Step11 Now we see apache software foundation page Click on server->convertor Then copy the URL Step12 Now we want to create client services Right click on project New->other->web services->web service client file Click on next button Paste the URL which is coped previously . Check all configuration as like step6 Step13 We want to create a class in our client project TestClient.java package pckg; import pckg.ConverterStub.CelsiusToFarenheit; import pckg.ConverterStub.CelsiusToFarenheitResponse;

public class ConverterClient {

public static void main(String[] args) { try { float celsiusValue = 100; ConverterStub stub = new ConverterStub();

CelsiusToFarenheit c2f = new CelsiusToFarenheit(); c2f.setCelsius(celsiusValue); CelsiusToFarenheitResponse res = stub.celsiusToFarenheit(c2f); System.out.println("Celsius : "+celsiusValue+" = "+"Farenheit : "+res.get_return()); } catch (Exception e) { e.printStackTrace(); } } } Step14 Now run this class as a java application..

All other classes are automatically generated which is not coped here . ConverterStub.java etc etc..

Vous aimerez peut-être aussi