Passing XML(DataSet) as Parameter ksoap2 android

后端 未结 2 1793
渐次进展
渐次进展 2021-01-14 03:48

i am trying to send XML requst to webservice using ksop2 but it is not workig

my web service request format is



        
相关标签:
2条回答
  • 2021-01-14 04:11

    Maybe a little late, but I just solved it implementing KvmSerializable class, and inside that class, the CDATA String was declared as a SoapObject. Then, I set the CDATA with SoapObject.setInnerText

            SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
    
    
            SoapObject fieldWithCdata = new SoapObject(NAMESPACE, "fieldWithCData");
            fieldWithCdata.setInnerText(cDatraString);
    
            CustomClass customClass = new customClass(string1, string2, string3, fieldWithCdata);
    
    
            PropertyInfo pi = new PropertyInfo();
            pi.setNamespace(NAMESPACE);
            pi.setName("customClass");
            pi.setValue(customClass);
    
            request.addProperty(pi);
    

    and in the CustomClass

    public class CustomClass implements KvmSerializable{
    
    
    private String string1;
    private String string2;
    private String string3;
    private SoapObject fieldWithCdata;
    

    ...

     public void setProperty(int index, Object value) {
        switch (index)
        {
            case INDEX_STRING1: //0
                this.string1 = value.toString();
                break;
            case INDEX_STRING2: //1
                this.string2 = value.toString();
                break;
            case INDEX_STRING3: //2
                this.string3 = value.toString();
                break;
            case INDEX_FIELDWITHCDATA://3
                this.fieldWithCdata = (SoapObject) value;
                break;
        }
    

    with

      public void getPropertyInfo(int index, Hashtable properties, PropertyInfo info) {
        switch(index){
            case INDEX_STRING1:
                info.name = "string1";
                info.type = PropertyInfo.STRING_CLASS;
                break;
            case INDEX_STRING2:
                info.name = "string2";
                info.type = PropertyInfo.STRING_CLASS;
                break;
            case INDEX_STRING3:
                info.name = "string3";
                info.type = PropertyInfo.STRING_CLASS;
                break;
            case INDEX_FIELDWITHCDATA:
                info.name = "fieldWithCdata";
                info.type = PropertyInfo.OBJECT_TYPE;
                break;
            default:
                break;
        }
    }
    
    0 讨论(0)
  • 2021-01-14 04:25

    Look at the documentation of ksoap2

    https://code.google.com/p/ksoap2-android/wiki/CodingTipsAndTricks#sending/receiving_array_of_complex_types_or_primitives

    you can create class that will implement marshable interface and add other property inside that class

    0 讨论(0)
提交回复
热议问题