<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.3.1" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>

<channel>
	<title>Binary Giant</title>
	<link>http://www.binarygiant.com/blog</link>
	<description>A Technology Blog with a Focus on Rich Internet Applications Using Adobe Flex, .NET, ColdFusion, and PHP by Lance Sims</description>
	<pubDate>Sun, 18 Jul 2010 03:04:55 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.1</generator>
	<language>en</language>
			<item>
		<title>Return Your iPhone 4</title>
		<link>http://www.binarygiant.com/blog/?p=37</link>
		<comments>http://www.binarygiant.com/blog/?p=37#comments</comments>
		<pubDate>Sun, 18 Jul 2010 03:04:55 +0000</pubDate>
		<dc:creator>Lance Sims</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.binarygiant.com/blog/?p=37</guid>
		<description><![CDATA[Steve Jobs won&#8217;t admit fault, so return your phones&#8230;.  Enough said.
]]></description>
			<content:encoded><![CDATA[<p>Steve Jobs won&#8217;t admit fault, so return your phones&#8230;.  Enough said.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.binarygiant.com/blog/?feed=rss2&amp;p=37</wfw:commentRss>
		</item>
		<item>
		<title>Cannot open user default database.  Login Failed (Microsoft SQL Server, Error: 4064)</title>
		<link>http://www.binarygiant.com/blog/?p=29</link>
		<comments>http://www.binarygiant.com/blog/?p=29#comments</comments>
		<pubDate>Tue, 30 Dec 2008 20:14:34 +0000</pubDate>
		<dc:creator>Lance Sims</dc:creator>
		
		<category><![CDATA[SQL Server 2005]]></category>

		<guid isPermaLink="false">http://www.binarygiant.com/blog/?p=29</guid>
		<description><![CDATA[I don&#8217;t know exactly what caused this, but today I tried to start SQL Server 2005 Management Studio, and got the following error: Cannot open user default database.  Login Failed (Microsoft SQL Server, Error: 4064)


When the &#8220;Connect to Server&#8221; dialog comes up, choose the Options&#62;&#62; button 
Next to &#8220;Connect to database:&#8221; type in &#8220;master&#8221; rather than [...]]]></description>
			<content:encoded><![CDATA[<p>I don&#8217;t know exactly what caused this, but today I tried to start SQL Server 2005 Management Studio, and got the following error: <strong><font color="#ff0000">Cannot open user default database.  Login Failed (Microsoft SQL Server, Error: 4064)</font></strong></p>
<p><a href="http://www.binarygiant.com/blog/wp-content/uploads/2008/12/error.jpg" title="4064 Error"><img src="http://www.binarygiant.com/blog/wp-content/uploads/2008/12/error.jpg" alt="4064 Error" width="481" height="136" /></a></p>
<ul>
<li>When the &#8220;Connect to Server&#8221; dialog comes up, choose the Options&gt;&gt; button <a href="http://www.binarygiant.com/blog/wp-content/uploads/2008/12/connect.jpg" title="Connect to database dialog"><img src="http://www.binarygiant.com/blog/wp-content/uploads/2008/12/connect.jpg" alt="Connect to database dialog" /></a></li>
<li>Next to &#8220;Connect to database:&#8221; type in &#8220;master&#8221; rather than &lt;Default&gt;<a href="http://www.binarygiant.com/blog/wp-content/uploads/2008/12/default.jpg" title="default"><img src="http://www.binarygiant.com/blog/wp-content/uploads/2008/12/default.jpg" alt="default" /></a><a href="http://www.binarygiant.com/blog/wp-content/uploads/2008/12/master.jpg" title="master"><img src="http://www.binarygiant.com/blog/wp-content/uploads/2008/12/master.jpg" alt="master" /></a></li>
<li>Connect</li>
</ul>
<p>It&#8217;s that simple.</p>
<p>If that does not completely solve the problem, then you&#8217;ll want to run SQL command from the command line, also very easy.</p>
<ul>
<li>Open a command prompt (Windows Key + R and type cmd)</li>
<li>Type
<ul>
<li> sqlcmd<span><font size="2" face="Arial"> -E -d master</font></span></li>
<li><span><font size="2" face="Arial">ALTER LOGIN [DomainName\UserName] WITH DEFAULT_DATABASE = master</font></span></li>
<li><span><font size="2" face="Arial">GO</font></span></li>
<li><span><font size="2"><font face="Arial">QUIT</font></font></span></li>
</ul>
</li>
</ul>
<p><a href="http://www.binarygiant.com/blog/wp-content/uploads/2008/12/cmd1.jpg" title="cmd1.jpg"><img src="http://www.binarygiant.com/blog/wp-content/uploads/2008/12/cmd1.jpg" alt="cmd1.jpg" /></a></p>
<p>Refer to  this <a href="http://geekswithblogs.net/TimH/archive/2008/02/11/119442.aspx" title="SQL Command">blog post</a> for more information</p>
]]></content:encoded>
			<wfw:commentRss>http://www.binarygiant.com/blog/?feed=rss2&amp;p=29</wfw:commentRss>
		</item>
		<item>
		<title>New Animated Title Window Component</title>
		<link>http://www.binarygiant.com/blog/?p=27</link>
		<comments>http://www.binarygiant.com/blog/?p=27#comments</comments>
		<pubDate>Sun, 28 Dec 2008 01:13:37 +0000</pubDate>
		<dc:creator>Lance Sims</dc:creator>
		
		<category><![CDATA[Flex]]></category>

		<category><![CDATA[Rich Internet Applications]]></category>

		<guid isPermaLink="false">http://www.binarygiant.com/blog/?p=27</guid>
		<description><![CDATA[I have put together an animated TitleWindow component-  you can view the sample application and view source to see how it is used.  I created the component to be used just like a TitleWindow is in a Flex application, but it animates your Flex pop ups.  You create instances of the AnimatedTitleWindow instead of TitleWindows [...]]]></description>
			<content:encoded><![CDATA[<p>I have put together an animated TitleWindow component-  you can view the <a href="http://www.binarygiant.com/demos/animatedpopup/AnimatedTitleWindowDemo.html" title="sample application">sample application</a> and view source to see how it is used.  I created the component to be used just like a TitleWindow is in a Flex application, but it animates your Flex pop ups.  You create instances of the AnimatedTitleWindow instead of TitleWindows and use the PopUpManager to add it to the application.  The difference is that you can specify an open effect and a close effect or both, or none.  There is a default animation behavior, and since it extends from TitleWindow you have all of the TitleWindow functionality available for your Flex pop ups.</p>
<p>There are many occasions for using TitleWindows as PopUps in Flex applications, and most of the time the code goes something like this:</p>
<ul>
<li>Create an instance of a TitleWindow</li>
<li>Set its properties (showCloseButton = true);</li>
<li>Add an eventLister for the close event</li>
<li>Instruct add any children to the TitleWindow (forms, custom components, etc.)</li>
<li>Use the PopUpManager.addPopUp() or PopUpManager.createPopUp(); methods to show the Pop Up to the user</li>
</ul>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;"><span class="kw3">private</span> <span class="kw2">function</span> buildPopUp<span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw3">void</span><br />
<span class="br0">&#123;</span><br />
<span class="co1">//instantiate an instance of a TitleWindow</span><br />
<span class="kw2">var</span> tw:TitleWindow = <span class="kw2">new</span> TitleWindow<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
tw.<span class="me1">showCloseButton</span> = <span class="kw2">true</span>;<br />
tw.<span class="me1">addEventListener</span><span class="br0">&#40;</span>CloseEvent.<span class="kw3">CLOSE</span>,onTWClose<span class="br0">&#41;</span>;<br />
<span class="co1">//instantiate some ui component that will be contained by the pop up</span><br />
<span class="kw2">var</span> someComp:SomeComp = <span class="kw2">new</span> SomeComp<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
<span class="co1">//set its properties, etc.</span><br />
someComp.<span class="me1">foo</span> = <span class="st0">&quot;foo&quot;</span>;<br />
<span class="co1">//add the component to the TitleWindow instance</span><br />
tw.<span class="me1">addChild</span><span class="br0">&#40;</span>someComp<span class="br0">&#41;</span>;<br />
<span class="co1">//use the PopUpManager class to add the pop up to the application</span><br />
PopUpManager.<span class="me1">addPopUp</span><span class="br0">&#40;</span>tw,Application.<span class="me1">appliction</span> as UIComponent<span class="br0">&#41;</span>;<br />
<span class="co1">//center the Pop Up</span><br />
PopUpMananger.<span class="me1">centerPopUp</span><span class="br0">&#40;</span>tw<span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span></div>
</div>
<p>You end up with something like this:</p>
<p><a href="http://www.binarygiant.com/blog/wp-content/uploads/2008/12/titlewindow.png" title="A Sample Title Window"><img src="http://www.binarygiant.com/blog/wp-content/uploads/2008/12/titlewindow.png" alt="A Sample Title Window" /></a></p>
<p>Using the AnimatedTitleWindow component is almost exactly the same; however, there is an added benefit of specifying an open effect, close effect, open animation duration, and close animation duration.  All of these properties have default settings as well, so you can literally use it out-of-the-box, just like the TitleWindow component, and it will perform an Iris effect on the open, and a resize effect on the close.</p>
<p>If you want to make the AnimatedTitleWindow behave in a more custom manner, you can create instances of <a href="http://livedocs.adobe.com/flex/201/html/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Book_Parts&amp;file=behaviors_068_05.html" title="Flex Effects">effects</a>, set their properties, and pass them to the AnimatedTitleWindow&#8217;s constructor, and it will play them accordingly.</p>
<p>For example, if you wanted to have the AnimatedTitleWindow open with a Dissolve effect and close with a Zoom effect, you could create an instance of each, pass them to the constructor of the AnimatedTitleWindow instance, and then when the PopUpManager adds or creates the Pop  Up it will play the animations on open and close of the component.</p>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;"><span class="kw3">private</span> <span class="kw2">function</span> addAnimatedPopUp<span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw3">void</span><br />
<span class="br0">&#123;</span><br />
<span class="co1">//create an instance of a Dissolve effect and set its properties</span><br />
<span class="kw2">var</span> dis:Dissovle = <span class="kw2">new</span> Dissolve<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
dis.<span class="me1">alphaFrom</span> = <span class="nu0">1.0</span>;<br />
dis.<span class="me1">alphaTo</span> = <span class="nu0">0.1</span>;<br />
dis.<span class="kw3">color</span> = <span class="st0">&quot;someColor&quot;</span>;<br />
<span class="co1">//create an instance of a Zoom</span><br />
<span class="kw2">var</span> zoom:Zoom = <span class="kw2">new</span> Zoom<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
zoom.<span class="me1">originX</span>=<span class="st0">&quot;Calculated&quot;</span>;<br />
zoom.<span class="me1">originY</span>=<span class="st0">&quot;Calculated&quot;</span>;<br />
zoom.<span class="me1">zoomWidthFrom</span>=<span class="nu0">0.1</span>;<br />
zoom.<span class="me1">zoomWidthTo</span>=<span class="nu0">1.0</span>;</p>
<p><span class="co1">//now create the instance of the animated pop up and add it to the application just like you would a TitleWindow with the PopUpManager</span><br />
<span class="kw2">var</span> anTW:AnimatedTitleWindow = <span class="kw2">new</span> AnimatedTitleWindow<span class="br0">&#40;</span>dis,zoom<span class="br0">&#41;</span>;<br />
<span class="co1">//add any children</span><br />
PopUpManager.<span class="me1">addPopUp</span><span class="br0">&#40;</span>anTW,Application.<span class="me1">application</span> as DisplayObject<span class="br0">&#41;</span>;<br />
PopUpManager.<span class="me1">centerPopUp</span><span class="br0">&#40;</span>anTW<span class="br0">&#41;</span>;<br />
<span class="co1">//that&#8217;s it the Pop Up is anmiated just the way you wanted it to be</span><br />
<span class="br0">&#125;</span></div>
</div>
<p>If you choose to use the default animations for the open and close (Iris,Resize) then all you have to do is instantiate an instance of the AnimatedTitleWindow and pass no properties to the constructor</p>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;"><span class="kw3">private</span> <span class="kw2">function</span> addDefaultAnimatedTitleWindow<span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw3">void</span><br />
<span class="br0">&#123;</span><br />
<span class="co1">//create an instance of the AnimatedTitleWindow</span><br />
<span class="kw2">var</span> anTW:AnimatedTitleWindow = <span class="kw2">new</span> AnimatedTitleWindow<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
<span class="co1">//add any children</span><br />
PopUpManager.<span class="me1">addPopUp</span><span class="br0">&#40;</span>anTW,Application.<span class="me1">application</span> as DisplayObject<span class="br0">&#41;</span>;<br />
PopUpManager.<span class="me1">centerPopUp</span><span class="br0">&#40;</span>anTW<span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span></div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.binarygiant.com/blog/?feed=rss2&amp;p=27</wfw:commentRss>
		</item>
		<item>
		<title>Remote-control warriors suffer war stress?</title>
		<link>http://www.binarygiant.com/blog/?p=26</link>
		<comments>http://www.binarygiant.com/blog/?p=26#comments</comments>
		<pubDate>Thu, 28 Aug 2008 15:53:13 +0000</pubDate>
		<dc:creator>Lance Sims</dc:creator>
		
		<category><![CDATA[Rants]]></category>

		<guid isPermaLink="false">http://www.binarygiant.com/blog/?p=26</guid>
		<description><![CDATA[ Recently a good friend of mine brought an article claming that remote-control aircraft operators are suffering from post traumatic stress disorder (PTSD) to my attention.  This article, according to my friend, is completely out of line and bogus, and this person wanted the world to know what they feel without fear of recrimination, so I [...]]]></description>
			<content:encoded><![CDATA[<p> Recently a good friend of mine brought an article claming that remote-control aircraft operators are suffering from post traumatic stress disorder (PTSD) to my attention.  This article, according to my friend, is completely out of line and bogus, and this person wanted the world to know what they feel without fear of recrimination, so I told them that I&#8217;d use my blog to give them a voice.</p>
<p>So read this article  <a href="http://www.msnbc.msn.com/id/26078087/" title="Remote-control warriors suffer war stress" target="_blank">http://www.msnbc.msn.com/id/26078087/</a> and then read the words of my friend, a career military member, and patriot below.</p>
<p><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><meta name="ProgId" content="Word.Document" /><meta name="Generator" content="Microsoft Word 11" /><meta name="Originator" content="Microsoft Word 11" /></p>
<link href="file:///C:%5CDOCUME%7E1%5CLSIMS%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C01%5Cclip_filelist.xml" rel="File-List" /><o:smarttagtype namespaceuri="urn:schemas-microsoft-com:office:smarttags" name="State"></o:smarttagtype><o:smarttagtype namespaceuri="urn:schemas-microsoft-com:office:smarttags" name="place"></o:smarttagtype><!--[if gte mso 9]><xml>  <w:WordDocument>   <w:View>Normal</w:View>   <w:Zoom>0</w:Zoom>   <w:PunctuationKerning/>   <w:ValidateAgainstSchemas/>   <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>   <w:IgnoreMixedContent>false</w:IgnoreMixedContent>   <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>   <w:Compatibility>    <w:BreakWrappedTables/>    <w:SnapToGridInCell/>    <w:WrapTextWithPunct/>    <w:UseAsianBreakRules/>    <w:DontGrowAutofit/>   </w:Compatibility>   <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>  </w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml>  <w:LatentStyles DefLockedState="false" LatentStyleCount="156">  </w:LatentStyles> </xml><![endif]--><!--[if !mso]><object  classid="clsid:38481807-CA0E-42D2-BF39-B33AF135CC4D" id=ieooui></object><br />
<style> st1\:*{behavior:url(#ieooui) } </style>
<p> <![endif]--></p>
<style> <!--  /* Style Definitions */  p.MsoNormal, li.MsoNormal, div.MsoNormal 	{mso-style-parent:""; 	margin:0in; 	margin-bottom:.0001pt; 	mso-pagination:widow-orphan; 	font-size:12.0pt; 	font-family:"Times New Roman"; 	mso-fareast-font-family:"Times New Roman";} @page Section1 	{size:8.5in 11.0in; 	margin:1.0in 1.25in 1.0in 1.25in; 	mso-header-margin:.5in; 	mso-footer-margin:.5in; 	mso-paper-source:0;} div.Section1 	{page:Section1;} --> </style>
<p><!--[if gte mso 10]></p>
<style>  /* Style Definitions */  table.MsoNormalTable 	{mso-style-name:"Table Normal"; 	mso-tstyle-rowband-size:0; 	mso-tstyle-colband-size:0; 	mso-style-noshow:yes; 	mso-style-parent:""; 	mso-padding-alt:0in 5.4pt 0in 5.4pt; 	mso-para-margin:0in; 	mso-para-margin-bottom:.0001pt; 	mso-pagination:widow-orphan; 	font-size:10.0pt; 	font-family:"Times New Roman"; 	mso-ansi-language:#0400; 	mso-fareast-language:#0400; 	mso-bidi-language:#0400;} </style>
<p> <![endif]--></p>
<p class="MsoNormal">First, let’s keep this in perspective… Predator “pilots” and Sensor Operators (SOs) do not conduct their business individually 24/7. They work 4 to 5 days a week, like regular folks, assuming 8-10 hour shifts spending approx 4-6 hours ‘in the seat’ at a stretch. The remainder of that shift is spent on administrative duties, ancillary training, required meetings, and other ‘aircrew’ training. AND, they do get to go home after their duty day, AND they do get to attend family functions as their schedule allows. Is there such a thing as PTSD?..Absolutely. However, having been an Intel professional for over 20 years, and having worked Intelligence, Surveillance, and Reconnaissance (ISR) missions spanning every war and limited conflict since Desert Storm across a multitude of airborne and overhead platforms providing still imagery as well as full motion video collection and analysis in a forward capacity as well as a reach-back environment, I maintain that these PTSD claims from these ‘Remote Control Warriors’ are complete bull$#!t!! Mr. Lindlaw, this is a fine piece of satire. Keeping this in perspective, and using a compare and contrast model, readers need to examine the article with circumspect. Our AF TAC-Ps and Army JTACs, who are the consumers of the Pred video, don’t operate in air-conditioned trailers, they work in the environment’s extremes- ridiculously hot in the spring/summer/fall months, cold in the winter months, enduring the relative frequency of dust storms and rain. Yes, rain. And when it rains, it’s <st1:place w:st="on"><st1:state w:st="on">Texas</st1:state></st1:place> rain that drops large amounts in a short period of time. Rain that raises the desert sand into inescapable mud that adds 5 pounds to each boot when stepped in. Nor do they have the luxury of dinners with spouses and kid’s soccer games at the end of the day, unless the former can be attached to having an MRE while sitting in the shade outside of your patrol vehicle, or hustling through the DFAC where the sign on the door reads “No Weapon-No Food.” The latter can be enjoyed when it is in the form of casual observation of a group of local national kids playing soccer in a vacant lot while out on patrol. And, killing people from 7000 miles away with computer keystrokes requires far less mental toughness than the tactical interview and taking of lives at close range. I maintain that, if these ‘Warriors’ don’t have the mental capacity to support our fielded forces while also enjoying all of the luxuries and amenities of life here at home, they lack the capacity to watch any PG-13 movie or complete their Self Aid and Buddy Care training that graphically shows open wounds, burns, and a popped-out eyeball. The high-resolution detail cited in the article is an embellishment. This whiplash transition is crap. Ask a Pred “pilot” when the last time was, and with what frequency he/she shoots a missile. Rest assured, on the occasion these ‘warriors’ pickle a weapon, the subsequent splash is met with high-fives and hell-yeahs that can be heard outside of their air-conditioned trailers from all members of the crew. Elation over the wholesale termination of bastards who desperately deserve it is what Predator crews and their supported customer(s) have in common. When they complain about their 24/7 operations, keep in mind the schedule they keep, referenced in the first few sentences. By comparison, those ISR consumers run an operation, are out on patrol, or are conducting weapons cleaning and inspections that provide for 3-6 hours of sleep before they are required to report for the next patrol/operation, often on an ad hoc basis where they are hustled out of the rack because they need to respond to a target of opportunity. Pred crews observe a duty day that does not exceed 12 hours and cannot exceed a certain total number of hours over the course of a month. They enjoy ‘crew-rest’, which requires that within that 12-hour period between missions they are provided the opportunity for 8 hours of sleep. Further, these “pilots” and SOs don’t validate their own targets or own the weapons they employ. Those functions/responsibilities reside with Intel professionals and TAC-P/JTAC, respectively. There is no BOOM! when Predator crews shoot a missile, or ‘potentially’ shoot a missile, for that matter. All they hear is the hum of their air conditioners. There are very few Intel qualified personnel working in the 196<sup>th</sup> RS. Most are former boom operators and aircraft maintainers held over from their days of flying refueling missions on KC-135/KC-10s. The armchair psychology taking place at March Air Reserve Base paints themselves, the community, and the Air Force like a bunch of pampered candy-asses. Thank you, Col Greg Davies for not allowing the entire Predator community to be painted with the same brush. I’ll be shaking your hand at WEPTAC. With a new CSAF, an increase in the demand for ISR and the emerging capabilities to satisfy that demand, we need personnel who have the moxie to provide support, especially from home station. If you predator crews whose foot fits in the shoe fashioned in the article can’t take the service in that direction, the please, for the love of God, country, and fellow servicemen, ETS as soon as possible, or go back to flying the gas-passer. Save the money spent on transition assistance and disability for those real warriors thrust back into society after doing the mission, not just supporting the mission from afar as they nervously walk thru a crowd at the fair or in a shopping mall, whose heads are still on a swivel in traffic, or who can scarcely enjoy a 4<sup>th</sup> of July fireworks display.</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
]]></content:encoded>
			<wfw:commentRss>http://www.binarygiant.com/blog/?feed=rss2&amp;p=26</wfw:commentRss>
		</item>
		<item>
		<title>Coding for Charity</title>
		<link>http://www.binarygiant.com/blog/?p=25</link>
		<comments>http://www.binarygiant.com/blog/?p=25#comments</comments>
		<pubDate>Thu, 21 Aug 2008 20:00:28 +0000</pubDate>
		<dc:creator>Lance Sims</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.binarygiant.com/blog/?p=25</guid>
		<description><![CDATA[I recently attended the 360 Flex conference in San Jose http://www.360flex.com.
The conference was great- there were topics for everything from beginners to Flex gurus.  I am happy to say that I learned an incredible amount about Flex and programming in general.  I met some great people too.
While at the conference I got to witness something [...]]]></description>
			<content:encoded><![CDATA[<p>I recently attended the 360 Flex conference in San Jose http://www.360flex.com.</p>
<p>The conference was great- there were topics for everything from beginners to Flex gurus.  I am happy to say that I learned an incredible amount about Flex and programming in general.  I met some great people too.</p>
<p>While at the conference I got to witness something truly remarkable.  There was a charity Flex Code Jam.  Several developers came together during the off-hours of the conference to donate their talents to a local Bay Area non profit.  The team came together to help create a web application using Flex for a local foodbank.</p>
<p>The foodbank provides food to a large number of people in the Bay Area, and they needed a way to aid hungry families in finding soup kitchen locations.</p>
<p>This is where the code jam people came in.  They created a really great Flex app that uses the Yahoo! maps API to locate, and provide information on where and how to get food.</p>
<p>It was really amazing to see how much technology helped this organization.</p>
<p>I am inspired by this act of kindness, and I would like to do something similar either as part of a team, or by myself.</p>
<p>So I am volunteering to donate my time to code for a charitable organization that needs a technology solution to help people.</p>
<p>My criteria are pretty simple:</p>
<p>The challenge has to be something that can be solved with technology, e.g. create a mapping applicaiton, or user interface to help people in need.</p>
<p>It can be anywhere, I live in the west, but I&#8217;m willing to help anyone with a worthy cause</p>
<p>If you are interested, please contact me through this site or email lance@binarygiant.com</p>
<p>Thanks,</p>
]]></content:encoded>
			<wfw:commentRss>http://www.binarygiant.com/blog/?feed=rss2&amp;p=25</wfw:commentRss>
		</item>
		<item>
		<title>Return Array Collections to Flex using Web Services and .NET</title>
		<link>http://www.binarygiant.com/blog/?p=22</link>
		<comments>http://www.binarygiant.com/blog/?p=22#comments</comments>
		<pubDate>Wed, 02 Apr 2008 05:28:09 +0000</pubDate>
		<dc:creator>Lance Sims</dc:creator>
		
		<category><![CDATA[.NET]]></category>

		<category><![CDATA[C#]]></category>

		<category><![CDATA[Flex]]></category>

		<category><![CDATA[Rich Internet Applications]]></category>

		<category><![CDATA[Web Services]]></category>

		<category><![CDATA[ActionScript]]></category>

		<category><![CDATA[C#.NET Web Service]]></category>

		<category><![CDATA[SOAP]]></category>

		<category><![CDATA[XML]]></category>

		<category><![CDATA[XmlDocument]]></category>

		<guid isPermaLink="false">http://www.binarygiant.com/blog/?p=22</guid>
		<description><![CDATA[One of the benefits of using AMF with Flex is that data comes back very clean and ready to use in your Flex applications with ActionScript.  Web services, however, don&#8217;t always have that advantage, because they wrap everything in a SOAP envelope, and many time requires code to extract XML, etc. to convert data [...]]]></description>
			<content:encoded><![CDATA[<p>One of the benefits of using AMF with Flex is that data comes back very clean and ready to use in your Flex applications with ActionScript.  Web services, however, don&#8217;t always have that advantage, because they wrap everything in a SOAP envelope, and many time requires code to extract XML, etc. to convert data into a usable format on the Flex side.</p>
<p>Format your WSDL correctly in your web service, and Flex will interpret the SOAP and XML into Array Collections that contain objects that represent your data.</p>
<p>At lease one way to perform this successfully using Flex and .NET web services is to use the XmlDocument class on the .NET side.  Generally you&#8217;ll get your data from a database, loop over the record set and create an XML version of the dataset, and return it to Flex via a web service.  Rather than returning the XML dataset as string, return it as a native XML document as an XmlDocument which is a .NET (at leaset C#) object.  Flex will interpret the SOAP and XML returned as an ArrayCollection.  It pretty simple.</p>
<p>Example:</p>
<p>C# code to get data from the database, convert the dataset into an xml string, and load that xml into an XmlDocument and return it to Flex</p>
<p><code>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;"><span class="br0">&#91;</span>WebMethod<span class="br0">&#93;</span><br />
<span class="kw3">public</span> XmlDocument GetClientsXML<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
XmlDocument clientXMLDoc = <span class="kw2">new</span> XmlDocument<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
<span class="co1">//create the connection to the database</span><br />
SqlConnection conn = <span class="kw2">new</span> SqlConnection<span class="br0">&#40;</span>WebConfigurationManager.<span class="me1">ConnectionStrings</span><span class="br0">&#91;</span><span class="st0">&quot;FOO&quot;</span><span class="br0">&#93;</span>.<span class="me1">ConnectionString</span><span class="br0">&#41;</span>;<br />
SqlCommand cmd = <span class="kw2">new</span> SqlCommand<span class="br0">&#40;</span><span class="st0">&quot;spGetClients&quot;</span>,conn<span class="br0">&#41;</span>;<br />
cmd.<span class="me1">CommandType</span> = CommandType.<span class="me1">StoredProcedure</span>;<br />
StringWriter sw = <span class="kw2">new</span> StringWriter<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
XmlTextWriter xw = <span class="kw2">new</span> XmlTextWriter<span class="br0">&#40;</span>sw<span class="br0">&#41;</span>;<br />
SqlDataReader dr;&lt;/code&gt;</p>
<p><span class="co1">//get the records</span><br />
<span class="kw3">try</span><br />
<span class="br0">&#123;</span><br />
conn.<span class="me1">Open</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
dr = cmd.<span class="me1">ExecuteReader</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
<span class="co1">//loop over the data set and create the xml for the clients</span><br />
<span class="kw1">if</span><span class="br0">&#40;</span>dr.<span class="me1">HasRows</span><span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
xw.<span class="me1">WriteStartElement</span><span class="br0">&#40;</span><span class="st0">&quot;clients&quot;</span><span class="br0">&#41;</span>;<br />
<span class="kw1">while</span><span class="br0">&#40;</span>dr.<span class="me1">Read</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
xw.<span class="me1">WriteStartElement</span><span class="br0">&#40;</span><span class="st0">&quot;client&quot;</span><span class="br0">&#41;</span>;<br />
xw.<span class="me1">WriteStartElement</span><span class="br0">&#40;</span><span class="st0">&quot;clientId&quot;</span><span class="br0">&#41;</span>;<br />
xw.<span class="me1">WriteString</span><span class="br0">&#40;</span><span class="br0">&#40;</span><span class="br0">&#40;</span>Int16<span class="br0">&#41;</span> dr<span class="br0">&#91;</span><span class="st0">&quot;ClientId&quot;</span><span class="br0">&#93;</span><span class="br0">&#41;</span>.<span class="kw3">ToString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
xw.<span class="me1">WriteEndElement</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
xw.<span class="me1">WriteStartElement</span><span class="br0">&#40;</span><span class="st0">&quot;firstName&quot;</span><span class="br0">&#41;</span>;<br />
xw.<span class="me1">WriteString</span><span class="br0">&#40;</span>dr<span class="br0">&#91;</span><span class="st0">&quot;FirstName&quot;</span><span class="br0">&#93;</span>.<span class="kw3">ToString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
xw.<span class="me1">WriteEndElement</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
xw.<span class="me1">WriteStartElement</span><span class="br0">&#40;</span><span class="st0">&quot;lastName&quot;</span><span class="br0">&#41;</span>;<br />
xw.<span class="me1">WriteString</span><span class="br0">&#40;</span>dr<span class="br0">&#91;</span><span class="st0">&quot;LastName&quot;</span><span class="br0">&#93;</span>.<span class="kw3">ToString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
xw.<span class="me1">WriteEndElement</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
xw.<span class="me1">WriteStartElement</span><span class="br0">&#40;</span><span class="st0">&quot;email&quot;</span><span class="br0">&#41;</span>;<br />
xw.<span class="me1">WriteString</span><span class="br0">&#40;</span>dr<span class="br0">&#91;</span><span class="st0">&quot;Email&quot;</span><span class="br0">&#93;</span>.<span class="kw3">ToString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
xw.<span class="me1">WriteEndElement</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
xw.<span class="me1">WriteStartElement</span><span class="br0">&#40;</span><span class="st0">&quot;city&quot;</span><span class="br0">&#41;</span>;<br />
xw.<span class="me1">WriteString</span><span class="br0">&#40;</span>dr<span class="br0">&#91;</span><span class="st0">&quot;City&quot;</span><span class="br0">&#93;</span>.<span class="kw3">ToString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
xw.<span class="me1">WriteEndElement</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
xw.<span class="me1">WriteStartElement</span><span class="br0">&#40;</span><span class="st0">&quot;State&quot;</span><span class="br0">&#41;</span>;<br />
xw.<span class="me1">WriteString</span><span class="br0">&#40;</span>dr<span class="br0">&#91;</span><span class="st0">&quot;State&quot;</span><span class="br0">&#93;</span>.<span class="kw3">ToString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
xw.<span class="me1">WriteEndElement</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
xw.<span class="me1">WriteStartElement</span><span class="br0">&#40;</span><span class="st0">&quot;zip&quot;</span><span class="br0">&#41;</span>;<br />
xw.<span class="me1">WriteString</span><span class="br0">&#40;</span>dr<span class="br0">&#91;</span><span class="st0">&quot;Zip&quot;</span><span class="br0">&#93;</span>.<span class="kw3">ToString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
xw.<span class="me1">WriteEndElement</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
xw.<span class="me1">WriteEndElement</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span><br />
xw.<span class="me1">WriteEndElement</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span></p>
<p><span class="br0">&#125;</span><br />
<span class="kw3">catch</span><span class="br0">&#40;</span>Exception ex<span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
Console.<span class="me1">WriteLine</span><span class="br0">&#40;</span>ex.<span class="kw3">Message</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span><br />
<span class="kw3">finally</span><br />
<span class="br0">&#123;</span><br />
conn.<span class="kw3">Close</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span><br />
<span class="co1">//parse the xml by loading it into the clientXMLDoc var and then return it as a native XML document</span><br />
clientXMLDoc.<span class="me1">LoadXml</span><span class="br0">&#40;</span>xw.<span class="kw3">ToString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
<span class="kw1">return</span> clientXMLDoc;<br />
<span class="br0">&#125;</span></div>
</div>
<p>ActionScript code to extract the ArrayCollection from the web service result</p>
<p><code>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;"><span class="kw3">public</span> <span class="kw2">function</span> result<span class="br0">&#40;</span>event:ResultEvent<span class="br0">&#41;</span>:<span class="kw3">void</span><br />
<span class="br0">&#123;</span><br />
<span class="co1">//now drill down into the soap object to get an array collection</span><br />
model.<span class="me1">clientListAC</span> = event.<span class="me1">result</span>.<span class="me1">clients</span>.<span class="me1">client</span> as ArrayCollection;&lt;/code&gt;</p>
<p><span class="co1">//notice that you need to traverse the result to find where it is in the SOAP/XML structure</span><br />
<span class="kw2">var</span> objClients:<span class="kw3">Object</span> = event.<span class="me1">result</span>; <span class="co1">//var to show how to drill into the soap object not used for anything else</span><br />
<span class="br0">&#125;</span></div>
</div>
<p>The best way to inspect your return result is to use the Flex Debugger or Service Capture to view the SOAP and XML.</p>
<p><a href="http://www.binarygiant.com/blog/wp-content/uploads/2008/04/soaparraycollection.png" title="soaparraycollection.png"><img src="http://www.binarygiant.com/blog/wp-content/uploads/2008/04/soaparraycollection.png" alt="soaparraycollection.png" /></a><a href="http://www.binarygiant.com/blog/wp-content/uploads/2008/04/servicecapturesoap.png" title="servicecapturesoap.png"><img src="http://www.binarygiant.com/blog/wp-content/uploads/2008/04/servicecapturesoap.png" alt="servicecapturesoap.png" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.binarygiant.com/blog/?feed=rss2&amp;p=22</wfw:commentRss>
		</item>
		<item>
		<title>Flex with Web Services, SOAP, .NET, and XML</title>
		<link>http://www.binarygiant.com/blog/?p=12</link>
		<comments>http://www.binarygiant.com/blog/?p=12#comments</comments>
		<pubDate>Mon, 31 Mar 2008 06:12:31 +0000</pubDate>
		<dc:creator>Lance Sims</dc:creator>
		
		<category><![CDATA[.NET]]></category>

		<category><![CDATA[C#]]></category>

		<category><![CDATA[Flex]]></category>

		<category><![CDATA[Rich Internet Applications]]></category>

		<category><![CDATA[Web Services]]></category>

		<category><![CDATA[ActionScript]]></category>

		<category><![CDATA[C#.NET Web Service]]></category>

		<category><![CDATA[SOAP]]></category>

		<category><![CDATA[XML]]></category>

		<category><![CDATA[XmlDocument]]></category>

		<guid isPermaLink="false">http://www.binarygiant.com/blog/?p=12</guid>
		<description><![CDATA[Flex and .NET web services can be a powerful combination, and using them together can also be challenging.  Using web services with Flex generally means you have to deal with SOAP (Simple Object Access Protocol), and this can be frustrating and tricky, in fact it can be so frustrating, that developers will forgo the [...]]]></description>
			<content:encoded><![CDATA[<p>Flex and .NET web services can be a powerful combination, and using them together can also be challenging.  Using web services with Flex generally means you have to deal with SOAP (Simple Object Access Protocol), and this can be frustrating and tricky, in fact it can be so frustrating, that developers will forgo the use of web services and opt for the HTTPService object when retrieving xml from a web service, which is not always the best alternative (in my opinion), since web services are more robust (in my opinion) than HTTPServices.</p>
<p>This post shows how to work with .NET web services in Flex, and how to bypass a lot of the SOAP headache.</p>
<p>The problem:</p>
<p>Returning a native XML from .NET web service to Flex makes the XML object difficult to access on the Flex side- I was basically<br />
unable to use e4x, even though I used namespaces, and operation return types properly.</p>
<p>C# Web Service code to retrieve XML from a database that contains client information for a fictitious business.</p>
<div class="codesnip-container" >
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;"><span class="br0">&#91;</span>WebMethod<span class="br0">&#93;</span><br />
public XmlDocument GetClientsXML<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
XmlDocument clientXMLDoc = new XmlDocument<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
<span class="co1">//create the connection to the database</span><br />
SqlConnection conn = new SqlConnection<span class="br0">&#40;</span>WebConfigurationManager.<span class="me1">ConnectionStrings</span><span class="br0">&#91;</span><span class="st0">&quot;FOO&quot;</span><span class="br0">&#93;</span>.<span class="me1">ConnectionString</span><span class="br0">&#41;</span>;<br />
SqlCommand cmd = new SqlCommand<span class="br0">&#40;</span><span class="st0">&quot;spGetClients&quot;</span>,conn<span class="br0">&#41;</span>;<br />
cmd.<span class="me1">CommandType</span> = CommandType.<span class="me1">StoredProcedure</span>;<br />
StringWriter sw = new StringWriter<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
XmlTextWriter xw = new XmlTextWriter<span class="br0">&#40;</span>sw<span class="br0">&#41;</span>;<br />
SqlDataReader dr;&lt;/code&gt;</p>
<p><span class="co1">//get the records</span><br />
try<br />
<span class="br0">&#123;</span><br />
conn.<span class="me1">Open</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
dr = cmd.<span class="me1">ExecuteReader</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
<span class="co1">//loop over the data set and create the xml for the clients</span><br />
<span class="kw1">if</span><span class="br0">&#40;</span>dr.<span class="me1">HasRows</span><span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
xw.<span class="me1">WriteStartElement</span><span class="br0">&#40;</span><span class="st0">&quot;clients&quot;</span><span class="br0">&#41;</span>;<br />
<span class="kw1">while</span><span class="br0">&#40;</span>dr.<span class="me1">Read</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
xw.<span class="me1">WriteStartElement</span><span class="br0">&#40;</span><span class="st0">&quot;client&quot;</span><span class="br0">&#41;</span>;<br />
xw.<span class="me1">WriteStartElement</span><span class="br0">&#40;</span><span class="st0">&quot;clientId&quot;</span><span class="br0">&#41;</span>;<br />
xw.<span class="me1">WriteString</span><span class="br0">&#40;</span><span class="br0">&#40;</span><span class="br0">&#40;</span>Int16<span class="br0">&#41;</span> dr<span class="br0">&#91;</span><span class="st0">&quot;ClientId&quot;</span><span class="br0">&#93;</span><span class="br0">&#41;</span>.<span class="me1">ToString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
xw.<span class="me1">WriteEndElement</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
xw.<span class="me1">WriteStartElement</span><span class="br0">&#40;</span><span class="st0">&quot;firstName&quot;</span><span class="br0">&#41;</span>;<br />
xw.<span class="me1">WriteString</span><span class="br0">&#40;</span>dr<span class="br0">&#91;</span><span class="st0">&quot;FirstName&quot;</span><span class="br0">&#93;</span>.<span class="me1">ToString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
xw.<span class="me1">WriteEndElement</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
xw.<span class="me1">WriteStartElement</span><span class="br0">&#40;</span><span class="st0">&quot;lastName&quot;</span><span class="br0">&#41;</span>;<br />
xw.<span class="me1">WriteString</span><span class="br0">&#40;</span>dr<span class="br0">&#91;</span><span class="st0">&quot;LastName&quot;</span><span class="br0">&#93;</span>.<span class="me1">ToString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
xw.<span class="me1">WriteEndElement</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
xw.<span class="me1">WriteStartElement</span><span class="br0">&#40;</span><span class="st0">&quot;email&quot;</span><span class="br0">&#41;</span>;<br />
xw.<span class="me1">WriteString</span><span class="br0">&#40;</span>dr<span class="br0">&#91;</span><span class="st0">&quot;Email&quot;</span><span class="br0">&#93;</span>.<span class="me1">ToString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
xw.<span class="me1">WriteEndElement</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
xw.<span class="me1">WriteStartElement</span><span class="br0">&#40;</span><span class="st0">&quot;city&quot;</span><span class="br0">&#41;</span>;<br />
xw.<span class="me1">WriteString</span><span class="br0">&#40;</span>dr<span class="br0">&#91;</span><span class="st0">&quot;City&quot;</span><span class="br0">&#93;</span>.<span class="me1">ToString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
xw.<span class="me1">WriteEndElement</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
xw.<span class="me1">WriteStartElement</span><span class="br0">&#40;</span><span class="st0">&quot;State&quot;</span><span class="br0">&#41;</span>;<br />
xw.<span class="me1">WriteString</span><span class="br0">&#40;</span>dr<span class="br0">&#91;</span><span class="st0">&quot;State&quot;</span><span class="br0">&#93;</span>.<span class="me1">ToString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
xw.<span class="me1">WriteEndElement</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
xw.<span class="me1">WriteStartElement</span><span class="br0">&#40;</span><span class="st0">&quot;zip&quot;</span><span class="br0">&#41;</span>;<br />
xw.<span class="me1">WriteString</span><span class="br0">&#40;</span>dr<span class="br0">&#91;</span><span class="st0">&quot;Zip&quot;</span><span class="br0">&#93;</span>.<span class="me1">ToString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
xw.<span class="me1">WriteEndElement</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
xw.<span class="me1">WriteEndElement</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span><br />
xw.<span class="me1">WriteEndElement</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span></p>
<p><span class="br0">&#125;</span><br />
catch<span class="br0">&#40;</span>Exception ex<span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
Console.<span class="me1">WriteLine</span><span class="br0">&#40;</span>ex.<span class="me1">Message</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span><br />
finally<br />
<span class="br0">&#123;</span><br />
conn.<span class="me1">Close</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span><br />
<span class="co1">//parse the xml by loading it into the clientXMLDoc var and then return it as a native XML document</span><br />
clientXMLDoc.<span class="me1">LoadXml</span><span class="br0">&#40;</span>xw.<span class="me1">ToString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
<span class="kw1">return</span> clientXMLDoc;<br />
<span class="br0">&#125;</span></div>
</div>
</div>
<p>That is the methodology used to get the string representation from the database.  Wanting to be a good developer I took it another step and wrapped the xml string into an XmlDocument and returned <em>this</em> to Flex at first</p>
<p>So now we have our xml document that will pass back to Flex which looks something like this</p>
<div class="codesnip-container" >
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;"><span class="sc3"><span class="re1">&lt;clients<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;clientid<span class="re2">&gt;</span></span></span>2<span class="sc3"><span class="re1">&lt;/clientid<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;firstname<span class="re2">&gt;</span></span></span>Daffy<span class="sc3"><span class="re1">&lt;/firstname<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;lastname<span class="re2">&gt;</span></span></span>Duck<span class="sc3"><span class="re1">&lt;/lastname<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;iail<span class="re2">&gt;</span></span></span>dduck@binarygiant.com<span class="sc3"><span class="re1">&lt;/iail<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;city<span class="re2">&gt;</span></span></span>Las Vegas<span class="sc3"><span class="re1">&lt;/city<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;state<span class="re2">&gt;</span></span></span>Nevada<span class="sc3"><span class="re1">&lt;/state<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;zip<span class="re2">&gt;</span></span></span>889141<span class="sc3"><span class="re1">&lt;/zip<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;/clients<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;client<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;clientid<span class="re2">&gt;</span></span></span>5<span class="sc3"><span class="re1">&lt;/clientid<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;firstname<span class="re2">&gt;</span></span></span>Some<span class="sc3"><span class="re1">&lt;/firstname<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;lastname<span class="re2">&gt;</span></span></span>Dude<span class="sc3"><span class="re1">&lt;/lastname<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;iail<span class="re2">&gt;</span></span></span>somedude@here.com<span class="sc3"><span class="re1">&lt;/iail<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;city<span class="re2">&gt;</span></span></span>San Diego<span class="sc3"><span class="re1">&lt;/city<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;state<span class="re2">&gt;</span></span></span>California<span class="sc3"><span class="re1">&lt;/state<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;zip<span class="re2">&gt;</span></span></span>99771<span class="sc3"><span class="re1">&lt;/zip<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;/client<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;client<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;/client<span class="re2">&gt;</span></span></span></div>
</div>
</div>
<p>So now that I had my xml I thought it would be easy to work with on the Flex side, because I had declared the return type of the &lt;mx:operation/&gt; tag as e4x, and I added the namespace declaration to my Actionscript code to the same as that of the XML document</p>
<div class="codesnip-container" >
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;"><span class="sc3"><span class="re1">&lt;mx:webservice<span class="re2">&gt;</span></span></span><br />
id=&quot;clientService&quot;<br />
wsdl=&quot;http://realityisabsolute.com/Foo/Client.asmx?wsdl&quot;<br />
showBusyCursor=&quot;true&quot;<span class="sc1">&amp;gt;</span><span class="sc3"><span class="re1">&lt;/mx:webservice<span class="re2">&gt;</span></span></span><span class="sc3"><span class="re1">&lt;/code<span class="re2">&gt;</span></span></span></p>
<p><span class="sc3"><span class="re1">&lt;mx:operation</span> <span class="re0">name</span>=<span class="st0">&quot;GetClientsXML&quot;</span> <span class="re0">concurrency</span>=<span class="st0">&quot;multiple&quot;</span> <span class="re0">resultformat</span>=<span class="st0">&quot;e4x&quot;</span><span class="re2">&gt;</span></span><br />
<span class="sc3"><span class="re1">&lt;/mx:WebService<span class="re2">&gt;</span></span></span></div>
</div>
</div>
<div class="codesnip-container" >
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;"><span class="co1">//namespace for the webservice call, this is required if you intend to use e4x</span><br />
<span class="kw3">private</span> namespace realityIsAbsolute = <span class="st0">&quot;http://realityisabsolute.com&quot;</span>;<br />
use namespace realityIsAbsolute;</div>
</div>
</div>
<p>In my Flex application I attempted to access the xml document using standard e4x syntax, but all my efforts failed.  I scoured posts about removing headers, adding namespaces, etc., and came up with not much more than a headache, and had to revert back to an fairly archaic method of accessing XML nodes with the ActionScript XML class.<br />
The Solution:</p>
<p>The project that inspired this post is a Flex/.NET application that uses the .NET framework&#8217;s XmlDocument class to return a native xml document to a Flex application.  What I have found is that when you return a native xml document to Flex from a .NET web service, you have to deal with a SOAP nightmare.  Instead of using the XmlDocument class on the web service side, I suggest you use the XmlTextWriter class to create a string representation of the XML document, return that string to Flex, and convert the string to XML on the Flex side (in one easy step), and then you&#8217;re ready to use e4x with you XML in Flex.</p>
<p>My ActionScript 3.0 code to access XmlDocument nodes</p>
<div class="codesnip-container" >
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;"><span class="co1">//parse out the soap object to get the clients</span><br />
<span class="kw2">var</span> clientXML:<span class="kw3">XML</span> = <span class="kw2">new</span> <span class="kw3">XML</span><span class="br0">&#40;</span>event.<span class="me1">result</span>.<span class="kw3">toString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
<span class="co1">//we set the resultFormat to e4x in the web service operation declaration, and we declared the namespace</span><br />
<span class="co1">//so we would think that we could access the xml using e4x, but we can&#8217;t. &nbsp;and after several attempts</span><br />
<span class="co1">//to strip the soap garbage, I gave up, and accessed the xml using the oh-so-fun decendants and children</span><br />
<span class="co1">//access notation.&lt;/code&gt;</span></p>
<p>clientXML = clientXML.<span class="me1">descendants</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">descendants</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span>; &nbsp;<span class="co1">//drilling even further to get an XMLList</span><br />
<span class="kw2">var</span> clientXMLList:XMLList = <span class="kw2">new</span> XMLList<span class="br0">&#40;</span>clientXML.<span class="me1">children</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</p>
<p><span class="co1">//even after I extracted the XMLList and convert it to an xml list collection, and set it on the model</span><br />
<span class="co1">//so that bindings throughout the application will pick it up, the soap garbage gets in the way of that,</span><br />
<span class="co1">//so my next step would be to convert it to an array collection, but I can do much more easily by telling</span><br />
<span class="co1">//the web service call to return the result as an object</span></p>
<p>model.<span class="me1">clientList2</span> = <span class="kw2">new</span> XMLListCollection<span class="br0">&#40;</span>clientXMLList<span class="br0">&#41;</span>;</p>
<p><span class="co1">//so you see that I had to inspect the xml that came across from the web service, drill in, and repeat</span><br />
<span class="co1">//a pretty arduous task of accessing the nodes using old methods. &nbsp;That is why instead of returning</span><br />
<span class="co1">//a native xml document from the web service, it is better to simply return a string and convert it to</span><br />
<span class="co1">//native xml using action script, then access it via e4x</span></div>
</div>
</div>
<p>Using the Flex Debugger to inspect my XML this is what I got back&#8230;. a SOAP mess.</p>
<p><a href="http://www.binarygiant.com/blog/wp-content/uploads/2008/03/clientxmlsoapmess.png" title="Flex Debugger with XML, SOAP"><img src="http://www.binarygiant.com/blog/wp-content/uploads/2008/03/clientxmlsoapmess.png" alt="Flex Debugger with XML, SOAP" height="334" width="745" /></a></p>
<p>The Solution:</p>
<p>I changed the .NET web service slightly, by removing the step where I convert the xml string on the XmlTextWriter to an XmlDocument on the C#.NET web service side.  The method now returns the string xml to Flex, and I can access it using e4x after converting the string to xml using ActionScript</p>
<p>C# .NET web service code</p>
<div class="codesnip-container" >
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;"><span class="br0">&#91;</span>WebMethod<span class="br0">&#93;</span><br />
public <span class="kw4">string</span> GetClients<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
<span class="co1">//create the connection to the database</span><br />
SqlConnection conn = new SqlConnection<span class="br0">&#40;</span>WebConfigurationManager.<span class="me1">ConnectionStrings</span><span class="br0">&#91;</span><span class="st0">&quot;FOO&quot;</span><span class="br0">&#93;</span>.<span class="me1">ConnectionString</span><span class="br0">&#41;</span>;<br />
SqlCommand cmd = new SqlCommand<span class="br0">&#40;</span><span class="st0">&quot;spGetClients&quot;</span>,conn<span class="br0">&#41;</span>;<br />
cmd.<span class="me1">CommandType</span> = CommandType.<span class="me1">StoredProcedure</span>;<br />
StringWriter sw = new StringWriter<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
XmlTextWriter xw = new XmlTextWriter<span class="br0">&#40;</span>sw<span class="br0">&#41;</span>;<br />
SqlDataReader dr;&lt;/code&gt;</p>
<p><span class="co1">//get the records</span><br />
try<br />
<span class="br0">&#123;</span><br />
conn.<span class="me1">Open</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
dr = cmd.<span class="me1">ExecuteReader</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
<span class="co1">//loop over the data set and create the xml for the clients</span><br />
<span class="kw1">if</span><span class="br0">&#40;</span>dr.<span class="me1">HasRows</span><span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
xw.<span class="me1">WriteStartElement</span><span class="br0">&#40;</span><span class="st0">&quot;clients&quot;</span><span class="br0">&#41;</span>;<br />
<span class="kw1">while</span><span class="br0">&#40;</span>dr.<span class="me1">Read</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
xw.<span class="me1">WriteStartElement</span><span class="br0">&#40;</span><span class="st0">&quot;client&quot;</span><span class="br0">&#41;</span>;<br />
xw.<span class="me1">WriteStartElement</span><span class="br0">&#40;</span><span class="st0">&quot;clientId&quot;</span><span class="br0">&#41;</span>;<br />
xw.<span class="me1">WriteString</span><span class="br0">&#40;</span><span class="br0">&#40;</span><span class="br0">&#40;</span>Int16<span class="br0">&#41;</span> dr<span class="br0">&#91;</span><span class="st0">&quot;ClientId&quot;</span><span class="br0">&#93;</span><span class="br0">&#41;</span>.<span class="me1">ToString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
xw.<span class="me1">WriteEndElement</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
xw.<span class="me1">WriteStartElement</span><span class="br0">&#40;</span><span class="st0">&quot;firstName&quot;</span><span class="br0">&#41;</span>;<br />
xw.<span class="me1">WriteString</span><span class="br0">&#40;</span>dr<span class="br0">&#91;</span><span class="st0">&quot;FirstName&quot;</span><span class="br0">&#93;</span>.<span class="me1">ToString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
xw.<span class="me1">WriteEndElement</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
xw.<span class="me1">WriteStartElement</span><span class="br0">&#40;</span><span class="st0">&quot;lastName&quot;</span><span class="br0">&#41;</span>;<br />
xw.<span class="me1">WriteString</span><span class="br0">&#40;</span>dr<span class="br0">&#91;</span><span class="st0">&quot;LastName&quot;</span><span class="br0">&#93;</span>.<span class="me1">ToString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
xw.<span class="me1">WriteEndElement</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
xw.<span class="me1">WriteStartElement</span><span class="br0">&#40;</span><span class="st0">&quot;email&quot;</span><span class="br0">&#41;</span>;<br />
xw.<span class="me1">WriteString</span><span class="br0">&#40;</span>dr<span class="br0">&#91;</span><span class="st0">&quot;Email&quot;</span><span class="br0">&#93;</span>.<span class="me1">ToString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
xw.<span class="me1">WriteEndElement</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
xw.<span class="me1">WriteStartElement</span><span class="br0">&#40;</span><span class="st0">&quot;city&quot;</span><span class="br0">&#41;</span>;<br />
xw.<span class="me1">WriteString</span><span class="br0">&#40;</span>dr<span class="br0">&#91;</span><span class="st0">&quot;City&quot;</span><span class="br0">&#93;</span>.<span class="me1">ToString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
xw.<span class="me1">WriteEndElement</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
xw.<span class="me1">WriteStartElement</span><span class="br0">&#40;</span><span class="st0">&quot;State&quot;</span><span class="br0">&#41;</span>;<br />
xw.<span class="me1">WriteString</span><span class="br0">&#40;</span>dr<span class="br0">&#91;</span><span class="st0">&quot;State&quot;</span><span class="br0">&#93;</span>.<span class="me1">ToString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
xw.<span class="me1">WriteEndElement</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
xw.<span class="me1">WriteStartElement</span><span class="br0">&#40;</span><span class="st0">&quot;zip&quot;</span><span class="br0">&#41;</span>;<br />
xw.<span class="me1">WriteString</span><span class="br0">&#40;</span>dr<span class="br0">&#91;</span><span class="st0">&quot;Zip&quot;</span><span class="br0">&#93;</span>.<span class="me1">ToString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
xw.<span class="me1">WriteEndElement</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
xw.<span class="me1">WriteEndElement</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span><br />
xw.<span class="me1">WriteEndElement</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span></p>
<p><span class="br0">&#125;</span><br />
catch<span class="br0">&#40;</span>Exception ex<span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
Console.<span class="me1">WriteLine</span><span class="br0">&#40;</span>ex.<span class="me1">Message</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span><br />
finally<br />
<span class="br0">&#123;</span><br />
conn.<span class="me1">Close</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span><br />
<span class="kw4">string</span> clientXML = sw.<span class="me1">ToString</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
<span class="kw1">return</span> clientXML;<br />
<span class="br0">&#125;</span></div>
</div>
</div>
<p>Convert the xml string returned from the web service to an ActionScript XML object and you can easily access it with e4x. In this instance I called parsed out the XML until I got to the root node for clients, called the children() method of the XML class to return an XMLList to pass to the constructor of the XMLListCollection class, and then set a property on the model (using Cairngorm) that is a dataprovider for some data components on the application.Flex/ActionScript 3.0 code to convert the string to an ActionScript XML object</p>
<div class="codesnip-container" >
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;"><span class="kw3">public</span> <span class="kw2">function</span> result<span class="br0">&#40;</span>event:<span class="kw3">Object</span><span class="br0">&#41;</span>:<span class="kw3">void</span><br />
<span class="br0">&#123;</span><br />
<span class="co1">//extract the string represenation of the xml from the web service result and convert it to native XML</span><br />
<span class="co1">//now we can access it using e4x, see the trace statements</span><br />
<span class="kw2">var</span> clientXML:<span class="kw3">XML</span> = <span class="kw2">new</span> <span class="kw3">XML</span><span class="br0">&#40;</span>event.<span class="me1">result</span>.<span class="kw3">toString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;&lt;/code&gt;</p>
<p><span class="co1">//set the var on the model that the data grid (and/or any other component) is bound to</span><br />
model.<span class="me1">clientList</span> = <span class="kw2">new</span> XMLListCollection<span class="br0">&#40;</span>clientXML.<span class="me1">children</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</p>
<p><span class="kw1">for</span><span class="br0">&#40;</span><span class="kw2">var</span> i:<span class="kw3">int</span> = <span class="nu0">0</span>; i &amp;lt; clientXML.<span class="kw3">length</span><span class="br0">&#40;</span><span class="br0">&#41;</span>; i ++<span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
<span class="kw3">trace</span><span class="br0">&#40;</span>clientXML.<span class="me1">client</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span>.<span class="me1">clientId</span><span class="br0">&#41;</span>;<br />
<span class="kw3">trace</span><span class="br0">&#40;</span>clientXML.<span class="me1">client</span><span class="br0">&#91;</span>i<span class="br0">&#93;</span>.<span class="me1">firstName</span> + <span class="st0">&quot; &quot;</span> + clientXML.<span class="me1">client</span><span class="br0">&#91;</span>i<span class="br0">&#93;</span>.<span class="me1">lastName</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
</div>
</div>
<p><a href="http://www.binarygiant.com/blog/wp-content/uploads/2008/03/goodclientxml.png" title="Client XML"><img src="http://www.binarygiant.com/blog/wp-content/uploads/2008/03/goodclientxml.png" alt="Client XML" /></a></p>
<p>You can see that there is a huge difference in the way that Flex allows you to treat xml returned from web services.  While writing this post I very briefly tested the new Flex 3 web service wizard.  It created about 7 files to handle all of the SOAP issues to get to the XML.  The files written by the wizard are no doubt powerful and extremely helpful, but if you are looking for a light-weight way to access XML using web services and .NET, this method works well.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.binarygiant.com/blog/?feed=rss2&amp;p=12</wfw:commentRss>
		</item>
		<item>
		<title>Passing XML Between Flex and .NET Web Services</title>
		<link>http://www.binarygiant.com/blog/?p=7</link>
		<comments>http://www.binarygiant.com/blog/?p=7#comments</comments>
		<pubDate>Mon, 17 Mar 2008 06:45:00 +0000</pubDate>
		<dc:creator>Lance Sims</dc:creator>
		
		<category><![CDATA[.NET]]></category>

		<category><![CDATA[C#]]></category>

		<category><![CDATA[Flex]]></category>

		<category><![CDATA[Rich Internet Applications]]></category>

		<category><![CDATA[Web Services]]></category>

		<category><![CDATA[ActionScript]]></category>

		<category><![CDATA[SOAP]]></category>

		<category><![CDATA[Webservices]]></category>

		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://www.binarygiant.com/blog/?p=7</guid>
		<description><![CDATA[When you have a Flex project (or other types of projects) that consume .NET web services, it can make life much easier to pass XML to the service(s), instead of multiple string, ints, or other primative objects.  Use XML to represent your object.  It is much easier to process XML returned to Flex [...]]]></description>
			<content:encoded><![CDATA[<p>When you have a Flex project (or other types of projects) that consume .NET web services, it can make life much easier to pass XML to the service(s), instead of multiple string, ints, or other primative objects.  Use XML to represent your object.  It is much easier to process XML returned to Flex by a .NET web service than the other way around, because Flex converts many SOAP objects to ArrayCollections under-the-hood, and developers can access them natively or they can use E4X to parse the XML.  It just depends on what works best for your development scenario.</p>
<p>.NET does not convert XML to a workable Object or DataSet under-the-hood (as far as I know), but it is easy to run the conversion pro grammatically, and you can be off and running with a workable DataSet or XMLDocument pretty quickly.</p>
<p>The project is an Event Scheduling Application:</p>
<p><a href="http://www.binarygiant.com/blog/wp-content/uploads/2008/03/picture-2.png" title="Calendar Entry Form"><img src="http://www.binarygiant.com/blog/wp-content/uploads/2008/03/picture-2.png" alt="Calendar Entry Form" height="243" width="437" /></a></p>
<p>The following is an example of how to achieve this.</p>
<p>First the Flex/ActionScript code:</p>
<p>After the user has entered the event data into the appropriate form fields, and they click the save button, the event handler for the save creates an XML representation of the event to pass to the .NET web service.  (Notice the binding symbols for the values captured from startDate_df and endDate_df, name_ti, and description_ta which are the form fields depicted above).</p>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;"><span class="kw3">private</span> <span class="kw2">function</span> createCalendarEvent<span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw3">void</span><br />
<span class="br0">&#123;</span><br />
<span class="co1">//vars used to manage and manipulate xml to be sent to .NET web service</span><br />
<span class="kw2">var</span> eventXML:<span class="kw3">XML</span>;<br />
<span class="kw2">var</span> eventXMLDoc:XMLDocument = <span class="kw2">new</span> XMLDocument<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
eventXML =</div>
</div>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;"><span class="sc3"><span class="re1">&lt;calendarevent<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;startdate<span class="re2">&gt;</span></span></span>{startDate_df.selectedDate.toUTCString()}<span class="sc3"><span class="re1">&lt;/startdate<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;enddate<span class="re2">&gt;</span></span></span>{endDate_df.selectedDate.toUTCString()}<span class="sc3"><span class="re1">&lt;/enddate<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;starttime<span class="re2">&gt;</span></span></span>{startDate_df.selectedDate.toUTCString()}<span class="sc3"><span class="re1">&lt;/starttime<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;endtime<span class="re2">&gt;</span></span></span>{endDate_df.selectedDate.toUTCString()}<span class="sc3"><span class="re1">&lt;/endtime<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;name<span class="re2">&gt;</span></span></span>{name_ti.text}<span class="sc3"><span class="re1">&lt;/name<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;description<span class="re2">&gt;</span></span></span>{description_ta.text}<span class="sc3"><span class="re1">&lt;/description<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;/calendarevent<span class="re2">&gt;</span></span></span></div>
</div>
<p>Now the code creates an instance of the WebService class and loads the WSDL for the web service.</p>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;">eventXMLDoc.<span class="kw3">ignoreWhite</span> = <span class="kw2">true</span>;<br />
eventXMLDoc.<span class="kw3">parseXML</span><span class="br0">&#40;</span>eventXML<span class="br0">&#41;</span>;</p>
<p><span class="co1">//create a web service instance(or better yet use your Service Locator)</span><br />
<span class="kw2">var</span> dotNetWebService:WebService = <span class="kw2">new</span> WebService<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
<span class="co1">//make sure you can communicate with the server</span><br />
<span class="kw3">try</span><br />
<span class="br0">&#123;</span><br />
dotNetWebService.<span class="me1">loadWSDL</span><span class="br0">&#40;</span><span class="st0">&quot;http://localhost/yourServer/foo.asmx?WSDL&quot;</span><span class="br0">&#41;</span>;<br />
<span class="co1">//now that the web service object is set up we call the method that will create</span><br />
<span class="co1">//the calendar event on the windows server, show the busy cursor while processing</span><br />
CursorManager.<span class="me1">setBusyCursor</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
<span class="co1">//use an asynchronus token to add a responder for the web service ResultEvent</span><br />
<span class="kw2">var</span> token:AsyncToken = dotNetWebService.<span class="me1">CreateCalenderEvent</span><span class="br0">&#40;</span>eventXML<span class="br0">&#41;</span>;<br />
token.<span class="me1">addResponder</span><span class="br0">&#40;</span><span class="kw2">new</span> ItemResponder<span class="br0">&#40;</span>onCreateCalendarEventResult,onFault<span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span><br />
<span class="co1">//catch the error and perform the neccessary error handling</span><br />
<span class="kw3">catch</span><span class="br0">&#40;</span><span class="kw3">error</span>:<span class="kw3">Error</span><span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
<span class="kw3">trace</span><span class="br0">&#40;</span><span class="kw3">error</span>.<span class="kw3">message</span><span class="br0">&#41;</span>;<br />
<span class="co1">//log error to database, etc.</span><br />
<span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
</div>
<p>After the web service call has completed we remove the busy cursor and alert the user to the success of the operation.</p>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;"><span class="co1">//event handler for the result event of the web service call, just alert the user of success</span><br />
<span class="kw3">private</span> <span class="kw2">function</span> onCreateCalendarEventResult<span class="br0">&#40;</span>event:ResultEvent,responder:<span class="kw3">Object</span><span class="br0">&#41;</span>:<span class="kw3">void</span><br />
<span class="br0">&#123;</span><br />
<span class="co1">//remove the busy cursor</span><br />
CursorManager.<span class="me1">removeBusyCursor</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
<span class="kw2">var</span> alert:Alert = Alert.<span class="kw3">show</span><span class="br0">&#40;</span><span class="st0">&quot;Event Successfully Created&quot;</span>,<span class="st0">&quot;Added&quot;</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span></div>
</div>
<p>If something went wrong during the call to the web service, e.g. and exception was thrown by the C# code on the server, this fault handler removes the busy cursor and alerts the user to tell them that a fault occurred.</p>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;"><span class="co1">//fault handler for web service call</span><br />
<span class="kw3">private</span> <span class="kw2">function</span> onFault<span class="br0">&#40;</span>fault:FaultEvent<span class="br0">&#41;</span>:<span class="kw3">void</span><br />
<span class="br0">&#123;</span><br />
<span class="co1">//remove the busy cursor CursorManager.removeBusyCurosr();</span><br />
<span class="co1">//log error and alert user that their event was not saved</span><br />
<span class="kw3">trace</span><span class="br0">&#40;</span>fault.<span class="me1">fault</span>.<span class="me1">faultString</span><span class="br0">&#41;</span>;<br />
<span class="kw2">var</span> alert:Alert = Alert.<span class="kw3">show</span><span class="br0">&#40;</span><span class="st0">&quot;The server encountered an error while saving your request&quot;</span>,<span class="st0">&quot;Fault&quot;</span><span class="br0">&#41;</span><br />
<span class="br0">&#125;</span></div>
</div>
<p>Using C# to write our web service we can leverage the XMLDataSet, and DataSet classes to manipulate  the calendar event data and save it to the Calendar database.</p>
<p>The C# is pretty straight forward- convert a string to an XMLDataSet and load a DataSet with the contents or &#8220;rows&#8221; of the XMLDataSet.  Once that is completed, call a stored procedure (or write the SQL in-line) to save the event to the database using the familiar DataSet access syntax to extract the values needed for the insertion.</p>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;"><span class="br0">&#91;</span>WebMethod<span class="br0">&#93;</span><br />
public <span class="kw4">void</span> CreateCalendarEvent<span class="br0">&#40;</span><span class="kw4">string</span> eventXML<span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
try<br />
<span class="br0">&#123;</span><br />
<span class="co1">//sql connection and commands</span><br />
SqlConnection conn = new SqlConnection<span class="br0">&#40;</span>WebConfigurationManager.<span class="me1">ConnectionStrings</span><span class="br0">&#91;</span><span class="st0">&quot;FOO&quot;</span><span class="br0">&#93;</span>.<span class="me1">ConnectionString</span><span class="br0">&#41;</span>;<br />
SqlCommand cmd = new SqlCommand<span class="br0">&#40;</span><span class="st0">&quot;spCreateCalendarEvent&quot;</span>,conn<span class="br0">&#41;</span>;<br />
<span class="co1">//set up the dataset that will feed the sql parameters</span><br />
DataSet ds = <span class="kw2">null</span>;<br />
XmlDataDocument eventDataDoc = new XmlDataDocument<span class="br0">&#40;</span><span class="br0">&#41;</span>;</p>
<p><span class="co1">//get the data into the XmlDataDocument</span><br />
<span class="kw1">if</span> <span class="br0">&#40;</span>eventXML != <span class="kw2">null</span><span class="br0">&#41;</span><br />
eventDataDoc.<span class="me1">DataSet</span>.<span class="me1">ReadXml</span><span class="br0">&#40;</span>new StringReader<span class="br0">&#40;</span>eventXML<span class="br0">&#41;</span><span class="br0">&#41;</span>;</p>
<p>ds = eventDataDoc.<span class="me1">DataSet</span>;</p>
<p><span class="co1">//this is the &quot;row&quot; that contains the event data we need to insert</span><br />
<span class="co1">//the calendar event into the database</span></p>
<p>DataRow dr = ds.<span class="me1">Tables</span><span class="br0">&#91;</span><span class="st0">&quot;CalendarEvent&quot;</span><span class="br0">&#93;</span>.<span class="me1">Rows</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span>;</p>
<p><span class="co1">//assign the parameters for the stored procedure call</span><br />
cmd.<span class="me1">Parameters</span>.<span class="me1">Add</span><span class="br0">&#40;</span><span class="st0">&quot;@startDate&quot;</span>, SqlDbType.<span class="me1">DateTime</span><span class="br0">&#41;</span>;<br />
cmd.<span class="me1">Parameters</span>.<span class="me1">Add</span><span class="br0">&#40;</span><span class="st0">&quot;@endDate&quot;</span>, SqlDbType.<span class="me1">DateTime</span><span class="br0">&#41;</span>;<br />
cmd.<span class="me1">Parameters</span>.<span class="me1">Add</span><span class="br0">&#40;</span><span class="st0">&quot;@startTime&quot;</span>, SqlDbType.<span class="me1">DateTime</span><span class="br0">&#41;</span>;<br />
cmd.<span class="me1">Parameters</span>.<span class="me1">Add</span><span class="br0">&#40;</span><span class="st0">&quot;@endTime&quot;</span>, SqlDbType.<span class="me1">DateTime</span><span class="br0">&#41;</span>;<br />
cmd.<span class="me1">Parameters</span>.<span class="me1">Add</span><span class="br0">&#40;</span><span class="st0">&quot;@createdByName&quot;</span>, SqlDbType.<span class="me1">VarChar</span>, <span class="nu0">50</span><span class="br0">&#41;</span>;<br />
cmd.<span class="me1">Parameters</span>.<span class="me1">Add</span><span class="br0">&#40;</span><span class="st0">&quot;@createdBySID&quot;</span>, SqlDbType.<span class="me1">VarChar</span>, <span class="nu0">47</span><span class="br0">&#41;</span>;</p>
<p><span class="co1">//now set the values for these parameters, converting strings back to dates</span><br />
cmd.<span class="me1">Parameters</span><span class="br0">&#91;</span><span class="st0">&quot;@startDate&quot;</span><span class="br0">&#93;</span>.<span class="me1">Value</span> = DateTime.<span class="me1">Parse</span><span class="br0">&#40;</span>dr<span class="br0">&#91;</span><span class="st0">&quot;startDate&quot;</span><span class="br0">&#93;</span>.<span class="me1">ToString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
cmd.<span class="me1">Parameters</span><span class="br0">&#91;</span><span class="st0">&quot;@endDate&quot;</span><span class="br0">&#93;</span>.<span class="me1">Value</span> = DateTime.<span class="me1">Parse</span><span class="br0">&#40;</span>dr<span class="br0">&#91;</span><span class="st0">&quot;endDate&quot;</span><span class="br0">&#93;</span>.<span class="me1">ToString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
cmd.<span class="me1">Parameters</span><span class="br0">&#91;</span><span class="st0">&quot;@startTime&quot;</span><span class="br0">&#93;</span>.<span class="me1">Value</span> = DateTime.<span class="me1">Parse</span><span class="br0">&#40;</span>dr<span class="br0">&#91;</span><span class="st0">&quot;startTime&quot;</span><span class="br0">&#93;</span>.<span class="me1">ToString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
cmd.<span class="me1">Parameters</span><span class="br0">&#91;</span><span class="st0">&quot;@endTime&quot;</span><span class="br0">&#93;</span>.<span class="me1">Value</span> = DateTime.<span class="me1">Parse</span><span class="br0">&#40;</span>dr<span class="br0">&#91;</span><span class="st0">&quot;endTime&quot;</span><span class="br0">&#93;</span>.<span class="me1">ToString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
cmd.<span class="me1">Parameters</span><span class="br0">&#91;</span><span class="st0">&quot;@createdByName&quot;</span><span class="br0">&#93;</span>.<span class="me1">Value</span> = HttpContext.<span class="me1">Current</span>.<span class="me1">Request</span>.<span class="me1">LogonUserIdentity</span>;<br />
cmd.<span class="me1">Parameters</span><span class="br0">&#91;</span><span class="st0">&quot;@createdBySID&quot;</span><span class="br0">&#93;</span>.<span class="me1">Value</span> = HttpContext.<span class="me1">Current</span>.<span class="me1">Request</span>.<span class="me1">LogonUserIdentity</span>.<span class="me1">Owner</span>;</p>
<p><span class="co1">//now execute the stored procedure</span><br />
conn.<span class="me1">Open</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
cmd.<span class="me1">ExecuteNonQuery</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
conn.<span class="me1">Close</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span><br />
catch<span class="br0">&#40;</span>Exception ex<span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
Console.<span class="me1">Writeline</span><span class="br0">&#40;</span>ex.<span class="me1">message</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span><br />
<span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.binarygiant.com/blog/?feed=rss2&amp;p=7</wfw:commentRss>
		</item>
		<item>
		<title>Gracefully Handle WSDL Faults in Flex Using Web Services</title>
		<link>http://www.binarygiant.com/blog/?p=6</link>
		<comments>http://www.binarygiant.com/blog/?p=6#comments</comments>
		<pubDate>Sun, 02 Mar 2008 23:41:30 +0000</pubDate>
		<dc:creator>Lance Sims</dc:creator>
		
		<category><![CDATA[.NET]]></category>

		<category><![CDATA[Flex]]></category>

		<category><![CDATA[Web Services]]></category>

		<guid isPermaLink="false">http://www.binarygiant.com/blog/?p=6</guid>
		<description><![CDATA[I recently came across this problem with an app I am writing at work using ASP.NET web services.  There are certain scenarios where the application I am working needs to use a different URL to get to a web service (primarily a development URL vs a production URL).
Several times I inadvertently pointed my web [...]]]></description>
			<content:encoded><![CDATA[<p>I recently came across this problem with an app I am writing at work using ASP.NET web services.  There are certain scenarios where the application I am working needs to use a different URL to get to a web service (primarily a development URL vs a production URL).</p>
<p>Several times I inadvertently pointed my web services to the wrong URL and would get an HTTP Request Error when the Flex Web Service could not load the WSDL.</p>
<p>This got me to thinking about a an elegant way to handle instances where a web server might be down, or a particular web service may be unavailable, for whatever reason.  I wanted to let users know that the Flex application is unable to communicate with the web server, and in most cases, basically disable the application, because let&#8217;s face it, an application is useless without data.</p>
<p>Most examples of Flex web services, particularly .NET web services being consumed by Flex demonstrate a web service declared using MXML and the URL to the WSDL hard coded into the WSDL property of that web service tag.  Examples of declaring web services with ActionScript proved to be similar.  The WSDL property is hard coded at the declaration of the web service object.</p>
<p>For example, most code snippets used to demonstrate using a web service would look somthing like the following</p>
<p>&lt;mx:WebService id=&#8221;myWebService&#8221; wsdl=&#8221;http://fooserver/somedirector/foo.asxm?wsdl&#8221; showBusyCursor=&#8221;true&#8221;/&gt;</p>
<p>What happens is that the Flex tries to load the WSDL for the web service when the application hits that WebService declaration, and if there is an HTTP Request error, Flex doesn&#8217;t handle it very gracefully, and for good reason.</p>
<p>It&#8217;s our job as developers to determine how we want to handle such exception.  In this particular instance, I want my application to bascially lock itself, so I&#8217;ll display a modal PopUp with no close button or something like that, if an HTTP Request error is dispatched by Flex.</p>
<p>So to do this, I declared the web service, in  ActionScript, but I could have just as easily used the &lt;mx:WebService /&gt; tag.  And I did not supply the wsdl property in the declaration, instead in an init() method I called the the loadWSDL() method of that WebService object at run time.  Adding an event listener for the FaultEvent event that will inevitably be dispatched if the Flex WebService encounters any issues in loading the WSDL.</p>
<p>In the FaultEvent event handler, I inspect the <font color="#0000ff">FaultEvent.fault.faultCode</font>, <font color="#0000ff">FaultEvent.fault.faultDetail</font>, and <font color="#0000ff">FaultEvent.faultString</font> properties.  If any one of these properties of the FaultEvent object for my WebService tell me that there was an error loading the WSDL, etc.  I lock the application down and tell the user to politely contact the sys admin for further support.  If this were an AIR application, I could use the filesystem to write this fault to an event log, etc.</p>
<p>The code is pretty simple:</p>
<div class="codesnip-container" ><font color="#0000ff"> import</font> mx.rpc.soap.WebService;<br />
<font color="#0000ff"> import</font> mx.rpc.events.FaultEvent;<br />
<font color="#0000ff"> import</font> mx.controls.Alert;<br />
<font color="#0000ff"> private</font> var fooWS:WebService = new WebService();<br />
<font color="#0000ff"> private</font> <font color="#00ccff">var</font> fooWSDL:String = &#8220;http://localhost:2251/foo.asmx?wsdl&#8221;;</div>
<p><font color="#339966">
<div class="codesnip-container" >/*in the init method register an event listener for the FaultEvent, and attempt to load the WSDL for the web service with the loadWSDL() method*/</div>
<p></font></p>
<div class="codesnip-container" ><font color="#0000ff">private</font> <font color="#339966">function</font> init():<font color="#0000ff">void</font><br />
{<br />
fooWS.addEventListener(FaultEvent.FAULT,onWSDLFault);<br />
fooWS.loadWSDL(fooWSDL);<br />
}</div>
<p><font color="#339966">
<div class="codesnip-container" >/*the event handler for the FaultEvent inspects the FaultEvent object&#8217;s fault.faultDetails fault.faultString and the fault.faultCode to see if it was an HTTP request error */</div>
<p></font></p>
<div class="codesnip-container" ><font color="#0000ff">private</font> function onWSDLFault(fault:FaultEvent):<font color="#0000ff">void</font><br />
{<br />
<font color="#339966">/*if the fault detail is that we were unable to load the wsdl,  then we know   that there is a problem communiating with the server*/</font><br />
if(fault.fault.faultDetail.toLowerCase() == &#8220;<font color="#800000">unable to load  wsdl</font>&#8221;<br />
|| fault.fault.faultString.toLowerCase() == &#8220;<font color="#800000">http requrest  error</font>&#8221;<br />
|| fault.fault.faultCode.toLowerCase() == &#8220;<font color="#800000">server.error.request</font>&#8220;)<br />
{<br />
<font color="#00ccff">var</font> alert:Alert = Alert.show(&#8221;<font color="#800000">The application is unable to communicate with   the web server, please try again.  If you continue to experience this   problem</font>, &#8221; +<br />
&#8220;<font color="#800000">please contact your system administrator</font>&#8220;);<br />
}<br />
fooWS.removeEventListener(FaultEvent.FAULT,onWSDLFault);<br />
}</div>
<p>This code works just as well if you wanted to use a &lt;mx:WebService/&gt; tag.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.binarygiant.com/blog/?feed=rss2&amp;p=6</wfw:commentRss>
		</item>
		<item>
		<title>Eclipse Cairngorm Plugin Update</title>
		<link>http://www.binarygiant.com/blog/?p=5</link>
		<comments>http://www.binarygiant.com/blog/?p=5#comments</comments>
		<pubDate>Fri, 16 Nov 2007 23:05:02 +0000</pubDate>
		<dc:creator>Lance Sims</dc:creator>
		
		<category><![CDATA[Cairngorm]]></category>

		<guid isPermaLink="false">http://www.binarygiant.com/blog/?p=5</guid>
		<description><![CDATA[I just ran across a post on Eric Feminella&#8217;s blog.  He is the architect of the Cairngen plugin for Flex- he will be releasing an update to the plugin first-thing next week.  Check out his post at http://www.ericfeminella.com/blog/2007/01/04/introducing-cairngen/
Thanks, Eric
]]></description>
			<content:encoded><![CDATA[<p>I just ran across a post on Eric Feminella&#8217;s blog.  He is the architect of the Cairngen plugin for Flex- he will be releasing an update to the plugin first-thing next week.  Check out his post at <a href="http://www.ericfeminella.com/blog/2007/01/04/introducing-cairngen/" rel="nofollow">http://www.ericfeminella.com/blog/2007/01/04/introducing-cairngen/</a></p>
<p>Thanks, Eric</p>
]]></content:encoded>
			<wfw:commentRss>http://www.binarygiant.com/blog/?feed=rss2&amp;p=5</wfw:commentRss>
		</item>
	</channel>
</rss>
