在 ksoap 2 中获取参数错误 android

getting parameter error in ksoap 2 android

我在 android

中使用 ksoap2 调用网络服务

我遇到了这个错误

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

请求这样显示

validLogin{uname=simar; pwd=simar; }

我尝试过的东西

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");

我合并了您上一篇 post 和这一篇的知识。 您在调用参数方面遇到问题(例如,名称空间“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());
            }