2013-12-12 46 views
0

我在使用此代码时得到了Exception,但它适用于其他链接。无法从Android中的Web服务解析

public class WebserviceCall { 

    static WebserviceCall com; 
    String namespace = "http://tempuri.org/"; 
    private String url = "http://sicsglobal.co.in/T-Drive/WebService_TDrive.asmx"; 
    String SOAP_ACTION; 
    SoapObject request = null, objMessages = null; 
    SoapSerializationEnvelope envelope; 
    AndroidHttpTransport androidHttpTransport; 

    public static WebserviceCall getInstance() { 
     if (com == null) 
      return new WebserviceCall(); 
     else 
      return com; 
    } 

    protected void SetEnvelope() { 
     try { 
      envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
      envelope.dotNet = true; 
      envelope.setOutputSoapObject(request); 
      androidHttpTransport = new AndroidHttpTransport(url); 
      androidHttpTransport.debug = true; 

     } catch (Exception e) { 
      System.out.println("Soap Exception SetEnvelope(); \n" 
        + e.toString()); 
     } 
    } 

    public String getConvertedWeight(String MethodName, String thisUsername, 
      String thisPassword) { 
     try { 
      SOAP_ACTION = namespace + MethodName; 
      request = new SoapObject(namespace, MethodName); 

      request.addProperty("userId", "" + thisUsername.trim()); 
      request.addProperty("password", thisPassword.trim()); 

      SetEnvelope(); 

      try { 
       androidHttpTransport.call(SOAP_ACTION, envelope); 
       String result = envelope.getResponse().toString(); 
       return result; 
      } catch (Exception e) { 
       return e.toString(); 
      } 
     } catch (Exception e) { 
      // TODO: handle exception 
      return e.toString(); 
     } 
    } 

} 
+1

由于需要在“在此处输入代码”部分输入代码,因此最常出现的情况是 – JBA

+0

发生了异常 –

+0

发布您的logcat输出 – ismail

回答

0

尝试使用Asynctask。

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

    protected void onPreExecute() { 

    } 

    @Override 
    protected String doInBackground(String... urls) { 

        //your code here 
      return response; 
    } 

    @Override 
    protected void onPostExecute(String response) { 
     //treat the response here 
    } 
} 

查看here了解更多信息。

如果这个dosn't工作,张贴您的logcat。