• Silverlight.FX
    Silverlight.FX is a light-weight application framework for building RichInternet Applications with Silverlight 2.
  • Silverlight3 Out-of-Browser Apps vs. Live Framework Mesh-Enabled Web Applications
  • .NET RIAServices - Building Data-Driven Applications with Microsoft Silverlight andMicrosoft ASP.NET
  • Securing Silverlight Application and WCF Service using ASP.Net Authentication Techniques
  • Model– View – ViewModel in Silverlight
Skip Navigation LinksHome / Articles / View Article

MIX08: Working with Data and Web Services in Microsoft Silverlight 2

+ Add to SilverlightShow Favorites
0 comments   /   aggregated from Laurent Bugnion (GalaSoft) on Mar 05, 2008  /  original article
(0 votes)
Categories: Misc

Pretty full room. Sorry VERY full room. Glad I cam not too late, even managed to find a plug for my laptop.

  • Any application will need to communicate wit a source of data outside of the browser
  • Product catalog, product database, etc...
  • What kind of data?
    • media (images, sounds, videos)
    • feeds
    • specific services for your app
    • Existing Intranet services
    • public internet services
  • Silverlight 1.0 connects to Media already
    • to connect to other services, use JavaScript and AJAX
  • In Silverlight 2, managed code to communicate with all kind of services
  • Demo: Use WCF for server-side service
    • Select generic WCF service (specific templates for WCF-based Silverlight will be available later)
    • Create service class with "Contract" attributes, "DataMember" attributes
    • To make a generic WCF service compatible with SL, change the binding to "BasicHttpBinding"
    • In Silverlight, add Service Reference.
    • Then can use methods of the service in Silverlight code.
    • Synchronous calls to WCF service impossible.

I don't quite get that part. Why not support synchrnous calls too, since Silverlight supports multithreading? Will try to ask a question later

  • And now we will learn how to databind. ItemsControls are now supported in Silverlight 2, cool! Dr WPF is going to be delighted :)
  • DataBinding is now exactly same as WPF. Cool!!


  • Create service using "Silverlight-Enabled WCF service (not in the beta yet, so need to tweak the generic WCF service).
  • Define contract.
  • Client, add reference to service and use proxy.


  • Thinking of supporting XAML-only binding to WCF services, for example

Breaking changes:

  • Web references is not there anymore, it'snow "Add service reference"

FYI: Data format is now SOAP and not JSON

Secure services:

  • Silverlight uses credentials stored on the browser, for example after an ASP.NET login.
  • For WCF to get user identity, ASP.NET compat mode must be turned on.

What about other service types:

  • Using "Add service reference" (but only for self-describing services, for example WSDL).
    • Example for Live Search API
    • Works with any SOAP 1.1 basic profile compatible service
    • Server-side doesn't matter
    • Future: Talk to SQL Astoria based services.
    • Cross domain is still an issue!!
    • Except is target opts in accepting cross domain calls. (so that's how they chose to solve that issue, then...)
    • SL looks for policy files: clientaccesspolicy.xml or crossdomain.xml.Specifies what is allowed and what not (subdomain paths, etc...)
      • Already used by Flick2, Yahoo, etc...
  • Write the code manually
    • Using XML, for example with XmlSerializer or LINQ to XML. Then, databind to the result.
  • Use built-in classes (RSS/Atom feeds)

The good news is that the code is standard .NET code. Only Silverlight specific parts are about the request (URI, etc...)

Allowed URLS.

  • HTTP and HTTPS (though with a few restrictions in Beta1)
  • Cross domain rule (must have policy file is not local)
  • No FTP or FILE URLs
  • Socket support! But only with originating server in Beta1, with some port restrictions

HTTP requests:

  • Using WebClient class (simple but limited functionality)
  • Using HttpWebRequest (advanced)
  • Supported features equivalent to Flash
    • GET and POST only
    • Setting header only for same domain GET requests
    • Response: Can read only content type
    • Response code: Only success or fail (403, 404...), no message body
    • Cannot override the browser
      • Can't control or turn off cache
      • Can't control HTTP authentication credentials
      • Can't read/write cookies
  • Solution: Use proxy...


  • Not really a reason to use it in SL except if a service is already existing

Note: Maybe in the future support for binary XML


  • Pre-built types SyndicationFeed class
  • Syndication restrictions same as in "standard" .NET 3.5



Comments RSS RSS
No comments

Add Comment