我想使用soap从我的Android应用程序中使用以下Web方法。任何人都可以帮助我吗?

时间:2015-04-22 09:29:03

标签: android asmx ksoap2

的WebMethod

    public XmlElement findUserInfoById(int Id)
    {
        //string name = ""; string email = ""; string phone = "";
        con.Open();
        SqlCommand cmd = new SqlCommand("select*from tblUsers where Id ="+ Id, con);
        cmd.ExecuteNonQuery();
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);
        con.Close();
        XmlDataDocument xmldata = new XmlDataDocument(ds);
        XmlElement xmlElement = xmldata.DocumentElement;
        return xmlElement;
    }

1 个答案:

答案 0 :(得分:0)

try {
        androidHttpTransport.call(SOAP_ACTION, envelope);
        SoapObject response = (SoapObject) envelope.getResponse();
        SoapObject s = (SoapObject) response.getProperty(0);
        for (int i = 0;i<s.getPropertyCount();i++){
            Object property = s.getProperty(i);
            if(property instanceof SoapObject){
                SoapObject category_list = (SoapObject) property;
                String strName = category_list.getProperty("name").toString();
                String strEmail = category_list.getProperty("email").toString();
                String strPhone = category_list.getProperty("phone").toString();
                Result = "Name : " + strName + "\nEmail : " + strEmail + "\nPhone : " + strPhone;
            }
        } 
    } catch (Exception e) {
        e.printStackTrace();
    }