I've created java webservices and clie开发者_JAVA技巧nts using Netbeans. However, the clients seem to have the WSDL already 'built-in'.
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?
NetBeans' auto-generated proxy factory provides two constructors.
The nullary one initializes the factory to the hardcoded URI provided to the "New Web Service Client from WSDL..." dialogue.
The second constructor accepts a URL to the WSDL documentation, and the service 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.
// alternate constructor: SampleDomainService(URL, QName)
SampleDomainService service = new SampleDomainService();
SampleDomain port = service.getSampleDomainPort();
SampleDomainRequestType request = new SampleDomainRequestType();
SampleDomainResponseType result = port.sampleOperation(request);
Have you considered having your client not use the server URL in the WSDL at all and instead just use a server address you configure it with?
Most auto-generated clients allow you to specify the location of the WSDL URL even if one is hard-coded (CXF for e.g. does that).
精彩评论