2015-04-20 145 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()); 
      }