简体   繁体   English

如何使Java Web服务客户端在执行时获取并解析WSDL?

[英]How do I make my java webservice client fetch and parse WSDL upon execution?

I've created java webservices and clients using Netbeans. 我已经使用Netbeans创建了Java Web服务和客户端。 However, the clients seem to have the WSDL already 'built-in'. 但是,客户端似乎已经“内置”了WSDL。

Is there an easy way of making my client fetch and parse the WSDL code upon execution, so that if the webservice moves to another server, the client is just invoked with a different commandline argument for where to find the webservice? 是否有一种简单的方法可以使我的客户端在执行时获取并解析WSDL代码,因此,如果Web服务移至另一台服务器,则仅使用不同的命令行参数调用该客户端以在何处找到该Web服务?

NetBeans' auto-generated proxy factory provides two constructors. NetBeans的自动生成的代理工厂提供了两个构造函数。

The nullary one initializes the factory to the hardcoded URI provided to the "New Web Service Client from WSDL..." dialogue. 空值将工厂初始化为提供给“从WSDL ...新建Web服务客户端”对话框的硬编码URI。

The second constructor accepts a URL to the WSDL documentation, and the service QName. 第二个构造函数接受指向WSDL文档的URL和服务QName。

When you have NetBeans insert the service call into your source code, the code fragment it generates uses the nullary constructor, but you can manually change that. 当您使NetBeans将服务调用插入源代码时,它生成的代码片段将使用null构造函数,但是您可以手动更改它。

// alternate constructor: SampleDomainService(URL, QName)
SampleDomainService service = new SampleDomainService();
SampleDomain port = service.getSampleDomainPort();
SampleDomainRequestType request = new SampleDomainRequestType();
SampleDomainResponseType result = port.sampleOperation(request);

您是否考虑过让客户端根本不使用WSDL中的服务器URL,而仅使用为其配置服务器地址?

大多数自动生成的客户端允许您指定WSDL URL的位置,即使其中一个是硬编码的(例如,使用CXF进行编码)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM