WCF Sessions with Silverlight and Flex

I wanted to adapt my Silverlight CRUD sample (which I also ported to Adobe Flex) to fix a glaring weakness, which is that any user can amend any entry.

I decided to add some logic that allows editing or deleting of only those rows created during the current session. The idea is that a user can amend the entry just made, but not touch any of the others.

WCF has its own session management but this is not supported by the BasicHttpBinding which is required by Silverlight.

Fortunately you can use ASP.NET sessions instead. This means setting your WCF web service for ASP.NET compatibility:

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]

Then you can write code using the HttpContext.Current.Session object.

This depends on cookies being enabled on the client. In my simple case it worked fine, in both Silverlight and Flex. In a real app you would probably want to use HTTPS.

I’d post the sample but unfortunately my Windows web space doesn’t support WCF.

Technorati tags: , , ,