Android手机客户端访问.NET服务器端的方法(2)
贴一下我自己写的代码:
private String NameSpace = "http://tempuri.org/"; private String LoginMd = "Login"; /** * 用户登录 * * @param username * @param userpassword * @return */ public String Login(String username, String userpassword) { String str = null; user_name = username; user_password = userpassword; try { // 指定webservice的命名空间和方法 SoapObject request = new SoapObject(NameSpace, LoginMd); // 设置调用方法的参数 request.addProperty("username", user_name); request.addProperty("userpassword", user_password); // 生成调用webservice方法的soap请求信息 SoapSerializationEnvelope envelope = new SoapSerializationEnvelope( SoapEnvelope.VER11); // 设置是否调用的是dotNet下的webservice envelope.dotNet = true; // envelope.setOutputSoapObject(request); // 创建httpTransport上SE对象 HttpTransportSE ht = new HttpTransportSE(url); // 调用webservice ht.call(Log_soapAction, envelope); // 使用getResponse方法获得webservice方法返回结果 if (envelope.getResponse() != null) { // SoapPrimitive response = (SoapPrimitive) // envelope.getResponse(); SoapObject soapob = (SoapObject) envelope.bodyIn; str = soapob.getProperty(0).toString(); // str=response.toString(); if (str.equals("false"))// 如果登录不成功 { str = "false"; } else {// 登录成功解析用户信息 // Userinfo(str); // GetPro(); flag = str; str = "true"; } } } catch (Exception e)// 异常处理,用户名或密码错误 { str = "error"; } return str; }