Thursday, December 07, 2006

Basic web service implementation

This post describes how to implement a simple webservice using Weblogic, Eclipse, and Apache Axis. We will go through these steps to implement the Webservice
  1. Enable Weblogic domain for WebServices
  2. Create a simple web service class.
  3. Auto-generate WebServices classes in Eclipse
  4. Auto-generate the classes for calling the web service.
  5. Create a Client Application
  1. Enable Weblogic domain for WebServices: Follow these steps to enable your weblogic domain for web services.
    1. Start the Configuration Wizard (c:/bea9.2/weblogic92/common/bin/config.cmd)
    2. In the Welcome window, select Extend an Existing WebLogic Domain. Click Next.
    3. Select the domain to which you want to apply the extension template. Click Next.
    4. Select Extend My Domain Using an Existing Extension template.
    5. Enter the following value in the Template Location text box: WL_HOME/common/templates/applications/wls_webservice.jar. Click Next.
    6. Select no. Click next.
    7. Verify that you are extending the correct domain, then click Extend.
  2. Create a simple web service class: Create an Eclipse Web Project. The reason for using a Web Project is that the J2EE specification requires that for implementing you need one of the following.
    • A Java class running in the Web container.
    • A stateless session EJB running in the EJB container.
    Create the following class within the web application.
    public class TestService {
    public String sayHello(String message) {
    System.out.println("sayHello:" + message);
    return "You said '" + message + "'";
  3. Auto-generate WebServices classes in Eclipse: Right-click on the class and select Web Services->Create Web Service. If you have a weblogic server defined in eclipse, then the Web service will be automatically published to the server. Make sure that your server definition looks like this.

  4. Auto-generate the classes for calling the web service: Create a Java application and copy the generated WSDL file from the web project. Right-click on the WSDL file and Web Services->Generate client. All the required classes will be generated, and the jar files will also be imported.
  5. Create a Client Application: We will use a simple Java client for this web service. The following is the code for the client application.
    import java.rmi.RemoteException;
    import service.TestService;
    import service.TestServiceProxy;
    public class SimpleClient {
    public static void main(String[] args) {
    TestService service = new TestServiceProxy();
    try {
    } catch (RemoteException e) {
This example was run on Weblogic 9.2, Eclipse Callisto 3.2, Java 5.0.


  1. I am getting a java classnotfound exception while generating the wsdl:-

    IWAB0398E Error in generating WSDL from Java: java.lang.ClassNotFoundException: TestService
    java.lang.ClassNotFoundException: TestService
    at org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(
    at org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(
    at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(
    at java.lang.ClassLoader.loadClass(

  2. What version of eclipse/java and weblogic are you using?

  3. Hi Abhi, I am working in weblogic 9.2 server. We are having an application which needs to access a Spring Bean from weblogic WebServices.

    So How I did that work was

    (1)I created weblogic webservice.
    (2)Created a Spring Bean which is having JDBC code which inserts some data into database.
    (3) I created an Interface (the method would be implemented in Spring Bean...)
    (4) I am using this spring Bean's Interface in weblogic WebService.For this I created a ApplicationContextFactory class.Which instantiate "applicationContext.xml file".
    so Once I get the instance of that ApplicationContext , then I am using the method "getBean("service"), to get the instance of the Interface.

    Then passing a String into that Interface method.

    Assumed that the flow would be like this.

    (a)webservice receives a String from client.
    (b)webservice get the Spring's Bean class using ApplicationContextFacotry.
    (c)pass the client send String as an argument to the Spring Bean's Method.
    (d) Which Spring Bean accepts and using the JDBC program it inserts into the database.

    But some when I run the WebService's from the Weblogic's workshop(9.2) and passing the a String a parameter to the is giving an error as

    " Error invoking webservice.SpringService (POJO): java.lang.NoClassDefFoundError:ComponentHandler.handleRequest:115
    java.lang.NoClassDefFoundError: org/springframework/context/support/ClassPathXmlApplicationContext: ComponentHandler.handleRequest:115
    java.lang.NoClassDefFoundError: org/springframework/context/support/ClassPathXmlApplicationContext
    at webservice.ApplicationContextFactory.getApplicationContext(
    at webservice.SpringService.insert(
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(
    at java.lang.reflect.Method.invoke(
    at weblogic.wsee.component.pojo.JavaClassComponent.invoke(
    at weblogic.wsee.handler.HandlerIterator.handleRequest(
    at weblogic.wsee.server.servlet.SoapProcessor.handlePost(
    at weblogic.wsee.server.servlet.SoapProcessor.process(
    at weblogic.wsee.server.servlet.BaseWSServlet$
    at weblogic.wsee.server.servlet.BaseWSServlet.service(
    at javax.servlet.http.HttpServlet.service(
    at weblogic.servlet.internal.StubSecurityHelper$
    at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(
    at weblogic.servlet.internal.ServletStubImpl.execute(
    at weblogic.servlet.internal.ServletStubImpl.execute(
    at weblogic.servlet.internal.WebAppServletContext$
    at weblogic.servlet.internal.WebAppServletContext.securedExecute(
    at weblogic.servlet.internal.WebAppServletContext.execute(

    So please help me in this regard.


  4. hi.. i've just started with webservices... i am using eclipse to build a webservice.. i am not sure abt the role of a webservice client, as in how a client invokes a webservice in eclipse. you've shown a code for a client application but i don't understand where i am suppose to place this code.. it'll be great if you can help me..

  5. How about building Java applications in a standard way - using Ant build scripts!

  6. hi abhi,

    can you please tell me as how to load excel file data in Mysql using java?


  7. Hi Abhi

    Do we have any good tutorial on

    Spring-MVC,Apache Axis and Hibernate

    Waiting for your earliest reply



Popular Posts