Java 在开发JAX-WS Web服务时删除注释并添加xml
我是web服务世界的新bie,我在开发JAX-WS时有一个问题,下面的web服务包括生产者和客户端,但我使用的是注释。您能告诉我如何在不使用使用XML注释的情况下开发相同的程序吗..本身 创建Web服务端点接口Java 在开发JAX-WS Web服务时删除注释并添加xml,java,web-services,jax-ws,Java,Web Services,Jax Ws,我是web服务世界的新bie,我在开发JAX-WS时有一个问题,下面的web服务包括生产者和客户端,但我使用的是注释。您能告诉我如何在不使用使用XML注释的情况下开发相同的程序吗..本身 创建Web服务端点接口 import javax.jws.WebMethod; import javax.jws.WebService; import javax.jws.soap.SOAPBinding; import javax.jws.soap.SOAPBinding.Style; //Service
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;
//Service Endpoint Interface
@WebService
@SOAPBinding(style = Style.RPC)
public interface HelloWorld{
@WebMethod String getHelloWorldAsString(String name);
}
创建Web服务端点实现
import javax.jws.WebService;
//Service Implementation
@WebService(endpointInterface = "com.mkyong.ws.HelloWorld")
public class HelloWorldImpl implements HelloWorld{
@Override
public String getHelloWorldAsString(String name) {
return "Hello World JAX-WS " + name;
}
}
创建端点发布服务器
import javax.xml.ws.Endpoint;
import com.mkyong.ws.HelloWorldImpl;
//Endpoint publisher
public class HelloWorldPublisher{
public static void main(String[] args) {
Endpoint.publish("http://localhost:9999/ws/hello", new HelloWorldImpl());
}
}
通过Wsimport工具的Java Web服务客户端
wsimport -keep http://localhost:9999/ws/hello?wsdl
它将生成必要的客户机文件,这取决于提供的wsdl文件。在这种情况下,它将生成一个接口和一个服务实现文件
最后,使用生成的存根类创建主类
package com.mkyong.client;
import com.mkyong.ws.HelloWorld;
import com.mkyong.ws.HelloWorldImplService;
public class HelloWorldClient{
public static void main(String[] args) {
HelloWorldImplService helloService = new HelloWorldImplService();
HelloWorld hello = helloService.getHelloWorldImplPort();
System.out.println(hello.getHelloWorldAsString("mkyong"));
}
}
我遇到这个问题时也遇到了同样的问题 终于在这里找到了所需的解释: 查找:覆盖注释这里有一个很好的方法让您开始使用jaxws(jdk中默认的jaxws实现基于metro)。