如何从asp.net

时间:2016-03-05 19:26:32

标签: android android-asynctask android-ksoap2 android-webservice android-database

这是我的网络服务代码。我不知道如何解析肥皂反应。我该怎么办?我甚至不知道它是json或Xml。所以请告诉我它是什么类型的回应?  我的回答是这样的

anyType的{Product_Details = anyType的{P_ID = 129; p_name = FFFF; C_name = GGGG;};}

public  class MyAsyncTask extends AsyncTask<String, String , String>
{

    @Override
    protected void onPostExecute(String arrPersons )
    {
        uid.setText(arrPersons);            
    }

    @Override
      protected void onProgressUpdate(String... text) 
    {

     uid.setText(text[0]);

    }

    @Override
    protected String doInBackground(String... arg0) 
    {

        SOAP_ADDRESS="";

        request=new SoapObject(WSDL_TARGET_NAMESPACE, OPERATION_NAME);
        publishProgress("Loading contents...");
        PropertyInfo pi=new PropertyInfo();
        pi.setName("PID");
        pi.setValue(Integer.parseInt(arg0[1]));
        pi.setType(String.class);
        request.addProperty(pi);
        pi=new PropertyInfo();

        envelope=new SoapSerializationEnvelope(SoapEnvelope.VER11);

        envelope.dotNet=true;
        envelope.setOutputSoapObject(request);

        httpTransport=new HttpTransportSE(SOAP_ADDRESS);
        try 
        {
            httpTransport.call(SOAP_ACTION, envelope);

            SoapObject response = (SoapObject)envelope.getResponse();


            for (int i = 0; i < response.getPropertyCount(); i++) 
            {
                Object property = response.getProperty(i);
                if (property instanceof SoapObject)
                {
                    SoapObject category_list = (SoapObject) property;
                  String  returnString1 = category_list.getProperty(0).toString();

                }
            }

         } 
        catch (Exception e) 
        {

            returnString1 = e.getMessage();
        }
        return  returnString1;

    }

}

2 个答案:

答案 0 :(得分:0)

格式可能是数据表的返回格式。您最好显示您在asp.net上创建的Web服务代码

答案 1 :(得分:0)

这是我用于Web服务的asp代码

public class qr : System.Web.Services.WebService {

[WebMethod]
public DataTable findData(String PID)
{
    String constr = ConfigurationManager.ConnectionStrings["ConnectionString2"].ConnectionString;
    using (SqlConnection con = new SqlConnection(constr))
    {
        using (SqlCommand cmd = new SqlCommand("SELECT * FROM Product_Details WHERE P_id = @P_id"))
        {
            cmd.Parameters.AddWithValue("@P_id", PID);
            cmd.Connection = con;
            con.Open();
            cmd.ExecuteNonQuery();
            using (SqlDataAdapter sda = new SqlDataAdapter())
            {
                sda.SelectCommand = cmd;
                using (DataTable dt = new DataTable())
                {
                    dt.TableName = "Product_Details";
                    sda.Fill(dt);
                    return dt;
                }
            }
        }
    }
}