在KSOAP 2机器人越来越参数错误 [英] getting parameter error in ksoap 2 android

查看:295
本文介绍了在KSOAP 2机器人越来越参数错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的调用Android的使用kso​​ap2 web服务

我收到此错误

 的SOAPFault  - 故障code:香皂:服务器'faultstring:服务器无法处理请求。 --->该参数化查询
java.lang.ClassCastException:org.ksoap2.SoapFault不能转换为org.ksoap2.serialization.SoapObject

我使用添加参数的PropertyInfo

 的PropertyInfo fromProp =新的PropertyInfo();
            fromProp.setName(UNAME);
            fromProp.setValue(测试);
            fromProp.setType(为String.class);
            request.addProperty(fromProp);
            的PropertyInfo toProp =新的PropertyInfo();
            toProp.setName(PWD);
            toProp.setValue(测试);
            toProp.setType(为String.class);
            request.addProperty(toProp);

要求显示像这样


  

validLogin {UNAME = SIMAR; PWD = SIMAR; }


东西我都试过


  

1),注释和以下行取消注释

  envelope.dotNet = TRUE;


  
  

2)不带参数的连接可以是任何服务器端错误
  完成并获得虚拟的结果。


  
  

3)即使试过这种


  
  

request.addProperty(的uname,SIMAR);


  
  

request.addProperty(PWD,SIMAR);



解决方案

我从你的preV后,从这个合而为一的知识。
你有调用参数(名称空间的尽头铁。缺少斜线的问题 http://23.253.164.20:8096/ ),并与参数空间不足对uname和pwd。我真的建议使用了SoapUI与你有transport.requestDump比较正确的请求。

工作code:

 公众最终静态字符串URL =htt​​p://23.253.164.20:8096/login.asmx;
公共静态最后弦乐NAMESPACE =htt​​p://23.253.164.20:8096/;
公共静态最后弦乐SOAP_ACTION_ preFIX =htt​​p://23.253.164.20:8096/validLogin;
私有静态最终字符串的方法=validLogin;
公共字符串getFahrenheit(字符串摄氏度){        尝试{
            // SoapEnvelop.VER11是SOAP 1.1版不变
            SoapSerializationEnvelope信封=新SoapSerializationEnvelope(
                    SoapEnvelope.VER12);
            SoapObject要求=新SoapObject空间(namespace,方法);
            的PropertyInfo fromProp =新的PropertyInfo();
            fromProp.setName(UNAME);
            fromProp.setValue(测试);
            fromProp.setType(为String.class);
            fromProp.setNamespace空间(namespace);
            request.addProperty(fromProp);
            的PropertyInfo toProp =新的PropertyInfo();
            toProp.setName(PWD);
            toProp.setValue(测试);
            toProp.setType(为String.class);
            toProp.setNamespace空间(namespace);
            request.addProperty(toProp);
            // bodyOut是这个信封被发送出去body对象
            envelope.bodyOut =请求;
            envelope.implicitTypes = TRUE;
            HttpTransportSE运输=新HttpTransportSE(URL);
            transport.debug = TRUE;
            尝试{
// transport.call空间(namespace + SOAP_ACTION_ preFIX +方法,包);
                transport.call(SOAP_ACTION_ preFIX,信封);
            }赶上(IOException异常五){
                e.printStackTrace();
            }赶上(XmlPullParserException E){
                e.printStackTrace();
            }
            // bodyIn与此信封收身对象
            如果(envelope.bodyIn!= NULL){
                //的getProperty()返回在某一个指标的特定属性。
                SoapPrimitive resultSOAP =(SoapPrimitive)((SoapObject)envelope.bodyIn)
                        .getProperty(0);
                的System.out.println(resultSOAP.toString());
            }

I am using calling webservice using ksoap2 in android

I am getting this error

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

I am adding parameter using 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);

request shows up like this

validLogin{uname=simar; pwd=simar; }

Things i have tried

1) Commenting and uncommenting of following line

envelope.dotNet = true;

2) No server side error as without parameter the connection can be done and get the dummy result

3) Even Tried this

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

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

解决方案

I merged knowledge from Your prev post and from this one. You Have problem with call parameters (fe. lack of slash on the end of namespace "http://23.253.164.20:8096/") and with lack of namespace on parameters uname and pwd. I really recommend to use SoapUI to compare correct request with what You have in transport.requestDump.

Working code:

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

这篇关于在KSOAP 2机器人越来越参数错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