1 Reply Latest reply on Aug 4, 2008 9:31 PM by whertzing

    Problem consuming XML data from .Net 2.0 Web Service

    whertzing
      I've tried a ton of variations, I must be missing something simple Hope a guru out there can help...

      Apologies on the size and formatting - I couldn't find the "Attach Code" button or link on the Post editing form. This is my first post here.

      I've a SQL Server 2005 stored procedure that returns the data I need using "For XML Explicit". I can copy that result (example at bottom), stick it into a file "numErrors.xml", access it from FLEX as:

      <mx:HTTPService id="srv" url="numErrors.xml" useProxy="false" result="Usp_NumErrors_ByPeriod_ForXML_ResultHandler(event)"/>

      <mx:Script><![CDATA[
      private function Usp_NumErrors_ByPeriod_ForXML_clickHandler():void
      {
      srv.send();
      }

      private function Usp_NumErrors_ByPeriod_ForXML_ResultHandler(event:ResultEvent):void
      {
      periodData = event.result.list.Period.source as Array;
      }
      ]]></mx:Script>

      The debugger shows the event.result in the ResultHandler is a ProxyObject, andI can access all the stuff in my data (parent nodes and child nodes) by using the element names (like Period in the example above) and attribute names (like NumOccurs).

      I can't hook it up to a live web service though. The web service is an ASP 2.0 .asmx file, implementing SOAP . The service is defined to return a .Net STRING (later chaged to an .Net XMLDocument), and it makes the live call to teh stored procedure in the database, which returns the very same XML data as I have in the file, and returns it.

      Here's the FLEX web service definition:

      <mx:WebService
      id="pws"
      wsdl="{pwsWSDL}"
      showBusyCursor="true">
      <mx:operation name="Usp_NumErrors_ByPeriod_ForXML" resultFormat="object"
      fault="onServiceFault(event)"
      result="Usp_NumErrors_ByPeriod_ForXML_ResultHandler(event)"/>
      </mx:WebService>

      If I invoke this web service, then the event.result in my _ResultHandler is a String (according to the debugger), and I can't get at the elements like Period or attributes like TotalNumErrosInPeriod within that string.

      I've tried a couple of approaches, none have been successful:
      1) tried to convert the String to a XML type using the various methods I found in the mx:XML class - couldn't get to the Period element, it's attributes, or it's children. tried setting (and removing) namespace. tried variations of XML and XMLList casts and conversion. Maybe I just didn't have the right incantation.

      2) Tried to return the result of the wsService as a "e4c" instead of a "object" - this was closer, the event.result was now a ProxyObject, and the number of elements and number of child elements were present - I could see the parent array Period and each Period's array of child elements named EE - but no luck getting the attribute names or values, in spite of various incantations in the mx:XML library dialect

      2) tried to modify the .Net Web Service layer to return a System.XML.XmlDocument - which got me closer; the event.result now had ProxyObjects, and i could see the presence of each element and their children, by their name. But I still can't see any attributes of the parent or the children. The following is the .NET C# Web Service code at the heart of this conversion (and I like wordy Method names )

      str = ServiceUtilities.ExecCmdThroughDataReaderForXML(cmd, CommandBehavior.SingleResult | CommandBehavior.SingleRow);
      XmlDocument x = new XmlDocument();
      x.LoadXml(str);
      return x;

      If anybody has experiance with consuming XML from ASP Web Services I'd sure like to know how to get my structured data (example below) across the wire so I can access it like I can the HTTPService data from a local file.

      Here's a snippet of the string the SQL Server Stored Procedure Usp_NumErrors_ByPeriod_ForXML produces. The SP uses "FOR XML EXPLICIT" and returns

      <list><Period EarlierDTS="2008-07-12T05:00:00" TotalNumErrorEvents="179096"><EE EventID="152" NumOccurs="18090"/><EE EventID="158" NumOccurs="41110"/><EE EventID="477" NumOccurs="20239"/><EE EventID="480" NumOccurs="20241"/><EE EventID="514" NumOccurs="25594"/></Period><Period EarlierDTS="2008-07-13T05:00:00" TotalNumErrorEvents="195803"><EE EventID="152" NumOccurs="19580"/><EE EventID="158" NumOccurs="47873"/><EE EventID="477" NumOccurs="23743"/><EE EventID="480" NumOccurs="23748"/><EE EventID="514" NumOccurs="21973"/></Period><Period EarlierDTS="2008-07-14T05:00:00" TotalNumErrorEvents="449624"><EE EventID="152" NumOccurs="23029"/><EE EventID="158" NumOccurs="253200"/><EE EventID="477" NumOccurs="36219"/><EE EventID="480" NumOccurs="36226"/><EE EventID="514" NumOccurs="30950"/></Period><Period EarlierDTS="2008-07-15T05:00:00" TotalNumErrorEvents="530368"><EE EventID="152" NumOccurs="23680"/><EE EventID="158" NumOccurs="328975"/><EE EventID="477" NumOccurs="35777"/><EE EventID="480" NumOccurs="35783"/><EE EventID="514" NumOccurs="30620"/></Period</list>