2015-02-23 100 views
0

我試圖從Android應用程序連接到外部web服務,但目前它在XML響應中崩潰,請幫助我注意如果調用結構構建不正確或任何響應代碼崩潰。這裏是我的代碼:連接到外部web服務無法在Android上響應

public class sri extends AsyncTask<String, String, String> 
{ 
public final static String URL = "http://qa-suia.ambiente.gob.ec:8092/suiawebservices/SuiaServices?wsdl"; 
public static final String NAMESPACE = "http://client.ambiente.gob.ec/"; 
public static final String SOAP_ACTION_PREFIX = "/"; 
private static final String METHOD = "getRuc"; 

private String resp; 
SoapSerializationEnvelope sobre = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
protected String doInBackground(String... param) 
{ 

    SoapObject request = new SoapObject(NAMESPACE,METHOD); 
    //String JsonString=Serializa(); 
    request.addProperty("user","99999999"); 
    request.addProperty("pass","xxxxxxxxxxxx"); 
    request.addProperty("rucNumber","99999999999"); 

    //sobre.dotNet=true; 
    sobre.setOutputSoapObject(request); 
    try 
    { 
     HttpTransportSE transporte=new HttpTransportSE(URL); 
     transporte.call(NAMESPACE+METHOD, sobre); 
    } catch (Exception e) 
    { 
     String msn="error"; 
     return msn; 
    } 

    try { 
     if (sobre != null) { 
      SoapPrimitive response = (SoapPrimitive)sobre.getResponse(); 
      resp=response.toString(); 

     } 
     else 
     { 

     } 
    } catch (Exception e) { 
     e.printStackTrace(); 
     resp = e.getMessage(); 
    } 

    return resp; 
} 

protected void onProgressUpdate(Integer... values) 
{   
} 

public void onPreExecute() 
{ 
} 


public void onPostExecute(String result) 
{ 

    String resultado=result; 


} 
+0

有什麼你看到的堆棧跟蹤? – ucsunil 2015-02-23 16:34:57

+0

你在使用像ksoap2這樣的外部庫嗎? – 2015-02-23 16:42:10

+0

@KristyWelsh是目前僅使用kso​​ap2和json – Luiggi 2015-02-23 16:49:44

回答

0

這裏的工作代碼,我做調用的.Net服務是什麼(它看起來就像你不能把你的要求放進一個信封裏):

private static SoapPrimitive callProcServiceForScalar(String serviceMethod, String storedProc, String params) throws Exception { 
    String NAMESPACE = "http://" + YourIPAddress + "/"; 
    String METHOD_NAME = getMethodName(serviceMethod); 
    String SOAP_ACTION = NAMESPACE + METHOD_NAME; 
    String URL = "http://" + YourIP + "/YourService.asmx"; 
    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 


    request.addProperty("sPassword", sYourPassword); 
    request.addProperty("sData", sServerDB); 
    request.addProperty("sSP_Name", storedProc); 
    request.addProperty("sParam", params); 

    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 



    // Enable the below property if consuming .Net service 
    envelope.dotNet = true; 
    envelope.setOutputSoapObject(request); 


    numberOfBytesTransmitted = numberOfBytesTransmitted + StringToBytes(request.toString()); 


    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL, timeout); 

    SoapPrimitive returnable = null; 
    try { 
     androidHttpTransport.call(SOAP_ACTION, envelope); 
     returnable = (SoapPrimitive)envelope.getResponse(); 
    } catch (Exception e) { 
     e.printStackTrace(); 
     throw new Exception("Msg:" + e.getMessage() + "; SP:" + storedProc + "; Params: " + params + "; Method:" + METHOD_NAME); 
    } 

    return returnable; 
} 
+0

該服務是與Java,我認爲這些網址沒有正確構建。 這是網絡服務http://qa-suia.ambiente.gob.ec:8092/suiawebservices/SuiaServices?wsdl 但它不以這種方式運作 public static final String URL =「http:// qa- suia.ambiente.gob.ec:8092/suiawebservices/SuiaServices?wsdl「; public static final String NAMESPACE =「http://client.ambiente.gob.ec/」; private static final String METHOD =「getRuc」; and llamda this transporte.call(NAMESPACE + METHOD,above); – Luiggi 2015-02-23 17:43:11

+0

您是否嘗試將您的請求放入信封中? – 2015-02-23 20:58:26