How to parse a complex object with ksoap2?









up vote
0
down vote

favorite












I'm using Android Studio and ksoap2 (version 3.6.2) to connect to a soap web service and i get a SoapObject in return but not as expected. I'm having problems creating the code for the nested properties inside the xml request. The webservice always send the same response even adding properties to the request (The .xml request works fine on SoapUI and the webservice sends the correct response).



Here is the .xml that i need to send from Android:



<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org /soap/envelope/" xmlns:glob="http://abc.def">
<soapenv:Header/>
<soapenv:Body>
<glob:MaterialByElements>
<MaterialSelectionByElements>
<SelectionByID>
<Code>I</Code>
<TypeCode>1</TypeCode>
<ID>IM-640</ID>
</SelectionByID>
</MaterialSelectionByElements>
</glob:MaterialByElements>
</soapenv:Body>
</soapenv:Envelope>


And here is the code in Android:



SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

SoapObject SelectionByID = new SoapObject(NAMESPACE, "SelectionByID");
SelectionByID .addProperty("Code", "I");
SelectionByID .addProperty("TypeCode", "1");
SelectionByID .addProperty("ID", "IM-640-1045");

SoapObject MaterialSelectionByElements = new SoapObject(NAMESPACE,"MaterialSelectionByElements");

MaterialSelectionByElements.addSoapObject(SelectionByID);
request.addSoapObject(MaterialSelectionByElements);


But the webservice always send the response as if i should be sending this on the request:



<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org /soap/envelope/" xmlns:glob="http://abc.def">
<soapenv:Header/>
<soapenv:Body>
<glob:MaterialByElements>
<MaterialSelectionByElements>

</MaterialSelectionByElements>
</glob:MaterialByElements>
</soapenv:Body>
</soapenv:Envelope>


Please, any help would be very appreciated. Thanks in advance!



Note: I have already checked the Namespace, MethodName and URL in the request.



Please, help.










