在访问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网络服务的代码。
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库。
答案 0 :(得分:1)
我将同样的问题更改为以下行(ver1.2)并且问题已解决
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
答案 1 :(得分:0)
这很可能意味着服务器以http错误响应。 ksoap无法解析http错误。 我们已手动将此功能添加到库中。