Posts Tagged ‘web service sample’

Weblogic 10.3 Sample JAXWS web service development

January 27, 2011 4 comments

This post explains development, deployment and running a web service in simpler steps…


Assuming you followed all the steps of weblogic installation and paths rightly set. If so move on to next step…


Write a sample web service

package com.weblogic.sample.service;
import javax.jws.WebMethod;
import javax.jws.WebService;
@WebService(serviceName = "MyWLService_Service", targetNamespace = "http://localhost:7001")
public class MyWLService {
@WebMethod(operationName = "sayHi")
public String sayHi() {
return "Hello Everyone! Weblogic Service response!";


I am using ANT script to build my web service.

  • set weblogic.path to <wl_path>\server\lib\weblogic.jar
  • You should have ANT installed and ANT_HOME set
  • we use jwsc and jws weblogic ant tasks to run the below script
<project name="MyWLService" default="build" basedir=".">
<target name="init">
<property name="" value="MyWLService" />
<property name="weblogic.path" value="C:\\oracle\\Middleware\\wlserver_10.3\\server\\lib\\weblogic.jar" />
<property name="src.dir" location="./src" />
<property name="bld.dir" location="./build" />
<property name="lib" location="./lib" />
<target name="clean" depends="init">
<delete dir="${bld.dir}" />
<delete dir="./war" />
<fileset dir=".">
<include name="${}.war" />
<target name="build-setup" depends="init">
<mkdir dir="${bld.dir}" />
<path id="add.class.path">
<pathelement path="${weblogic.path}" />
<pathelement path="${java.class.path}" />

<target name="ws-compile" depends="init, clean, build-setup">
<taskdef name="jwsc" classname="">
<pathelement path="${weblogic.path}" />
<jwsc srcdir="${src.dir}" destdir="${bld.dir}" classpathref="add.class.path">
<jws file="com/weblogic/sample/service/" type="JAXWS" />
<target name="build" depends="ws-compile" />

Run the ant task by issuing ‘ant build’ command. You should see a war file created in your projects folder.


Now go to weblogic admin console http://localhost:7001/console

login with you userid/password

On successful login, you’ll see the home page. On the left hand side navigation, select Deployments

Install war in the deployments

Click on Install button and select the just created war file


Now, select your war file and click next.

In the next screen let the default options be selected, click next till you see FINISH button.


You should now see a success message stating your war deployed successfully.

Now you should check if wsdl file got generated successfully or not

In the browser http://localhost:7001/MyWLService/MyWLService_Service?WSDL your wsdl file should get loaded. This ensures that your webservice is deployed successfully and it’s time for invoking your service.


Since I’ve APACHE CXF installed on my machine I’ll use WSDL2JAVA to generate client code. You may also depend on other stacks to generate client code.

Another easy way is to install soapUI, it’s very simple to use and all you need to do is to map the wsdl to the project and invoke the service.

However with WSDL2JAVA ‘am gonna issue a command at a desired folder path where I would want to have my client

<p>wsdl2java -client http://localhost:7001/MyWLService/MyWLService_Service?WSDL</p>

In the client code just execute client class with main method() that’s it!

Next post on securing this web service.