Question

Hey all, i'm having a little problem with ksoap2 and getting response i have the following code on Blackberry client side:

private boolean AddVoiceNote()
{
    _webMethod = "AddVoiceNote";
    _soapAction.concat(_webMethod);
    Boolean response = null;

    SoapObject methodCall = new SoapObject(_serviceNameSpace, _webMethod);
    SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

    soapEnvelope.bodyOut = methodCall;
    soapEnvelope.dotNet = false;
    soapEnvelope.encodingStyle = SoapSerializationEnvelope.XSD;
    soapEnvelope.setOutputSoapObject(methodCall);

    methodCall.addProperty("name", _voiceNote.get_nombre());
    methodCall.addProperty("comment", _voiceNote.get_comentario());
    methodCall.addProperty("audio", Base64.encode(_voiceNote.get_audioArray()));
    methodCall.addProperty("id", String.valueOf(_voiceNote.get_userId()));
    methodCall.addProperty("postTwitter", String.valueOf(_voiceNote.is_twitterPost()));
    methodCall.addProperty("postFacebook", String.valueOf(_voiceNote.is_facebookPost()));

    HttpTransport transport = new HttpTransport(_serviceURL);

    transport.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
    try {

        transport.call(_soapAction, soapEnvelope);
        SoapObject responseSoap = (SoapObject)soapEnvelope.getResponse();
        response = (Boolean)responseSoap.getProperty("return");
        System.out.println(responseSoap.toString());
        return response.booleanValue();
    } catch (IOException e) {
        return false;
    } catch (XmlPullParserException e) {
        return false;
    }

}

And this is the web method it is calling:

@WebMethod(operationName = "AddVoiceNote")
public Boolean AddVoiceNote(
@WebParam(name = "name")String name,
@WebParam(name = "comment")String comment,
@WebParam(name = "audio")String audio,
@WebParam(name = "id")String id,
@WebParam(name = "postTwitter")String postTwitter,
@WebParam(name = "postFacebook")String postFacebook)
{
    VoiceNote voiceNote = new VoiceNote();
    VoiceNoteMananger voiceNoteManager = new VoiceNoteMananger();

    voiceNote.setComentario(comment);
    voiceNote.setNombre(name);
    voiceNote.setIdUser(Long.parseLong(id));
    voiceNote.setFacebookPost(Boolean.getBoolean(postFacebook));
    voiceNote.setTwitterPost(Boolean.parseBoolean(postTwitter));
    voiceNote.setTrack(audio.getBytes());

    return voiceNoteManager.addVoiceNote(voiceNote);
}

The problem i'm having is properly getting the response, i get a ClassCastException when trying to get it and the debugger just exits the method, any idea how I can fix this? Oh also here's the response xml I get from my Web Method:

<?xml version='1.0' encoding='UTF-8'?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
 <S:Body><ns2:AddVoiceNoteResponse xmlns:ns2="http://WebService/">
  <return>true</return></ns2:AddVoiceNoteResponse>
 </S:Body>
</S:Envelope>
Was it helpful?

Solution

Sorry, I don't have the privilege to write comments, otherwise I would not post an answer for this little hint...

Actually, the envelope has got a method "stringToBoolean". Here's a link to the method in the API.

Greetings

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top