share|improve this question

























    up vote
    0
    down vote

    favorite












    I'm using Android Studio and ksoap2 (version 3.6.2) to connect to a soap web service and i get a SoapObject in return but not as expected. I'm having problems creating the code for the nested properties inside the xml request. The webservice always send the same response even adding properties to the request (The .xml request works fine on SoapUI and the webservice sends the correct response).



    Here is the .xml that i need to send from Android:



    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org /soap/envelope/" xmlns:glob="http://abc.def">
    <soapenv:Header/>
    <soapenv:Body>
    <glob:MaterialByElements>
    <MaterialSelectionByElements>
    <SelectionByID>
    <Code>I</Code>
    <TypeCode>1</TypeCode>
    <ID>IM-640</ID>
    </SelectionByID>
    </MaterialSelectionByElements>
    </glob:MaterialByElements>
    </soapenv:Body>
    </soapenv:Envelope>


    And here is the code in Android:



    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

    SoapObject SelectionByID = new SoapObject(NAMESPACE, "SelectionByID");
    SelectionByID .addProperty("Code", "I");
    SelectionByID .addProperty("TypeCode", "1");
    SelectionByID .addProperty("ID", "IM-640-1045");

    SoapObject MaterialSelectionByElements = new SoapObject(NAMESPACE,"MaterialSelectionByElements");

    MaterialSelectionByElements.addSoapObject(SelectionByID);
    request.addSoapObject(MaterialSelectionByElements);


    But the webservice always send the response as if i should be sending this on the request:



    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org /soap/envelope/" xmlns:glob="http://abc.def">
    <soapenv:Header/>
    <soapenv:Body>
    <glob:MaterialByElements>
    <MaterialSelectionByElements>

    </MaterialSelectionByElements>
    </glob:MaterialByElements>
    </soapenv:Body>
    </soapenv:Envelope>


    Please, any help would be very appreciated. Thanks in advance!



    Note: I have already checked the Namespace, MethodName and URL in the request.



    Please, help.










    share|improve this question























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I'm using Android Studio and ksoap2 (version 3.6.2) to connect to a soap web service and i get a SoapObject in return but not as expected. I'm having problems creating the code for the nested properties inside the xml request. The webservice always send the same response even adding properties to the request (The .xml request works fine on SoapUI and the webservice sends the correct response).



      Here is the .xml that i need to send from Android:



      <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org /soap/envelope/" xmlns:glob="http://abc.def">
      <soapenv:Header/>
      <soapenv:Body>
      <glob:MaterialByElements>
      <MaterialSelectionByElements>
      <SelectionByID>
      <Code>I</Code>
      <TypeCode>1</TypeCode>
      <ID>IM-640</ID>
      </SelectionByID>
      </MaterialSelectionByElements>
      </glob:MaterialByElements>
      </soapenv:Body>
      </soapenv:Envelope>


      And here is the code in Android:



      SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

      SoapObject SelectionByID = new SoapObject(NAMESPACE, "SelectionByID");
      SelectionByID .addProperty("Code", "I");
      SelectionByID .addProperty("TypeCode", "1");
      SelectionByID .addProperty("ID", "IM-640-1045");

      SoapObject MaterialSelectionByElements = new SoapObject(NAMESPACE,"MaterialSelectionByElements");

      MaterialSelectionByElements.addSoapObject(SelectionByID);
      request.addSoapObject(MaterialSelectionByElements);


      But the webservice always send the response as if i should be sending this on the request:



      <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org /soap/envelope/" xmlns:glob="http://abc.def">
      <soapenv:Header/>
      <soapenv:Body>
      <glob:MaterialByElements>
      <MaterialSelectionByElements>

      </MaterialSelectionByElements>
      </glob:MaterialByElements>
      </soapenv:Body>
      </soapenv:Envelope>


      Please, any help would be very appreciated. Thanks in advance!



      Note: I have already checked the Namespace, MethodName and URL in the request.



      Please, help.










      share|improve this question













      I'm using Android Studio and ksoap2 (version 3.6.2) to connect to a soap web service and i get a SoapObject in return but not as expected. I'm having problems creating the code for the nested properties inside the xml request. The webservice always send the same response even adding properties to the request (The .xml request works fine on SoapUI and the webservice sends the correct response).



      Here is the .xml that i need to send from Android:



      <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org /soap/envelope/" xmlns:glob="http://abc.def">
      <soapenv:Header/>
      <soapenv:Body>
      <glob:MaterialByElements>
      <MaterialSelectionByElements>
      <SelectionByID>
      <Code>I</Code>
      <TypeCode>1</TypeCode>
      <ID>IM-640</ID>
      </SelectionByID>
      </MaterialSelectionByElements>
      </glob:MaterialByElements>
      </soapenv:Body>
      </soapenv:Envelope>


      And here is the code in Android:



      SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

      SoapObject SelectionByID = new SoapObject(NAMESPACE, "SelectionByID");
      SelectionByID .addProperty("Code", "I");
      SelectionByID .addProperty("TypeCode", "1");
      SelectionByID .addProperty("ID", "IM-640-1045");

      SoapObject MaterialSelectionByElements = new SoapObject(NAMESPACE,"MaterialSelectionByElements");

      MaterialSelectionByElements.addSoapObject(SelectionByID);
      request.addSoapObject(MaterialSelectionByElements);


      But the webservice always send the response as if i should be sending this on the request:



      <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org /soap/envelope/" xmlns:glob="http://abc.def">
      <soapenv:Header/>
      <soapenv:Body>
      <glob:MaterialByElements>
      <MaterialSelectionByElements>

      </MaterialSelectionByElements>
      </glob:MaterialByElements>
      </soapenv:Body>
      </soapenv:Envelope>


      Please, any help would be very appreciated. Thanks in advance!



      Note: I have already checked the Namespace, MethodName and URL in the request.



      Please, help.







      android-studio soap xml-parsing android-ksoap2 ksoap






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 2 at 2:03









      Adan Cordero

      12




      12






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          After a lot of research i found the answer. I am working with a SAP webservice and Android Handhelds. To achieve the xml request with ksoap2 i had to use this to create the SoapObject:



           SoapObject request = null;
          SoapObject SelectionByID = new SoapObject(null, "SelectionByID");
          SelectionByID.addProperty("Code", "I");
          SelectionByID.addProperty("TypeCode", "1");
          SelectionByID.addProperty("ID", "IM-640");
          SoapObject MaterialSelectionByElements = new SoapObject("", "MaterialSelectionByElements");
          MaterialSelectionByElements.addSoapObject(SelectionByID);
          request=MaterialSelectionByElements;


          But it seems that the ksoap2 serialization use the
          http://www.w3.org/2001/XMLSchema-instance eschema by default. So i had to serialize on the SAP way using this class:



          public static class SAPSerializationEnvelope extends SoapSerializationEnvelope 

          public String namespace;
          public SAPSerializationEnvelope(int version, String namespace)
          super(version);
          this.namespace= namespace;


          @Override
          public void write(XmlSerializer writer) throws IOException

          writer.setPrefix("soapenv", "http://schemas.xmlsoap.org/soap/envelope/");
          writer.setPrefix("glob", namespace);
          writer.setPrefix("soapenv", env);
          writer.startTag(env, "Envelope");
          writer.startTag(env, "Header");
          writeHeader(writer);
          writer.endTag(env, "Header");
          writer.startTag(env, "Body");
          writer.setPrefix("glob", namespace);
          writer.startTag(namespace, "MaterialByElementsQuery_sync");
          writeBody(writer);
          writer.endTag(namespace, "MaterialByElementsQuery_sync");
          writer.endTag(env, "Body");
          writer.endTag(env, "Envelope");



          @Override
          public Object getResponse() throws SoapFault
          return super.getResponse();





          And thats it. The xml is the expected one by the webservice. I still don´t know why the SAP webservices are still using SOAP instead of Restful services. We are in 2018 and this kind of webservices looks a little bit old.






          share|improve this answer




















            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53111769%2fhow-to-parse-a-complex-object-with-ksoap2%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote













            After a lot of research i found the answer. I am working with a SAP webservice and Android Handhelds. To achieve the xml request with ksoap2 i had to use this to create the SoapObject:



             SoapObject request = null;
            SoapObject SelectionByID = new SoapObject(null, "SelectionByID");
            SelectionByID.addProperty("Code", "I");
            SelectionByID.addProperty("TypeCode", "1");
            SelectionByID.addProperty("ID", "IM-640");
            SoapObject MaterialSelectionByElements = new SoapObject("", "MaterialSelectionByElements");
            MaterialSelectionByElements.addSoapObject(SelectionByID);
            request=MaterialSelectionByElements;


            But it seems that the ksoap2 serialization use the
            http://www.w3.org/2001/XMLSchema-instance eschema by default. So i had to serialize on the SAP way using this class:



            public static class SAPSerializationEnvelope extends SoapSerializationEnvelope 

            public String namespace;
            public SAPSerializationEnvelope(int version, String namespace)
            super(version);
            this.namespace= namespace;


            @Override
            public void write(XmlSerializer writer) throws IOException

            writer.setPrefix("soapenv", "http://schemas.xmlsoap.org/soap/envelope/");
            writer.setPrefix("glob", namespace);
            writer.setPrefix("soapenv", env);
            writer.startTag(env, "Envelope");
            writer.startTag(env, "Header");
            writeHeader(writer);
            writer.endTag(env, "Header");
            writer.startTag(env, "Body");
            writer.setPrefix("glob", namespace);
            writer.startTag(namespace, "MaterialByElementsQuery_sync");
            writeBody(writer);
            writer.endTag(namespace, "MaterialByElementsQuery_sync");
            writer.endTag(env, "Body");
            writer.endTag(env, "Envelope");



            @Override
            public Object getResponse() throws SoapFault
            return super.getResponse();





            And thats it. The xml is the expected one by the webservice. I still don´t know why the SAP webservices are still using SOAP instead of Restful services. We are in 2018 and this kind of webservices looks a little bit old.






            share|improve this answer
























              up vote
              0
              down vote













              After a lot of research i found the answer. I am working with a SAP webservice and Android Handhelds. To achieve the xml request with ksoap2 i had to use this to create the SoapObject:



               SoapObject request = null;
              SoapObject SelectionByID = new SoapObject(null, "SelectionByID");
              SelectionByID.addProperty("Code", "I");
              SelectionByID.addProperty("TypeCode", "1");
              SelectionByID.addProperty("ID", "IM-640");
              SoapObject MaterialSelectionByElements = new SoapObject("", "MaterialSelectionByElements");
              MaterialSelectionByElements.addSoapObject(SelectionByID);
              request=MaterialSelectionByElements;


              But it seems that the ksoap2 serialization use the
              http://www.w3.org/2001/XMLSchema-instance eschema by default. So i had to serialize on the SAP way using this class:



              public static class SAPSerializationEnvelope extends SoapSerializationEnvelope 

              public String namespace;
              public SAPSerializationEnvelope(int version, String namespace)
              super(version);
              this.namespace= namespace;


              @Override
              public void write(XmlSerializer writer) throws IOException

              writer.setPrefix("soapenv", "http://schemas.xmlsoap.org/soap/envelope/");
              writer.setPrefix("glob", namespace);
              writer.setPrefix("soapenv", env);
              writer.startTag(env, "Envelope");
              writer.startTag(env, "Header");
              writeHeader(writer);
              writer.endTag(env, "Header");
              writer.startTag(env, "Body");
              writer.setPrefix("glob", namespace);
              writer.startTag(namespace, "MaterialByElementsQuery_sync");
              writeBody(writer);
              writer.endTag(namespace, "MaterialByElementsQuery_sync");
              writer.endTag(env, "Body");
              writer.endTag(env, "Envelope");



              @Override
              public Object getResponse() throws SoapFault
              return super.getResponse();





              And thats it. The xml is the expected one by the webservice. I still don´t know why the SAP webservices are still using SOAP instead of Restful services. We are in 2018 and this kind of webservices looks a little bit old.






              share|improve this answer






















                up vote
                0
                down vote










                up vote
                0
                down vote









                After a lot of research i found the answer. I am working with a SAP webservice and Android Handhelds. To achieve the xml request with ksoap2 i had to use this to create the SoapObject:



                 SoapObject request = null;
                SoapObject SelectionByID = new SoapObject(null, "SelectionByID");
                SelectionByID.addProperty("Code", "I");
                SelectionByID.addProperty("TypeCode", "1");
                SelectionByID.addProperty("ID", "IM-640");
                SoapObject MaterialSelectionByElements = new SoapObject("", "MaterialSelectionByElements");
                MaterialSelectionByElements.addSoapObject(SelectionByID);
                request=MaterialSelectionByElements;


                But it seems that the ksoap2 serialization use the
                http://www.w3.org/2001/XMLSchema-instance eschema by default. So i had to serialize on the SAP way using this class:



                public static class SAPSerializationEnvelope extends SoapSerializationEnvelope 

                public String namespace;
                public SAPSerializationEnvelope(int version, String namespace)
                super(version);
                this.namespace= namespace;


                @Override
                public void write(XmlSerializer writer) throws IOException

                writer.setPrefix("soapenv", "http://schemas.xmlsoap.org/soap/envelope/");
                writer.setPrefix("glob", namespace);
                writer.setPrefix("soapenv", env);
                writer.startTag(env, "Envelope");
                writer.startTag(env, "Header");
                writeHeader(writer);
                writer.endTag(env, "Header");
                writer.startTag(env, "Body");
                writer.setPrefix("glob", namespace);
                writer.startTag(namespace, "MaterialByElementsQuery_sync");
                writeBody(writer);
                writer.endTag(namespace, "MaterialByElementsQuery_sync");
                writer.endTag(env, "Body");
                writer.endTag(env, "Envelope");



                @Override
                public Object getResponse() throws SoapFault
                return super.getResponse();





                And thats it. The xml is the expected one by the webservice. I still don´t know why the SAP webservices are still using SOAP instead of Restful services. We are in 2018 and this kind of webservices looks a little bit old.






                share|improve this answer












                After a lot of research i found the answer. I am working with a SAP webservice and Android Handhelds. To achieve the xml request with ksoap2 i had to use this to create the SoapObject:



                 SoapObject request = null;
                SoapObject SelectionByID = new SoapObject(null, "SelectionByID");
                SelectionByID.addProperty("Code", "I");
                SelectionByID.addProperty("TypeCode", "1");
                SelectionByID.addProperty("ID", "IM-640");
                SoapObject MaterialSelectionByElements = new SoapObject("", "MaterialSelectionByElements");
                MaterialSelectionByElements.addSoapObject(SelectionByID);
                request=MaterialSelectionByElements;


                But it seems that the ksoap2 serialization use the
                http://www.w3.org/2001/XMLSchema-instance eschema by default. So i had to serialize on the SAP way using this class:



                public static class SAPSerializationEnvelope extends SoapSerializationEnvelope 

                public String namespace;
                public SAPSerializationEnvelope(int version, String namespace)
                super(version);
                this.namespace= namespace;


                @Override
                public void write(XmlSerializer writer) throws IOException

                writer.setPrefix("soapenv", "http://schemas.xmlsoap.org/soap/envelope/");
                writer.setPrefix("glob", namespace);
                writer.setPrefix("soapenv", env);
                writer.startTag(env, "Envelope");
                writer.startTag(env, "Header");
                writeHeader(writer);
                writer.endTag(env, "Header");
                writer.startTag(env, "Body");
                writer.setPrefix("glob", namespace);
                writer.startTag(namespace, "MaterialByElementsQuery_sync");
                writeBody(writer);
                writer.endTag(namespace, "MaterialByElementsQuery_sync");
                writer.endTag(env, "Body");
                writer.endTag(env, "Envelope");



                @Override
                public Object getResponse() throws SoapFault
                return super.getResponse();





                And thats it. The xml is the expected one by the webservice. I still don´t know why the SAP webservices are still using SOAP instead of Restful services. We are in 2018 and this kind of webservices looks a little bit old.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 10 at 4:06









                Adan Cordero

                12




                12



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53111769%2fhow-to-parse-a-complex-object-with-ksoap2%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Use pre created SQLite database for Android project in kotlin

                    Darth Vader #20

                    Ondo