3
嘿,我在與ksoap2一個小問題,並得到迴應,我對黑莓客戶端下面的代碼:問題與Ksoap2響應
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;
}
}
這是Web方法被調用:
@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?哦也,這裏的響應XML我從我的Web方法獲得:
<?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>
什麼是ClassCastException? – 2010-11-12 16:21:05
發生在這一行SoapObject responseSoap =(SoapObject)soapEnvelope.getResponse();只是說ClassCastException – 8vius 2010-11-12 18:36:43
將演員從SoapObject更改爲對象之後y注意getResponse()爲空T_T – 8vius 2010-11-12 18:40:36