views:

218

answers:

2

I have a WSDL file for a web service. I'm using JAX-WS/wsimport to generate a client interface to the web service. I don't know ahead of time the host that the web service will be running on, and I can almost guarantee it won't be http://localhost:8080. How to I specify the host URL at runtime, e.g. from a command-line argument?

The generated constructor MyService(URL wsdlLocation, QName serviceName) doesn't seem like what I want, but maybe it is? Perhaps one of the variants of Service.getPort(...)?

Thanks!

+1  A: 

The constructor should work fine for your needs, when you create MyService, pass it the url of the WSDL you want i.e. http://someurl:someport/service?wsdl.

Sam Merrell
Ok. Just so I understand... MyService will request the WSDL and then use whatever's in the <soap:address> tag to determine where the service actually is?
Dave Ray
I think that is right, I've tried to look it up but I can't find anything to answer clearly.
Sam Merrell
Yes. JAX-WS will load the WSDL at wsdlLocation and then parse the WSDL for the service and port specified by serviceName and portName, respectively. JAX-WS will use the URL specified in the WSDL port when invoking the Web service. Thus, you will need to know the WSDL URL, service QName, and port QName in order to interact with the remote service using the code you listed above.
DavidValeri
A: 

If you have a look in the generated source close to the generated constructor, you should be able to figure out what to put in it from the default constructor, should look something like:

public OrdersService() {
    super(WSDL_LOCATION, new QName("http://namespace.org/order/v1", "OrdersService"));
}

You should be able to find the def of WSDL_LOCATION in the static field further up in the class.

Jonas Andersson