2

在访问 WCF (.svc) Web 服务时,我已经遇到此错误 2 周了。但是在 C# 中,当我将 Web 服务添加为服务引用时,它可以工作。

org.xmlpull.v1.XmlPullParserException: unexpected type (position:END_DOCUMENT null@1:1 in     java.io.InputStreamReader@418188c0)

Web 服务targetNamespace=""urn:data.link.abc"和方法的详细信息是

<wsdl:operation name="EncryptPassword">
<wsdl:input wsaw:Action="EncryptPassword" name="EncryptPasswordRequest" message="tns:EncryptPasswordRequest"/>
<wsdl:output wsaw:Action="urn:data.link.abc/ABCContract/EncryptPasswordResponse"     name="EncryptPasswordReply" message="tns:EncryptPasswordReply"/>
</wsdl:operation>

这是我访问 .svc Web 服务的代码。

public final String web_serviceEncryptPassword(String password)
{
    String NAMESPACE = "urn:data.link.abc";
    String METHOD_NAME = "EncryptPassword";
    String SOAP_ACTION =  NAMESPACE + "/" + "EncryptPassword";
    String URL = "http://192.168.20.254:8081/Service.svc"; //"http://192.168.20.254:8081/Service.svc?wsdl";

    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.dotNet = true;
    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
    Object result = null;
    try
    {
        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
        //request.addProperty("_Password", password);
        PropertyInfo propertyInfo = new PropertyInfo();
        propertyInfo.setName("arg0");
        propertyInfo.setValue(password);
        propertyInfo.setType(String.class);
        request.addProperty(propertyInfo);


        envelope.setOutputSoapObject(request);
        envelope.bodyOut = request;

        //They said they have an authorization, but same error still showed up when I added the header for the                 
        //Authorization...
        //List<HeaderProperty> headers = new ArrayList<HeaderProperty>();
        //String authentication = android.util.Base64.encodeToString(
        //         "user.a:password".getBytes(), android.util.Base64.NO_WRAP);
        //headers.add(new HeaderProperty("Authorization", "Basic " + authentication));
        //// headers.add(new HeaderProperty("Authorization", "user.a:password"));

        androidHttpTransport.debug = true;
        androidHttpTransport.call(SOAP_ACTION, envelope);//, headers);
        SoapObject response = (SoapObject) envelope.getResponse();
        result = Boolean.parseBoolean(response.getProperty(0).toString());

    }
    catch (Exception E)
    {
        E.printStackTrace();
    }

    return result.toString();
}

我使用 ksoap2-android-assembly-2.5.7-jar-with-dependencies.jar 作为我的 KSOAP2 库。

4

2 回答 2

1

我在 (ver1.2) 的行下面更改了相同的问题,问题已解决

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
于 2013-10-27T18:30:47.427 回答
0

这很可能意味着服务器以 http 错误响应。ksoap 无法解析 http 错误。我们已手动将此功能添加到库中。

于 2014-09-22T08:29:43.173 回答