I am a beginner in Java and Android and have struggled for the better part of the day with the following problem:
I use ksoap2 to call a login method from a webservice. I expect to get a User object as response, not a SoapObject.
The call from Android is:
private static final String URL = "http://192.168.0.13:8080/LoginWS/LoginWS?wsdl";
  private static final String NAMESPACE = "http://ws/";
  private static final String METHOD_LOGIN = "login";
  ......
  SoapObject request = new SoapObject(NAMESPACE, METHOD_LOGIN);
      SoapSerializationEnvelope env =
          new SoapSerializationEnvelope(SoapEnvelope.VER11);
      request.addProperty("user", user);
      env.setOutputSoapObject(request);
      env.addMapping(NAMESPACE, "user", User.class);
      HttpTransportSE transport = new HttpTransportSE(URL);
      transport.debug = true;
      transport.call(NAMESPACE + METHOD_LOGIN, env);
      SoapObject response = (SoapObject) env.getResponse();
      System.out.println(response);
  ......
The Android User class is:
public class User implements KvmSerializable{
  private int id;
  private String username;
  private String password;
  private String telephone;
  public User(){
  }
  public User(String username, String password, String telephone){
    this.username = username;
    this.password = password;
    this.telephone = telephone;
  }
  public String getUsername() {
    return username;
  }
  public void setUsername(String username) {
    this.username = username;
  }
  public int getId() {
    return id;
  }
  public void setId(int id) {
    this.id = id;
  }
  public String getPassword() {
    return password;
  }
  public void setPassword(String password) {
    this.password = password;
  }
  public String getPhoneNumber() {
    return telephone;
  }
  public void setPhoneNumber(String phoneNumber) {
    this.telephone = phoneNumber;
  }
  @Override
  public Object getProperty(int i) {
    switch(i)
    {
      case 0:
        return id;
      case 1:
        return username;
      case 2:
        return password;
      case 3:
        return telephone;
    }
    return null;
  }
  @Override
  public int getPropertyCount() {
    return 4;
  }
  @Override
  public void setProperty(int i, Object o) {
    switch(i)
    {
      case 0:
        id = Integer.parseInt(o.toString());
        break;
      case 1:
        username = o.toString();
        break;
      case 2:
        password = o.toString();
        break;
      case 3:
        telephone = o.toString();
        break;
      default:
        break;
    }
  }
  @Override
  public void getPropertyInfo(int i, Hashtable hashtable, PropertyInfo propertyInfo) {
    switch(i)
    {
      case 0:
        propertyInfo.type = PropertyInfo.INTEGER_CLASS;
        propertyInfo.name = "id";
        break;
      case 1:
        propertyInfo.type = PropertyInfo.STRING_CLASS;
        propertyInfo.name = "username";
        break;
      case 2:
        propertyInfo.type = PropertyInfo.STRING_CLASS;
        propertyInfo.name = "password";
        break;
      case 3:
        propertyInfo.type = PropertyInfo.STRING_CLASS;
        propertyInfo.name = "telephone";
        break;
      default:
        break;
    }
  }
}
anyType{id=0; username=john; password=doe; telephone=074000000000; }
<?xml version='1.0' encoding='UTF-8'?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns2:loginResponse xmlns:ns2="http://ws/"><user><id>0</id><username>john</username><password>doe</password><telephone>074000000000</telephone></user></ns2:loginResponse></S:Body></S:Envelope>
On the server side:
The WS class:
@WebService(serviceName = "LoginWS")
@Stateless()
public class LoginWS {
@EJB
private LoginService userService;
@WebMethod(operationName = "login")
@WebResult(name="user")
public User login(@WebParam(name = "user") User user) {
return userService.login(user);
}
}
The User class:
public class User {
  private int id;
  private String username;
  private String password;
  private String telephone;
  public long getId() {
    return id;
  }
  public void setId(int id) {
    this.id = id;
  }
  public String getUsername() {
    return username;
  }
  public void setUsername(String username) {
    this.username = username;
  }
  public String getPassword() {
    return password;
  }
  public void setPassword(String password) {
    this.password = password;
  }
  public String getTelephone() {
    return telephone;
  }
  public void setTelephone(String telephone) {
    this.telephone = telephone;
  }
I am a beginner in Java and Android and have struggled for the better part of the day with the following problem: I use ksoap2 to call a login method from a webservice. I expect to get a User object as response, not a SoapObject. The call from Android is:
The Android User class is:
env.getResponse() returns SoapObject, not a User object. Its toString() prints
I activated the transport debug and saw that responseDump has the value:
On the server side: The WS class:
The User class:
The webservice is on the Glassfish server from Netbeans. Its generated wsdl is (http://w8-pc:8080/LoginWS/LoginWS?wsdl):
Please tell me what I am doing wrong, I need
|
--
You received this message because you are subscribed to the Google Groups "ksoap2-android" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ksoap2-android+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to ksoap2-androi...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to ksoap2-android+unsubscribe@googlegroups.com.