JAX-WS部署最佳实践:WSDL位置和客户端生成

3

我按照以下步骤创建了一个Web服务:

  • 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");
    }
    

问题:

  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个回答

2
  1. “默认位置”是指99%情况下将被覆盖。在我的代码中,服务也可以在没有指定wsdl URL的情况下创建,因此将使用默认URL。
  2. 当您覆盖wsdl文件的默认URL地址时,它将不会被使用。很多时候,Web服务提供者只给了我们wsdl文件,然后我们从本地硬盘上的wsdl生成存根,因此我们总是需要覆盖默认值。

PS:我还可以告诉你另一种无需生成存根即可调用WebService的技术。您只需要像客户端上可用的“远程接口”(由服务器类实现)即可。当您负责制作和使用WebService时,这非常有效。当接口演进时,它非常有效,因为当您更改它时,您不需要重新生成存根。以下是JBoss 7(JAX-WS)作为服务器,客户端使用Apache CXF库的示例:http://www.mastertheboss.com/jboss-web-services/developing-web-services-on-jboss-as-7


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接