Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Adobe Summit 2023 [19th to 23rd March, Las Vegas and Virtual] | Complete AEM Session & Lab list

Problem consuming XML data from .Net 2.0 Web Service

Avatar

Level 1
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>

1 Reply

Avatar

Level 1
Still have not fiugred this out. Hope somebody can help. I
belive my problem must be in parsing the XML data returned. Ineed
to get the Period array (and EE subarray of each Period. I'm
wondering if I need to do something with namespaces to access these
nodes within the XML?



When I specify my webserverice result as "E4X", I have tried
a bunch of things to drill down to the data:

private function
Usp_NumErrors_ByPeriod_ForXML_ResultHandler(event:ResultEvent):void

{

var x1:XML = event.result[0];

var x2:XMLList = x1.children();

var x3:XML = x2[0];

var x3c:XMLList = x3.children();

var x3a:XMLList = x3.attributes();

var x4:XML = x3[0];

var x4c:XMLList = x4.children();

var x4a:XMLList = x4.attributes();



The debugger shows this:



event.result = XMLList (@5405a61)

[0] = XML

<Usp_NumErrors_ByPeriod_ForXMLResponse xmlns="
http://tempuri.org/" xmlns:soap="
http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="
http://www.w3.org/2001/XMLSchema">


<Usp_NumErrors_ByPeriod_ForXMLResult xmlns="
http://tempuri.org/" xmlns:soap="
http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="
http://www.w3.org/2001/XMLSchema">


<list xmlns:soap="
http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="
http://www.w3.org/2001/XMLSchema">

<Period EarlierDTS="2008-08-04T06:00:00"
TotalNumErrorEvents="27598" xmlns:soap="
http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="
http://www.w3.org/2001/XMLSchema">


<EE EventID="151" NumOccurs="504" xmlns:soap="
http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="
http://www.w3.org/2001/XMLSchema"/>


<EE EventID="152" NumOccurs="429" xmlns:soap="
http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="
http://www.w3.org/2001/XMLSchema"/>


<EE EventID="158" NumOccurs="8655" xmlns:soap="
http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="
http://www.w3.org/2001/XMLSchema"/>


<EE EventID="200" NumOccurs="89" xmlns:soap="
http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="
http://www.w3.org/2001/XMLSchema"/>


<EE EventID="267" NumOccurs="39" xmlns:soap="
http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="
http://www.w3.org/2001/XMLSchema"/>


<EE EventID="424" NumOccurs="301" xmlns:soap="
http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="
http://www.w3.org/2001/XMLSchema"/>


<EE EventID="477" NumOccurs="4155" xmlns:soap="
http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="
http://www.w3.org/2001/XMLSchema"/>


<EE EventID="480" NumOccurs="4155" xmlns:soap="
http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="
http://www.w3.org/2001/XMLSchema"/>


<EE EventID="483" NumOccurs="49" xmlns:soap="
http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="
http://www.w3.org/2001/XMLSchema"/>


<EE EventID="514" NumOccurs="8894" xmlns:soap="
http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="
http://www.w3.org/2001/XMLSchema"/>


<Period EarlierDTS="2008-08-04T14:00:00"
TotalNumErrorEvents="1" xmlns:soap="
http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="
http://www.w3.org/2001/XMLSchema">


<EE NumOccurs="0" xmlns:soap="
http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="
http://www.w3.org/2001/XMLSchema"/>


<Period EarlierDTS="2008-08-04T22:00:00"
TotalNumErrorEvents="1" xmlns:soap="
http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="
http://www.w3.org/2001/XMLSchema">


<EE NumOccurs="0" xmlns:soap="
http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="
http://www.w3.org/2001/XMLSchema"/>






The ultimate experience is back.

Join us in Vegas to build skills, learn from the world's top brands, and be inspired.

Register Now