2013-09-26 50 views
1

我在訪問WCF(.svc)時已經遇到這個錯誤2周了, Web服務,但在C#,當我加入了Web服務作爲服務引用,它的工作原理。org.xmlpull.v1.XmlPullParserException:意外類型(位置:END_DOCUMENT null @ 1:1在Android KSOAP2中,但在C#中它正在工作

org.xmlpull.v1.XmlPullParserException: unexpected type (position:END_DOCUMENT [email protected]:1 in  [email protected]) 

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 service。

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(); 
} 

我使用kso​​ap2-android-assembly-2.5.7-jar -with-dependencies.jar作爲我的KSOAP2庫。

回答

0

我有以下線改變了同樣的問題(ver1.2),並解決了問題

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
0

這很可能意味着該服務器的HTTP錯誤響應。 ksoap無法解析http錯誤。 我們已經將此功能手動添加到庫中。

相關問題