更新时间:2021-07-03 23:28:43
根据我在上面评论中链接的文章:: http://www.ibm.com/developerworks/webservices/tutorials/ws-eclipse-javase1/index。 html
Based on the article I linked in the comments above :: http://www.ibm.com/developerworks/webservices/tutorials/ws-eclipse-javase1/index.html
使用JWS注释,您可以在Java应用程序中设置Web服务以公开其某些功能。不需要额外的库。以下示例使用Java 6编写。
With the JWS annotations you can setup a Web Service in your java application to expose some of its functionality. There is no extra libraries needed. The below examples were written with Java 6.
定义Web服务的示例:
An example of Defining your web service :
import javax.jws.WebMethod;
import javax.jws.WebService;
@WebService
public class MyWebService {
@WebMethod
public String myMethod(){
return "Hello World";
}
}
注意 @ WebService 和 @ WebMethod 。阅读他们链接的API,并根据需要进行配置。这个例子可以在不改变事物的情况下工作
Note the 2 annotations of @WebService and @WebMethod. Read their API's which are linked and configure them as required. This example will work without changing a thing
然后你只需要设置监听器。您将在课程中找到 javax.xml。 ws.Endpoint
You then only need to setup the Listener. You will find that in the class javax.xml.ws.Endpoint
import javax.xml.ws.Endpoint;
public class Driver {
public static void main(String[] args) {
String address = "http://127.0.0.1:8023/_WebServiceDemo";
Endpoint.publish(address, new MyWebService());
System.out.println("Listening: " + address);
}
}
运行此程序,您将成为能够使用 http://127.0.0.1:8023/_WebServiceDemo?WSDL 来访问您的Web服务。此时,您可以轻松配置要在应用程序之间来回发送的内容。
Run this program and you will be able to hit your web service using http://127.0.0.1:8023/_WebServiceDemo?WSDL. At this point it is easy to configure what you want to send back and forth between the applications.
如您所见,无需设置特殊的Web服务项目供您使用。
As you can see there is no need to setup a special web service project for your use.