简体   繁体   English

生成Web服务的Wsdl /客户端存根

[英]Generate Wsdl/Client Stubs For Web Service

I have been doing some reading up on web services programming with Java, Eclipse, etc. and I found one particular example where the person created the web service and client by doing the following: 我一直在阅读有关使用Java,Eclipse等进行Web服务编程的内容,并且发现了一个特定的示例,该人员通过执行以下操作来创建Web服务和客户端:

  1. define the web service java class (interface + impl) 定义Web服务Java类(接口+ impl)
  2. deploy the web service using Endpoint.publish 使用Endpoint.publish 部署 Web服务
  3. grab the wsdl from the url of the web service (eg, localhost://greeting?wsdl) 从Web服务的URL中获取wsdl (例如localhost:// greeting?wsdl)
  4. use wsimport to generate stubs 使用wsimport生成存根
  5. create a client class using generated stubs 使用生成的存根创建客户端类

Is there another way to generate the wsdl without having to publish the web service and download it? 是否有另一种无需发布Web服务并下载就可以生成wsdl的方法? Perhaps a maven plugin to auto-generate wsdl and client stubs? 也许是一个Maven插件来自动生成wsdl和客户端存根?

Update : Rather than creating a new question I am just going to piggyback on this one. 更新 :我不会提一个新问题,而只是just带这个问题。

I have created my web service by defining an interface: 我通过定义接口创建了Web服务:

@WebService
public interface HelloWorldWs {
    @WebMethod
    public String sayHello(String name);
}

and an impl class: 和一个impl类:

@WebService(endpointInterface = "com.me.helloworldws.HelloWorldWs")
public class HelloWorldWsImpl implements HelloWorldWs {
    @Override
    @WebMethod
    public String sayHello(String name) {
        return "Hello World Ws, " + name;
    }
}

When I run wsgen I get the following error: 当我运行wsgen时 ,出现以下错误:

The @javax.jws.WebMethod annotation cannot be used in with @javax.jws.WebService.endpointInterface element.

Eclipse seems to be okay with it. Eclipse似乎还可以。

Any idea why? 知道为什么吗?

Note, I originally did not have the annotation but when I tried to call my webservice I got the following error: 注意,我最初没有注释,但是当我尝试调用Web服务时,出现以下错误:

com.me.helloworldws.HelloWorldWsImpl is not an interface

The JSR 224 says in 3.1 section: JSR 224在3.1节中说:

An SEI is a Java interface that meets all of the following criteria: SEI是满足以下所有条件的Java接口:

  • Any of its methods MAY carry a javax.jws.WebMethod annotation (see 7.11.2). 它的任何方法都可以带有javax.jws.WebMethod注释(参见7.11.2)。
  • javax.jws.WebMethod if used, MUST NOT have the exclude element set to true . 如果使用javax.jws.WebMethod ,则必须将exclude元素设置为true

If the implementation class include the javax.jws.WebMethod , then you cant put @WebMethod(exclude=true) and that in not possible, according to specification. 如果实现类包括javax.jws.WebMethod ,则根据规范,您不能放置@WebMethod(exclude=true)而这不可能。

Depends of custom version of Eclipse, shows a warning for this. 取决于Eclipse的定制版本,为此显示了警告。 eg Rational Application Developer for Websphere shows: 例如,用于Websphere的Rational Application Developer显示:

JSR-181, 3.1: WebMethod cannot be used with the endpointInterface 
              property of WebService

While programming/building a project (with some advanced IDE) normally you should be able to find it between auto-generated stuff - the IDE should generate it. 通常,在使用一个高级IDE编程/构建项目时,您应该能够在自动生成的东西之间找到它-IDE应该会生成它。 Just check carefully. 只是仔细检查。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM