简体   繁体   English

无法获取Web服务的输出

[英]Can not get the output of web service

I have a class designed to access my web service methods. 我有一个旨在访问我的Web服务方法的类。 the problem is when I'm trying to access the output of my web service method in an Async call, It's empty. 问题是当我尝试在异步调用中访问Web服务方法的输出时,它为空。 what should I do? 我该怎么办?
This is my web service class: 这是我的网络服务类:

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;
    }
}

and this is how I'm trying to call web service: 这就是我试图调用网络服务的方式:

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);
        }
    }
}

The three types used by an asynchronous task are the following: 异步任务使用的三种类型如下:

  • Params, the type of the parameters sent to the task upon execution. 参数,执行时发送给任务的参数类型。

  • Progress, the type of the progress units published during the background computation. 进度,后台计算期间发布的进度单位的类型。

  • Result, the type of the result of the background computation. 结果,背景计算结果的类型。

onPostExecute(Result) is invoked on the UI thread after the background computation finishes. 后台计算完成后,将在UI线程上调用onPostExecute(Result) The result of the background computation is passed to this step as a parameter and you are not passing the resulting value. 后台计算的结果作为参数传递到此步骤,而您没有传递结果值。

private class AsyncCallWS extends AsyncTask<String, Void, String> {

    private ProgressDialog dialog;
    private Activity activity;
    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);

        String wsOutput = ws.CallMethod("GetPersonalInfo", pi);

        return wsOutput;
    }

    @Override
    protected void onPostExecute(String result) {

        if (this.dialog.isShowing()) {
            this.dialog.dismiss();
        }

        Log.d("Ehsan","OUTPUT IS:"+ result);
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM