Hello! First post here - please be kind! =)
I have written the following web service and have a quesiton about the
concept of state & stateless:
The following example code is hanging on to values during subsequent calls
to the service. Is there a way I can make it clear the property values
following each call to the service?
package org.sandbox;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
@WebService()
public class TestService {
private String lastName;
@WebMethod()
public void setLastName(@WebParam(name = "value") String value) {
this.lastName = value;
}
@WebMethod
public String getLastName() {
return this.lastName;
}
}
I have deployed it successfully to my local Apache / Tomcat web server /
application server and it runs great with one exception. Each time I run the
client code it retains the value from the previous run of the method
getLastName() / setLastName().
Question: Is there a way to control the state / scope similar to that of a
JSP page or servlet? I have used XFire and with that I can set scope to one
of three values: Application / Session / Request with the default being
Request. Is there a way of achieving this same behavior using the web
services produced by NetBeans?
Instead seeing this output:
LastName = Smith
LastName = Smith
I would like to see:
LastName = null
LastName = Smith
That is if somehow I can set scope to Request. However, I would expect to
see:
LastName = Smith
LastName = Smith
if scope were set to Application or Session.
In short, can I control scope of the values / properties of web services?
Here is the client code:
package org.sandbox;
public class Main {
public Main() {
}
public static void main(String[] args) {
TestServiceService ts = new TestServiceService();
TestService port = ts.getTestServicePort();
System.out.println("LastName = " + port.getLastName());
port.setLastName("Smith");
System.out.println("LastName = " + port.getLastName());
}
}
Thank for any advice and direction!
Michael