Using WebOrb as a Web Service Proxy when CrossDomain.xml is not available
So you have the CrossDomain.xml blues. I had the same issue and I need to grab an RSS Feed to display in my Flex App.
A simple demonstration can be seen here http://gregjessup.net/marketevents/
The Latest Market News is actually an RSS request from yahoo finance top stories, which would return XML but when done directly using HTTPService (seen below)…
<mx:HTTPService result="gotData(event)" showBusyCursor="true" id="RSSfeed"
url="http://finance.yahoo.com/rss/topstories" resultFormat="object" />
you’d get the god forsaken Security Sandbox Error because the request is not trusted by finance.yahoo.com … ( see for yourself http://finance.yahoo.com/crossdomain.xml )
So the fix is to use a proxy. I’ve seen some stuff out on the net that allows you to do it with PHP, but I am a WebOrb fanatic, and it allows me to stick with C#, and not have to worry about another environment. To be honest, once you learn WebOrb…you’ll never look back.
So the solution is quite simple and you can download the
You’ll see in my WebFetch class, I am just passing a URL and it returns the HTML or XML as a string. That like the rest of the code is very straight forward…but I’m not going to go into much detail here.
In the MarketEvents.cs file you’ll see getNews() and getNewsDataSet()
I would recommend getNewsDataSet() simply because it parse the XML into an object in your Middle Tier, and thus is leaves doing much less work on the FLEX client side.
public DataSet getNewsDataSet()
{
//create a new DataSet that will hold our values
DataSet rssDataSet = null;
WebFetch.WebFetch wf = new WebFetch.WebFetch();
string xmlString = wf.getWebPage("http://finance.yahoo.com/rss/topstories");
//check if the xmlString is not blank
if (String.IsNullOrEmpty(xmlString))
{
//stop the processing
return rssDataSet;
}
try
{
using (StringReader stringReader = new StringReader(xmlString))
{
rssDataSet = new DataSet();
rssDataSet.ReadXml(stringReader);
}
}
catch
{
rssDataSet = null;
}
return rssDataSet;
}
Using getNewDataSet() the Flex side is easy just set your datagrid.dataprovider = e.result.item
If you prefer to return a string and then work on the XML on the FLEX side…I’ll give you both the C# and the FLEX code….
C# Code
public string getNews()
{
WebFetch.WebFetch wf = new WebFetch.WebFetch();
return wf.getWebPage("http://finance.yahoo.com/rss/topstories");
}
FLEX Code (I’m assuming you know how to call a remote object from Flex so this is what happens when you get the result back)
private function gotNews (e:ResultEvent) : void {
RSS = new ArrayCollection();
var xml:XML = new XML(e.result);
var obj:Object = xmlToObject(xml);
entries.dataProvider=obj.rss.channel.item; //where entries is my datagrid
}
private function xmlToObject(value:XML):Object {
var xmlStr:String = value.toXMLString();
var xmlDoc:XMLDocument = new XMLDocument(xmlStr);
var decoder:SimpleXMLDecoder = new SimpleXMLDecoder(true);
var resultObj:Object = decoder.decodeXML(xmlDoc);
return resultObj;
}



