Silverlight 3 Out of Browser and Data Services
The other night I was in the process of getting a rather large application converted to run as an out of browser application with Silverlight 3 and I hit a problem I wanted to share. I figured if I hit it someone else would and would be great to save you some time.
The application uses ADO.NET Data Services to do some queries for lookup values and other application data. After a few tweaks for minor things to get it to run on Silverlight 3 I was off and running trying to get it to work out of the browser (OOB). After doing the typical stuff like looking for any HtmlPage.* calls and making sure they only happen if HtmlPage.IsEnabled is true I was able to get the application up and running. In case your not familar with HtmlPage.IsEnabled it allows you to check if the Html Bridge is active and you can work with the HtmlPage elements. When an application runs OOB you can’t make calls to HtmlPage.* methods without getting a Html/Dom is disabled unhandled exception being thrown. So by wrapping any calls to HtmlPage with checks to see if the Html Bridge is enabled you can avoid that error when running OOB.
Ok, now back to the ADO.NET Data Services error – all was going well the application was starting up OOB. Just when I thought things were going well I got a weird error on a Data Services calling “CreateNativeRequest”
Looking at the stack trace of the error showed this:
at System.Data.Services.Http.ScriptXmlHttpRequest.CreateNativeRequest() at System.Data.Services.Http.ScriptXmlHttpRequest..ctor() at System.Data.Services.Http.HttpWebRequest.InvokeRequest() at System.Data.Services.Http.HttpWebRequest.BeginGetResponse(AsyncCallback callback, Object state) at System.Data.Services.Client.QueryAsyncResult.BeginExecute() at System.Data.Services.Client.DataServiceRequest.BeginExecute(Object source, DataServiceContext context, AsyncCallback callback, Object state) at System.Data.Services.Client.DataServiceQuery`1.BeginExecute
I thought maybe it was because I was using a absolute Uri to talk to the host so I gave a relative URL a try in a test application and got the following error:
at System.Windows.Browser.HtmlPage.VerifyThreadAndEnabled() at System.Windows.Browser.HtmlPage.get_Document()
at System.Data.Services.Client.DataServiceContext..ctor(Uri serviceRoot)
at TestSL3DSOOB.PersonDS.MyContext..ctor(Uri serviceRoot)
at TestSL3DSOOB.MainPage..ctor()
So you probably noticed the call to HtmlPage.get_Document above and can probably infer from that that it must be doing some HtmlPage.* calls which as we discussed earlier aren’t compatible with running Silverlight 3 OOB.
So at least for the beta, I’m going to have to wait to see if this gets fixed when Silverlight 3 releases but for now hopefully knowing about the issue will save you a few hours of head bashing! That said, if you haven’t tried building a Silverlight 3 OOB application give it a try – I run a twitter client OOB and the funny thing is I still once and a while start looking for the browser address bar to type in a URL!
Speaking of Twitter – if your on Twitter add me to your list – http://Twitter.com/DavidYack
References (1)
-
Response: dantel oya modelleridantel ve dantel oya modelleri sitesi
Reader Comments (2)
Yes this is true, I certify that this happens.
Hi David,
My name is Phani and I work on the ADO.NET Data Services team. Starting with this release of ADO.NET Data Services v1.5 CTP2, our Silverlight client library supports Cross-domain and Out Of Browser network access . Please try this out and give us your feedback.
http://blogs.msdn.com/astoriateam/archive/2009/08/31/ado-net-data-services-v1-5-ctp2-now-available-for-download.aspx