JAX-WS部署最佳实践:WSDL位置和客户端生成 [英] JAX-WS deployment best practice: WSDL location and client generation
问题描述
我按照以下步骤创建了Web服务:
I followed these steps to create a webservice:
- 创建了服务接口& @WebService和@WebMethod批注的实现
- 部署了服务
- 使用wsimport生成的客户端存根
-
使用如下客户端程序调用了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");
}
问题:
- WSDL位置在客户端程序中提供. WSDL位置也在wsimport生成的客户端存根中进行了硬编码.为什么要这样冗余?
-
我使用wsimport使用"localhost"路径创建了客户端存根:
- 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?
I created the client stubs using wsimport using "localhost" path:
wsimport -keep http://localhost:9080/HelloWorldPOC/HelloWorldPOCImplService?wsdl
- 我从本地服务器运行了客户端测试程序,URL服务器部分为本地主机".有效.然后,从另一个系统运行相同的客户端,并将服务器部分作为服务器的主机名.奏效了.
- 这意味着不使用生成的客户端存根中的WSDL位置吗?
- 我们可以在本地主机上生成WSDL并将其部署到任何地方,而无需重新生成客户端存根?仅呼叫者客户端需要从已部署的服务器检索WSDL.是这种做法吗?还是我们需要为每个已部署的服务器重新生成客户端?
- 您可以将其理解为默认位置,该位置将被覆盖99%.在我生成的代码中,也可以在没有指定wsdl URL的情况下创建服务,因此将使用默认URL.
- 当您覆盖wsdl文件的默认URL地址时,当然不会使用它.很多时候,Web服务生产者只给我们wsdl文件,然后我们从放置在本地硬盘驱动器上的wsdl生成存根,因此我们总是需要覆盖默认值.
推荐答案
PS:我可以八卦另一种技术,该技术如何在不产生桩头的情况下调用Web服务.您仅需要客户端上可用的远程接口"之类的东西(由服务器类实现).当您负责生产和使用Web服务时,这非常有效.接口发展时,它非常有效,因为更改接口时,不需要重新生成存根.以下是使用JBoss 7(JAX-WS)作为服务器以及在客户端上使用Apache CXF库的示例:
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
这篇关于JAX-WS部署最佳实践:WSDL位置和客户端生成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!