Home Tutorials News Software Online Money Web Designing
| Contact | Twitter

Web Services with Apache Axis 1.4 Tutorial: server and client sides

Web services are a handy method of integrating independent systems. Apache Axis is one of the best free tools available for implementing and deploying web services, and also for implementing the web service clients.

In this article we will create a simple, but complete web service and a client for this service step-by-step. Article will be explanatory as much as possible to succeed you in implementing it yourself alone after completing this tutorial.

Prerequisites

  • Must be familiar with Java
  • Familiar with basics on a web server like Tomcat
  • Some knowledge in configuring Axis will be an added advantage

System Configuration Requirements

We will be discussing the configuration in brief as our scope is mainly on web services. (If Axis already configured, jump to implementation). If you find any issues on the configuration part, you can refer to Apache Axis site for troubleshooting. (But if you can not solve it yourself do not worry, post the issue under the comments section in this article, and we’ll get back to you).

JDK installation
These examples have been tested on a machine with JDK 1.6 version.

Web Server
You must have a web server installed; and we will be using Tomcat (5.5 version) web server. If you are not having one, better download Tomcat here{link} and install it yourself (it is quite easy to install Tomcat). Now your CATALINA_HOME environment variable should point to the Tomcat installation directory.

Apache Axis 1.4
Download Apache Axis 1.4 here{link}. Extract the downloaded file and you’ll find a folder named “axis” inside webapps folder.
%Axis_1.4_dir%\webapps\axis
Copy this “axis” folder into your web server’s webapps folder.
%CATALINA_HOME%\webapps

CLASS PATH
Now you must add following libraries into your CLASSPATH environment variable. All of these are available under %Axis_1.4_dir%\lib folder.
  • axis.jar
  • commons-discovery.jar
  • commons-logging.jar
  • jaxrpc.jar
  • log4j-1.2.8.jar
  • saaj.jar
  • wsdl4j.jar
That’s all for configuring Axis 1.4 on your system, quite easy isn’t it? Let’s move on to the implementation part.


Implementation - web service and client

The implementation will consist of two parts. First we will implement web service part; a Calculator will be exposed as a web service. Next a client to use this Calculator web service will be implemented. (Client part starts from here).

Calculator Web Service

Implementing the web service consists of 7 steps. We will be explaining each step in detail.
  1. Functionality provider
  2. Web service’s interface
  3. Java2WSDL - Generate WSDL file
  4. WSDL2Java - Generate server side and client side classes for web service
  5. Bind Web service with Functionality provider
  6. Bundle required classes
  7. Register web service with axis

Project structure

Before starting coding, we'll have a look at the project structure. We are using a separate folder for the project, called "WS-Sample". We will be creating source (.java) files under "WS-Sample\src" folder and storing generated class (.class) files under a "WS-Sample\classes" folder.


1. Functionality provider

First we need to write class with calculator functionality before exposing it as a web service. We have implemented it as a pretty complex high end calculator class, named SimpleCalculator and it's listed below. (It is just a pretty simple class with three methods). This class has no information related to a web service and has been written as a simple independent class. So in the time this class was written, no one has thought of any web service stuff. But we will expose this class as a web service. (Yes, what you guessed is correct. Later you can expose your existing Java classes as web services.)

package org.kamal.wssample;

public class SimpleCalculator {

public int add(int a, int b) {
return a + b;
}
public int subtract(int a, int b) {
return a - b;
}
public int multiply(int a, int b) {
return a * b;
}
}

We'll compile above class using following command so that the generated .class file will reside in a folder named "classes" while preserving the package structure.

WS-Sample\src> javac -d ..\classes 
org\kamal\wssample\SimpleCalculator.java

2. Web service’s interface

Now we should write an interface that defines the services that will be provided by our web service. We will expose only two methods through our service; add() and subtract() methods (although we can expose any number of services within one web service). We did choose only two methods to emphasize the fact that we can control which methods we expose. And we will write this class in a separate package; org.kamal.wssample.ws.

package org.kamal.wssample.ws;

public interface Calculator {
int add (int x, int y);
int subtract(int x, int y);
}

And compile using following command.

WS-Sample\src> javac -d ..\classes 
org\kamal\wssample\ws\Calculator.java

3. Java2WSDL - Generate WSDL file


Axis has a tool called Java2WSDL, which generates a WSDL file for a web service using a Java class. We should use the Calculator interface and generate WSDL file as follows. Java2WSDL file requires the Calculator.class file (not Calculator.java) for the operation. Also we will provide the following information.
  • o – name for WSDL file -> calculator.wsdl
  • n – target namespace -> urn:org.kamal.calculator
  • l – url of web service -> http://localhost:8080/axis/services/calculator
WS-Sample\classes> java org.apache.axis.wsdl.Java2WSDL 
-o ..\calculator.wsdl
-n urn:org.kamal.calculator
-l http://localhost:8080/axis/services/calculator
org.kamal.wssample.ws.Calculator

This command will generate a file named calculator.wsdl inside your project folder.

4. WSDL2Java - Generate server side and client side classes for web service

Axis has another tool named WSDL2Java, which can generate server side and client side Java classes using a WSDL file. These classes are needed for deploying the web service and for accessing the service by a Java client. This tool must be provided with WSDL file that we generated in the previous step. It needs the following information as well.
  • o – output folder -> src
  • p – package for generated classes -> org.kamal.wssample.ws.generated
  • s – generate server side classes as well
WS-Sample> java org.apache.axis.wsdl.WSDL2Java 
-o src
-p org.kamal.wssample.ws.generated
-s
calculator.wsdl

Generated java classes will be saved in org.kamal.wssample.ws.generated package. This tool will generate five Java classes in this case with two .wsdd files as listed below.
  • Calculator.java
  • CalculatorService.java
  • CalculatorServiceLocator.java
  • CalculatorSoapBindingImpl.java
  • CalculatorSoapBindingStub.java
  • deploy.wsdd
  • undeploy.wsdd
Now we should compile those generated classes using the following command.

WS-Sample\src> javac –d ..\classes 
org\kamal\wssample\ws\generated\*.java

5. Bind Web service with Functionality provider

As you may have noted; even though we wrote org.kamal.wssample.SimpleCalculator class at the start, we have not used it so far. Now we are going to bind it to the web service.

There is a class named CalculatorSoapBindingImpl inside org.kamal.wssample.ws.generated package. This is the class used to bind our existing SimpleCalculator class to the web service calls. In CalculatorSoapBindingImpl class, there are two methods; add() and subtract(). In this class, we can use the SimpleCalculator to call the actual methods as follows.

package org.kamal.wssample.ws.generated;

import org.kamal.wssample.SimpleCalculator;

public class CalculatorSoapBindingImpl
implements org.kamal.wssample.ws.generated.Calculator{

private SimpleCalculator calc = new SimpleCalculator();

public int add(int a, int b) throws java.rmi.RemoteException {
return calc.add(a, b);
}

public int subtract(int from, int x) throws java.rmi.RemoteException {
return calc.subtract(from, x);
}
}

Just analyze the above class, all method calls are delegated to the actual implementation class SimpleCalculator inside this binding class.

6. Bundle required classes

Now we will create a jar file with all these classes, so that we can use it for deploying our web service. Use the jar command as follows.

WS-Sample\classes> jar cvf ..\calculatorServerSide.jar 
org\kamal\wssample\*.class
org\kamal\wssample\ws\*.class
org\kamal\wssample\ws\generated\*.class

Now copy this jar file into %CATALINA_HOME%\webapps\axis\WEB-INF\lib folder.

WS-Sample> copy calculatorServerSide.jar 
"%CATALINA_HOME%\webapps\axis\WEB-INF\lib"

We will create another jar file to use in the client side. For the client side we only need the classes that were generated by the WSDL2java tool (which are located inside org\kamal\wssample\ws\generated package), except the CalculatorSoapBindingImpl class.

WS-Sample\classes> jar cvf ..\calculatorClientSide.jar 
org\kamal\wssample\ws\generated\CalculatorSoapBindingStub.class
org\kamal\wssample\ws\generated\CalculatorServiceLocator.class
org\kamal\wssample\ws\generated\CalculatorService.class
org\kamal\wssample\ws\generated\Calculator.class

7. Register web service with axis

Axis comes with a tool for registering web services with Axis; it is called AdminClient. Look into org\kamal\wssample\ws\generated folder and you will find two WSDD (web service deployment descriptor) files; deploy.wsdd and undeploy.wsdd. These files were generated by WSDL2Java tool and as used in deploying/undeploying a web service.

Note: (Tomcat) Server must be started before executing the following command.

WS-Sample\src> java org.apache.axis.client.AdminClient 
org\kamal\wssample\ws\generated\deploy.wsdd

This command will deploy the web service into axis. Now restart (Tomcat) server.

To verify our web service is deployed correctly; try following url from your browser.
http://localhost:8080/axis/services/calculator?wsdl
(change the port 8080 in url to match the port on your machine)

This will show up a complete wsdl file, and it is the complete definition of the web service that we have deployed.

Now everything on web service (server side) is completed and our web service is successfully deployed.


Web Service client

Now it’s time for us to write a client to access this web service and use provided services. For this we need the calculatorClientSide.jar file that we created in an earlier step.

For the client side we will create a new project folder named “WS-Client” with sub folders named src, classes and lib. Copy the generated calculatorClientSide.jar file into the "WS-Client\lib" folder.


We will create the client as follows. Since our web service exposed two methods, add() and subtract(); client class will use the service and call those add() and subtract() methods.

package org.kamal.wsclient;

import org.kamal.wssample.ws.generated.Calculator;
import org.kamal.wssample.ws.generated.CalculatorService;
import org.kamal.wssample.ws.generated.CalculatorServiceLocator;

public class CalcClient {

public static void main(String[] args) throws Exception {
CalculatorService service = new CalculatorServiceLocator();
Calculator calc = service.getcalculator();

System.out.println("15 + 6 = " + calc.add(15, 6));
System.out.println("15 - 6 = " + calc.subtract(15, 6));
}
}

The above class has not used even a single class that we wrote for Calculator implementation, only a few classes that WSDL2Java tool generated. We have not exposed the server side classes, but just provided a way to get the service from those classes.

Compile the class with following command.

WS-Sample-Client\src> javac 
-classpath %CLASSPATH%;..\lib\calculatorClientSide.jar
-d ..\classes
org\kamal\wsclient\CalcClient.java

Now we can run our web service client using following command.

WS-Sample-Client\classes> java 
-cp %CLASSPATH%;.;..\lib\calculatorClientSide.jar
org.kamal.wsclient.CalcClient

You would see the following as the result.

15 + 6 = 21
15 – 6 = 9

Our web service client, CalcClient has accessed the web service and received the results from the operations done by SimpleCalculator class (which is running on server side).

As you can see, generating the client side is much easier than the server side.

Labels: , , , ,

Search Related Articles

Do you like this post?

