Dušan Rychnovský
Dušan Rychnovský

Reputation: 12459

SOAP WS - a single client for multiple different installations of the same service

Motivation

I'm building a command-line utility which allows the user to manipulate user accounts on a server from a remote computer. For this purpose, the server provides a SOAP WS API.

The question

If I generate the client code from the WSDL file with the wsimport tool, the application becomes fixed to a single server installation (the IP address of the server is fixed in the code on multiple places).

I would need the application to allow the user to work with any server installation. They should only be asked for the IP address of the target server at application start-up.

What is the best/correct way to achieve this?

Upvotes: 1

Views: 1253

Answers (1)

jdev
jdev

Reputation: 5622

After generating wsdl proxy. the is a file with annotation @WebServiceClient.

I generate proxy for following url (wsdl location)

http://192.168.1.185:10530/service?wsdl

In constructor of class you can pass desired url that set by setter string or file or any data read from database.

looking for file with annotation @WebServiceClient(that contain getBasicHttpBinding method) then add following. before using this set the desired url and call getBasichttpBinding....

private static String serviceUrl = "";

public static void setUrl(String url){
    serviceUrl = url;
}

public ServiceClient(URL wsdlLocation, QName serviceName) {
    super(wsdlLocation, serviceName);
}

public ServiceClient() {
    super(serviceUrl, new QName("http://tempuri.org/", "Service"));
}

Upvotes: 4

Related Questions