Reputation: 1656
I am new with Java EE and SOAP. I have tried to create a simple web service application and its client (environment: NetBeans 7.2.1 IDE, GlassFish Server 3.1, Java 1.6).
Web service code:
package simplews;
import javax.jws.*;
@WebService(serviceName = "SimpleWebService")
public class SimpleWebService {
String something = null;
@WebMethod(operationName = "setSomething")
@Oneway
public void setSomething(@WebParam(name = "smth") String smth) {
something = smth;
}
@WebMethod(operationName = "getSomething")
public String getSomething() {
return something;
}
}
Client application code:
package simpleclientapp;
import simplews.*;
public class SimpleClientApp {
public static void main(String[] args) {
SimpleWebService_Service service = new SimpleWebService_Service();
SimpleWebService port = service.getSimpleWebServicePort();
port.setSomething("trololo");
String smth = port.getSomething();
System.out.println(smth);
}
}
Unfortunately, the client application printed out null
. After short investigation I have realised, that on the server side a new SimpleWebService
object is created for each client call (sounds like stateless approach).
What is wrong here? Why the client port does not refer to the same WS object for each call?
Upvotes: 1
Views: 339
Reputation: 4974
You're right, JAX-WS web services are stateless by default and you can't rely on something thatviolates this premise. Follow a different approach in storing such values. You can read this doc Java TM API for XML Web Services (JAX-WS) Stateful Web Service with JAX-WS RI, if you really want to follow the direction in your post.
Upvotes: 1
Reputation: 17940
Web services are stateless by nature. In order to keep state between requests, you have to persist the data (in a file,database etc.).
Upvotes: 1