Alireza Noori
Alireza Noori

Reputation: 15233

Java - Create a web service from an available class

I had a java project and after lots of research I managed to convert it to a Dynamic Web Project in Eclipse. Now I want to add a new Web Service to it. I have already developed a class. I want to convert it to a standard Web service so I can call it from my silverlight application. Here's my current class:

public class MyWebService 
{
    @Resource
    WebServiceContext context;

    @WebMethod
    public String ProcessQuery(@WebParam(name="query") String q)
    {
        MessageContext messageContext = context.getMessageContext();
        HttpServletRequest request = (HttpServletRequest) messageContext.get(SOAPMessageContext.SERVLET_REQUEST);
        // now you can get anything you want from the request
    }

    public static void main(String[] args) throws Exception 
    {
        String address = "http://127.0.0.1:8023/_WebServiceDemo";
        Endpoint.publish(address, new MyWebService());
        new DocumentServer();
        System.out.println("Listening: " + address);
    }
}

How can I do it in Eclipse? Please post a link to a tutorial or a quick step by step guide. I'm a .Net developer and I'm very new to Java.

Thank you.

PS: So basically I want to publish this service in a standard way rather than calling this main function and using Endpoint.publish() method.

Upvotes: 2

Views: 6720

Answers (1)

justkt
justkt

Reputation: 14766

The Eclipse wiki has a tutorial using the Web Tools Platform to do just what you are looking for. It requires WTP and Tomcat, if you don't have those already available to Eclipse. It starts with an unannotated class and finishes with a WSDL and test client. It allows you to view generated SOAP messages.

To create, it instructs you to select the file you want to convert into a web service and run File -> New -> Other... -> Web Services -> Web Service. Then you click Next, move the slider to the Start Service position, and client to Test Client. You select Monitor the Web Service and then click Finish. Then you can play with your Test Client and see your generated WSDL.

Note that the above paragraph is a summary of the tutorial, which you can find in full at the provided link.

Upvotes: 3

Related Questions