我有一个旨在访问我的 Web 服务方法的类。问题是当我试图在异步调用中访问我的 Web 服务方法的输出时,它是空的。我应该怎么办?
这是我的网络服务类:
package ClassLibrary;
public class WebService {
private String namespace="";
private String url="";
public WebService(String namespace,String url) {
super();
this.namespace = namespace;
this.url = url;
}
public String CallMethod(String methodName,PropertyInfo pi) {
String result = "default";
SoapObject request = new SoapObject(namespace, methodName);
request.addProperty(pi);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(url);
try {
androidHttpTransport.call(namespace+methodName, envelope);
SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
result= response.toString();
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
}
这就是我试图调用网络服务的方式:
private class AsyncCallWS extends AsyncTask<String, Void, Void> {
private ProgressDialog dialog;
private Activity activity;
public String wsOutput="";
public String methodName="";
private WebService ws;
public AsyncCallWS(Activity activity,String methodName) {
this.activity = activity;
this.dialog = new ProgressDialog(activity);
this.methodName = methodName;
}
@Override
protected Void doInBackground(String... params) {
ws = new WebService(PublicVariable.NAMESPACE, PublicVariable.URL);
PropertyInfo pi= new PropertyInfo();
pi.setName("UserID");
pi.setValue("1");
pi.setType(String.class);
wsOutput=ws.CallMethod("GetPersonalInfo", pi);
return null;
}
@Override
protected void onPostExecute(Void result) {
if (this.dialog.isShowing()) {
this.dialog.dismiss();
}
if (methodName == "GetPersonalInfo") {
Log.d("Ehsan","OUTPUT IS:"+ wsOutput);
}
}
}