Java-从可用的类创建Web服务 [英] Java - Create a web service from an available class

查看:51
本文介绍了Java-从可用的类创建Web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Java项目,经过大量研究,我设法将其转换为Eclipse中的Dynamic Web Project.现在,我想向其中添加一个新的Web服务.我已经上过一堂课.我想将其转换为标准的Web服务,以便可以从silverlight应用程序中调用它.这是我目前的课程:

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);
    }
}

如何在Eclipse中做到这一点?请发布指向教程的链接或快速的分步指南.我是.Net开发人员,而且对Java还是很陌生.

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.

谢谢.

PS:因此,基本上,我想以一种标准方式发布此服务,而不是调用此主要函数并使用Endpoint.publish()方法.

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

推荐答案

Eclipse Wiki 具有使用Web工具平台完成所需内容的教程.如果您没有Eclipse,则需要WTP和Tomcat.它以无注释的类开头,以WSDL和测试客户端结尾.它允许您查看生成的SOAP消息.

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.

要创建,它会指示您选择要转换为Web服务的文件,然后运行 File->.新->其他...->网络服务->Web服务.然后,单击 Next ,将滑块移至 Start Service 位置,并将客户端移至 Test Client .您选择监视Web服务,然后单击完成.然后,您可以使用Test Client并查看生成的WSDL.

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.

这篇关于Java-从可用的类创建Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