在安卓上调用网络服务



尝试使用异步,但即使没有吐司也无法处理程序,还尝试了调用调用方法runUI读取但没有运气,

异步方法有效,但它也会出现运行时异常

当我

使用异步方法数据进入文本视图时太晚(5-10 分钟),但是当我在调试器中使用它时,它会立即得到 ,

下面的网络服务是使用Wizdl应用程序进行测试,响应是即时的

我很困惑,请帮忙

private final String NAMESPACE = "http://????????.com/EventGetter/";
private final String URL = "http://?????????.com/EventGetter.asmx";
private final String SOAP_ACTION = "http://????????.com/EventGetter/GetTimeTable";
private final String METHOD_NAME = "GetTimeTable"; 
private class TPaccessData extends AsyncTask<String, Void, Void>{
    @Override
    protected Void doInBackground(String... params) {
        GetData();
        return null;
    }
    @Override
    protected void onPostExecute(Void result) {
        Log.i(LogStr, "onPostExecute");
    }
    @Override
    protected void onPreExecute() {
        GetData();
        Log.i(LogStr, "onPreExecute");
    }
    @Override
    protected void onProgressUpdate(Void... values) {
        Log.i(LogStr, "onProgressUpdate");
    }
}
public void GetData(){
    //Create request
    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
    //set properties aka param
    request.addProperty("stream","where ttBatch = 'F.Y.J.C'");
    //Create envelope
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
            SoapEnvelope.VER11);
    envelope.dotNet = true;
    //Set output SOAP object
    envelope.setOutputSoapObject(request);
    //Create HTTP call object
    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
    try {
        androidHttpTransport.debug = true;
        //Invole web service
        androidHttpTransport.call(SOAP_ACTION, envelope);
        //Get the response
        SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
        //Assign it to Text static variable
        text.setText(response.toString());
    } catch (Exception e) {
        e.printStackTrace();
    }
}

还尝试在onCreate方法中调用获取数据

 NotifyList.this.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            GetData();
          //  TPaccessData task = new TPaccessData();
          //   task.execute();
        }
    });

从 onPreExecute() 中删除 youe GetData() 方法。并在 onPost 中调用此线路

text.setText(response.toString());

最新更新