1

我是初学者。我正在创建一个使用返回 SOAP 的 Azure Web 服务的 Android 应用程序。Web 服务的地址是http://XXXXXXXX.cloudapp.net/Service.svc/

我正在使用 ksoap2 来使用该服务。我想涵盖所有基础。我已经处理了 Android 设备中没有互联网连接的情况。但是,我想处理 Web 服务关闭的不太可能的情况。

人们是如何做到这一点的?我是否在 catch 中使用某种异常处理程序?哪个抓?提前致谢。我正在使用 AsyncTask:

  public class getSetWSDate extends AsyncTask<Void, Void, Void>

{

   ProgressDialog dialog;

   @Override
   protected void onPreExecute() {
       // TODO Auto-generated method stub
       super.onPreExecute();

       dialog = ProgressDialog.show(activity, "", "Please wait...");

   }

   @Override
   protected Void doInBackground(Void... params) {
       // TODO Auto-generated method stub

       try {
            SoapObject request = new SoapObject(NAMESPACE, DATE_METHOD_NAME); 

               SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
               envelope.dotNet = true;
               envelope.setOutputSoapObject(request);

               HttpTransportSE ht = new HttpTransportSE(URL);
               ht.debug = true;

               ht.call(SOAP_ACTION_DATE, envelope);


               final  SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
               final String strDate = response.toString();


               SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
                Date webServiceDate = new Date(); //"2013-07-07 10:00:00" 
                try {

                    webServiceDate = (Date)dateFormat.parse(strDate);
                } catch (ParseException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

                catch (Exception e) {
                      e.printStackTrace();
                  }
       syncDateDatasource.open();


   syncDateDatasource.createDate(webServiceDate);
   syncDateDatasource.close();
       }        catch (Exception e) {
              e.printStackTrace();
          }
       return null;
   }

   @Override
   protected void onPostExecute(Void result) {
       // TODO Auto-generated method stub
       super.onPostExecute(result);

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

       try {
         ....


       } catch (Exception e) {
                  e.printStackTrace();
              }

   }

}

4

0 回答 0