Web サービス メソッドにアクセスするように設計されたクラスがあります。問題は、非同期呼び出しで 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;
}
}
これが私がWebサービスを呼び出そうとしている方法です:
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);
}
}
}