users@glassfish.java.net

NB 6.9, GF 3.0.1. Newbe with Web Service

From: <glassfish_at_javadesktop.org>
Date: Wed, 04 Aug 2010 00:50:43 PDT

Hi,

I am trying a simple WS that adds two int. This is the code,
 
@WebService()
@Stateful()
public class AddNumbers {
 
    private int num1;
    private int num2;
 
    /**
     * Web service operation
     */
    @WebMethod(operationName = "setNum1")
    public void setNum1(@WebParam(name = "num1")
    int num1) {
        //TODO write your implementation code here:
        this.num1 = num1;
    }
 
    /**
     * Web service operation
     */
    @WebMethod(operationName = "setNum2")
    public void setNum2(@WebParam(name = "num2")
    int num2) {
        //TODO write your implementation code here:
        this.num2 = num2;
    }
 
    /**
     * Web service operation
     */
    @WebMethod(operationName = "addNumbers")
    public int addNumbers() {
        //TODO write your implementation code here:
        return this.num1 + this.num2;
    }
 
}

 
And the client is as follows,
 
public class Main {
 
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        int num1 = 5;
        int num2 = 3;
 
        // The client connects to the service with this code.
        AddNumbersService service = new AddNumbersService();
        AddNumbers port = service.getAddNumbersPort();
 
        port.setNum1(num1);
        port.setNum2(num2);
 
        System.out.println(num1 + " + " + num2 + " = " + port.addNumbers());
 
    }
 
}

 
Everything is ok, but the result of the operation is always 0.
 
What is going wrong?
 
Regards,
Jose
[Message sent by forum member 'josealvarezdelara']

http://forums.java.net/jive/thread.jspa?messageID=479304