JAX-WS deployment best practice: WSDL location and client generation

岁酱吖の 提交于 2020-01-04 02:16:27

问题


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("http://helloworld.poc.com/", "HelloWorldPOCImplService");
    
      Service service = Service.create(url, qname);
    
      HelloWorldPOCImpl hello = service.getPort(HelloWorldPOCImpl.class);
    
      hello.execute("hello");
    
      System.out.println("Done");
    }
    

Questions:

  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?

回答1:


  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: http://www.mastertheboss.com/jboss-web-services/developing-web-services-on-jboss-as-7



来源:https://stackoverflow.com/questions/12278327/jax-ws-deployment-best-practice-wsdl-location-and-client-generation

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!