在访问 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 库。