0

I'm trying to connect to a external webservice from an Android app, but currently it crashes on the XML response, please help me notice if the call structure is built incorrectly or any the response code is crashed. Here is my code:

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;


}
Luiggi
  • 1
  • 1

1 Answers1

0

Here's working code for what I'm doing calling a .Net Service (It looks like you're not putting your request into an envelope):

    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;
}
Kristy Welsh
  • 7,828
  • 12
  • 64
  • 106
  • the service is with java, I think the urls are not constructed properly. This is the web service http://qa-suia.ambiente.gob.ec:8092/suiawebservices/SuiaServices?wsdl but it does not function in this way      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 Feb 23 '15 at 17:43
  • Have you tried putting your request into an envelope? – Kristy Welsh Feb 23 '15 at 20:58