【问题标题】:how to parse soapobject response from asp.net如何解析来自asp.net的soapobject响应
【发布时间】:2016-03-05 19:26:31
【问题描述】:

这是我的网络服务代码。我不知道如何解析肥皂响应。我该怎么办?我什至不知道它是 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;

    }

}

【问题讨论】:

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


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      这是我的 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;
                      }
                  }
              }
          }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-10-17
        • 1970-01-01
        • 2015-02-26
        • 1970-01-01
        • 1970-01-01
        • 2016-09-29
        • 2018-08-27
        • 2016-05-29
        相关资源
        最近更新 更多