我一直在阅读一些关于使用Java、Eclipse等进行web服务编程的书籍,我发现了一个特别的例子,其中有人通过以下方式创建了web服务和客户端:
- 定义web服务java类(interface + impl)
- 使用Endpoint.publish 部署 web服务
- 从web服务的url(例如localhost://greeting?wsdl)中获取wsdl
- 使用 wimport 生成存根
- 使用生成的存根创建客户端类
是否有另一种方法来生成wsdl而不必发布web服务并下载它?也许是一个maven插件来自动生成wsdl和客户端存根?
更新:与其创造一个新问题,我只是想借用这个问题。
我通过定义一个接口创建了我的web服务:@WebService
public interface HelloWorldWs {
@WebMethod
public String sayHello(String name);
}
和一个impl类:
@WebService(endpointInterface = "com.me.helloworldws.HelloWorldWs")
public class HelloWorldWsImpl implements HelloWorldWs {
@Override
@WebMethod
public String sayHello(String name) {
return "Hello World Ws, " + name;
}
}
当我运行wsgen我得到以下错误:
The @javax.jws.WebMethod annotation cannot be used in with @javax.jws.WebService.endpointInterface element.
Eclipse似乎没有问题。
知道为什么吗?
注意,我最初没有注释,但当我试图调用我的web服务时,我得到了以下错误:
com.me.helloworldws.HelloWorldWsImpl is not an interface
JSR 224在3.1节中说:
SEI是满足以下所有条件的Java接口:
- 它的任何方法可以携带
javax.jws.WebMethod
注释(见7.11.2)。javax.jws.WebMethod
如果使用,绝对不能将exclude
元素设置为true
。
如果实现类包含javax.jws.WebMethod
,那么你不能放入@WebMethod(exclude=true)
,根据规范,这是不可能的。
依赖于Eclipse的自定义版本,显示一个警告。例如,Rational Application Developer for Websphere显示:
JSR-181, 3.1: WebMethod cannot be used with the endpointInterface
property of WebService
在编程/构建项目(使用一些高级IDE)时,通常您应该能够在自动生成的东西之间找到它- IDE应该生成它。