3

大家好,我在使用 ksoap2 时遇到了一点问题并得到了响应,我在 Blackberry 客户端有以下代码:

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;
    }

}

这是它正在调用的网络方法:

@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);
}

我遇到的问题是正确获得响应,我在尝试获取它时收到 ClassCastException 并且调试器刚刚退出该方法,知道如何解决这个问题吗?哦,这也是我从 Web Method 获得的响应 xml:

<?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>
4

1 回答 1

0

对不起,我没有写评论的特权,否则我不会为这个小提示发布答案......

实际上,信封有一个方法“stringToBoolean”。这是 API 中方法的链接。

问候

于 2011-02-06T17:12:41.480 回答