views:

427

answers:

3

I've created java webservices and clients 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?

A: 

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?

matt b
If I read your response correctly, then that's exactly what I'm trying to do. Or?
ventolin
A: 

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).

kabram
+1  A: 

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);
Noel Ang
This looks like exactly what I need, thanks Noel.. The only problem is, it doesn't seem to find a constructor for the service that takes 2 String arguments. Any ideas? It should be already there, right?
ventolin
I'm using NetBeans 6.5.1 currently. With this version, I can position the editor cursor right after the opening parenthesis of the constructor call, key in CTRL+space, and the editor *does* find and list the alternate constructor. You can find the factory's source code yourself and verify that the other constructor exists: it's somewhere in build/generated/wsimport/client.
Noel Ang
By the way, the other constructor does not take 2 String arguments, but a java.net.URL and a javax.xml.namespace.QName.
Noel Ang
That's it! Thanks so much! You've been an immense help.
ventolin