4 Replies Latest reply on Oct 8, 2008 10:13 PM by bitwyse

    Stuck on SOAP WebService

    wildkatana
      Okay, I have been banging my head against this code all day and still can't quite get it, although I have made some progress. I am trying to access A WebService through SOAP. I can get the request sent and everything and it returns the xml document as a result. But the problem is, I don't know how to access individual parts of that result. I think that the result is being sent as a string instead of XML, but I'm not sure how to fix that... I am very new to all of this (Just started using Flex and APIs and Mashups and SOAP and XML today lol) but I am excited to learn and would appreciate some pointers. Here is my code: (I am trying to make a mashup)

      (...)
      <mx:WebService
      id="WeatherService"
      wsdl=" http://www.weather.gov/forecasts/xml/DWMLgen/wsdl/ndfdXML.wsdl"
      useProxy="false">
      <mx:operation name="NDFDgen"
      fault="mx.controls.Alert.show(event.fault.faultString)"
      result="showResults()">
      <mx:request>
      <latitude>38.9900</latitude>
      <longitude>-77.0100</longitude>
      <product>time-series</product>
      <startTime>2004-01-01T00:00:00</startTime>
      <endTime>2012-02-12T00:00:00</endTime>
      <weatherParameters>
      <maxt>1</maxt>
      <mint>0</mint>
      <temp>0</temp>
      (...)
      <wgust>0</wgust>
      </weatherParameters>

      </mx:request>
      </mx:operation>
      </mx:WebService>

      (...)

      public function showResults():void {
      Alert.show(WeatherService.NDFDgen.lastResult);
      }

      The problem is that when I try to access data inside the xml I get errors. This is what I try to do:
      Alert.show(WeatherService.NDFDgen.lastResult.head.source.credit);

      This is a sample of the xml file:
      <?xml version="1.0"?>
      <dwml version="1.0" xmlns:xsd=" http://www.w3.org/2001/XMLSchema" xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation=" http://www.nws.noaa.gov/forecasts/xml/DWMLgen/schema/DWML.xsd">
      <head>
      <product srsName="WGS 1984" concise-name="time-series" operational-mode="official">
      <title>NOAA's National Weather Service Forecast Data</title>
      <field>meteorological</field>
      <category>forecast</category>
      <creation-date refresh-frequency="PT1H">2008-05-20T07:04:30Z</creation-date>
      </product>
      <source>
      <more-information> http://www.nws.noaa.gov/forecasts/xml/</more-information>
      <production-center>Meteorological Development Laboratory<sub-center>Product Generation Branch</sub-center></production-center>
      <disclaimer> http://www.nws.noaa.gov/disclaimer.html</disclaimer>
      <credit> http://www.weather.gov/</credit>
      <credit-logo> http://www.weather.gov/images/xml_logo.gif</credit-logo>
      <feedback> http://www.weather.gov/feedback.php</feedback>
      </source>
      </head>
      <data>
      <location>
      (...)

      Any ideas what I am doing wrong? Thanks in advance also any pointers to help my coding would be appreciated, I am very new.
        • 1. Re: Stuck on SOAP WebService
          Developer504 Level 1
          I'm new to Flex myself so take this with a grain of salt, but I think if your data source is XML you have to convert it using E4X to do more than a simple display. What specific errors are you getting?

          I have one program which reads XML from an HTTPService Post and snaps that to a datagrid, maybe you could try that.
          • 2. Re: Stuck on SOAP WebService
            wildkatana Level 1
            Hmmm. I think what I need to do is figure out a way to convert a string variable (the xml) to an xml variable. Any ideas on that? I have the xml data stored in a string variable right now, but I want to traverse it's contents using the '.' Any ideas?
            • 3. Re: Stuck on SOAP WebService
              addigud
              Hi

              Dont know if this is still a problem but here goes.. the easiest way is to use the XMLList.

              var list:XMLList = new XMLList(xmlString); From here you can traverse the list via Children() and such

              • 4. Re: Stuck on SOAP WebService
                bitwyse Level 1
                You can also do something like this:
                var myXML : XML = new XML( xmlStringData );
                myXMLdataFormat = "e4x";

                Then you could use simple e4x constructs to access the data like . . .
                myXML..nodeName or
                myXML.nodeName( @attribName )

                you can google flex e4x and find lot's of great e4x sample code.
                Hope that helps. . .