我正在尝试使用 ksoap2 调用 java web 服务。我正在使用 ksoap2-android-assembly-2.6.5-jar-with-dependencies.jar 和 Android API 级别 8。
活动代码:
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� ...@3:97 in java.io.InputStreamReader@44f5de78)
06-12 13:01:51.563: E/Soap(471): org.xmlpull.v1.XmlPullParserException: unexpected type (position:TEXT ������������U��n� ...@3:97 in java.io.InputStreamReader@44f5de78)
有什么想法可能导致这种情况吗?可能与字符编码、GZIP 或不正确的肥皂版本有关吗?
任何帮助将不胜感激。
谢谢大卫