2015-04-20 182 views
0

我使用使用kso​​ap2在android系統越來越參數錯誤

我收到此錯誤

SoapFault - faultcode: 'soap:Server' faultstring: 'Server was unable to process request. ---> The parameterized query 
java.lang.ClassCastException: org.ksoap2.SoapFault cannot be cast to org.ksoap2.serialization.SoapObject 

我使用加入參數的PropertyInfo

  PropertyInfo fromProp =new PropertyInfo(); 
      fromProp.setName("uname"); 
      fromProp.setValue("test"); 
      fromProp.setType(String.class); 
      request.addProperty(fromProp); 
      PropertyInfo toProp =new PropertyInfo(); 
      toProp.setName("pwd"); 
      toProp.setValue("test"); 
      toProp.setType(String.class); 
      request.addProperty(toProp); 

調用Web服務要求出現這樣的

validLogin{uname=simar; pwd=simar; }

事我試圖

1)註釋和的取消註釋以下行

envelope.dotNet = true; 

2)否服務器側誤差作爲不帶參數的連接可以是 完成並得到虛擬結果

3)即使想這

request.addProperty("uname","simar");

request.addProperty("pwd","simar");

回答

0

我合併知識,從你的上一個職位和這一個。 對於調用參數(在名稱空間末尾缺少斜槓「http://23.253.164.20:8096/」)以及參數uname和pwd上缺少命名空間,您有問題。我真的推薦使用SoapUI來比較正確的請求和你在transport.requestDump中有什麼。

工作代碼:

public final static String URL = "http://23.253.164.20:8096/login.asmx"; 
public static final String NAMESPACE = "http://23.253.164.20:8096/"; 
public static final String SOAP_ACTION_PREFIX = "http://23.253.164.20:8096/validLogin"; 
private static final String METHOD = "validLogin"; 
public String getFahrenheit(String celsius) { 

     try { 
      // SoapEnvelop.VER11 is SOAP Version 1.1 constant 
      SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
        SoapEnvelope.VER12); 
      SoapObject request = new SoapObject(NAMESPACE, METHOD); 
      PropertyInfo fromProp =new PropertyInfo(); 
      fromProp.setName("uname"); 
      fromProp.setValue("test"); 
      fromProp.setType(String.class); 
      fromProp.setNamespace(NAMESPACE); 
      request.addProperty(fromProp); 
      PropertyInfo toProp =new PropertyInfo(); 
      toProp.setName("pwd"); 
      toProp.setValue("test"); 
      toProp.setType(String.class); 
      toProp.setNamespace(NAMESPACE); 
      request.addProperty(toProp); 
      //bodyOut is the body object to be sent out with this envelope 
      envelope.bodyOut = request; 
      envelope.implicitTypes=true; 
      HttpTransportSE transport = new HttpTransportSE(URL); 
      transport.debug=true; 
      try { 
//      transport.call(NAMESPACE + SOAP_ACTION_PREFIX + METHOD, envelope); 
       transport.call(SOAP_ACTION_PREFIX, envelope); 
      } catch (IOException e) { 
       e.printStackTrace(); 
      } catch (XmlPullParserException e) { 
       e.printStackTrace(); 
      } 
      //bodyIn is the body object received with this envelope 
      if (envelope.bodyIn != null) { 
       //getProperty() Returns a specific property at a certain index. 
       SoapPrimitive resultSOAP = (SoapPrimitive) ((SoapObject) envelope.bodyIn) 
         .getProperty(0); 
       System.out.println(resultSOAP.toString()); 
      }