我試圖使用ksoap2調用java web服務。我現在用的是ksoap2-Android的組裝2.6.5-JAR-與-dependencies.jar和Android API 8級。ksoap2 Android意外類型的響應
活動代碼:
private static final String SECURITY_NAMESPACE = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";
private static final String USERNAME_TOKEN_NAMESPACE = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd";
private static final String PASSWORD_TYPE = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
Element usernameElement = new Element().createElement(SECURITY_NAMESPACE, "Username");
usernameElement.addChild(Node.TEXT, "username");
Element passwordElement = new Element().createElement(SECURITY_NAMESPACE, "Password");
passwordElement.setAttribute(null, "Type", PASSWORD_TYPE);
passwordElement.addChild(Node.TEXT, "password");
Element usernameTokenElement = new Element().createElement(USERNAME_TOKEN_NAMESPACE, "UsernameToken");
usernameTokenElement.addChild(Node.ELEMENT, usernameElement);
usernameTokenElement.addChild(Node.ELEMENT, passwordElement);
Element securityElement = new Element().createElement(SECURITY_NAMESPACE, "Security");
securityElement.setAttribute(null, "mustUnderstand", "1");
securityElement.setPrefix(null, SECURITY_NAMESPACE);
securityElement.addChild(Node.ELEMENT, usernameTokenElement);
Element[] header = new Element[]{securityElement};
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.headerOut = header;
envelope.setOutputSoapObject(request);
HttpTransportSE httpTransport = new HttpTransportSE(URL);
httpTransport.debug = true;
try{
httpTransport.call(SOAP_ACTION, envelope);
SoapObject response = (SoapObject) envelope.getResponse();
}catch (Exception e) {
Log.e("Soap", e.getMessage(), e);
}
當我打這個電話,我得到以下例外:
06-12 13:01:51.563: E/Soap(471): unexpected type (position:TEXT ������������U��n� [email protected]:97 in [email protected])
06-12 13:01:51.563: E/Soap(471): org.xmlpull.v1.XmlPullParserException: unexpected type (position:TEXT ������������U��n� [email protected]:97 in [email protected])
任何想法可能會導致這種情況?這可能與字符編碼,GZIP或不正確的肥皂版本有關嗎?
任何幫助將不勝感激。
感謝 大衛
嘗試切換到'SoapEnvelope.VER12'(代替VER11)。 –