Set() and Get() in Web Service

Dear all, I have a very simple Web service which has a pair of basic operations: setName(String name) and getName().But after I setName("kevin"), the getName() always returns null. Any clue for that? I am using Axis 1.3. Many thanks in advance.Kevin
[291 byte] By [kevnyanga] at [2007-11-26 21:37:47]
# 1

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

hunter9000a at 2007-7-10 3:20:18 > top of Java-index,Java Essentials,Java Programming...
# 2
Why are you trying to maintain a state in a web service?Please post the code for your service (don't forget the code tags please).I have an idea why it's unhappy but I want to see what you have before I comment.PS.Message was edited by: puckstopper31
puckstopper31a at 2007-7-10 3:20:18 > top of Java-index,Java Essentials,Java Programming...
# 3

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.

puckstopper31a at 2007-7-10 3:20:18 > top of Java-index,Java Essentials,Java Programming...
# 4

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

kevnyanga at 2007-7-10 3:20:18 > top of Java-index,Java Essentials,Java Programming...