简体   繁体   中英

How to publish wsdl for java

I have following java class and have published a wsdl for it, my question is that is there anyway to have different webservice classes and publish a single wsdl? I mean another seperate class to this one with number of methods or I have to have a webservice class as the main class of the application to keep all the webmethod methods and generate the wsdl from that?

package com.Services;


import javax.jws.WebService;
import javax.jws.WebMethod;

@WebService(name = "Hellos", targetNamespace = "http://localhost:8081/Mywebservice2/services/Hellos")
public class Hellos {


    @WebMethod
    public Customer[] mycustomers() {
    .....

    }

    @WebMethod
    public String Receiver(String name){
        ....
    }
}

Exactly, that should be the way you should design your application. you should have one consolidated java file and that should be exposed. Clients should be given multiple end-points.

WSDL correspond to your service and literally each public method corresponds to a service. You can write many classes and methods but they will not be part of your wsdl if methods are private.

If you using any IDE plugin then it asks you during service creation what all public methods you want to be exposed to outer world. So in one java project you can have as many classes or methods you want. Finally when converting your project into web service you can decide which all methods can work as end point/service and then these will be part of your WSDL .

The tool wsgen since JDK 1.6 for generate de WSDL file takes only one Service Endpoint Interface or SEI .

wsgen [options] <SEI>

You can read that:

The wsgen tool generates JAX-WS portable artifacts used in JAX-WS web services. The tool reads a web service endpoint implementation class (SEI) and generates all the required artifacts for web service deployment, and invocation

And:

Note that you do not have to generate WSDL at the development time as JAXWS runtime will automatically generate a WSDL for you when you deploy your service.

In another hand, WSDL 1.1 supports having multiple services in a single WSDL file, but these services shares types. In that case, it's prefer put all in one service.

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