R – Get XML by Post method from Webservice in Flex

actionscriptapache-flexflashservice

I created a servlet in java that will give me a xml response when called

protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {      
        response.setContentType("text/xml; charset=utf-8");                                                      // Set the servlet's response type to XML.
        PrintWriter out = null;

        try {
            out = response.getWriter();

            XMLOutputFactory of = XMLOutputFactory.newInstance();

            XMLStreamWriter writer = of.createXMLStreamWriter(out);

            writer.writeStartDocument();
            writer.writeStartElement("Test");
            for(int i = 1; i <= 100; i++) {
                writer.writeStartElement("TheNumber");
                writer.writeAttribute("number", "" + i);
                writer.writeAttribute("value", "" + Math.pow(2, i));
                writer.writeEndElement();
            }
            writer.writeEndElement();
            writer.close();

            out.close();
        } catch (Exception ex) {

        }
}

Now I want to get this xml in flex, can someone give me a hint? I tried mx:WebService and mx:HttpService but both of them did not work.

Thanks in advance

Sebastian

Best Answer

Since you've already solved your issue with HttpService, now it's time to graduate to using Flex remoting with their Granite Data Services or BlazeDS, unless you have some major reason you can't. Parsing XML and using XML for data transmission is a no-no, terrible performance, and in general a bad idea if you can avoid it.

http://www.graniteds.org/

http://opensource.adobe.com/wiki/display/blazeds/BlazeDS/

Related Topic