Web Development Adventures in a .NET world

By Ola Karlsson
Simultaneously calling multiple methods on a WCF service from silverlight

A while back I had to debug some performance issues in an existing Silverlight app, as the problem / solution was a bit obscure and finding info about it was quite tricky, I thought I’d share, maybe it can help the next person with this problem.

The App

On start, the app would do a number of calls to different methods on a WCF service, this to populate the UI with the necessary data. Recently one of those services had been changed and was now taking quite a bit longer than it used to. This was resulting in quite a long loading time for the whole UI, which was set up so it wouldn’t let the user interact with anything, until all the service calls had finished.

First I broke out the longer running service call from the others, then removed the constraint that it had to be loaded for the UI in general to become responsive. I also added a loading indicator just on that area of the UI, thinking that the main UI would load while this particular section could keep loading independently.

The Problem

However this is where things started to get a bit strange. I found that even after these changes, the main UI wouldn’t activate until the long running call returned. So now, I did what I should have done to start with, I got Fiddler out and had a look at what was really happening.

What I found was that, once the call to the long running service method was placed, all subsequent call were waiting for that one to return before executing.

LongRunningCall

Not having really worked with WCF previously or knowing much about it in general, I was stumped… I knew of the issues where Silverlight is restricted by the browsers networking features in regards to number of simultaneous connections etc. However that just didn’t seem to be the issue here, you can clearly see in Fiddler that there’s numerous calls, but they’re just not returning. I thought of the problem maybe being in the WCF service, but the calls were really not that complicated and surely the service should be able to handle a lot more than what I was throwing at it!

So I did what every developer does in this type of scenario, I hit the search engines. I did a whole bunch of searching on things like “multiple simultaneous WCF calls from Silverlight” and “Calling long running WCF services from Silverlight” etc. etc. This however, pretty much got me nowhere, I found a whole heap of resources on how to do WCF calls from Silverlight but most of them were very basic and of no use what so ever.

The fog is clearing

It wasn’t until I came across the term “ WCF blocking calls” and started incorporating that in my searches I started to get somewhere. Those searches quite quickly brought me to the following thread in the Silverlight forum “Long-running WCF call blocking subsequent calls” which discussed the exact problem I was facing and the best part, one of the guys there had the solution!

The short answer is in the forum post and the guys answering, has also done a more extensive blog post about it called “Silverlight, WCF, and ASP.Net Configuration Gotchas” which covers it very well. 

So come on what’s the solution?! I heard you ask, unless you’ve already gone to the links and looked it up ;)

The Solution

Well, it turns out that the issue is founded in a mix of Silverlight, Asp.Net and WCF, basically if you’re doing multiple calls to a single WCF web-service and you have Asp.Net session state enabled, the calls will be executed sequentially by the service, hence any long running calls will block subsequent ones. So why is Asp.Net session state effecting us, we’re working in Silverlight, right? We'll as mentioned earlier, by default Silverlight uses the browsers networking stack when doing service calls, hence to the WCF service, the call looks like it might as well be coming from a normal Asp.Net. To get around this, we look to a feature introduced in Silverlight 3, namely the Client HTTP Stack.

The Client HTTP Stack to the rescue

By using the following syntax (for example in our App.xaml.cs, Application_Startup method)

WebRequest.RegisterPrefix("http://", WebRequestCreator.ClientHttp);

we can set our Silverlight application to use the Client HTTP Stack, which incidentally solves our problem! By using Silverlights own networking stack, rather than that of the browser, we get around the Asp.Net - WCF session state issue.
The above code specifies that all calls to addresses starting with “http://” should go through the client stack, this can actually be set more granular and you can specify it to be used only for certain domains etc.

Summary

The actual solution is well covered in the forum and blog posts I link to above. This post is more about sharing my experience, hopefully helping to spread the word about this and maybe make it a bit easier for the next poor guy with this issue to find the solution.

Until next time,
Ola

New Silverlight 4 books

A while back I was contacted by a publishing company called PACKT Publishing, they were saying they had some new Silverlight books and were looking for reviewers.

