Here is an Axis client of the ATotal Web Service:
0264: import ATotal_pkg. ATotal; // MyTestClient.java
0265: import ATotal_pkg. ATotalService;
0266: import ATotal_pkg. ATotalServiceLocator;
0267: import ATotal_pkg. ATotalSoapBindingStub;
0268: import java.io. BufferedReader;
0269: import java.io. InputStreamReader;
0270: import java.io. IOException;
0271: import javax.xml.rpc. ServiceException;
0272: public class MyTestClient
0273: {
0274: public static void main(String[] pArgs) throws IOException, ServiceException
0275: {
0276: ATotalService tATotalService = new ATotalServiceLocator();
0277: ATotal tATotal = tATotalService.getATotal();
0278: ATotalSoapBindingStub tATotalSoapBindingStub = (ATotalSoapBindingStub)tATotal;
0279: tATotalSoapBindingStub.setMaintainSession(true);
0280: BufferedReader tKeyboard = new BufferedReader(new InputStreamReader(System.in));
0281: while (true)
0282: {
0283: System.out.print("Increment: ");
0284: String tLine = tKeyboard.readLine();
0285: if ( tLine.equals("") ) break;
0286: double tIncrement = Double.parseDouble(tLine);
0287: double tNewTotal = tATotal.inc(tIncrement);
0288: System.out.println("NewTotal is now: " + tNewTotal);
0289: }
0290: }
0291: }
The client sits there waiting for the user to type some value.
It thens calls inc
which will add the value to the total being stored by the Web Service.
The client then waits for another value to be typed.
An empty line is used to terminate the execution of the client.
The code of this client is similar to the code of the Axis Web Service client given earlier. The only new idea is contained in the statements:
0278: ATotalSoapBindingStub tATotalSoapBindingStub = (ATotalSoapBindingStub)tATotal; 0279: tATotalSoapBindingStub.setMaintainSession(true);The call of setMaintainSession ensures that the session id is collected from the first HTTP response and is used in the HTTP requests of any subsequent calls of methods of the Web Service.