3

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

I have been given some an .wsdl files with some .xsd files that it imports.

I am told that a web-service can be created from the .wsdl file by using wsdl2java from the apache axis2 project.

The web-service I am trying to build is expecting to have data pushed to it and I would like to test it that I have the process right for data to be pushed to a web-service that I created.

The basis for my actions have been from here, but not too sure how much of it is applicable.

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

the steps I have taken so far are:

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

This creates a build.xml file and src directory

I then try and run

ant 

or

ant jar.client

After this I am not too sure what to do, in order to get the web-server running so that I could test it...any suggestions would be greatly appreciated.

Thanks in advance.

f_puras
  • 2,521
  • 4
  • 33
  • 38
h.l.m
  • 13,015
  • 22
  • 82
  • 169
  • Try the `-ss` option to generate a skeleton for the server. – approxiblue Aug 11 '15 at 03:00
  • 1
    is that in the `wsdl2java.sh -uri tmp.wsdl -d adb -s` line? i.e. converting it to `wsdl2java.sh -uri tmp.wsdl -d adb -s -ss`? – h.l.m Aug 11 '15 at 08:10
  • How would you also test the new service? – h.l.m Aug 11 '15 at 08:25
  • If you add that option you should get a skeleton class for the web service. Then [you deploy it](https://axis.apache.org/axis2/java/core/docs/userguide-buildingservices.html#deployrun). – approxiblue Aug 11 '15 at 14:08

2 Answers2

1

In SOAP web service:- The basic concept in web service is that it has consumer and producer. A consumer is one which consumes a web service and a producer is one which produces a web service. A producer publish its service so that consumer can consume it. It basically publishes a wsdl file so that you can create a client code or jar out of it and can directly call it from your code. You can use soap UI to call the web service directly as well. If you are looking for generating producer code from wsdl as well it will not be good enough since it will not provide business logic to you and you need to implement it by yourself. This is not a recommended approach. Generally first java implementation is written and based on it a wsdl is created from which client jars are created for the clients to use the web service in their code. For directly testing the producer soapui is used. If you want to create producer it is a straight forward process. Need to create a dynamic project in eclipse-->create a class-->use @WebService(serviceName="xyz") on class and similarly on method level define @WebMethod. Deploy it as run on server and you are done with your Hello World Web service producer.

For creating the client:-

Lets take an example of a published wsdl on the net as :-

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

First you need to create the 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. It will be GeoIPService. Now in your class call the webservice method as:-

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 by using axis2 or simply wsimport

Put 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

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

For testing using soapui you use need to download it and create a new soap project. Give any name and browse to your local drive where all the schema and wsdl is present. It will create all the requests for your. You need to fill in the values in the request parameters ("?") and run the service. If everything went well it will display a result.

Note:-

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

Axis2 merely 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 doesn't use JAXB but instead offers the choice of ADB (default), Apache XmlBeans, or JiBX for data-binding. The most popularly used are either xmlbeans or JAXB.

Goyal Vicky
  • 1,249
  • 16
  • 16
  • Moreover can have a look at http://stackoverflow.com/questions/22460571/how-do-you-convert-wsdl-to-java-classes-using-eclipse – Goyal Vicky Aug 15 '15 at 11:30
1

You lookup the wsdl file from publishing URL and reverse engineer the webservice to generate the types so use wsimport

wsimport -d . -p servicesource -keep tmp.wsdl 
karim mohsen
  • 2,164
  • 1
  • 15
  • 19