views:

58

answers:

0

I just went through a few resources on the web to write WebServices using annotations and they claim that the web service is exposed as a servlet. But, it doesn't seem to work for me. It throws a ClassCastException. The code is below:

import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;

@SOAPBinding(style = Style.RPC)
@WebService(serviceName = "FirstWS", portName = "FirstWSPort")
public class FirstAnnotatedWebService {
    @WebMethod(operationName = "sayHello", action = "urn:SayHello")
    public String sayHello(String name) {
        return "Hello, " + ((name == null || name.length() == 0) ? "World!" : name + "!");
    }
}

And the 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"&gt;
    <display-name>FirstWS</display-name>
    <servlet>
        <servlet-name>FirstWS</servlet-name>
        <servlet-class>FirstAnnotatedWebService</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>FirstWS</servlet-name>
        <url-pattern>FirstWS</url-pattern>
    </servlet-mapping>
</web-app>

I have deployed this web application as MyWar.war in JBoss 4.0.x. I am trying to access http://localhost:8080/MyWar/FirstWS?wsdl.