How to recover a soapObject from a return from the webservice

Asked

Viewed 971 times

3

 androidHttpTransport.call(SOAP_ACTION4, envelope);
            SoapObject result = (SoapObject) envelope.getResponse();

            System.out.println(result.getProperty("nmConsultor"));
            return result.toString();

In case I would like to recover the properties contained in my return...

Someone can help me??

  • If possible, use a REST Service with Json, as each SOAP envelope is too large and can consume enough data traffic on Android.

  • the problem is that the webservice is created outside the company... so I have no say in =/

  • I understand, anyway that would be a good argument.

1 answer

2

Using ksoap2 v2.5.8 library, I do so:

public static String conectWs(String URL, String NAMESPACE, String METHOD_NAME, String strDataXmt, String param) throws Exception{

    HttpTransportSE androidHttpTransport = null;
    SoapObject request = new SoapObject(NAMESPACE , METHOD_NAME);

    request.addProperty(param, strDataXmt);
    //androidHttpTransport.debug = true;

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

    androidHttpTransport = new HttpTransportSE(URL);
    androidHttpTransport.call(NAMESPACE + METHOD_NAME, envelope);
    Object results = (Object) envelope.getResponse();

    return results.toString();
}

Then, to read this result string as an Xml, I do this parse:

 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();  
 DocumentBuilder builder = factory.newDocumentBuilder();  
 Document doc = builder.parse(new InputSource(new StringReader(stringDeResultado)));  

 doc.getDocumentElement().normalize();
 NodeList nodeList = doc.getElementsByTagName("suaTag");
  • Thanks Brother, and in case you see an XML reply... I’m not able to parse, because this coming in String format, then I can’t recover the properties... Thank you for your attention

  • I edited the post, see if that’s what you’ve been wanting

  • I could do it, but this with returning this error... Unexpected token (position:TEXT anyType{Gestorwe...@1:163 in java.io.Stringreader@41750d08) , what could it be? sorry for the inconvenience, I never messed with XML and Webservice... Thank you very much for the help

  • You can send me the contents of String at the time of parse?

  • string = anyType{GestorWebServices=anyType{cdRetorno=0; dsRetorno=anyType{}; cdConsultor=7; nmConsultor=Ediana Frainer Mazotto; cdHash=010200020007008307042014205205; }; }

  • Boy, that return there is not an XML no. That’s why the error.

  • in the service ta saying it comes xml http://gestorweb.guiafacil.com/gestorwebservices/GestorWebServices.asmx?op=AutenticarTablet

  • this link you sent me is not opening, it seems that because of timeout. It is in debug mode?

  • tries this one http://gestorweb.guiafacil.com/gestorwebservices/GestorWebServices.asmx

  • not funfando this url no...

  • very strange I’m moving it here now and it’s funfando

  • http://gestorweb.guiafacil.com/gestorwebservices/GestorWebServices.asmx strange because here funnel and already it is from outside that

Show 7 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.