Android 如何将类添加到SoapObject-like属性?

Android 如何将类添加到SoapObject-like属性?,android,wcf,ksoap2,Android,Wcf,Ksoap2,我对android编程非常陌生。(我英语不好。如果你发现错误,我道歉。) 因此,我有一个关于wcf服务的课程: 和检查此凭证的方法: android的代码: 我的班级在wcf服务。如何在android中创建类的实例,或者如何将类添加到SoapObject-like属性?如何实现它?只有3种默认类型的PropertyInfo,因此必须基于Soap XML结构创建SoapObject 1.PropertyInfo.STRING_CLASS 2.PropertyInfo.INTEGER_CLA

我对android编程非常陌生。(我英语不好。如果你发现错误,我道歉。)
因此,我有一个关于wcf服务的课程:

和检查此凭证的方法:

android的代码:


我的班级在wcf服务。如何在android中创建类的实例,或者如何将类添加到SoapObject-like属性?如何实现它?

只有3种默认类型的
PropertyInfo
,因此必须基于
Soap XML结构创建
SoapObject

1.PropertyInfo.STRING_CLASS

2.PropertyInfo.INTEGER_CLASS

3.PropertyInfo.OBJECT_CLASS
但是对于Soap解析,我们可以像在
Json解析中的
Gson
一样传递类类型

使用此
SoapResponseParser

import java.lang.reflect.Field;
import java.lang.reflect.Type;

public class SoapResponseParser {

    public static void parseBusinessObject(String input, Object output)
            throws NumberFormatException, IllegalArgumentException,
            IllegalAccessException, InstantiationException {

        @SuppressWarnings("rawtypes")
        Class theClass = output.getClass();
        Field[] fields = theClass.getDeclaredFields();

        for (int i = 0; i < fields.length; i++) {
            Type type = fields[i].getType();
            fields[i].setAccessible(true);

            // detect String
            if (fields[i].getType().equals(String.class)) {
                String tag = fields[i].getName() + "=";

                if (input.contains(tag)) {
                    String strValue = input.substring(
                            input.indexOf(tag) + tag.length(),
                            input.indexOf(";", input.indexOf(tag)));
                    if (strValue.length() != 0) {
                        if (strValue.contains("anyType")) {
                            fields[i].set(output, "-");
                        } else
                            fields[i].set(output, strValue);
                    }
                }
            }

            // detect int or Integer
            if (type.equals(Integer.TYPE) || type.equals(Integer.class)) {
                String tag = fields[i].getName() + "=";

                if (input.contains(tag)) {
                    String strValue = input.substring(
                            input.indexOf(tag) + tag.length(),
                            input.indexOf(";", input.indexOf(tag)));
                    if (strValue.length() != 0) {
                        fields[i].setInt(output, Integer.valueOf(strValue));
                    }
                }
            }

            // detect float or Float
            if (type.equals(Float.TYPE) || type.equals(Float.class)) {
                String tag = fields[i].getName() + "=";
                if (input.contains(tag)) {
                    String strValue = input.substring(
                            input.indexOf(tag) + tag.length(),
                            input.indexOf(";", input.indexOf(tag)));
                    if (strValue.length() != 0) {
                        fields[i].setFloat(output, Float.valueOf(strValue));
                    }
                }
            }
            // detect double or Double
            if (type.equals(Double.TYPE) || type.equals(Double.class)) {
                String tag = fields[i].getName() + "=";
                if (input.contains(tag)) {
                    String strValue = input.substring(
                            input.indexOf(tag) + tag.length(),
                            input.indexOf(";", input.indexOf(tag)));
                    if (strValue.length() != 0) {
                        fields[i].setDouble(output, Double.valueOf(strValue));
                    }
                }
            }
        }

    }
}

我的班级在wcf服务。如何在android中创建该类的实例?
private static final String METHOD_NAME = "CheckUserCredential";
private static final String NAMESPACE = "http://tempuri.org/";
private static final String SOAP_ACTION 
                           = "http://tempuri.org/ISelfCareMobileService/CheckUserCredential";

private static final String URL = "http://10.0.2.2:5795/SelfCareMobileService.svc"; 

private static final int SOAP_VERSION = SoapEnvelope.VER11; 
public boolean Login()
{
    try 
    {
        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

        //Here I should add my wcf class like argument to SoapObject
        request.addProperty("Credential", Credential);

        SoapSerializationEnvelope envelope 
                                 = new SoapSerializationEnvelope(SOAP_VERSION);
        envelope.dotNet = true;         
        envelope.setOutputSoapObject(request);

        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL, 60000);
        androidHttpTransport.debug = true;
        androidHttpTransport.call(SOAP_ACTION, envelope);
        Object result = envelope.getResponse();

        return true;
    } 
    catch (Exception e) 
    {
        return false;
    }       
}
1.PropertyInfo.STRING_CLASS

2.PropertyInfo.INTEGER_CLASS

3.PropertyInfo.OBJECT_CLASS
import java.lang.reflect.Field;
import java.lang.reflect.Type;

public class SoapResponseParser {

    public static void parseBusinessObject(String input, Object output)
            throws NumberFormatException, IllegalArgumentException,
            IllegalAccessException, InstantiationException {

        @SuppressWarnings("rawtypes")
        Class theClass = output.getClass();
        Field[] fields = theClass.getDeclaredFields();

        for (int i = 0; i < fields.length; i++) {
            Type type = fields[i].getType();
            fields[i].setAccessible(true);

            // detect String
            if (fields[i].getType().equals(String.class)) {
                String tag = fields[i].getName() + "=";

                if (input.contains(tag)) {
                    String strValue = input.substring(
                            input.indexOf(tag) + tag.length(),
                            input.indexOf(";", input.indexOf(tag)));
                    if (strValue.length() != 0) {
                        if (strValue.contains("anyType")) {
                            fields[i].set(output, "-");
                        } else
                            fields[i].set(output, strValue);
                    }
                }
            }

            // detect int or Integer
            if (type.equals(Integer.TYPE) || type.equals(Integer.class)) {
                String tag = fields[i].getName() + "=";

                if (input.contains(tag)) {
                    String strValue = input.substring(
                            input.indexOf(tag) + tag.length(),
                            input.indexOf(";", input.indexOf(tag)));
                    if (strValue.length() != 0) {
                        fields[i].setInt(output, Integer.valueOf(strValue));
                    }
                }
            }

            // detect float or Float
            if (type.equals(Float.TYPE) || type.equals(Float.class)) {
                String tag = fields[i].getName() + "=";
                if (input.contains(tag)) {
                    String strValue = input.substring(
                            input.indexOf(tag) + tag.length(),
                            input.indexOf(";", input.indexOf(tag)));
                    if (strValue.length() != 0) {
                        fields[i].setFloat(output, Float.valueOf(strValue));
                    }
                }
            }
            // detect double or Double
            if (type.equals(Double.TYPE) || type.equals(Double.class)) {
                String tag = fields[i].getName() + "=";
                if (input.contains(tag)) {
                    String strValue = input.substring(
                            input.indexOf(tag) + tag.length(),
                            input.indexOf(";", input.indexOf(tag)));
                    if (strValue.length() != 0) {
                        fields[i].setDouble(output, Double.valueOf(strValue));
                    }
                }
            }
        }

    }
}
MyCredentialClass credentilas= new MyCredentialClass();
SoapResponseParser.parseBusinessObject(result .toString(),credentilas);