Runtime tools : Channels components : Mobile Channel : Tasks : Invoking server operation : Invoking session operation using the advanced way
  
Invoking session operation using the advanced way
Pass the Map which contains the passed values, operation name and result id defined in the server side context definition as the parameters. After invoking the API, you can get the synchronized result.
There are two approaches:
Approach 1: Pass JavaBean to the server side and get another JavaBean returned. Following is the sample code for login.
In the client side, input the User (username and password), and a resultbean is returned:
public static void main(String[] args) throws Exception {
DataAdapter adapter = new MobileAdapter();
if (adapter.establishSession()) {
User user = new User();
user.setUserName("aaaa");
user.setPassword("bbbb");
Map param = new HashMap();
param.put("userBean", user);
Result result = (Result) adapter.invoke("MobileSignInOp", param, "resultBean");
adapter.invoke("MobileSignInOp", param, "resultBean");
System.out.println(result);
}
}
Following are the code samples for Data definition, Context definition, and Operation implementation in the server side:
Data definition:
Screen capture of data definition
Context definition:
Screen capture of context definition
Operation implementation:
Screen capture of operation
Approach 2: Pass the simple attribute to the server side and get JavaBean returned
Following is the sample code for querying user by useid:
public static void main(String[] args) throws Exception {
  DataAdapter adapter = new MobileAdapter();
  if (adapter.establishSession()) {
    Map query = new HashMap();
    query.put("userId","111");
    //Query user by userId
    User resultUser = (User)     adapter.invoke("MobileQueryUserOp",query, "userBean");
    //print the result
    System.out.println("the user " + resultUser);
  }
}
Following are the code samples for Data definition, Context definition, and Operation implementation in the server side:
Data definition:
Screen capture of data definition
Context definition:
Screen capture of context definition
Operation implementation:
Screen capture of operation
Go up to
Invoking server operation