-1

这是我的web服务代码。我不知道如何解析soap响应,我该怎么做?我甚至不知道它是json还是Xml.So请告诉我它是哪种类型的响应? 我的回答是这样如何解析来自asp.net的soapobject响应

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; 

    } 

} 

回答

0

格式可能在数据表中返回格式。你更好地展现你的asp.net

0

创建您的Web服务代码,这是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; 
       } 
      } 
     } 
    } 
}