To be honest, to start with I was a bit sceptic,  I’d never heard of PACKT publishing, so my first step was to look it up and make sure the message was even real. Having had a look at their site etc., it all seemed legit, and I decided to have a look at what they had to offer. Hey what can I say, who am I to pass up on some free Silverlight 4 books?! :)

The two new books they’ve released are “Microsoft Silverlight 4 Data and Services Cookbook” and “Microsoft Silverlight 4 Business Application Development : Beginner's Guide”.

So in the next few weeks I’ll be reading through these books and share my thoughts about them here.

IF you’re interested in checking out these books yourself, here’s some linked images the publishers provided.

Microsoft Silverlight 4 Data and Services Cookbook Microsoft Silerlight 4-PACKT-Business

Also you can download some sample chapters here:

Microsoft Silverlight 4 Business Application Development : Beginner's Guide :
Chapter 1 – Getting Started

Microsoft Silverlight 4 Data and Services Cookbook:
Chapter No.2 – An Introduction to Data Binding

Is it worth learning Silverlight and WCF RIA Services?

Tonight I came across this question on the QA site Stackoverflow, basically a person was asking if it was worth learning “Silverlight RIA” or if he should just learn “normal Silverlight”.

He had a background on VB6 and Winforms but had done some WPF. Also by the sound of it he works building intranet LOB applications as he was saying that the apps would run internally and that they were currently using Click Once.

Anyhow, my answer got a bit long and turned into something of a rant but I think it had some decent point making it worth to cross-post it here :-)

Start of Answer:
-------------------------------------------------------------------------------------------

Hi Jonathan,

To start with I'm wondering if there might be some confusion going on here.

There's actually no such thing as "Silverlight RIA", so lets clarify some concepts, RIA is commonly defined Rich Internet Applications, Silverlight is one of a number of technologies that can be used to build such applications.

However there's also the Microsoft technology WCF RIA Services, which is what I'm guessing you're referring to. WCF RIA Services were until recently known as .Net RIA Services.

WCF RIA Services (currently in Beta 2) has so far largely been targeted at Silverlight and is even hosted under the silverlight.net domain, which is probably where a lot of the confusion comes from.

However in theory it's not tied to Silverlight at all, and is just a technology on top WCF to provide easy data access for RIA type of applications, for a more technical overview have a look at this blogpost by Nikhil Kothari it was written back in March 2009 about .Net RIA Services, so it might be a little out of date but it will give you a good idea on what it's about.

After defining these terms, it's a bit tricky to answer your question "Is Silverlight RIA worth learning or should I stick to normal Silverlight?"

Silverlight is definitely worth learning, by the looks of things Microsoft is going to stick with it. The latest recommendation I heard from someone close to Microsoft,  was to go with Silverlight if you can for new LOB (Line Of Business) Apps, if there's something Silverlight can't do, then look to WPF.

Coming from a VB6/Winforms background there will be a bit of a learning curve, but if you've already done a couple WPF apps then you're on good way already.

Silverlight for LOB? Silverlight 3 started bringing in more features related to development of LOB, like for example support for WCF RIA Services. It looks like this is set to continue in Silverlight 4 (due out first half of 2010), with things like support for printing and COM for working with MS Office applications. There's also coming more and more pre-made controls from various 3rd party vendors for many of the standard LOB type of functionality.

So what about WCF RIA Services? It's definitely worth having a look at, it seems to be the preferred way of data access by Microsoft. It provides things like easy access to authentication and data validation. However saying that it's still in beta and there has been some voices raised against it, around the internet so it's probably worth doing some research, before going all in.

Finally, you say that you're applications will be accessed internally but that you don't want the hassle of locally installed software, Silverlight fits that perfectly, just roll out the small Silverlight plugin to your users machines and you're good to go. Any changes needed, just recompile your project and deploy your .xap file to the webserver and it will automatically get pushed out to the users next time they use the app.

Sorry for the somewhat long and rambling answer, I hope it's helped answer your questions :)

Cheers,
Ola

Resources for my SDDN presentation on Silverlight and IIS Smooth Streaming

