Mejores prácticas de implementación de JAX-WS: ubicación de WSDL y generación de clientes

I followed these steps to create a webservice:

  • Created a service interface & implementation with @WebService and @WebMethod annotations
  • Deployed the service
  • Generated client stubs with wsimport
  • Invoked webservice with a client program that looks like:

    public static void main(String[] args) throws Exception {
      URL url = new URL("http://SERVER:PORT/HelloWorldPOC/HelloWorldPOCImplService?wsdl");
      QName qname = new QName("", "HelloWorldPOCImplService");
      Service service = Service.create(url, qname);
      HelloWorldPOCImpl hello = service.getPort(HelloWorldPOCImpl.class);


  1. The WSDL location is provided in the client program. The WSDL location is hardcoded in the wsimport generated client stub as well. Why this redundancy?
  2. I created the client stubs using wsimport using "localhost" path:

    wsimport -keep http://localhost:9080/HelloWorldPOC/HelloWorldPOCImplService?wsdl
    • I ran the client test program from the localhost with URL server part as "localhost". It worked. Then ran the same client from another system with server part as the hostname of the server. It worked.
    • This means the WSDL location in the generated client stubs are not used?
    • And we can generate the WSDL on localhost and deploy it anywhere without regenerating the client stubs? Only the caller client needs to retrieve the WSDL from the deployed server. Is this accepted practice or do we need to regenerate client for every deployed server?

preguntado el 05 de septiembre de 12 a las 10:09

1 Respuestas

  1. You can understand it as default location which will be in 99% overridden. In my generated code, service could be created also without specified wsdl URL, so then default URL will be used.
  2. When you override default URL address of wsdl file, of course it will be not used. Many times webservice producer gave us only wsdl file, and then we generate stubs from wsdl placed on local hard drive, so we need always to override default value.

PS: I could gossip another technique how to call webservices without stubs generation. You need only something like "remote interface" available on client (implemented by server class). It is very efficient when you are responsible for producing and consuming the webservice. It is very efficient when the interface evolves, because when you change it, you do not need to regenerate stubs. Here is example with JBoss 7 (JAX-WS) as the server and Apache CXF library used on client:

contestado el 10 de mayo de 13 a las 18:05

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.