5 Replies Latest reply on Apr 9, 2009 12:00 AM by BJG2

    Why does Flex change the XML while passing it to a web service?

      (Earlier posted in Flex SDK Developer Forums. --Changed location)

       

      Hi All,

       

      Is it natural for Flex to replace all <, >, and & with &lt;, &gt; and &amp; , respectively, in an XML before passing it as parameter to a web service call?

       

      I invoke a web service through the mx:WebService component and pass a simple XML as parameter

      Code:
      <b>bhaskar</b>


      But, the service receives this as the request parameter

      Code:
      &lt;b&gt;bhaskar&lt;/b&gt;


      Note: I have verified the request using BlaseDS and have also checked the server logs for the request the service received.

       

      So, is there no way Flex can send the original XML?
      Note: I read somewhere that to fix some issue they used the approach of replacing all <, >, and & with &lt;, &gt; and &amp; , respectively.

       

      Is there a way out (other than converting the XML received at the server side back to original format, before operating on it)?

       

      ------------------------------------------------------------------------------------------ --------------------------------------------------------------

       

      The REPLY I got from Matt was:

      8 Apr, 2009
      Re: Why does Flex change the XML while passing it to a web service?

      Hi,

       

      It depends on what property the web service was expecting.  Are you passing a String and therefore we're XML-encoding it, or are you passing an XML object?

       

      Note that since this question is really about using Flex and not developing Flex, it's better addressed on Flexcoders or the Flex Discussion forums ( http://forums.adobe.com/community/flex/flex_general_discussion)

       

      Matt

      ------------------------------------------------------------------------------------------ ----------------------------------------------------------------

        • 1. Re: Why does Flex change the XML while passing it to a web service?
          Level 1

          Hi Matt,

           

          I am passing the parameter as a String. So, I can understanad it getting XML encoded.

           

          But the problem is that if I pass an XML object, the SOAP body in the request doesnot contain the passed parameter (XML)!

           

          I am invoking the web service like this:

           

                      var payloadXML2;
                     
                      private function invoke():void {
                          payloadXML2 = new XML(payload.text);               
                          trace("Sending payload \"" + payloadXML2.toString() + "\"");
                          SOAPService.returnInputXMLPayload();
                         
                      }

           

          My web service is this:

           

             <mx:WebService id="SOAPService"
                  destination="HTTPDestination3"
                  result="getResult(event)"
                  fault="getFault(event)"
                  useProxy="true">
                 
                  <mx:operation name="returnInputXMLPayload" resultFormat="e4x">
                      <mx:request xmlns="">
                          <parameters>{this.payloadXML2}</parameters>   
                      </mx:request>
                  </mx:operation>
              </mx:WebService>

           

          When I traced the request using BlaseDS, I found this:

           

          <SOAP-ENV:Envelope

          xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"

          xmlns:xsd="http://www.w3.org/2001/XMLSchema"

          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

           

          <SOAP-ENV:Body>

          <tns0:returnInputXMLPayloadElement xsi:nil="true"

                 xmlns:tns0="http://apps.tools.services.soap/types/"/>

          </SOAP-ENV:Body>

          </SOAP-ENV:Envelope>

           

          Any ideas why this is hapenning?

           

          --thanks Bhaskar

          • 2. Re: Why does Flex change the XML while passing it to a web service?
            markuspedro

            Hi,

            the change og some chars is normally.

            I suggest you to use Base64 encode before sending the xml to webserver.

            Obviously,at receving, use base64 decode.

             

            Try this.

            Bye

            markus

            • 3. Re: Why does Flex change the XML while passing it to a web service?
              Cyril Hanquez Level 3

              Try this :

               

               

                          var payloadXML2;
                         
                          private function invoke():void {
                              payloadXML2 = new XML(payload.text);               
                              trace("Sending payload \"" + payloadXML2.toString() + "\"");
                              SOAPService.returnInputXMLPayload(payloadXML2);
                             
                          }

               

              web service

               

                 <mx:WebService id="SOAPService"
                      destination="HTTPDestination3"
                      result="getResult(event)"
                      fault="getFault(event)"
                      useProxy="true">
                     
                      <mx:operation name="returnInputXMLPayload" resultFormat="e4x"/>

               

                  </mx:WebService>

               

              or

               

                          [Bindable]

                          private var payloadXML2;
                         
                          private function invoke():void {
                              payloadXML2 = new XML(payload.text);               
                              trace("Sending payload \"" + payloadXML2.toString() + "\"");
                              SOAPService.returnInputXMLPayload();

                             
                          }    

               

              web service:

               

                 <mx:WebService id="SOAPService"
                      destination="HTTPDestination3"
                      result="getResult(event)"
                      fault="getFault(event)"
                      useProxy="true">
                     
                      <mx:operation name="returnInputXMLPayload" resultFormat="e4x">
                          <mx:request xmlns="">
                              <parameters>{payloadXML2}</parameters>   
                          </mx:request>
                      </mx:operation>
                  </mx:WebService>

              1 person found this helpful
              • 4. Re: Why does Flex change the XML while passing it to a web service?
                Level 1

                Hi All,

                 

                I am now able to invoke the service (that takes an XML, returns an XML) through Flex.  Kiss

                 

                I solved the problem in the following way:

                 

                Invoke the service by passing the XML object inside the webServiceObject.operationName() call.

                 

                Code:
                [Bindable]
                public var payloadXML:XML;

                private function invoke_query():void{
                                    
                     this.payloadXML = new XML(this.payload.text).normalize();
                     trace("Calling query => " + this.payloadXML.toXMLString());
                     SOAPService.returnInputXMLPayload(this.payloadXML);
                }


                The mx:WebService component:

                 

                Code:
                <mx:WebService id="SOAPService" showBusyCursor="true" 
                            useProxy="false"
                            wsdl="http://localhost:8888/ServicesTest-SoapXMLService-context-root/MyWebService1SoapHttpPort?WSDL">

                        <mx:operation name="returnInputXMLPayload" resultFormat="e4x"
                                result="get_result(event);"
                                fault="get_fault(event);" />
                               
                </mx:WebService>


                The XML I passed was:. (This XML is read from the this.payload TextArea). (Correct)

                 

                Code:
                <tns0:returnInputXMLPayloadElement           
                    xmlns:tns0="http://apps.tools.services.soap/types/"
                    xmlns="http://apps.tools.services.soap/types/">

                    <tns0:payload>
                        <contact>
                          <name>
                               Bhaskar
                          </name>
                          <friendOf>
                               Rajesh
                          </friendOf>
                     </contact>
                    </tns0:payload>
                </tns0:returnInputXMLPayloadElement>


                Earlier, I was passing the XML like this: (Incorrect)

                Code:
                <contact><name>Bhaskar</name><friendOf>Rajesh</friendOf></contact>


                Now I have wrapped the XML within the Request Element and the Parameter names (as per the WSDL).


                NOTE: WSDL is attached with this post.

                This solves these problems:

                • When I was passing the XML as string, it was getting XML encoded (<, >, & replaced with &lt;, &gt; and &amp;). Also this was adding the parameter-name tag twice (see earlier posts to this thread) over the actual XML (This is still an issue, perhaps with the way the service call is made!)
                • When I passed an XML object inside the <mx:request><parameters></parameters></mx:request> tag, nothing was passed (a blank SOAP Body).
                • I then hard-coded the complete SOAP Envelope, and passed like this:
                Code:
                <mx:WebService id="SOAPService"
                         ...          
                     <mx:operation name="returnInputXMLPayload" resultFormat="e4x">
                          <mx:request format="xml">
                                    <tns0:returnInputXMLPayloadElement           
                                       xmlns:tns0="http://apps.tools.services.soap/types/"
                                       xmlns="http://apps.tools.services.soap/types/">

                                       <tns0:payload>
                                            <contact>
                                             <name>
                                               Bhaskar
                                          </name>
                                          <friendOf>
                                                 Rajesh
                                             </friendOf>
                                            </contact>
                                        </tns0:payload>
                                    </tns0:returnInputXMLPayloadElement>
                          </mx:request>
                     </mx:operation>
                </mx:WebService>

                • But, I could not then substitute an XML object into the <mx:request format="xml"></mx:request> tag, as the compiler said it expected an XML.

                 

                So, finally, I got the breakthrough using the approach described here.

                 

                Special Thanks to everybody who helped me cracking the problem! (Please see the similar thread at FlexDevelopers.eu forums also)

                 

                --thanks Bhaskar

                • 5. Re: Why does Flex change the XML while passing it to a web service?
                  Level 1

                  While the primary issue has been solved,

                  there is still an issue (although not critical) where Flex adds the parameter-name tag twice while building the SOAP Envelope (mentioned at the end (in bullets) in the last post)

                   

                  thanks

                  Bhaskar