I recently (25/11/2009) did a presentation on using Silverlight and IIS Media Services – Smooth Streaming, at the Perth SDDN November meeting

As promised, here’s the resources I mentioned in that presentation, apologies for the delay.

 

Can’t view pages from the Web Development Server (Cassini)

Are you all of the sudden getting “Internet Explorer cannot display the webpage” / “Address Not Found” when trying to run a web application from inside Visual Studio?

This caused me a fair bit of headache yesterday, so now that I found the solution, I figured I’d try to spread the word.

Basically what’s happened is that an update for “Windows Defender and Microsoft Forefront Client Security” in the form of a new signature file was released on the 9th of March (Signature versions 1.53.283.0). This update was to address possible scenarios where a machines host file might get changed by a trojan or the like. Unfortunately however this had the side effect on some systems that the localhost entry in the host file was removed or corrupted, leading to any attempt to got to http://localhost/[whatever] will fail.

The solution as outlined in the links below in further detail, is to re-add the localhost entry (127.0.0.1       localhost) to your host file (C:\Windows\System32\drivers\etc\hosts).

I appreciate that these things are important etc. but for [insert appropriately bad word here] sake Microsoft, if you push out potentially breaking changes let us know!

In my case what happened was that, as a good Windows user I have automatic updates turned on and I let the machine restart when it needs to etc. Yesterday, after I’d not used Visual studio on my laptop for a couple days,  all of the sudden while sitting on a bus trying to do some Silverligth stuff, I couldn’t display any html pages when running then from VS. After some attempts at working out what the heck was going on and being on a bus with no internet connection I had to give up and pack up my laptop. Later after 30 min of Googling I found these two post helping me work out what had happened.
ASP.NET Web Development Server Stops Working
Visual studio Development Server problem in Vista

So I guess Microsoft had let us know in the way that the “Visual Web Developer team” let us know on their blog but come on, this should have been more publically announced in some way, according to some of the comments there are people out there who have struggled for days with this issue. I’m not really sure how they should have done it and maybe I’m just irritated because I got stung, lesson learnt from this. Turn off the automatic update and apply updates manually, once you know what they’re doing!

Happy coding :)
Ola

The Alternative Podcast List

Earlier today I noticed a new post on Scott Hanselmans blog, where he lists potential technical podcasts for .Net developers and asks other to put up their lists.

Now, most of the ones on his list are pretty much the same as I subscribe to, but having quite an interest in non .Net web development and RIA etc. I do have a couple he’s not mentioning.

I figured I’ll just add the ones which are a bit different from the ones mentioned on Scots' list.

  • Pixel8ed http://getpixel8ed.com
    This is a podcast by Craig Shoemaker, who also does the Polymorphic podcast, where the Polymorphic podcast is aimed at general programming and .Net concepts. Pixel8ed is focused on UX and related ideas and areas.
  • RIA Weekly http://www.riaweekly.com/
    A podcast dedicated to news in the RIA space. Even though the podcast is sponsored by Adobe and one of the hosts is Ryan Stewart, a platform evangelist for Adobe, they do a pretty decent job of covering news across the board, not just Adobe specific things.
  • Boagworld http://www.boagworld.com/
    ”A podcast for those who design, develop or run websites”, a podcast mainly about web design but also covering thing like accessibility and web standards.
February Perth .Net UG Silverlight talk

Thursday last week I did a presentation on RIA and Silverlight for the Perth .Net Community of Practice and as promised here’s the links from the presentation.

Some great examples of how RIA can be used to enhance the user experience of a website.
http://silverlight.net/samples/sl2/silverlightairlines/run/default.html
http://maps.google.com
http://memorabilia.hardrock.com/

Where does the desktop end and where does the web start, RIA blurring the lines
https://www.photoshop.com/express/landing.html

RIA Benchmarking, Bubbelmark is an animation test to practically benchmark different RIA technologies against each other.
http://www.bubblemark.com

