6

我正在尝试使用 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 或不正确的肥皂版本有关吗?

任何帮助将不胜感激。

谢谢大卫

4

1 回答 1

1

我在使用 ksoap2 2.6.5 时遇到了同样的问题。我用版本修复了这个问题。2.5.4

这里: http ://code.google.com/p/ksoap2-android/source/browse/m2-repo/com/google/code/ksoap2-android/ksoap2-android-assembly/#ksoap2-android-assembly%2F2 .5.4

于 2012-07-03T11:15:36.857 回答