简体   繁体   中英

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:

  1. define the web service java class (interface + impl)
  2. deploy the web service using Endpoint.publish
  3. grab the wsdl from the url of the web service (eg, localhost://greeting?wsdl)
  4. use wsimport to generate stubs
  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? Perhaps a maven plugin to auto-generate wsdl and client stubs?

Update : Rather than creating a new question I am just going to piggyback on this one.

I have created my web service by defining an interface:

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

and an impl class:

@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:

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

Eclipse seems to be okay with it.

Any idea why?

Note, I originally did not have the annotation but when I tried to call my webservice I got the following error:

com.me.helloworldws.HelloWorldWsImpl is not an interface

The JSR 224 says in 3.1 section:

An SEI is a Java interface that meets all of the following criteria:

  • Any of its methods MAY carry a javax.jws.WebMethod annotation (see 7.11.2).
  • javax.jws.WebMethod if used, MUST NOT have the exclude element set to 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.

Depends of custom version of Eclipse, shows a warning for this. eg Rational Application Developer for Websphere shows:

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. Just check carefully.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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