使用asynctaskloader从服务器获取数据

时间:2014-05-14 08:50:04

标签: android ksoap2 asynctaskloader

这是我从服务器获取数据的代码。

public class POSDataCloud {
private static String SOAP_ACTION1 = "http://tempuri.org/GetDescription";    
private static String NAMESPACE = "http://tempuri.org/"; 
private static String METHOD_NAME1 = "GetDescription";     
private static String URL = "http://182.160.99.115:2080/webservice1.asmx?WSDL";

public String GetPOSData(int POSID)
{
    String ret="";
    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME1);    
    //request.addProperty("Id",POSID);
    PropertyInfo property = new PropertyInfo();
    {
        property.name = "Id";
        property.setNamespace(NAMESPACE);
        property.type = PropertyInfo.STRING_CLASS;
        property.setValue("3"); 
    }
    request.addProperty(property);

    //Declare the version of the SOAP request   
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);           
    envelope.setOutputSoapObject(request);
    envelope.implicitTypes=true;
    envelope.dotNet = true;
    try
    {
          HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);                   
          //this is the actual part that will call the webservice
          androidHttpTransport.call(SOAP_ACTION1, envelope);          
          // Get the SoapResult from the envelope body.
          SoapObject result = (SoapObject)envelope.bodyIn;
          if(result != null)
          {
              ret=result.getProperty(0).toString();
          }
          else
          {
              ret="no response";
          }
    } 
    catch (Exception ex)
    {
      ex.printStackTrace();
      ret=ex.getMessage();
    }
    return ret;


}

}

但是我想用asyncTaskLoader来做它。怎么做呢? 编辑:其实property.setValue是PosId.how在asynctaskloader中的loadInBackground中传递posId?我只需要执行loadInBackground方法。我认为它有posId参数。但我不能得到asynctaskloader的任何一个参数的例子loadInBackground方法。非常感谢任何人帮助我。

0 个答案:

没有答案