WSDL2JAVA for developing Web Services Client

Its very convinent to create a Web Service Client using the tool WSDL2JAVA. Below are the steps to create one in Eclipse.

Step-1. Create a project in Eclipse ( we will call it testWSClient )

Step-2.  Create a new run time configuration in Eclipse by clicking on “Run” and the new run time configuration Icon on the pop-up dialog box.

I also offer online tutorial in java and whitebox if you are interested check it out. 

    1.  Main Tab –
      1. In the new Run-time config’s “Main” Tab enter “org.apache.axis.wsdl.WSDL2Java” for Main Class Test box
      2. Enter or Browse Project name “testWSClient”
      3. Type some name for this config in the name text box ( ex – runwsdl2java )
    2. Arguments Tab –
      1. Enter the following in the Argument Tab –  http://machinename.companyname.com:8080/module/services/servicemodule/MyService?wsdl -o src – This is the URL of the Web Service for which you want to generate Java code, and the command ” -o src” instructs wsdl2java to do just that
    3. Class Path Tab –
      1. Make sure you have  actvitation.jar, axis.jar, common-discovery.jar, common-logging.jar, commons-net.1.3.0.jar, javamail1.4.jar, jaxrpc.jar, saaj.jar and wsdl4j.jar in the classpath of your project and run time config

Step-3 –  Now Run the runwsdl2java by selecting it from the Run dropdown, you should see the following

  1. Objects with package details being created for “ComplexTypes” in the WSDL, these are plan data objects
  2. A Port Type Interface with Methods corrspoinding to “Port Types” created
  3.  Service and ServiceLocator classes created with methods
    1. getServiceHttpPort(java.net.URL portAddress)
    2. getServiceHttpPort()
  4. A HTTP Binding Stub Class

Note : It should be noted that all these classes are generated automatically by the wsdl2java tool.

Step-4 –  Now Write your Client to invoke and access the methods in the WSDL, and interact with the web services.

   NOte : Before we start make sure that the “ServiceHttpPort_address” variable in ServiceLocator class is pointing to the correct WSDL URL, which you provided when you were running the wsdl2java, it normally will be, but this is just a check, might not be required.

Now you can write a client, example below

public static void main(String[] args) throws MalformedURLException
{

Service service = new ServiceLocator();
try {
System.out.println(service.getServiceHttpPort().xyzMethod(getMyObject()));
}
catch (Exception e) {
System.out.println(e.toString());
}
 }

 private MyObject getMyObject() {

// Note this MyObject will be a complexType in the WSDL and generated by the wsdl2java tool, we are creating it to pass it to the method xyzMethod ( also in WDL as a Port Type and acccessible thru ServiceLocater) which takes MyObject as a parameter

  MyObject obj = new MyObject( someparameter);

}

Advertisements

16 Comments

Filed under webservice

16 responses to “WSDL2JAVA for developing Web Services Client

  1. daringtakers

    Thanks bro…
    I was looking for the same steps…

  2. daringtakers

    Thanks bro…
    I was looking for the same steps…

  3. Developer from Greece

    Thanks for the help! It worked fine! I just needed to add some extra jars in order WSDL2Java to run successfully and write a client!

  4. cazadore

    hi i am trying generate a stub class from wsdl and i used to your example but it doesnt work can u help me.

  5. cazadore

    hi i am trying to generate a stub class from wsdl an di used to your example but it doesnt work pls help

  6. cazadore

    hi the error message is java.lang.ExceptionInInitializerError.

  7. karun

    Could you help me to solve this….I am getting problem to call wsdl2jva generated classes since i am completely new to java. .i followed these steps to test webservices which i implemented in OO Perl:
    1. java org.apache.axis.wsdl.WSDL2Java http://www.cbs.dtu.dk/ws/SignalP/SignalP_3_1_ws0.wsdl
    2.I got and can see 3 folders have different files since we imported schemas from different location for wsdl file
    3.Main and the service named(SignalP_3_1_ws0.wsdl) folder has 4 java classes like bindingstuff, porttype, services and servicelocator
    4. I try to write client like public class javaClient
    {
    public static void main(String [] args) throws Exception {

    WSSignalP_3_1_ws0 service = new WSSignalP_3_1_ws0_ServiceLocator();
    system.out.println(service.runService(“id”,”sequence”,””));
    }

  8. i am not sure how it works in OO Perl, send me your class file i can take a look;

  9. Sheeraz Junejo

    I am having a problem as well…I am using a WSDL file instead of URL and wsdl2java is only generating two classes i.e. *CallBackHandler and *Stub nothing else…there is no sevrice or ServiceLocator to call.. do you know how to fix it…

    • SM

      This will depend on options, see more at -http://axis.apache.org/axis2/java/core/docs/reference.html
      selecting these will help :
      axis2-1.6.2\bin>wsdl2java -uri -o -ss -t
      -sd -g -or

  10. Pingback: Axis and SalesForce – WSDL2JAVA Process

  11. Pingback: Building Axis2/C Web Services with the help of Axis2/Java Tools … | free pdf download

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s