Subscribe to get latest
Digg This! Digg this!
reddit it!Reddit it!
Bookmark in del.icio.usSave to Delicious
Print it
SlashdotSlashdot It!


Post a Comment

We appreciate your opinions, suggestions and criticism.

  1. Anonymous Anonymous (August 12, 2008 9:08 AM)  
    I'm new to web services. Thanks this helped me a lot.
  2. Nice work, thanks.
  3. Anonymous Anonymous (August 13, 2008 6:57 AM)  
    This is what i have been looking for simple easy to understand...my kind of tutorial


    thanks
    kris
  4. while Generating WSDL file using java2wsdl this exception occur.I have added mentioned jar files in classpath.pls help me


    E:\WS-Sample\src>java org.apache.axis.wsdl.Java2WSDL -o ..\calculator.wsdl -n ur
    n:org.kamal.calculator -l http://localhost:8080/axis/services/calculator org.kam
    al.wssample.ws.Calculator
    Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/axis/wsdl/
    Java2WSDL


    E:\WS-Sample\src>echo %CLASSPATH%
    E:\axis-1_4\lib
  5. This error has caused because your CLASSPATH is incorrect.

    CLASSPATH=E:\axis-1_4\lib

    In setting the CLASSPATH, you should point to your jar files rather than the lib directory like;
    CLASSPATH=E:\axis-1_4\lib\axis.jar;E:\axis-1_4\lib\commons-discovery.jar;.. etc.

    Try that and let me know whether you could resolve the issue.
  6. while compailing the generated class file the following is occur please help me,reply as soon as posible


    C:\Users\COMPAQ-GTI\Desktop\work\axis-ex\WS-Sample\src>javac -d C:\Users\COMPAQ-GTI\Desktop\work\axi
    s-ex\WS-Sample\classes.gen org\kamal\wssample\ws\generated\*.java
    org\kamal\wssample\ws\generated\CalculatorSoapBindingStub.java:32: as of release 1.5, 'enum' is a ke
    yword, and may not be used as an identifier
    (try -source 1.4 or lower to use 'enum' as an identifier)
    oper.setStyle(org.apache.axis.enum.Style.RPC);
    ^
    org\kamal\wssample\ws\generated\CalculatorSoapBindingStub.java:33: as of release 1.5, 'enum' is a ke
    yword, and may not be used as an identifier
    (try -source 1.4 or lower to use 'enum' as an identifier)
    oper.setUse(org.apache.axis.enum.Use.ENCODED);
    ^
    org\kamal\wssample\ws\generated\CalculatorSoapBindingStub.java:43: as of release 1.5, 'enum' is a ke
    yword, and may not be used as an identifier
    (try -source 1.4 or lower to use 'enum' as an identifier)
    oper.setStyle(org.apache.axis.enum.Style.RPC);
    ^
    org\kamal\wssample\ws\generated\CalculatorSoapBindingStub.java:44: as of release 1.5, 'enum' is a ke
    yword, and may not be used as an identifier
    (try -source 1.4 or lower to use 'enum' as an identifier)
    oper.setUse(org.apache.axis.enum.Use.ENCODED);
    ^
    4 errors
  7. Hi,

    As the error message shows, it's due an invalid use of 'enum' keyword. What is the version that you are using, 1.4 or 1.5?

    Let me know the followings you used.
    1. JRE version
    2. JDK version

    Cheers.
  8. Anonymous Anonymous (August 28, 2008 3:29 PM)  
    Uday's question:
    while deploying the web services the following occurs

    > java org.apache.axis.client.AdminClient org\
    kamal\wssample\ws\generated\deploy.wsdd
    Processing file org\kamal\wssample\ws\generated\deploy.wsdd
    Exception: AxisFault
    faultCode: {http://xml.apache.org/axis/}HTTP
    faultSubcode:
    faultString: (404)Not found
    faultActor:
    faultNode:
    faultDetail:
    {}:return code: 404

    The requested URL /axis/services/AdminService was not found on this server

    {http://xml.apache.org/axis/}HttpErrorCode:404
  9. Hi Uday,

    You must start Tomcat with Axis, before running this command. It seems your Tomcat server is not started yet. Try again after starting it.
  10. thanks for reply
    i started tomcat(5.5),my os is vista, i set classpath pointing to alljar files in axis 1.4\lib
  11. Hi Uday,

    Were you able to resolve the issue after starting Tomcat?
  12. thanks for replay

    I followed all the above steps
    I)os vista
    i)installed j2sdk 1.5
    2)installed tomcat 5.5
    3)installed axis 1.4

    i successfully executed all 6 steps above .
    started tomcat(5.5) and validated
    http://localhost:8080/axis/happyaxis.jsp
    while executing the error is occurring.
  13. Uday,

    In your error we see that the AdminService is not available.
    "The requested URL /axis/services/AdminService was not found on this server".

    So please verify your AdminService is up and running with following URL.

    http://localhost:8080/axis/services/AdminService?wsdl
  14. thanks for reply
    how to enable AdminService
  15. Uday, you don't have to enable it explicitly, it should be enabled by default. (Not sure whether there's any restrictions on Vista).
  16. Kamal Mettananda

    An Excellent article for a newbie like me. Keep it up.

    Thanks a lot.
  17. Hi Srinivas,

    Thanks for your appreciation. It really encourages me.

    Kamal
  18. C:\WS-Sample\src>java org.apache.axis.client.AdminClient org\kamal\wssample\ws\generated\deploy.wsdd
    Processing file org\kamal\wssample\ws\generated\deploy.wsdd
    Exception: AxisFault
    faultCode: {http://schemas.xmlsoap.org/soap/envelope/}
    Server.userException
    faultSubcode:
    faultString: org.xml.sax.SAXNotRecognizedException: Feature: http://xml.org/sax
    /properties/lexical-handler
    faultActor:
    faultNode:
    faultDetail:
    {http://xml.apache.org/axis/}
    stackTrace:org.xml.sax.SAXNotRecognizedExce
    ption: Feature: http://xml.org/sax/properties/lexical-handler
    at org.apache.xerces.jaxp.SAXParserImpl.
    setProperty(SAXParserImpl.java:1
    55)
    at org.apache.axis.encoding.
    DeserializationContext.parse(Deserialization
    Context.java:226) ....
  19. Hi Uday,

    Seems you have been able to resolve the AdminService issue.

    To resolve this exception, try adding the latest xerces jar to your class path.
  20. Excellent tutorial, You made me life simpler. You should start writing books.

    If you have similar tutorial on WS-Management and Wiseman implementation, please share with me. My email address vponnuru23@yahoo.com
  21. Hi vponnuru,

    I'm really happy to hear your comments. At this moment, this is the only tutorial on web services (read other tutorials here).
    Please subscribe through email or RSS (shown at the top of the site) to receive the latest content.
  22. Hi,

    When i am performing this step getting problem like
    D:\WS-Sample\src>java org.apache.axis.client.AdminClient org\kamal\wssample\ws\generated\deploy.wsdd
    Processing file org\kamal\wssample\ws\generated\deploy.wsdd
    Exception:: java.lang.NullPointerException

    Kindly help me for the same.

    Thanks,
    Manjesh Kumar
  23. Hi Manjesh,

    Don't worry, we'll work together and get this resolved.

    Can you post the complete stack trace, so that we can pick the place where this exception is thrown?
  24. I am trying to create WS according to your guidance steps. i have complete till 6th steps successfully but when i am trying to perform 7th step as following
    D:\WS-Sample\src>java org.apache.axis.client.AdminClient org\kamal\wssample\ws\generated\deploy.wsdd
    Processing file org\kamal\wssample\ws\generated\deploy.wsdd
    Exception:: java.lang.NullPointerException

    getting problem. Kindly help me.


    Regards,
    Manjesh Kumar
  25. Manjesh,

    Is this all that you see in the error message? Isn't there any other information in the error message?

    I will need some more information as this does not tell anything that can be used in resolving the issue.
  26. Hi,

    Can i get any link to create axis ws using SOAP Monitor.

    Thanks.

    Manjesh Kumar
  27. Tomcat 5.5
    JDK 6
    Axis 1.4
    Windows Vista

    When I try to access http://localhost:8080/axis/services/calculator?wsdl, I get an exception.

    Exception - java.lang.UnsupportedClassVersionError: Bad version number in .class file

    Did try few things but no success. Ultimate solution used Tomcat6. It worked.

    Hope this helps.
  28. Hi Manjesh,

    I'll try to post the details of setting up SOAP monitor as soon as possible. Please get subscribed through email, so that you will get notified.
  29. Hi,
    This UnsupportedClassVersionError error must be raised due to version issue described here.

    Anyway thanks for sharing it with our readers.
  30. Hi,

    Thanks, for such a nice article.Can u please also post some content on how to make a small part of already written application , a web service.My web App is already in place ,now i have to write a web service so that some PDF can access some functionality of my web App.Thanks, SS
  31. Hi,

    While I'm generating the server and client slide classes through the following command.

    E:\jakarta-tomcat-5.0.28\webapps\axis>java org.apache.axis.wsdl.WSDL2Java -o src -p org.kamal.wssample.ws.generated -s NHLService.wsdl

    I'm getting this error below:


    Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/axis/wsdl/WSDL2Java
  32. Hi,

    I'll try to provide you with a post on exposing existing functionalities as web services.
  33. Hi,

    // Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/axis/wsdl/WSDL2Java

    Your CLASSPATH variable does not point to all necessary .jar files. Just add them as I have mentioned at the start of the tutorial and try again.

    If you still have the issue, post us value of the CLASSPATH variable.
  34. Thanks, this is really helpful.

    I'm going to subscribe to your site to get updates.
  35. Hi Kamal, i have seen your article and it's really a good one for a newbie to web services. I hope you will help me with some issues in dealing with Apache Axis..I have generated a a server side classes from the given WSDL. Also, i have written a client side API which interfaces with those proxy classes, which i generated from the wsdl using axis..Now, i have written a client-side java program that uses the Client side API to invoke the service on the Server side...for that java program, i have to pass a SOAP request and i couldn't figure it out how all these pieces interact and come into work...any suggestions would be of great help...have a good day
  36. Thanks a lot, this is pretty good
  37. Hi

    Why I never found axis.jar in the lib folder? There are only axis2-adb-1.4.1.jar, axis2-adb-codegen-1.4.1.jar, axis2-kernel-1.4.1.jar... axix-*** jar files.

    Thanks.
  38. Hi,
    I am very new to Axis WS. i am trying to run simple WS but getting problem.
    1) First created AddFunction.java file as
    public class AddFunction
    {
    public int add(int a, int b){
    System.out.println("Inside of WS: A="+a+"and B="+b);
    int sum = a+b;
    System.out.println("SUM : "+sum);
    return sum;
    }
    }

    2) copy it to ..axis\AddFunction.java and renamed as AddFunction.jws
    3) created server-config.wsdd in axis\WEB-INF

    and also mapped AddFunction WS as service in server-config.wsdd file

    4) Now created Client side file (i.e AddFunctionClient.java) to call AddFunction WS as following
    import org.apache.axis.client.Call;
    import org.apache.axis.client.Service;

    import javax.xml.namespace.QName;

    public class AddFunctionClient
    {
    public static void main(String [] args) {
    try {
    if (args.length < 2){
    System.out.println("Usage:: java AddFunctionClient num1 num2");
    return;
    }
    int a = Integer.parseInt(args[0]);
    int b = Integer.parseInt(args[1]);
    String endpoint = "http://localhost:8080/axis/AddFunction.jws";

    Service service = new Service();
    Call call = (Call) service.createCall();
    call.setOperationName(new QName("http://localhost:8080/axis/AddFunction.jws", "add"));
    call.setTargetEndpointAddress( new java.net.URL(endpoint) );
    System.out.println("Usage:: ");
    Integer ret = (Integer) call.invoke( new Object[] { new Integer(a), new Integer(b)} );

    System.out.println("addInt(" + a + " + " + b + ") = " + ret);
    } catch (Exception e) {
    System.err.println("Execution failed. Exception: " + e);
    }
    }
    }

    5) When i am running the AddFunctionClient file by typing command as following
    java AddFunctionClient 10 20
    getting problem like
    Execution failed. Exception: java.lang.NullPointerException



    But on server side WS prited after getting call as
    17:08:06,833 INFO [STDOUT] Inside of WS: A=1and B=2
    17:08:06,833 INFO [STDOUT] SUM : 3


    Kindly sir let me know why i am geeting "Execution failed. Exception: java.lang.NullPointerException" problem at client side.

    or let me know other way if you have.

    Thanks in advance.

    Regards,
    Manjesh Kumar
  39. // Why I never found axis.jar in the lib folder

    Seems you have downloaded Axis2 rather than Axis 1.4. Please download Axis 1.4 from here.
  40. Hi Manjesh,

    To find out the place where NullPointerException is thrown, can you give the full stack trace of the exception.
  41. Hi Kamal,

    after executing all the steps, I got the following exception while running the client......... Can you say the reason. I didn't also got wsdl on IE for calculator

    -------------

    c:\WS-Sample\WS-Sample-Client\classes>java -classpath %CLASSPATH%;.;..\lib\calcu
    latorClientSide.jar org.kamal.wsclient.CalcClient
    - Unable to find required classes (javax.activation.DataHandler and javax.mail.i
    nternet.MimeMultipart). Attachment support is disabled.
    Exception in thread "main" AxisFault
    faultCode: {http://xml.apache.org/axis/}Server.NoService
    faultSubcode:
    faultString: The AXIS engine could not find a target service to invoke! target
    Service is calculator
    faultActor:
    faultNode:
    faultDetail:
    {http://xml.apache.org/axis/}hostname:IND-1K151BSH1

    The AXIS engine could not find a target service to invoke! targetService is cal
    culator
    at org.apache.axis.message.SOAPFaultBuilder.createFault(SOAPFaultBuilder
    .java:222)
    at org.apache.axis.message.SOAPFaultBuilder.endElement(SOAPFaultBuilder.
    java:129)
    at org.apache.axis.encoding.DeserializationContext.endElement(Deserializ
    ationContext.java:1087)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endEleme
    nt(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scan
    EndElement(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImp
    l$FragmentContentDispatcher.dispatch(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImp
    l.scanDocument(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(U
    nknown Source)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(U
    nknown Source)
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown So
    urce)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Un
    known Source)
    at javax.xml.parsers.SAXParser.parse(Unknown Source)
    at org.apache.axis.encoding.DeserializationContext.parse(Deserialization
    Context.java:227)
    at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:696)
    at org.apache.axis.Message.getSOAPEnvelope(Message.java:435)
    at org.apache.axis.handlers.soap.MustUnderstandChecker.invoke(MustUnders
    tandChecker.java:62)
    at org.apache.axis.client.AxisClient.invoke(AxisClient.java:206)
    at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
    at org.apache.axis.client.Call.invoke(Call.java:2767)
    at org.apache.axis.client.Call.invoke(Call.java:2443)
    at org.apache.axis.client.Call.invoke(Call.java:2366)
    at org.apache.axis.client.Call.invoke(Call.java:1812)
    at org.kamal.wssample.ws.generated.CalculatorSoapBindingStub.add(Calcula
    torSoapBindingStub.java:118)
    at org.kamal.wsclient.CalcClient.main(CalcClient.java:13)

    c:\WS-Sample\WS-Sample-Client\classes>
  42. //I didn't also got wsdl on IE for calculator
    First try the AxisServlet to get a list of all the services deployed on your Axis instance using following link.

    http://localhost:8080/axis/servlet/AxisServlet

    Check whether you can see your Calculator service there.
  43. Good job on this article. I'm having a problem with the last step. I got all the way to the web service client and am gettting a NullPointerException in the client code. It looks like the "service.getCalculator()" code returns null. I have deployed the service to the server and I am able to access the wsdl via
    http://localhost:8080/axis/services/calculator?wsdl

    Basically, when "calc.add()" is called in the client, the "calc" object is null.

    Does anybody have a clue what is wrong here?

    Thanks!
  44. thanks for your helpful tutorial. however, I get an error at "3. Java2WSDL - Generate WSDL file".
    when I want to execute the command:
    java org.apache.axis.wsdl.Java2WSDL -o ..\calculator.wsdl -n urn:org.kamal.calculator -l http://localhost:8080/axis/services/calculator org.kamal.wssample.ws.Calculator

    according to your instructions I always get this error:
    Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/axis/wsdl/
    Java2WSDL
    Caused by: java.lang.ClassNotFoundException: org.apache.axis.wsdl.Java2WSDL
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)

    I checked the classpath, I have all the mentioned .JAR files linked in there. I also execute the commans from the correct path "\WS-Sample\classes".

    any hints what else could be the problem?

    thank you!
  45. me again. I could solve the problem. solution for me was this command:
    set CLASSPATH=C:\axis-1_4\lib\axis.jar;C:\axis-1_4\lib\commons-discovery-0.2.jar;C:\axis-1_4\lib\commons-logging-1.0.4.jar;C:\axis-1_4\lib\jaxrpc.jar;C:\axis-1_4\lib\log4j-1.2.8.jar;C:\axis-1_4\lib\saaj.jar;C:\axis-1_4\lib\wsdl4j-1.5.1.jar;

    as a help for others. I first was searching to find the solution in Eclipse in the project. Although I had to set the classpath with the command prompt.
  46. Hi E-Nature,

    Thanks for sharing your experience with our readers.

    Another alternative to this is to set an Environment variable named CLASSPATH with these libs.
  47. Error at: "7. Register web service with axis"

    wrong:
    java org.apache.axis.client.AdminClient
    org\kamal\wsample\ws\generated\deploy.wsdd

    correct (with two 's'):
    java org.apache.axis.client.AdminClient
    org\kamal\wssample\ws\generated\deploy.wsdd
  48. Hi Kamal,

    I am getting following error, while deploying.Could you please, look at the same. I have provided all class path and path correctly.

    Exception: AxisFault
    faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
    faultSubcode:
    faultString: java.net.ConnectException: Connection refused: connect
    faultActor:
    faultNode:
    faultDetail:
    {http://xml.apache.org/axis/}stackTrace:java.net.ConnectException: Connection refused: connect
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
    at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
    at java.net.Socket.connect(Socket.java:519)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.axis.components.net.DefaultSocketFactory.create(DefaultSocketFactory.java:153)
    at org.apache.axis.components.net.DefaultSocketFactory.create(DefaultSocketFactory.java:120)
    at org.apache.axis.transport.http.HTTPSender.getSocket(HTTPSender.java:191)
    at org.apache.axis.transport.http.HTTPSender.writeToSocket(HTTPSender.java:404)
    at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:138)
    at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
    at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
    at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
    at org.apache.axis.client.AxisClient.invoke(AxisClient.java:165)
    at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
    at org.apache.axis.client.Call.invoke(Call.java:2767)
    at org.apache.axis.client.Call.invoke(Call.java:1792)
    at org.apache.axis.client.AdminClient.process(AdminClient.java:439)
    at org.apache.axis.client.AdminClient.process(AdminClient.java:404)
    at org.apache.axis.client.AdminClient.process(AdminClient.java:410)
    at org.apache.axis.client.AdminClient.process(AdminClient.java:320)
    at org.apache.axis.client.AdminClient.main(AdminClient.java:463)
  49. // faultString: java.net.ConnectException: Connection refused: connect

    Seems you haven't stared Tomcat before running the AdminClient. You must start Tomcat before running this.
  50. // correct (with two 's'):

    E-Nature, I'm fixing it right now.

    Thanks for pointing.
  51. Hi Kamal,

    Thanks for following answer, but I have started/restarted tomcat multiple times but without any success.

    I changed the command to
    java org.apache.axis.client.AdminClient -l http://localhost:8084/axis/services/AdminService /pathname/deploy.wsdd

    and it worked.


    // faultString: java.net.ConnectException: Connection refused: connect

    Seems you haven't stared Tomcat before running the AdminClient. You must start Tomcat before running this.
  52. Hi Kamal,

    Do you have any step by step example where a external webservice is called using axis(wsdl2java) e.g. StockQuote.

    Thanks.
  53. // java org.apache.axis.client.AdminClient -l http://localhost:8084/axis/services/AdminService

    As you have been running Tomcat on port 8084, the above url must be used.
  54. Hi Kamal,

    Thanks for your wonderful tutorial.
    Everything works fine for me but when i am trying to run the client i am getting exception, please find the stack trace below,
    Exception in thread "Main Thread" AxisFault
    faultCode: {http://xml.apache.org/axis/}Server.NoService
    faultSubcode:
    faultString: The AXIS engine could not find a target service to invoke! targetService is calculator
    faultActor:
    faultNode:
    faultDetail:
    {http://xml.apache.org/axis/}hostname:GBT

    The AXIS engine could not find a target service to invoke! targetService is calculator
    at org.apache.axis.message.SOAPFaultBuilder.createFault(SOAPFaultBuilder.java:222)
    at org.apache.axis.message.SOAPFaultBuilder.endElement(SOAPFaultBuilder.java:129)
    at org.apache.axis.encoding.DeserializationContext.endElement(DeserializationContext.java:1087)
    at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
    at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanEndElement(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
    at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
    at javax.xml.parsers.SAXParser.parse(SAXParser.java:375)
    at org.apache.axis.encoding.DeserializationContext.parse(DeserializationContext.java:227)
    at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:696)
    at org.apache.axis.Message.getSOAPEnvelope(Message.java:435)
    at org.apache.axis.handlers.soap.MustUnderstandChecker.invoke(MustUnderstandChecker.java:62)
    at org.apache.axis.client.AxisClient.invoke(AxisClient.java:206)
    at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
    at org.apache.axis.client.Call.invoke(Call.java:2767)
    at org.apache.axis.client.Call.invoke(Call.java:2443)
    at org.apache.axis.client.Call.invoke(Call.java:2366)
    at org.apache.axis.client.Call.invoke(Call.java:1812)
    at com.works.test.CalculatorSoapBindingStub.add(CalculatorSoapBindingStub.java:131)
    at com.works.test.service.client.TestClientAction.main(TestClientAction.java:17)


    Thanks,
    Vijay.
  55. Hi kamal,
    Thanks for the tutorial.

    Even if i started tomacat i am getting the exception
    Processing file org\sat\wssample\ws\generated\deploy.wsdd
    Exception: AxisFault
    faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
    faultSubcode:
    faultString: java.net.ConnectException: Connection refused: connect
    faultActor:
    faultNode:
    faultDetail:
    {http://xml.apache.org/axis/}stackTrace:java.net.ConnectException: Conne
    ction refused: connect

    could u please help as early as possible
  56. //Connection refused: connect

    What is the port that you are running tomcat?
  57. This is excellent place to start learning web services. I do a question regarding the WS-Sample and WS-Sample-client directories you created. Should they be part of the Axis directory that we copied under \tomcat\webapps\axis or these directories are seperate projects that run in tomcat\webapps?
  58. Hi Kamal,

    Thank you for the tutorial, It is very easy to understand.

    I am getting the following error when I try to register ws with axis. I read all comments and tried to enter this url on browser http://localhost:8080/axis/services/AdminService

    I receive the text on the browser as following:

    Hi there, this is an AXIS service!

    Perhaps there will be a form for invoking the service here...

    Look like the AXIS serivce is running, but I am not able to register it. Please give me advice.


    C:\Users\Huynh Le\workspace\WS-Sample\src>java org.apache.axis.client.AdminClient org\hle\wssample\ws\genera
    ted\deploy.wsdd
    Processing file org\hle\wssample\ws\generated\deploy.wsdd
    Exception: AxisFault
    faultCode: {http://xml.apache.org/axis/}HTTP
    faultSubcode:
    faultString: (404)Not found
    faultActor:
    faultNode:
    faultDetail:
    {}:return code: 404
    <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
    <HTML><HEAD>
    <TITLE>404 Not found</TITLE>
    </HEAD><BODY><H1>Not found</H1>
    The requested URL /axis/services/AdminService was not found on this server</B
    ODY></HTML>

    {http://xml.apache.org/axis/}HttpErrorCode:404

    Thank you
  59. Perfect, the only simple and strait forward Web Services tutorial on the web :))
  60. Configuring Axis1.4, tomact5.5 with jdk1.4 after configuring all are working fine. But while deployment I am not able to deploy wsdd file .In normal case tomcat 5.5 doesn’t support jdk 1.4,but after putting some jar inside tomcat 5.5 it’s working fine.I have added some jar (jmx.jar, xercesImpl.jar, xml-apis.jar) to make it tomcat5 compatible with jdk 1.4.
    I Configured like that:
    tomact 5.5
    Axis 1.4
    jdk 1.4
  61. Hi Kamal,

    Great job and Great mind!!

    A quick question that I have is, Axis 1.4 does not have bin directory, then how do I start the Axis server if I need.But Axis2 has bin folder.

    Thanks, Eas
  62. Hi Kamal,

    Even after verfying that the Tomcat is up and running, xerces.jar is in place and also updated in classpath (as below). I am getting the error that I have given below the classpath.

    **************************
    classpath:
    .;%JAVA_HOME%\lib;%ANT_HOME%\lib;C:\axis-1_4\lib\log4j.properties;C:\Program Files\QuickTime\QTSystem\QTJava.zip;C:\axis-1_4\lib\axis.jar;C:\axis-1_4\lib\commons-discovery-0.2.jar;C:\axis-1_4\lib\commons-logging-1.0.4.jar;C:\axis-1_4\lib\jaxrpc.jar;C:\axis-1_4\lib\log4j-1.2.8.jar;C:\axis-1_4\lib\saaj.jar;C:\axis-1_4\lib\wsdl4j-1.5.1.jar;C:\axis-1_4\lib\mail-1.4.jar;C:\axis-1_4\lib\activation-1.1.jar;C:\axis-1_4\lib\Xerces.jar;C:\axis-1_4\WS-Sample-Client\lib;C:\axis-1_4\WS-Sample-Client\lib\calculatorClientSide.jar;C:\axis-1_4\WS-Sample-Client\lib\xerces.jar;C:\axis-1_4\lib\xercesImpl.jar;C:\axis-1_4\lib\xercesSamples.jar;C:\axis-1_4\WS-Sample-Client\lib\xercesImpl.jar;C:\axis-1_4\WS-Sample-Client\lib\xercesSamples.jar;

    ***********************************
    Exception in thread "main" AxisFault
    faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
    faultSubcode:
    faultString: java.net.ConnectException: Connection refused: connect
    faultActor:
    faultNode:
    faultDetail:
    {http://xml.apache.org/axis/}stackTrace:java.net.ConnectException: Conne
    ction refused: connect
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
    at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
    at java.net.Socket.connect(Socket.java:520)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
    java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
    sorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at org.apache.axis.components.net.DefaultSocketFactory.create(DefaultSoc
    ketFactory.java:153)
    at org.apache.axis.components.net.DefaultSocketFactory.create(DefaultSoc
    ketFactory.java:120)
    at org.apache.axis.transport.http.HTTPSender.getSocket(HTTPSender.java:1
    91)
    at org.apache.axis.transport.http.HTTPSender.writeToSocket(HTTPSender.ja
    va:404)
    at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:138)

    at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrateg
    y.java:32)
    at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
    at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
    at org.apache.axis.client.AxisClient.invoke(AxisClient.java:165)
    at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
    at org.apache.axis.client.Call.invoke(Call.java:2767)
    at org.apache.axis.client.Call.invoke(Call.java:2443)
    at org.apache.axis.client.Call.invoke(Call.java:2366)
    at org.apache.axis.client.Call.invoke(Call.java:1812)
    at org.kalee.wssample.ws.generated.CalculatorSoapBindingStub.add(Calcula
    torSoapBindingStub.java:118)
    at org.kalee.wsclient.CalcClient.main(CalcClient.java:9)

    {http://xml.apache.org/axis/}hostname:48804B1

    java.net.ConnectException: Connection refused: connect
    at org.apache.axis.AxisFault.makeFault(AxisFault.java:101)
    at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:154)

    at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrateg
    y.java:32)
    at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
    at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
    at org.apache.axis.client.AxisClient.invoke(AxisClient.java:165)
    at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
    at org.apache.axis.client.Call.invoke(Call.java:2767)
    at org.apache.axis.client.Call.invoke(Call.java:2443)
    at org.apache.axis.client.Call.invoke(Call.java:2366)
    at org.apache.axis.client.Call.invoke(Call.java:1812)
    at org.kalee.wssample.ws.generated.CalculatorSoapBindingStub.add(Calcula
    torSoapBindingStub.java:118)
    at org.kalee.wsclient.CalcClient.main(CalcClient.java:9)
    Caused by: java.net.ConnectException: Connection refused: connect
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
    at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
    at java.net.Socket.connect(Socket.java:520)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
    java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
    sorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at org.apache.axis.components.net.DefaultSocketFactory.create(DefaultSoc
    ketFactory.java:153)
    at org.apache.axis.components.net.DefaultSocketFactory.create(DefaultSoc
    ketFactory.java:120)
    at org.apache.axis.transport.http.HTTPSender.getSocket(HTTPSender.java:1
    91)
    at org.apache.axis.transport.http.HTTPSender.writeToSocket(HTTPSender.ja
    va:404)
    at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:138)

    ... 11 more
    *********************************************************
  63. Dear Kamal,
    In continuation of my earlier comment, I rechecked once again carefully the classpath details and found that I had not linked the wsdl4j.jar. After correcting this and running step 3 for creating the wsdl file I get a message as under:
    WS-Sample\classes> java org.apache.axis.wsdl.Java2WSDL
    -o ..\calculator.wsdl
    -n urn:org.kamal.calculator
    -l http://localhost:8080/axis/services/calculator
    org.kamal.wssample.ws.Calculator

    log4j:WARN No appenders could be found for logger (org.apache.axis.i18n.ProjectResourceBundle)
    log4j:WARN Please initialize the log4j system properly
    java.lang.ClassNotFoundException: org.kamal.wssample.ws.Calculator

    could you please guide to proceed further?

    kbs.
  64. Hi kbs,

    Can you check whether this Calculator.class file is available inside classes/org/kamal/wssample/ws/ folder. This error means that the program can not find the specified .class file.

    Hope this helps.
  65. Hi Kamal,
    Thanks for your guidance. The class file was present but apparently it was due to my mistake of deleting the jre link in the classpath. Once this was rectified the wsdl creation went through. It did however give the following message.

    log4j: WARN no appenders could be found for logger (org.apache.axis.i18n.ProjectResourceBundle)
    log 4j: WARN please initialize the log4j system properly

    After running through all the steps, the final result however was interesting! (I am not sure if I would deserve a mathematics Nobel Prize for this!!)

    There was the same warning and the final output was
    15 + 6 = -3
    15 - 6 = -3
    The command line details are:
    C:\WS-Sample-Client\classes> java
    -cp %CLASSPATH%;.;..\lib\calcuatorClientSide.jar
    org.kamal.wsclient.CalcClient
    log4j: WARN no appenders could be found for logger org.apache.axis.i18n.ProjectResourceBundle
    log 4j: WARN please initialize the log4j system properly
    15 + 6 = -3
    15 - 6 = -3
    C:\WS-Sample-Client\classes>

    I am looking forward to your guidance.

    Thanks,
    kbs
  66. log4j warings: you can ignore them for the time being.

    But I can hardly guess how your results are always coming as -3. Have you checked your add() and subtract() methods?
  67. Hi Kamal,
    I did little more probing. The problem seems to stem from the wrong creation of CalculatorSoapBindingImpl.java. The coding is below. I wonder as to from it is picking up -3 and puts it as return value which is apparently leading to incorrect result. I have also appended the calculator.wsdl
    I have checked and rechecked both SimpleCalculator.java a well as Calculator.java to ensure that they are ok.
    Any clue?

    Thanks,
    kbs

    /**
    * CalculatorSoapBindingImpl.java
    *
    * This file was auto-generated from WSDL
    * by the Apache Axis 1.4 Apr 22, 2006 (06:55:48 PDT) WSDL2Java emitter.
    */
    /*
    package org.kamal.wssample.ws.generated;

    public class CalculatorSoapBindingImpl implements org.kamal.wssample.ws.generated.Calculator{
    public int add(int in0, int in1) throws java.rmi.RemoteException {
    return -3;
    }

    public int subtract(int in0, int in1) throws java.rmi.RemoteException {
    return -3;
    }

    }
    **********************
    (?xml version="1.0" encoding="UTF-8"?)
    (wsdl:definitions targetNamespace="urn:org.kamal.calculator" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="urn:org.kamal.calculator" xmlns:intf="urn:org.kamal.calculator" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema")
    (!--WSDL created by Apache Axis version: 1.4
    Built on Apr 22, 2006 (06:55:48 PDT)--)

    (wsdl:message name="addResponse")

    (wsdl:part name="addReturn" type="xsd:int"/)

    (/wsdl:message)

    (wsdl:message name="subtractRequest")

    (wsdl:part name="in0" type="xsd:int"/)

    (wsdl:part name="in1" type="xsd:int"/)

    (/wsdl:message)

    (wsdl:message name="subtractResponse")

    (wsdl:part name="subtractReturn" type="xsd:int"/)

    (/wsdl:message)

    (wsdl:message name="addRequest")

    (wsdl:part name="in0" type="xsd:int"/)

    (wsdl:part name="in1" type="xsd:int"/)

    (/wsdl:message)

    (wsdl:portType name="Calculator")

    (wsdl:operation name="add" parameterOrder="in0 in1")

    (wsdl:input message="impl:addRequest" name="addRequest"/)

    (wsdl:output message="impl:addResponse" name="addResponse"/)

    (/wsdl:operation)

    (wsdl:operation name="subtract" parameterOrder="in0 in1")

    (wsdl:input message="impl:subtractRequest" name="subtractRequest"/)

    (wsdl:output message="impl:subtractResponse" name="subtractResponse"/)

    (/wsdl:operation)

    (/wsdl:portType)

    (wsdl:binding name="calculatorSoapBinding" type="impl:Calculator")

    (wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/)

    (wsdl:operation name="add")

    (wsdlsoap:operation soapAction=""/)

    (wsdl:input name="addRequest")

    (wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:org.kamal.calculator" use="encoded"/)

    (/wsdl:input)

    (wsdl:output name="addResponse")

    (wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:org.kamal.calculator" use="encoded"/)

    (/wsdl:output)

    (/wsdl:operation)

    (wsdl:operation name="subtract")

    (wsdlsoap:operation soapAction=""/)

    (wsdl:input name="subtractRequest")

    (wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:org.kamal.calculator" use="encoded"/)

    (/wsdl:input)

    (wsdl:output name="subtractResponse")

    (wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:org.kamal.calculator" use="encoded"/)

    (/wsdl:output)

    (/wsdl:operation)

    (/wsdl:binding)

    (wsdl:service name="CalculatorService")

    (wsdl:port binding="impl:calculatorSoapBinding" name="calculator")

    (wsdlsoap:address location="http://localhost:8080/axis/services/calculator"/)

    (/wsdl:port)

    (/wsdl:service)

    (/wsdl:definitions)

    ***************
  68. Hi kbs,

    You haven't been following the steps, right? Have a look at step 5 named "Bind Web service with Functionality provider".
  69. Kamal,
    It would be nice if you can rewrite your tutorial with annotations. I thought by using annotations you don't need to do anything other than to write the class
  70. Hi Kamal,
    Thanks a lot for your guidance. I had indeed missed the crucial step 5. Once this was done it went through like a cake and I was delighted. Let me also join others in complimenting you for an excellent tutorial. While other tutorials give broad guidelines, yours was significantly different with minute details and step by step guidance. This brought home the concepts clearly.
    Now having had some idea of the whole process, I have a suggestion to make, for your consideration. We are compiling the generated classes in step 4 itself before tweaking/editing the CalculatorSoapBindingImpl class in step 5 to bind the Web service with Functionality provider. I therefore feel that compiling the generated classes should be done after step 5 and not before. This could possibly help the uninitiated like me who follow the tutorial.
    Thanks once again and looking forward to more such exhaustive tutorials in the days ahead.
    With regards,
    kbs.
  71. Hello Kamal,
    Is there a way to debug the webservices code particularly the server side API.
  72. Great tutorial!!! Very nice and very well explained...

    Cheers!!!
    jAY
  73. Just Excellent. Thanks a lot!!
  74. hi
    i want to create web service client using jsp..
    The web service is hosted on https://webservices.netsuite.com/wsdl/v2008_1_0/netsuite.wsdl
    how to invoke it in jsp....
    provie sample code if possble
    or some links
    please do help
  75. Ravi: create web service client using jsp..
    It seems you are not asking the correct question. JSP is not a place to call a web service, you better write a java client using the WSDL file.
  76. really nice work. it made my life simpler. thanks a lot -mathew
  77. Hi
    I am trying to create and deploy the sample application as it has been stated.But I get an error in the third step.I am not able to convert Java to WSDL.The trace is:


    C:\WS-Sample\classes>java org.apache.axis.wsdl.Java2WSDL
    Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/axis/wsdl/
    Java2WSDL
    Caused by: java.lang.ClassNotFoundException: org.apache.axis.wsdl.Java2WSDL
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)

    C:\WS-Sample\classes> -o ..\calculator.wsdl
    '-o' is not recognized as an internal or external command,
    operable program or batch file.

    C:\WS-Sample\classes> -n urn:org.kamal.calculator
    '-n' is not recognized as an internal or external command,
    operable program or batch file.

    C:\WS-Sample\classes> -l http://localhost:8080/axis/services/calculator
    '-l' is not recognized as an internal or external command,
    operable program or batch file.

    C:\WS-Sample\classes> org.kamal.wssample.ws.Calculator
  78. Excellent article!
    Just a note to people who run into the null being retured to the client: everytime you do step 4 (generate server-side classes), you have to re-do step 5 (call implementation method from web service impl).
  79. Thank U very much for the wonderful article which made my job easier.
  80. hi my question was to consume web services using jsp page..
    i am generated client proxy and packed the class files into jar files and using the jar files in my jsp...
    Is that the correct way to do???
    please give some inputs...
    thanks and regrds
    Ravi
  81. Hi,
    I tried doing the above steps by replacing the return type with my custom java class. That gives an "java.lang.reflect.InvocationTargetException" exception.
    What changes (if any) do I need to make to replace the integer return type with user-defined java class?
    Thanks
  82. Really great tutorial man. U r doing a great service. This tutorial helped me a lot with ma work. Thanks
  83. i'm not very good in java. when i try to do the compilation of the 5generated java files it generate an error saying

    javac: invalid flag: ud
    Usage: javac &lt option &gt &lt source files &gt

    can u please help me to solve this. regards.

    ps: nice tutorial. quite easy to understand
  84. Hi Kamal thank you very much for Providing a good sample.
    really it helped me a lot. i am new bie to Apache Axis.
  85. Anonymous Anonymous (April 02, 2009 10:13 AM)  
    Hi Kamal,

    Thanks a lot for sharing this material and it is very useful for me in learning webservices-Apache Axis (1.4). Please share us any information if you prepared on Axis 2.0

    Regards,
    Sarayu
  86. Anonymous Anonymous (April 09, 2009 3:03 PM)  
    Hi kamal,

    I am still having a little problem. I managed to follow every step of the tutorial, except the last one, the actual test.

    I allways get the stack wich you can find at the bottom.

    Can you help me? Thx in advance
    Tim

    My classpath is as follows, and the jars are there in that folder:
    C:\axis\axis.jar;C:\axis\commons-discovery-0.2.jar;C:\axis\commons-logging-1.0.4.jar;C:\axis\jaxrpc.jar;C:\axis\saaj.jar;C:\ax
    is\wsdl4j-1.5.1.jar;C:\axis\log4j-1.2.8.jar;

    Exception in thread "main" java.lang.Error: Unresolved compilation problems:
    org.apache cannot be resolved to a type
    org.apache cannot be resolved to a type
    javax.xml.rpc cannot be resolved to a type
    javax.xml.rpc cannot be resolved to a type
    javax.xml.rpc cannot be resolved to a type
    The method getcalculator(URL) from the type CalculatorServiceLocator refers to the missing type ServiceException
    javax.xml.rpc cannot be resolved to a type
    The constructor CalculatorSoapBindingStub() refers to the missing type AxisFault
    The method setPortName(String) is undefined for the type CalculatorSoapBindingStub
    org.apache cannot be resolved to a type
    javax.xml.rpc cannot be resolved to a type
    The constructor CalculatorSoapBindingStub() refers to the missing type AxisFault
    The method setPortName(String) is undefined for the type CalculatorSoapBindingStub
    javax.xml.rpc cannot be resolved to a type
    javax.xml.rpc cannot be resolved to a type
    javax.xml.rpc cannot be resolved to a type
    The method getPort(Class) from the type CalculatorServiceLocator refers to the missing type ServiceException
    The method getcalculator() from the type CalculatorServiceLocator refers to the missing type ServiceException
    The method getPort(Class) from the type CalculatorServiceLocator refers to the missing type ServiceException
    org.apache.axis.client.Stub cannot be resolved to a type
    javax.xml.rpc cannot be resolved to a type
    javax.xml.rpc cannot be resolved to a type
    javax.xml.rpc cannot be resolved to a type
    The method setEndpointAddress(String, String) from the type CalculatorServiceLocator refers to the missing type ServiceException

    at org.kamal.wssample.ws.generated.CalculatorServiceLocator.(CalculatorServiceLocator.java:10)
    at org.kamal.wsclient.CalcClient.main(CalcClient.java:14)
  87. Hi Sarayu, I'll try to prepare another tutorial with Axis 2.0.
  88. // Exception in thread "main" java.lang.Error: Unresolved compilation problems:

    Can you paste the command you are using to compile your classes?
  89. Anonymous Anonymous (April 09, 2009 3:50 PM)  
    Hey Kamal,

    I used exact the command mentioned in the tutorial
    I also tried it in Eclipse.

    I suppose my problem is in the client jar file. should there be a reference to the jaxrpc.jar somewhere?

    thx
    Tim
  90. As I have mentioned in the start, I was using jdk1.6 which includes these classes. If you are not using that, please try adding jaxrpc.jar into the classpath.
  91. Anonymous narayana (April 14, 2009 9:45 AM)  
    Hi Kamal,
    this is very nice and excellent tutorial for webservices.you done good job for beginners.
    i have faced one problem during running the webservice client.
    plz look into this problem and solve me asap.
    1. my tomcat is running under 8090 port number.oracle is running 8080 port in my system.so i have changed like that.
    2. while i am trying to registering webservice with AXIS.
    i.e.,java org.apache.axis.client.AdminClient org\kamal\wssample\ws\generated\deploy.wsdd
    i have faced the problem like this.
    > java org.apache.axis.client.AdminClient org\
    kamal\wssample\ws\generated\deploy.wsdd
    Processing file org\kamal\wssample\ws\generated\deploy.wsdd
    Exception: AxisFault
    faultCode: {http://xml.apache.org/axis/}HTTP
    faultSubcode:
    faultString: (404)Not found
    faultActor:
    faultNode:
    faultDetail:
    {}:return code: 404
    so i have changed registering like this.
    java org.apache.axis.client.AdminClient org\kamal\wssample\ws\generated\deploy.wsdd -p 8090
    so it is working fine and i have restarted the server and i saw calculator service in console.
    3. my actual problem is calling the webservice like
    java -cp %CLASSPATH%;.;..\lib\calculatorClientSide.jar org.kamal.wsclient.CalcClient
    i got this error
    Exception: AxisFault
    faultCode: {http://xml.apache.org/axis/}HTTP
    faultSubcode:
    faultString: (404)Not found
    faultActor:
    faultNode:
    faultDetail:
    {}:return code: 404

    Request you to look into my problem.is any wrong with port number.i am unable to change my oracle port no form 8080.
    waiting for your reply.
  92. Hi Narayana,

    Can you try changing the 3rd step as follows?

    WS-Sample\classes> java org.apache.axis.wsdl.Java2WSDL
    -o ..\calculator.wsdl
    -n urn:org.kamal.calculator
    -l http://localhost:8090/axis/services/calculator
    org.kamal.wssample.ws.Calculator
  93. Hi kamal,
    i have generated WSDL files using the port no 8090 like your suggestion only...
    I am looking forward to your guidance.
  94. dear kamal, i get an error in the 4th step when i try to run
    WS-Sample\src> javac –d ..\classes
    org\kamal\wssample\ws\generated\*.java

    the error is

    javac: invalid flag: ud
    Usage: javac &lt option &gt &lt source files &gt

    how to overcome this? waiting for your reply.
  95. Hi mIsTiK cHaZeR,

    Try replacing the "*.java" part with the correct named of the files.
  96. same error comes when i compile the files separately. is this error connected to the classpath?
  97. Yes it is related to the classpath. Can you verify that your classpath is correct?
  98. SET CLASSPATH=C:\axis-1_2_1\lib\activation.jar;.;C:\axis-1_2_1\lib\axis.jar;C:\axis-1_2_1\lib\axis-ant.jar;C:\axis-1_2_1\lib\jaxrpc.jar;C:\axis-1_2_1\lib\commons-discovery-0.2.jar;C:\axis-1_2_1\lib\commons-logging-1.0.4.jar;C:\axis-1_2_1\lib\wsdl4j-1.5.1.jar;C:\axis-1_2_1\lib\xalan-2.7.1.jar;C:\axis-1_2_1\lib\xercesImpl-2.9.1.jar;C:\axis-1_2_1\lib\xml-apis-1.3.04.jar;C:\axis-1_2_1\lib\mail.jar;C:\axis-1_2_1\lib\opensaml-1.1.jar;C:\axis-1_2_1\lib\wss4j.jar;C:\axis-1_2_1\lib\bcprov-ext-jdk15-140.jar;C:\axis-1_2_1\lib\bcprov-jdk15-140.jar;C:\axis-1_2_1\lib\xmlsec-1.4.0.jar;C:\axis-1_2_1\lib\log4j-1.2.8.jar;C:\axis-1_2_1\lib\saaj.jar;C:\axis-1_2_1\lib\xml-serializer-2.7.1


    this is my classpath.
  99. Are you facing this issue only when using the "javac" command for these classes? Can you create a sample java class in a package on your machine (not inside this project) and try to compile it?
  100. I just noticed something in your classpath.

    It ends as;

    ....;C:\axis-1_2_1\lib\saaj.jar;C:\axis-1_2_1\lib\xml-serializer-2.7.1

    The final jar file is not having the extension (xml-serializer-2.7.1.jar). Please correct that and try again.
  101. yes i can compile java files in other packages. i corrected that error but no use. so i changed the directory and went inside D:\Web Service Files\WS-Sample\src\org\ushan\wssample\ws\generated and compiled the files and generated the .class files in the same directory and then copied them in to D:\Web Service Files\WS-Sample\classes\org\ushan\wssample\ws\generated. is that ok. when i was doing so i got this >>>


    D:\Web Service Files\WS-Sample\src>cd org\ushan\wssample\ws\generated

    D:\Web Service Files\WS-Sample\src\org\ushan\wssample\ws\generated>javac *.java
    Note: CalculatorServiceLocator.java uses unchecked or unsafe operations.
    Note: Recompile with -Xlint:unchecked for details.

    D:\Web Service Files\WS-Sample\src\org\ushan\wssample\ws\generated>
  102. You can ignore those warning messages, however that is not the way to compile classes inside packages.

    I would suggest you to set the classpath explicitly inside command prompt with the required jar files and compile these classes from the src directory.
  103. i retried the process. i guess now it's working. i got this same message same as above. this is ok rite??

    D:\Web Service Files\WS-Sample\src>javac -d ..\classes org\ushan\wssample\ws\gen
    erated\*.java
    Note: org\ushan\wssample\ws\generated\CalculatorServiceLocator.java uses uncheck
    ed or unsafe operations.
    Note: Recompile with -Xlint:unchecked for details.

    D:\Web Service Files\WS-Sample\src>
  104. Ok, so your issue was in the classpath variable (missing .jar).

    You can ignore those warning messages for now.
  105. thanks kamal. this helped me a lot. i'll buzz u if there are any other issues that matters me. thanx again for the great help.
  106. dear kamal,

    i get the final out put of your tutorial successfully. it's really good and got a really nice understanding on web services. as i'm new to this topic i have more questions. is there a possible way to run this web service on a web browser and how to do that? and if i need to add two numbers which i like at the run time which files should i modify?
  107. i hav to say more that i hav followed your tutorial using axis 1.2.1 tomcat 5.5 and jdk 1.5. it seems this guide works fine with these configurations too.
  108. Hi mIsTiK cHaZeR,
    // if i need to add two numbers which i like at the run time

    You can use any number at the client side. As you can see from the CalcClient class, we pass the parameters to the web service in this class. So you only have to change the client class to pass runtime values.
  109. Anonymous Anonymous (April 21, 2009 12:38 AM)  
    Hi Kamal,

    Getting an error at step 4: WSDL2Java - Generate server side and client side classes for web service

    java -classpath "D:/lib/axis.jar;D:/lib/commons-discovery-0.2.jar;D:/lib/commons-logging-1.0.4.jar;D:/lib/jaxrpc.j
    ar;D:/lib/log4j-1.2.8.jar;D:/lib/saaj.jar;D:/lib/wsdl4j-1.5.1.jar;D:/lib/axis-ant.jar;D:/lib/activation.jar;D:/lib/mail.jar;."
    org.apache.axis.wsdl.Java2WSDL
    -o src
    -p sample.ws.generated
    -s
    calculator.wsdl

    Error: Unable to parse first argument for option -p
    Java2WSDL emitter
    Usage: java org.apache.axis.wsdl.Java2WSDL [options] class-of-portType

    What I am missing here?

    Thank you
  110. Anonymous Anonymous (April 21, 2009 6:29 AM)  
    Figured it out: wrong tool
    instead of Java2WSD should be WSDL2Java
  111. hi Kamal,
    i got an error when i try to run a different web service deployed according to this tutorial. it says

    D:\My TSD\Web Service Files\Customer Web Service\CustomerClient\classes>java -cp
    %CLASSPATH%;.;..\lib\customerClientSide.jar ushan.CustomerServiceClient
    AxisFault
    faultCode: {http://xml.apache.org/axis/}Server.NoService


    faultSubcode:
    faultString: The AXIS engine could not find a target service to invoke! target
    Service is CustomerService
    faultActor:
    faultNode:
    faultDetail:
    {http://xml.apache.org/axis/}hostname:tsd-e6336916066



    The AXIS engine could not find a target service to invoke! targetService is Cus
    tomerService
    at org.apache.axis.message.SOAPFaultBuilder.createFault(SOAPFaultBuilder
    .java:221)
    at org.apache.axi.............................................................................................................................................
  112. Anonymous Anonymous (April 25, 2009 6:02 PM)  
    Hi,

    I get the following error:

    java.lang.ClassNotFoundException: org.kamal.wssample.ws.Calculator
    at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:323)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:268)
    at org.apache.axis.utils.ClassUtils$2.run(ClassUtils.java:187)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.apache.axis.utils.ClassUtils.loadClass(ClassUtils.java:161)
    at org.apache.axis.utils.ClassUtils.forName(ClassUtils.java:100)
    at org.apache.axis.wsdl.fromJava.Emitter.setCls(Emitter.java:2079)
    at org.apache.axis.wsdl.Java2WSDL.run(Java2WSDL.java:584)
    at org.apache.axis.wsdl.Java2WSDL.main(Java2WSDL.java:682)

    My CLASSPATH includes all required libraries:

    /usr/share/java/axis/axis.jar:/usr/share/java/commons-discovery.jar:/usr/share/java/commons-logging.jar:/usr/share/java/axis/jaxrpc.jar:/usr/share/java/log4j.jar:/usr/share/java/axis/saaj.jar:/usr/share/java/wsdl4j.jar

    and I have replicated the directory strucutre exaclty as described in the article. Ijust do not know, how to get over this problem.

    I also tried to strace and ltrace the compilation. strace gives very little information. I do not see any attempt to touch the file whatsoever. ltrace end with "+++ killed by SIGTRAP +++". Total confusion on my side.
  113. Anonymous Anonymous (April 26, 2009 3:08 AM)  
    It turned out theat I did not have my current directory "." in my CLASSPATH, therefore the java2wsdl tool was not able to load the Calculator class.

    I ran into another problem - I could not deploy the service, because AdminService was not found. The reason was I installed Axis version 1.4.1 instead of Axis version 1.4, which is ni fact version 2.0. Very confusing. I spent several hours figuring out what went wrong. I could not understand the the AdminService just was not there.

    After this the example worked without any problem. An excelent tutorial. I am a complete newbie to web services.

    Just one remark - CalculatorSoapBindingImpl (step 5) has to be edited before compilation in step 4 takes place. Steps 4 and 5 have to be rearranged in the following way:

    A. generate server side and client side classes for web service
    B. bind Web service with Functionality provider
    C. compile

    I have nothing else to add. Great work. Thank you very much.
  114. Anonymous Anonymous (April 30, 2009 4:38 PM)  
    This is really Ultimate tutorial for the beginner.Thanks a lot for providing such good tutorial
    Kumar Saurabh
  115. Anonymous Anonymous (June 12, 2009 12:27 PM)  
    Hey Kamal

    Thanks for your posting.It is awsome.I am a new bee to webservices but working on live project.I am using axis 1.4 and soap 1.0.I wrote a client which calls a service using ssl over https.I wrote a callback handler to insert the security header tokens for authentication .i.e sending username,password,nonce and creation time.Now when i recieve the response i do get back security header along with envelope.Now i don't know what to do as i am getting following error.


    org.xml.sax.SAXException: SimpleDeserializer encountered a child element, which is NOT expected, in something it was trying to deserialize.
    at org.apache.axis.AxisFault.makeFault(AxisFault.java:101)
  116. Anonymous Anonymous (July 08, 2009 10:43 AM)  
    Hey, Kamal, its realy kamaaal.
    this post is realy hlpful for the people like me, the beginners.
    kp doing the gud job.

    thnx for the article
  117. Anonymous Anonymous (July 18, 2009 3:41 PM)  
    Great job man, keep it up.
  118. Anonymous Anonymous (July 23, 2009 11:14 AM)  
    This is really very good tutorial. I've seen many tutorials but no one mention clearly.
  119. Anonymous Anonymous (July 28, 2009 11:21 AM)  
    HI KAMAL

    THANKS FOR THIS TUTORIAL. IT HELPED US A LOT IN COMPLETING OUR MAJOR PROJECT WEBSERVICES.THE ONLY PROBLEM WE GOT IS WITH DATABASE CONNECTIVITY BUT LATER ON WE SOLVED IT WITH ORACLE DRIVER.
  120. PLS REPLY AS SOON AS POSSIBLE !!!

    Hi Kamal,

    Thanks for your tutorial. It is helping me ...

    On this step I am getting the exception on the browser

    AXIS error
    Sorry, something seems to have gone wrong... here are the details:

    Fault - ; nested exception is:
    org.apache.axis.ConfigurationException: Could not find class for the service named: org.sample.wssample.ws.generated.CalculatorSoapBindingImpl
    Hint: you may need to copy your class files/tree into the right location (which depends on the servlet system you are using).; nested exception is:
    java.lang.ClassNotFoundException: org.sample.wssample.ws.generated.CalculatorSoapBindingImpl
    AxisFault
    faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.generalException
    faultSubcode:
    faultString: Could not find class for the service named: org.sample.wssample.ws.generated.CalculatorSoapBindingImpl
    Hint: you may need to copy your class files/tree into the right location (which depends on the servlet system you are using).; nested exception is:
    java.lang.ClassNotFoundException: org.sample.wssample.ws.generated.CalculatorSoapBindingImpl
    faultActor:
    faultNode:
    faultDetail:
    {http://xml.apache.org/axis/}hostname:cpltn84qvsb

    Could not find class for the service named: org.sample.wssample.ws.generated.CalculatorSoapBindingImpl
    Hint: you may need to copy your class files/tree into the right location (which depends on the servlet system you are using).; nested exception is:
    java.lang.ClassNotFoundException: org.sample.wssample.ws.generated.CalculatorSoapBindingImpl
    at org.apache.axis.providers.java.JavaProvider.getServiceClass(JavaProvider.java:432)
    at org.apache.axis.providers.java.JavaProvider.initServiceDesc(JavaProvider.java:461)
    at org.apache.axis.handlers.soap.SOAPService.getInitializedServiceDesc(SOAPService.java:286)
    at org.apache.axis.deployment.wsdd.WSDDService.makeNewInstance(WSDDService.java:500)
    at org.apache.axis.deployment.wsdd.WSDDDeployableItem.getNewInstance(WSDDDeployableItem.java:274)
    at org.apache.axis.deployment.wsdd.WSDDDeployableItem.getInstance(WSDDDeployableItem.java:260)
    at org.apache.axis.deployment.wsdd.WSDDDeployment.getService(WSDDDeployment.java:427)
    at org.apache.axis.configuration.FileProvider.getService(FileProvider.java:231)


    Please help me. Also please let me know is it possible to include xsd validations in the wsdl ??? thanks in advance ... eagerly waiting for ur reply... Pls reply soon ...
  121. For:
    org.apache.axis.ConfigurationException: Could not find class for the service named: org.sample.wssample.ws.generated.CalculatorSoapBindingImpl

    It seems either you have changed the package structure or using incorrect package named, according to the originally package names following should be the correct name.
    org.kamal.wssample.ws.generated.CalculatorSoapBindingImpl

    If you have changed it, please check other locations that you haven't changed.
  122. Anonymous Anonymous (August 07, 2009 4:14 PM)  
    Very Nice , Clear and Greate Work.Thank You - Rajesh Kumar Raj
  123. Anonymous Anonymous (August 10, 2009 9:00 AM)  
    Hi Kamal,

    I am new with implementing WebServices with Axis. On reading your article I have few questions which is pretty not clear for me, can you please help me out with the following questions?

    1) In the 3rd step, you have mentioned the interface class alone to create the wsdl file and nowhere you havent mentioned the actual class, i.e SimpleCalculator.java when creating the wsdl file

    2) Then in the 4th step you perform the wsdl2java, in that you mention the wsdl file alone to create client and server side code to deploy and invoke the webservice.

    3) After doing wsdl2java, you get five automatically generated java classes. Out of which, in CalculatorSoapBindingImpl.java class how do you get the following line included?

    private SimpleCalculator calc = new SimpleCalculator().....

    and hows this possible? Because you havent mentioned of SimpleCalculator.java anywhere when creating the wsdl file or wsdl2java operation.
  124. Anonymous Anonymous (August 12, 2009 6:08 PM)  
    Hi Kamal

    I am done every thing on Weblogic 8.1 but whenever i run client.I am getting following exception.Please help me.....

    C:\WS-Workspace\WS-Client\class>java -classpath %CLASSPATH%;..\lib\calculatorCli
    entSide.jar com.xav.wsclient.CalcClient
    Exception in thread "main" AxisFault
    faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
    faultSubcode:
    faultString: java.lang.NullPointerException
    faultActor:
    faultNode:
    faultDetail:
    {http://xml.apache.org/axis/}hostname:xss-444

    java.lang.NullPointerException
    at org.apache.axis.message.SOAPFaultBuilder.createFault(SOAPFaultBuilder
    .java:222)
    at org.apache.axis.message.SOAPFaultBuilder.endElement(SOAPFaultBuilder.
    java:129)
    at org.apache.axis.encoding.DeserializationContext.endElement(Deserializ
    ationContext.java:1087)
    at org.apache.crimson.parser.Parser2.maybeElement(Unknown Source)
    at org.apache.crimson.parser.Parser2.content(Unknown Source)
    at org.apache.crimson.parser.Parser2.maybeElement(Unknown Source)
    at org.apache.crimson.parser.Parser2.content(Unknown Source)
    at org.apache.crimson.parser.Parser2.maybeElement(Unknown Source)
    at org.apache.crimson.parser.Parser2.parseInternal(Unknown Source)
    at org.apache.crimson.parser.Parser2.parse(Unknown Source)
    at org.apache.crimson.parser.XMLReaderImpl.parse(Unknown Source)
    at javax.xml.parsers.SAXParser.parse(Unknown Source)
    at org.apache.axis.encoding.DeserializationContext.parse(Deserialization
    Context.java:227)
    at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:696)
    at org.apache.axis.Message.getSOAPEnvelope(Message.java:435)
    at org.apache.axis.handlers.soap.MustUnderstandChecker.invoke(MustUnders
    tandChecker.java:62)
    at org.apache.axis.client.AxisClient.invoke(AxisClient.java:206)
    at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
    at org.apache.axis.client.Call.invoke(Call.java:2767)
    at org.apache.axis.client.Call.invoke(Call.java:2443)
    at org.apache.axis.client.Call.invoke(Call.java:2366)
    at org.apache.axis.client.Call.invoke(Call.java:1812)
    at com.xav.wssample.ws.generated.CalculatorSoapBindingStub.add(Calculato
    rSoapBindingStub.java:118)
    at com.xav.wsclient.CalcClient.main(CalcClient.java:14)
  125. Thanks for your swift reply.
    I am developing a small project which will help us to test the main application. To develop that I got a wsdl and xsd from them. I have installed all the below s/W,
    1. Jdk1.5
    2. Tomcat 6.0
    3. Apache Axis 1.4
    4. SOAP UI (instead of client)
    From given wsdl, I have generated server side classes (like stub, skeleton, other java classes and wsdd) by using wsdl2java tool. Then added all the compiled classes in the web-inf folder and deploy the service by using admin client tool.
    Now I am able to see the service in the axis service list page. From there I got a wsdl file and I am planning to use soapUI as client to test this project.Now if I use this wsdl (system generated) in soapUI client. It is throwing null pointer exception where as that wsdl (client provided) is not. I found the diff between the 2 version of wsdl.

    Continuing in the next comment.
  126. Great tutorial bhai. This was very useful to revise my Axis knowledge in less then 10 minutes and prepare for interview. Reading documents takes way too much time and this is what I needed.
    -Madhu
  127. Hi,
    while Generating WSDL file using java2wsdl this exception occur.i m using jboss-4.0.5.GA server and jdk1.6.0_11.
    java.lang.UnsupportedClassVersionError: org/kamal/wssample/ws/Calculator (Unsupp
    orted major.minor version 50.0)
    at java.lang.ClassLoader.defineClass0(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$100(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at org.apache.axis.utils.ClassUtils$2.run(ClassUtils.java:177)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.apache.axis.utils.ClassUtils.loadClass(ClassUtils.java:160)
    at org.apache.axis.utils.ClassUtils.forName(ClassUtils.java:100)
    at org.apache.axis.wsdl.fromJava.Emitter.setCls(Emitter.java:2079)
    at org.apache.axis.wsdl.Java2WSDL.run(Java2WSDL.java:584)
    at org.apache.axis.wsdl.Java2WSDL.main(Java2WSDL.java:682)

    Please help me.
  128. Hi, Please let me know what the problem is, I am trying to deploy on local OAS.
    I deployed Axis as a war on OAS.

    C:\Testws\WS-Sample\src>java org.apache.axis.client.AdminClient org\kamal\wssamp
    le\ws\generated\deploy.wsdd
    Processing file org\kamal\wssample\ws\generated\deploy.wsdd
    Exception: AxisFault
    faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
    faultSubcode:
    faultString: java.net.ConnectException: Connection refused: connect
    faultActor:
    faultNode:
    faultDetail:
    {http://xml.apache.org/axis/}stackTrace:java.net.ConnectException: Conne
    ction refused: connect
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
    at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
    at java.net.Socket.connect(Socket.java:507)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
    java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
    sorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at org.apache.axis.components.net.DefaultSocketFactory.create(DefaultSoc
    ketFactory.java:153)
    at org.apache.axis.components.net.DefaultSocketFactory.create(DefaultSoc
    ketFactory.java:120)
    at org.apache.axis.transport.http.HTTPSender.getSocket(HTTPSender.java:1
    91)
    at org.apache.axis.transport.http.HTTPSender.writeToSocket(HTTPSender.ja
    va:404)
    at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:138)

    at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrateg
    y.java:32)
    at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
    at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
    at org.apache.axis.client.AxisClient.invoke(AxisClient.java:165)
    at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
    at org.apache.axis.client.Call.invoke(Call.java:2767)
    at org.apache.axis.client.Call.invoke(Call.java:1792)
    at org.apache.axis.client.AdminClient.process(AdminClient.java:439)
    at org.apache.axis.client.AdminClient.process(AdminClient.java:404)
    at org.apache.axis.client.AdminClient.process(AdminClient.java:410)
    at org.apache.axis.client.AdminClient.process(AdminClient.java:320)
    at org.apache.axis.client.AdminClient.main(AdminClient.java:463)

    {http://xml.apache.org/axis/}hostname:SKAKKERLLWS1007
  129. Hi,
    while executing the web service client pgm( java -cp %CLASSPATH%;.;..\lib\calculatorClientSide.jar org.kamal.wsclient.CalcClient ), i got the following error:
    Exception in thread "main" java.lang.NoClassDefFoundError: org/kamal/wsclient/CalcClient
    Caused by: java.lang.ClassNotFoundException: org.kamal.wsclient.CalcClient
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    Could not find the main class: org.kamal.wsclient.CalcClient. Program will exit.

    please help me

    Thanks in advance..
    Nithya
  130. Thanks a lot Kamal, this is excellent tutorial for newbies.
    I am wondering if you can provide a way to for web clients to access the services.
    For example a form to access this service.
    I believe web services is for web clients most of the time.

    Thank you.
  131. Hello Kamal,
    I have follow all your steps, my last steps was
    cd WS-sample/src
    java org.apache.axis.client.AdminClient org/yagnesh/wssample/ws/generated/deploy.wsdd -p 8081
    Processing file org/yagnesh/wssample/ws/generated/deploy.wsdd

    Done processing

    ### but when I try to access http://localhost:8081/axis/services/calculator?wsdl

    I get this error:
    AXIS error

    Could not generate WSDL!

    There is no SOAP service at this location

    Any idea?
  132. // Anonymous (August 10, 2009 9:00 AM)
    // private SimpleCalculator calc = new SimpleCalculator().....
    // and hows this possible? Because you havent mentioned of SimpleCalculator.java anywhere when creating the wsdl file or wsdl2java operation.

    In Step 5: I have mentioned this; you are editing the generated BindingImpl class to delegate all method calls to this SimpleCalculator class.
  133. // 127. Anonymous (September 11, 2009 11:40 AM)
    // java.lang.UnsupportedClassVersionError: org/kamal/wssample/ws/Calculator (Unsupported major.minor version 50.0)

    This seems to be related to the JDK/JRE version issue. Please read the explanation here.
  134. // 128. Anonymous (September 24, 2009 1:08 AM)
    // Exception: AxisFault
    // faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
    // faultSubcode:
    // faultString: java.net.ConnectException: Connection refused: connect

    Seems you haven't stared Tomcat before running the AdminClient. You must start Tomcat before running this.
  135. // Nithya (September 24, 2009 3:10 PM)
    // Exception in thread "main" java.lang.NoClassDefFoundError: org/kamal/wsclient/CalcClient
    Caused by: java.lang.ClassNotFoundException: org.kamal.wsclient.CalcClient

    Hi Nithya,
    This is simply a classpath error; runtime could not find the CalcClient class. Please correct the classpath error and try again.

    Are you running this command from "classes" folder of the project?
  136. // 130. Anonymous (October 03, 2009 3:57 AM)
    // I am wondering if you can provide a way to for web clients to access the services.

    If you are trying to use the web services with a web application; you can use a Servlet to act as a client to your web services.
  137. // 131. Yagnesh (October 10, 2009 2:25 AM)
    // but when I try to access http://localhost:8081/axis/services/calculator?wsdl

    It seems you have started Tomcat on 8081? Have you correctly changed the WSDL generation step?
  138. Hello Kamal,
    Yes I did, as a matter of fact here are all the steps.

    cd WS-sample/classes
    java org.apache.axis.wsdl.Java2WSDL -o ../calculator.wsdl -n urn:org.yagnesh.calculator -l http://verity2.hwwilsonweb.com:8081/axis/services/calculator org.yagnesh.wssample.ws.Calculator
    cd WS-sample
    java org.apache.axis.wsdl.WSDL2Java -o src -p org.yagnesh.wssample.ws.generated -s calculator.wsdl

    javac -d ../classes org/yagnesh/wssample/ws/generated/*.java

    edit
    WS-sample/src/org/yagnesh/wssample/ws/generated/CalculatorSoapBindingImpl.java

    package org.yagnesh.wssample.ws.generated;

    import org.yagnesh.wssample.SimpleCalculator;

    public class CalculatorSoapBindingImpl implements org.yagnesh.wssample.ws.genera
    ted.Calculator{
    private SimpleCalculator calc = new SimpleCalculator();
    public int add(int in0, int in1) throws java.rmi.RemoteException {
    return calc.add(in0, in1);
    }

    public int subtract(int in0, int in1) throws java.rmi.RemoteException {
    return calc.subtract(in0,in1);
    }

    }

    recompile
    javac -d ../classes org/yagnesh/wssample/ws/generated/*.java

    create jar file:
    cd WS-sample/classes
    jar cvf ../calculatorServerSide.jar org/yagnesh/wssample/*.class org/yagnesh/wssample/ws/*.class org/yagnesh/wssample/ws/generated/*.class

    jar cvf ../calculatorClientSide.jar org/yagnesh/wssample/ws/generated/CalculatorSoapBindingStub.class org/yagnesh/wssample/ws/generated/CalculatorServiceLocator.class org/yagnesh/wssample/ws/generated/CalculatorService.class org/yagnesh/wssample/ws/generated/Calculator.class
    cd WS-sample/src
    java org.apache.axis.client.AdminClient org/yagnesh/wssample/ws/generated/deploy.wsdd -p 8081
    Processing file org/yagnesh/wssample/ws/generated/deploy.wsdd
  139. It is a very good tutorial for a beginner. Thank you very much Kamal for your effort. Keep it up! All the best!
    -Harihar
  140. Hi Kamal,
    Thanks for this wonderful tutorial, it helped me a lot.

    Can we customize the access url http://localhost:8080/MyApp/MyServices/calculator

    If yes, will we be able to use the AdminClient for registering webservice ?

    Also can we deploy Axis 1.4 web services on Oracle 9iAS ?

    Thanks in advance.
  141. Hi Kamal,

    Should we run the AdminClient to register webservice from the same machine where we are hosting webservices or can we run it remotely also ? Please advice, Thanks.
  142. Great Tutorial, one minor change required though. We need to customize the server Side classes BEFORE compiling them. This issue has also been mentioned by someone else( in comment number 113) and I quote that person again since the changes proposed by him have not yet materialized.Here it goes.

    "CalculatorSoapBindingImpl (step 5) has to be edited before compilation in step 4 takes place. Steps 4 and 5 have to be rearranged in the following way:

    A. generate server side and client side classes for web service
    B. bind Web service with Functionality provider
    C. compile"

    Thanks again for a great tutorial
    Ahsun Taqveem
  143. Hi,
    I am new in web services, I go through the above said way
    but I am getting an error when I am running the command

    C:\workspace\WS Sample>java org.apache.axis.wsdl.WSDL2Java -o src -p org.kamal.wssample.ws.generated -s calculator.wsdl

    I am getting an error like

    java.net.MalformedURLException: no protocol: calculator.wsdl
    at java.net.URL."init"(URL.java:567)
    at java.net.URL."init"(URL.java:464)
    at java.net.URL."init"(URL.java:413)
    at weblogic.apache.xerces.impl.XMLEntityManager.startEntity(XMLEntityManager.java:8
    at weblogic.apache.xerces.impl.XMLEntityManager.startDocumentEntity(XMLEntityManage
    at weblogic.apache.xerces.impl.XMLDocumentScannerImpl.setInputSource(XMLDocumentSca
    at weblogic.apache.xerces.parsers.DTDConfiguration.parse(DTDConfiguration.java:499)
    at weblogic.apache.xerces.parsers.DTDConfiguration.parse(DTDConfiguration.java:581)
    at weblogic.apache.xerces.parsers.XMLParser.parse(XMLParser.java:152)
    at weblogic.apache.xerces.parsers.DOMParser.parse(DOMParser.java:257)
    at weblogic.apache.xerces.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:2
    at weblogic.xml.jaxp.RegistryDocumentBuilder.parse(RegistryDocumentBuilder.java:149
    at org.apache.axis.utils.XMLUtils.newDocument(XMLUtils.java:369)
    at org.apache.axis.utils.XMLUtils.newDocument(XMLUtils.java:420)
    at org.apache.axis.wsdl.symbolTable.SymbolTable.populate(SymbolTable.java:482)
    at org.apache.axis.wsdl.gen.Parser$WSDLRunnable.run(Parser.java:361)
    at java.lang.Thread.run(Thread.java:619)

    Please help me.Thanks in advance.
  144. Hi

    I am new in web services,I am getting an error when I am executing dos command on point 4 as

    C:\workspace\WS Sample>java org.apache.axis.wsdl.WSDL2Java -o src -p org.kamal.wssample.ws.generated -s calculator.wsdl

    I am getting the following error
    java.net.MalformedURLException: no protocol: calculator.wsdl
    at java.net.URL.init(URL.java:567)
    at java.net.URL.init(URL.java:464)
    at java.net.URL.init(URL.java:413)
    at weblogic.apache.xerces.impl.XMLEntityManager.startEntity(XMLEntityManager.java:836)
    at weblogic.apache.xerces.impl.XMLEntityManager.startDocumentEntity(XMLEntityManager.java
    at weblogic.apache.xerces.impl.XMLDocumentScannerImpl.setInputSource(XMLDocumentScannerIm
    at weblogic.apache.xerces.parsers.DTDConfiguration.parse(DTDConfiguration.java:499)
    at weblogic.apache.xerces.parsers.DTDConfiguration.parse(DTDConfiguration.java:581)
    at weblogic.apache.xerces.parsers.XMLParser.parse(XMLParser.java:152)
    at weblogic.apache.xerces.parsers.DOMParser.parse(DOMParser.java:257)
    at weblogic.apache.xerces.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:201)
    at weblogic.xml.jaxp.RegistryDocumentBuilder.parse(RegistryDocumentBuilder.java:149)
    at org.apache.axis.utils.XMLUtils.newDocument(XMLUtils.java:369)
    at org.apache.axis.utils.XMLUtils.newDocument(XMLUtils.java:420)
    at org.apache.axis.wsdl.symbolTable.SymbolTable.populate(SymbolTable.java:482)
    at org.apache.axis.wsdl.gen.Parser$WSDLRunnable.run(Parser.java:361)
    at java.lang.Thread.run(Thread.java:619)

    Please help me.Thanks in Advance
  145. Hi Kamal,

    I go through your tutorials and run the web services.Initially I found some issue in making the server side as well as Client side java core generation.But finally I run the application.It really a nice tutorials for the new Web services developer.
    It will be nice if you add the tutorials for the Apache Axis2.It really a nice work.Thanks a lot.

    Thanks
    Chhote
ARCHIVES
Select Month:
ABOUT AUTHOR
Kamal Mettananada is a Software Architect, Java Explorer and Blogger. Digizol consists of computer related articles, tutorials, tips and other information.

Free counter and web stats

Subscribe to our feed using your online news reader, approximately 1-2 articles per week.
^top^