Steps to Create a Web Service Using Axis2 - Client Code

I am trying to create a web service, my trading tools:

**

Axis2, Eclipse, Tomcat, Ant

**

I need to create a web service from code, i.e. write a base java class that will have methods for declaring in WSDL. Then use java2WSDL.sh to create my WSDL.

So this approach is correct:

  • Write my Java class with actual business logic
package packageNamel; public class Hello{ public void World(String name) { SOP("Hello" + name); } } 
  1. Now when I pass this Hello.java to java2WSDL.sh, it will give me WSDL.
  2. Finally, I will write the services.xml file and create Hello.aar with the following dir structure:

    Hello.aar

    • PACKAGENAME
      • Hello.class
    • META-INF
      • services.xml
      • MANIFEST.MF
      • Hello.WSDL

Now, I suppose my service will be deployed when I put aar in tomcat1 / webapps / axis2 / WEB-INF / services

But, here is my problem, HOW I ACCESS TO THE World(String name) ??? METHOD, that is, I do not know about the client code!

Please enlighten me by making a very simple web service and calling the method. The above 3 steps may be wrong. This is a community wiki, feel free to edit.

thank

+4
java web-services axis2
Apr 01 '10 at 8:33
source share
2 answers

I assume that you are only interested in web services clients?

Option 1

Calling a web service using Axis2 REST support , for example:

http: // localhost: 8080 / axis2 / services / MyService / myOperation? param1 = one & param2 = two

Option 2

Use SOAPUI . It can generate SOAP messages for you by reading your WSDL service. My client testers have made extensive use of this with a very broad understanding of web services technologies. An impressive tool.

Option 3

Groovy client (same approach for other JVM-based languages)

Use the wsdl2java tool to create a client stub class for the Shakespeare web service:

generate.sh

 $AXIS2_HOME/bin/wsdl2java.sh -d adb -s -o build -uri http://www.xmlme.com/WSShakespeare.asmx?WSDL ant -file build/build.xml 

GetSpeech.groovy

 // Dependencies // ============ import com.xmlme.webservices.ShakespeareStub @Grapes([ @Grab(group='org.apache.axis2', module='axis2-kernel', version='1.5.1'), @Grab(group='org.apache.axis2', module='axis2-adb', version='1.5.1'), @Grab(group='org.apache.axis2', module='axis2-transport-local', version='1.5.1'), @Grab(group='org.apache.axis2', module='axis2-transport-http', version='1.5.1'), @Grab(group='xerces', module='xercesImpl', version='2.6.2'), @GrabConfig(systemClassLoader=true) ]) // Main program // ============ def stub = new ShakespeareStub() // Request payload def request = new ShakespeareStub.GetSpeech() request.setRequest("Friends, romans, countrymen") // Send request response = stub.getSpeech(request) println response.getGetSpeechResult() 

Use the -cp parameter to add the generated code to the script class classpath

 groovy -cp build/build/classes GetSpeech 
+4
Apr 01 '10 at 23:45
source share

If you have access to WSDL, the following code / JAX -WS client can be used to call any SOAP-based web service.

 import java.net.URL; import javax.xml.namespace.QName; import javax.xml.ws.Service; public class WebserviceClient { public static void main(String[] args) throws Exception { URL url = new URL ("http://localhost:9999/ws/additionService?wsdl"); QName qname = new QName("http://test/", "AdditionServiceImplService");//Line 2 Service service = Service.create(url, qname); AdditionService additionService = service .getPort(AdditionService.class); System.out.println(additionService.add(1, 2)); } } 

On line 2, QName first argument is the namespace used in WSDL, and the second argument is simply the name of the service.

0
Sep 01 '15 at 19:03
source share



All Articles