Shine Draw(http://www.shinedraw.com/) – Flash vs Silverlight repository, compares various animation effects implemented in Flash and Silverlight and lets the visitors vote which is better.

Thanks to everyone who came to the presentation, if you have any feedback or questions, don’t hesitate to drop me a line.

Cheers.

Blogging, Life and jQuery

Soooo, it’s been a bit quiet here lately, eh.

Well as per always, life got in the way. Between work, family and life in general, there just haven’t been much time for anything else. However as things are slowly calming down, I’m now hoping to get back into the swing of things with the blog!

The title says “Blogging, life and jQuery”, what’s that all about? Well firstly I thought I’d talk a bit about that changes I’m wanting to make to this blog. Then as part of of those changes, I’ll talk a bit about what’s been going on in my world in general.

Blogging

I’ve decided to try and make some changes to this blog. When I started  blogging, I tried to make my posts very focused, “professional” and tutorial like. However that style of posts require lots and lots of time and effort to produce. I would still like to post tutorials every now and then but they wont be very frequent.  
So instead to get some more life into the blog I’ll try to make more frequent posts reflecting what ever is on my mind at the time, a little bit like the later posts before “the big silence”.

Life

Well as a father of two, a three and half year old and a 6months old. I can tell you one thing for certain, the people who say that once you have one child, you might as well have two, because there’s not much difference in the effort involved looking after them, they’re lying! That said I wouldn’t change a thing!
However having a young family, means there’s not much time for extra curricular activities and take a way time for some sports activities to keep me at least reasonably fit, I’m afraid the old computing passion has had to go on the back burner to some extent.

jQuery

Ok time to get something web dev related in this post. I was recently fortunate enough, to be on a project which involved developing a product/plan recommendation engine/app, for one of our clients. The fortunate thing about this was that it was to be done all in jQuery.

Not having worked with jQuery before, it was quite a learning curve. However seeing as there’s been a alot of talk about jQuery lately with the announcement of it being endorsed by Microsoft and everything. I was looking forward to getting a chance to having a look at it.

Basically it took me and another developer a couple of weeks to get our heads around it but in the end we got the job done and it’s now up and running, you can check it out here: http://www.iinet.com.au/needhelp/

Silverlight

What about Silverlight? The blog has up until now been very focused on Silverlight, will this change? Not really, as I mentioned earlier I’m hoping to getting some more general content in here, but Silverlight is still very much one of my main interest when it comes to web development.

And that being the case I’m exited to announce that the Perth .Net User Groups’ February presentation will be on Silverlight 2 and it will be presented by no ne less then myself and Stephen Price. We’ve still not locked down 100%, what we’ll cover etc. but it should be a good evening. So if you’re in or around Perth make sure you come and check it out :)

Cheers,
Ola

Silverlight 2 RTW on Monday?

I just spotted this on Twitter and I must say this is looking good!

Basically Microsoft came out yesterday on their PressPass site, with a press release saying that there will be a teleconference on Monday (13 October) where ScottGu (Scott Guthrie) will make a "significant announcement related to Microsoft Silverlight".

I did some poking around on the internet and found one or two mentions of this, at ZDNet and on Kurt Brockett's blog but that was it, for some reason, maybe because it's weekend? This doesn't seem to have been covered much on other blogs, so I thought I'd spread the word :)

On Kurt's blog there are some comments discussing the possible release, and among others, there's a comment by Adam Kinney hinting that he's busy upgrading his Beta 2 projects for release. Someone else however is saying that Silverlight 2 won't be released on Monday, and that it will just be an announcement about the release date.

Either way, exiting stuff, bring on Monday!!

 

 

NFL Flash Player

As per my last post the US National Footaball League (NFL) have choosen to go with Adobe and Flash to provide online video and media content. A couple of people like Gilbert Corrales  and Ryan Stewart have already had a look at the look and feel of the player and some of it's features. Notable features include 5 concurrent feeds giving the possibility to swap between cameras etc. Unfortunately, just as with the NBC coverage of the Beijing Olympics using Silverlight, the content on the NFL site is US only. So unfortunately no NFL Flash goodness for the rest of us.

 

More Posts Next page »