Unless you show us some code, my best guess is that the getName() method looks like this:
public String getName() {
return null;
}
Although that's most likely not the case. :-)
After a quick test to duplicate what you're trying to do here's what I think is going on.
If you're using a locator class or method to get the reference to your end point which would look something like this
private CalculatorPort locateCalculatorService()
throws IOException, ServiceException
{
String wsdlUrl = "http://localhost:7001/CalculatorService/Calculator?WSDL" ;
Calculator service = new Calculator_Impl(wsdlUrl) ;
return service.getCalculatorPort() ;
}
if you call the locator method like this
public void someMethod()
{
locateCalculatorService().setString("kevin'") ;
locateCalculatorService().getString() ;
}
What's happening is that you have two different instances of the service end point.
So try it like this instead
public void someMethod()
{
CalculatorPort port = locateCalculatorService() ;
port.setString('kevin') ;
port getString() ;
}
Try it that way.
Doesn't change my feeling that keeping state of this type on a service is not a good idea but if you really have to it actually does work.
Hope this helps,
PS.
Dear Puckstopper31,
Thanks for the help. The reason I keep the state of the Web Service is that I want to use this way to pass the parameter(i.e. name "kevin") to that Web Service.
The Web Service is as follows:
public class CastepInputCml
{
private String name;
public void setName(String argName)
{
name = argName;
}
public String getName()
{
return name;
}
}
Here is my WS client code:
public static void main(String[] args)
{
try
{
CastepInputCmlServiceLocator locator = new CastepInputCmlServiceLocator();
CastepInputCml service = (CastepInputCml)locator.getCastepInputCml();
service.setName("Kevin");
System.out.println("The parameter passed to the web service is: "+service.getName());
}
catch Exception (e) { }
}
In this case, the System.out.println("The parameter passed to the web service is: "+service.getName()) is always null.
In your reply, I don't quite understand "using a locator class or method to get the reference to your end point", are you talking WSRF? Do you mean usually Web service is stateless and can not maintain state? But if I want to use set() method to pass parameter to a web service,what is the best way? I like to discuss this with you.
Thanks
Kevin