wood burning stoves 2.0
The moose likes Web Services and the fly likes JAX-WS web service simple example Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "JAX-WS web service simple example" Watch "JAX-WS web service simple example" New topic

JAX-WS web service simple example

iamiqbal.m Mohiuddin

Joined: May 11, 2006
Posts: 12

I am new to web services.

I have a sample web service as below.
package sample;

import javax.jws.WebMethod;
import javax.jws.WebService;

public class MSTDealLoggerWS {
public MSTDealLoggerWS() {}

@WebMethod(operationName="add", action="urn:Add")
public int add(int i, int j) {
int k = i +j ;
System.out.println(i + "+" + j +" = " + k);

return k;

I was able to generate the other artifacts using wsgen. It has generated wsdl and other bean classes [Add.java, AddResponse.java]
I have created a war file to deploy this webservice in jboss-4.2.2.GA. The structure of my war file is :

|-- classes [this has sample package and MSTDealLoggerWS]
|-- lib [no jars here]
|--wsdl [generated wsdl]

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<definitions targetNamespace="http://mstdeal/ws" name="LoggerServiceWS" xmlns:tns="http://mstdeal/ws" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns="http://schemas.xmlsoap.org/wsdl/">
<xsd:import namespace="http://mstdeal/ws" schemaLocation="LoggerServiceWS_schema1.xsd"/>
<message name="add">
<part name="parameters" element="tns:add"/>
<message name="addResponse">
<part name="parameters" element="tns:addResponse"/>
<portType name="Logger">
<operation name="add">
<input message="tns:add"/>
<output message="tns:addResponse"/>
<binding name="LoggerPortBinding" type="tns:Logger">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="add">
<soapperation soapAction="urn:Add"/>
<soap:body use="literal"/>
<soap:body use="literal"/>
<service name="LoggerServiceWS">
<port name="LoggerPort" binding="tns:LoggerPortBinding">
<soap:address location="http://localhost:8080/LoggerServiceWS/LoggerServiceWS"/>

when i deploy this on JBoss 4.2.2 [server-default-deploy folder]
and when i hit http://localhost:8080/LoggerServiceWS/LoggerServiceWS?wsdl

i am not able to see wsdl. It says 404 exception.

This is a very simple example. Highly appreciate if someone can help me why .wsdl is not deployed.

Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
Your web service is probably not deployed because there was some error at deployment time. Please review the server log to try to obtain more information.
Best wishes!
iamiqbal.m Mohiuddin

Joined: May 11, 2006
Posts: 12
Thanks Ivan.

I have checked the logs i dont see anything in the logs.

My web.xml is

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

I am using eclipse ide. I have added jboss server and then added my project.
To my knowledge we dont need any deployment descriptor for jax-ws web service.

Is this all i need or Do i need to specify anything in app server so that it knows about jax-ws?

Appreciate your inputs.

Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
You are correct, if the application server supports JAX-WS, then you have all you need and should not have to do any additional configuration.
To determine if the problem is your program or the application server, I would recommend you to try to deploy your program on another application server, for instance GlassFish.
If your program works on GlassFish, then the problem is with the JBoss AS. If your program does not work on GlassFish, then the problem probably is with your program.
Best wishes!
Vinod K Singh
Ranch Hand

Joined: Sep 30, 2008
Posts: 198
See if Building JAX-WS Web Service helps you in anyway.

My Blog
iamiqbal.m Mohiuddin

Joined: May 11, 2006
Posts: 12
Thanks Vinod.

I did check your blog.
Do we need sun-jaxws.xml as mentioned in your blog?

Doesn't JAX-WS annotations take care of this and free us from deployment descriptors.

Last when i did was deployment descriptor was getting generated automatically when we deploy on app. server.
I am trying to achieve the same.

Do i need to set something in JBoss server so that it detects wsdl. when i hit http://localhost:port/jbossws
I see page coming up. Thats means JAX-WS is enabled / installed on this server.

Can anyone provide me a working war file which has web service. I just want to deploy that and see whether i can hit the wsdl or not?
Just to rule out one of the possibility that my war file is messed up.

Thanks in advance.
Vinod K Singh
Ranch Hand

Joined: Sep 30, 2008
Posts: 198
There are several approaches to deploy web service and people choose the one based on their requirement and comfort level. You can find entire source code of a simple web service at the link provided in previous post.
I agree. Here's the link: http://aspose.com/file-tools
subject: JAX-WS web service simple example
It's not a secret anymore!