Android访问webservice.客户端登录注册(2)


 public UserInfo findUserByName(String name) {
  // TODO Auto-generated method stub
  SoapObject soapObject = new SoapObject(NAMESPACE, FIND_METHOD_NAME);
  soapObject.addProperty("name", name);
  SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
    SoapEnvelope.VER11);// 版本
  envelope.bodyOut = soapObject ;
  envelope.dotNet = false ;
  envelope.setOutputSoapObject(soapObject) ;
  HttpTransportSE trans = new HttpTransportSE(URL) ;
  trans.debug = true ; // 使用调试功能
  try {
   trans.call(SOAP_ACTION, envelope) ;
  } catch (IOException e) {
   e.printStackTrace();
  } catch (XmlPullParserException e) {
   e.printStackTrace();
  }
  SoapObject result = (SoapObject) envelope.bodyIn;
    Gson gson = new Gson();
    String json = result.getProperty(0).toString();
    UserInfo userInfo = new UserInfo();
    userInfo = gson.fromJson(json, UserInfo.class); 
  System.out.println("Web Service返回的数据是:"+result.getProperty(0));
  System.out.println("Web Service返回的userInfo"+userInfo);
  return userInfo;
 
 
 }
 public void saveUser(String name,String password) {
  // TODO Auto-generated method stub
  SoapObject soapObject = new SoapObject(NAMESPACE, SAVE_METHOD_NAME);
  soapObject.addProperty("name", name);
  soapObject.addProperty("password", password); 
  SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
    SoapEnvelope.VER11);// 版本
  envelope.bodyOut = soapObject ;
  envelope.dotNet = false ;
  envelope.setOutputSoapObject(soapObject) ;
  HttpTransportSE trans = new HttpTransportSE(URL) ;
  trans.debug = true ; // 使用调试功能
  try {
   trans.call(SOAP_ACTION, envelope) ;
  } catch (IOException e) {
   e.printStackTrace();
  } catch (XmlPullParserException e) {
   e.printStackTrace();
  }
 
 }
}

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/57228e00f2aea9618c81658da0bdcf02.html