Silverlight 2.0 data and web services explained
Mashups and large downloads challenge
Mix 08 Microsoft Silverlight team member Eugene Osovetsky has explained to a packed Mix 08 session how Silverlight 2.0, released as beta on Wednesday, interacts with external data and web services.
No surprise: the first thing we saw was based on the Windows Communication Foundation (WCF), Microsoft's universal .NET web services API.
Presuming you use ASP.NET and Visual Studio, this involves creating a WCF service by marking up .NET code with attributes such as ServiceContract and DataContract, then consuming the service in a Silverlight application by adding a Service Reference and coding against it. Silverlight requires AJAX-style asynchronous calls to a proxy class, with the results processed in a callback event handler. Silverlight has rich bindable data controls including a listbox and a datagrid.
That's all well and good, but not everyone wants or can use end-to-end .NET. Fortunately Silverlight also supports standard SOAP by importing a WSDL, or generic web services using XML or JSON, though a little more code is needed. Once again, the Silverlight code involves asynchronous calls, this time using a generic WebClient class that will already be familiar to .NET programmers.
There are complications with REST, though. The problem is that Silverlight, like Adobe Systems' Flash, does not have its own networking stack but relies on the browser's plug-in API. This gets you benefits like sharing the browser's authenticated connections, but also brings limitations.
Apparently it is simply not possible to use HTTP PUT or DELETE methods, a problem that leads to hacks like HTTP POSTs that delete data, breaking the HTTP specification. This is not the fault of Silverlight, but it is unfortunate. For similar reasons, there is no access to SOAP fault messages.
There is also a big issue with cross-domain data sources, which poses a problem for mash ups. Cross-domain access is prevented by default for security reasons. Otherwise, a bad Silverlight application might hijack an existing authenticated connection to some other site.
Cross-domain data is the essence of mash ups, though. The solution with Silverlight is that services can opt in to being called cross domain by including a policy file. Silverlight has its own, or will observe a Flash policy file. Therefore, public services that work with Flash should also work with Silverlight. Cross-domain access over SSL is promised, but not supported in the current beta.
This puts Silverlight at a disadvantage to Flash for downloading large amounts of data, since Flash can use Adobe's efficient ActionScript Message Format. In mitigation, Silverlight is inherently flexible and there is plenty of scope for custom solutions.®
Sponsored: Customer Identity and Access Management