4 Replies Latest reply on Oct 1, 2010 3:55 PM by LocoNochance

    HTTPService dropping the XML Declaration?

    LocoNochance

      Hello,

       

      I'm maintaining an application in Flex Builder 3 (build 3.0.2.214193) on a Mac OSX.

      I have declared an HTTPService object for retrieving XML from a server running PeopleSoft.


      When we were developing on Flex Builder 2.0 and on a Windows XP environment the code would something like this:

       

      MXML:

      <mx:HTTPService id="posrService"
           result="posrResultHandler(event)"

           request="{requestXMLDoc}"

           url="{destination.selectedItem.url}

           method="POST"

           contentType="application/xml"

           fault="posrErrorHandler(event)"
      />

       

      AS:

      requestXMLDoc = new XMLDocument("<?xml version=\"1.0\"?>\n" + myXML.toString())

      posrService.send();

       

      And this would work fine.

       

      After upgrading and switching platforms, the same code results in the "<?xml version="1.0"?>" getting dropped, and the PeopleSoft cannot parse the XML body.

       

      So I changed the AS to read:

      requestXMLDoc = new XMLDocument(myXML.toString())

      requestXMLDoc.xmlDecl = "<?xml version=\"1.0\"?>"

      posrService.send();

       

      But I still don't get the xml declaration.

      For debugging I added an alert of requestXMLDoc.toString()  and it shows the xml declaration, so I can only assume for some reason the HTTPService is dropping it for some reason. What I've been doing up to now is making all my changes on the mac, transferring the files to an old windows server which has the mcmxl comiler on it, and compiling the swf there as the final step of the migration. But it makes it hard to test changes to the actual XML request/response.

       

      Any thoughts or suggestions would be much appreciated.

       

      Thanks. Rob

        • 2. Re: HTTPService dropping the XML Declaration?
          LocoNochance Level 1

          Thank you for the quick reply. The issue isn't on the response from the PeopleSoft application. The PeopleSoft application is saying it can't parse the request because the XML Declaration doesn't exist. I've verified in the PeopleSoft application that the XML declaration is missing.

           

          Thanks again for any help.

          • 3. Re: HTTPService dropping the XML Declaration?
            jfb00 Level 3

            Like I said before try this in your post code:

             

            resultFormat="e4x"
            contentType="application/x-www-form-urlencoded"

            LIKE:

             

            <mx:HTTPService id="posrService"
                 result="posrResultHandler(event)"

                 request="{requestXMLDoc}"

                 url="{destination.selectedItem.url}

                 method="POST"

                 resultFormat="e4x"
                 contentType="application/x-www-form-urlencoded"

                 fault="posrErrorHandler(event)"
            />

             

             

            Johnny

            Please rate my answer

            1 person found this helpful
            • 4. Re: HTTPService dropping the XML Declaration?
              LocoNochance Level 1

              I figured it out, and your answer did inspire the solution, although it wasn't 100% there. I'm not sure how this is relevant, but I'm going to blame the target server on this one:

               

              1. I made the changes you suggested, they didn't work. The target server returned that the body content was null.
              2. I moved the attributes to code ( posrService.contentType = "application/x-www-form-urlencoded", posrService.resultFormat...) - same response
              3. I knew the content type was supposed to be XML, so I set it back to "application/xml", then eventually, since it was in code I changed it to "text/xml". Flex Builder doesn't like this when it's in the MXML, but in code this worked fine. And lo and behold, I got the expected response!

              So I'm blaming the application server for not knowing what "application/xml" means. That's an issue for another day.

               

              Final code:

               

              MXML:

              <mx:HTTPService id="posrService"
                   result="posrResultHandler(event)"

                   request="{requestXMLDoc}"

                   url="{destination.selectedItem.url}

                   method="POST"

                   -- contentType="application/xml" --

                   fault="posrErrorHandler(event)"


              />

               

              AS:

              requestXMLDoc = new XMLDocument(myXML.toString())

              requestXMLDoc.xmlDecl = "<?xml version=\"1.0\"?>"

              posrService.contentType = "text/xml"

              posrService.send();

               

              Thanks again for the suggestions.

               

              Strike through not showing on screen, so added --