Change URL of web service client in code

Hi,How do I change the URL of a web service client in code.i.e. I want to read the location of the web service from the deployment descriptor to easily switch between test and live versions.How do I do it?ThanksK
[254 byte] By [cmainooa] at [2007-11-27 2:21:57]
# 1

Hi,

First create property called for example myServiceAddress of type String in your ApplicationBean1. Also create set and get methods. Next add managed property to your managed-beans.xml. It should look like:

<managed-bean>

<managed-bean-name>ApplicationBean1</managed-bean-name>

<managed-bean-class>mypackage.ApplicationBean1</managed-bean-class>

<managed-bean-scope>application</managed-bean-scope>

<managed-property>

<property-name>myServiceAddress</property-name>

<property-class>java.lang.String</property-class>

<value>service addres (ie. http://localhost:8080/MyService) </value>

</managed-property>

</managed-bean>

Next on your page add web service client by clicking "Add to page" on web service in servers tab. This will create property called for example MyServiceClient and type webservice.myservice.myservice.MyServiceClient.

Finally add this piece of code to your init() method:

getMyServiceClient().setAddress( getApplicationBean1().getMyServiceAddress() );

alternatively you can use

import javax.xml.rpc.Stub;

//...

public void init() {

//..

Stub stub = (Stub)getMyServiceClient();

stub._setProperty(Stub.ENDPOINT_ADDRESS_PROPERTY, getApplicationBean1().getMyServiceAddress() );

}

best regards

Grzegorz

Grzegorz.Kluczeka at 2007-7-12 2:25:15 > top of Java-index,Development Tools,Java Tools...