我是 Web 服务世界的新手,当我开发 JAX-WS 时,我有一个疑问,即下面的 Web 服务(生产者和客户端),但我正在使用注释,您能告诉我如何开发相同的注释吗?不使用使用 XML 的注释的程序..本身..
创建 Web 服务端点接口(interface)
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 文件。此时会生成一个接口(interface)和一个服务实现文件。
最后是使用生成的 stub 类的主类..
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"));
}
}
最佳答案
我在遇到同样的问题时遇到了这个问题...
终于在这里找到了如此需要的解释:http://jonas.ow2.org/JONAS_5_1_1/doc/doc-en/pdf/jaxws_developer_guide.pdf
查找:覆盖注释
关于java - 在开发 JAX-WS Web 服务时删除注释并添加 xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11924362/