我想调用 ASMX web 服务, 如何从 doInBackground 取回活动中的 SoapObject 或 List ,web 服务工作正常,它在日志文件上显示值,我的代码是,文件我调用 web 服务
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;
import android.util.Log;
public class WebserviceMainCategory {
static String SOAP_ACTION = "http://tempuri.org/loadProductCatagory";
static String METHOD_NAME = "loadProductCatagory";
static String NAME_SPACE = "http://tempuri.org/";
static String URL = "http://74.53.87.146/seharwebservice/Service.asmx";
public List<String> main_items = new ArrayList<String>();
public static String[] namess ;
static int s ;
public static SoapObject soap;
public SoapObject webServiceMain_list() {
SoapObject request = new SoapObject(NAME_SPACE, METHOD_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.implicitTypes = true;
envelope.setAddAdornments(false);
envelope.setOutputSoapObject(request);
HttpTransportSE httpTransportSe = new HttpTransportSE(URL);
httpTransportSe.debug = true;
try {
httpTransportSe.call(SOAP_ACTION, envelope);
Object result = envelope.getResponse();
soap = (SoapObject) result;
/*
SoapObject result2nd = (SoapObject) result;
s = result2nd.getPropertyCount();
//String[]arrayLis = new String[s];
namess = new String[s];
for(int i=0; i<result2nd.getPropertyCount(); i++)
{
Log.d("ddd", result2nd.getPropertyAsString(i));
namess[i]=result2nd.getPropertyAsString(i);
Log.d("array", namess[i]);
main_items.add(result2nd.getPropertyAsString(i));
}
*/
} catch (IOException e) {
e.printStackTrace();
} catch (XmlPullParserException e) {
e.printStackTrace();
}
return soap;
}
}
我在哪里创建 AsyncTask 类
class Main_itemsList extends AsyncTask<Void, Void, SoapObject> {
@Override
protected SoapObject doInBackground(Void... params) {
WebserviceMainCategory mAuth = new WebserviceMainCategory();
return mAuth.webServiceMain_list();
}
public void execute(SoapObject aa) {
}
}
如何在主要活动中获得响应,
喜欢我活动中的代码
SoapObject 肥皂 = 新 Main_itemsList().execute();
我们的
ListArray aa = new Main_itemsList().execute();
谢谢..