Setting up and testing wsdl2java and axis2 webservice

I am very new to building web services, so please forgive my ignorance.

I was given some files .wsdl

with some .xsd

files it imports.

I was told that a web service can be created from a file .wsdl

using wsdl2java

from a project apache axis2

.

The web service I am trying to build expects data to be bound to it and I would like to validate it that I have a process right to pass data to the web service I created.

My actions are based on here , but not too sure how applicable it is.

I am on MacOSX but also have access to a ubuntu system.

the steps i have taken so far:

cd /directory/of/wsdl/file
wsdl2java.sh -uri tmp.wsdl -d adb -s

      

This creates a file build.xml

andsrc

Then I will try to run

ant 

      

or

ant jar.client

      

After that, I'm not too sure what to do to get the web server up and running so I can test it ... any suggestions would be greatly appreciated.

Thanks in advance.

+3


source to share


2 answers


In a SOAP web service: - The basic concept of a web service is that it has a consumer and a producer. The consumer is the one that consumes the web service, and the producer is the one that produces the web service. The manufacturer publishes their service for the consumer to use. It basically publishes a wsdl file so that you can generate client code or jar from it and can call it directly from your code. You can use a soapy interface to call a web service directly. If you are looking to generate producer code from wsdl, that won't be good enough as it won't provide you with the business logic and you have to implement it yourself. This is not recommended. As a rule, the first Java implementation is written and a wsdl is created on its basis, from which client banks are created in order toso that clients use the web service in their code. For direct testing, the manufacturer soapui is used. If you want to create a manufacturer, this is a straight forward process. You need to create a dynamic project in eclipse β†’ create a class β†’ use @WebService (serviceName = "xyz") for the class and similarly define @WebMethod at the method level. Deploy it as running on the server and you are done with the Hello World web service producer.Deploy it as running on the server and you are done with the Hello World web service producer.Deploy it as running on a server and you are done with the Hello World web service producer.

To create a client: -

Let's take an example of posted wsdl on the net as: -

http://www.webservicex.net/geoipservice.asmx?WSDL

      

First you need to create client jar or java classes as: -

wsimport -keep -s C:\wsdl http://www.webservicex.net/geoipservice.asmx?WSDL

      

Look at the documentation or look at the service name in the wsdl. This will be GeoIPService. Now in your class, call the webservice method like: -

package com.soap.client;

import net.webservicex.GeoIP;
import net.webservicex.GeoIPService;
import net.webservicex.GeoIPServiceSoap;
public class SoapWebServiceClient {

    public static void main(String[] args) {
        GeoIPService ipService = new GeoIPService();
        GeoIPServiceSoap gp = ipService.getGeoIPServiceSoap();
        GeoIP ip = gp.getGeoIP("117.198.208.1"); //google.com
        System.out.println(ip.getCountryName());
    }

}

      



Now similarly for local wsdl you can create classes and jars using axis 2 or just wsimport

Place your wsdl and schemas in a folder as shown below: -

C:\wsdl>wsimport -keep -s C:\wsdl C:\wsdl
C:\wsdl>wsimport -clientjar client.jar C:\wsdl

      

He will create a client for you. Have a look at the service name and similarly you can test the deployed service from java code as shown above.

To test using soapui, you need to download it and create a new soap project. Give a name and go to your local drive where all schemas and wsdl are present. It will create all your requests. You need to fill in the values ​​in the query parameters ("?") And start the service. If all goes well, the result will be displayed.

Note: -

wsimport is a command line tool for the JAX-WS reference implementation. JAX-WS RI uses JAXB for data binding.

Axis2 implements the JAX-WS API to some extent, so the Java artifacts generated can be quite different compared to those generated by the JAX-WS RI. Also Axis2 does not use JAXB, but instead offers a choice of ADB (default), Apache XmlBeans, or JiBX for data binding. The most widely used are either xmlbeans or JAXB.

+1


source


You are viewing the wsdl file from url post and reverse engineering the web service to generate types, so use wsimport



wsimport -d . -p servicesource -keep tmp.wsdl 

      

+1


source







All Articles