aspose file tools*
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
Author

JAX-WS web service simple example

iamiqbal.m Mohiuddin
Greenhorn

Joined: May 11, 2006
Posts: 12
Hello:

I am new to web services.

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

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


@WebService(
name="Logger",
serviceName="LoggerServiceWS",
targetNamespace="http://mstdeal/ws"
)
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 :

LoggerServiceWS.war
|-- WEB-INF
|-- 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/">
<types>
<xsd:schema>
<xsd:import namespace="http://mstdeal/ws" schemaLocation="LoggerServiceWS_schema1.xsd"/>
</xsd:schema>
</types>
<message name="add">
<part name="parameters" element="tns:add"/>
</message>
<message name="addResponse">
<part name="parameters" element="tns:addResponse"/>
</message>
<portType name="Logger">
<operation name="add">
<input message="tns:add"/>
<output message="tns:addResponse"/>
</operation>
</portType>
<binding name="LoggerPortBinding" type="tns:Logger">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="add">
<soapperation soapAction="urn:Add"/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="LoggerServiceWS">
<port name="LoggerPort" binding="tns:LoggerPortBinding">
<soap:address location="http://localhost:8080/LoggerServiceWS/LoggerServiceWS"/>
</port>
</service>
</definitions>


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
    
    1
Hi!
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
Greenhorn

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">
<display-name>LoggerServiceWS</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>

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
    
    1
Hi!
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
Greenhorn

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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: JAX-WS web service simple example