Duplex sample updated to Silverlight 4

I was following this thread on the Silverlight forums and was asked to update the Duplex sample to Silverlight 4.

Click here to download the code.

More information about Duplex Services are available here:

Happy Silverlighting!

Silverlight 4, MEF and MVVM: loading different “MEF Modules” in the same Container

Today I’ve finally found some time to make modifications in the “MEF MVVM” project on Codeplex in order to:

  • create a new module using WCF RIA Services and dynamically load this it inside the “MEF module container” described in the previous post;
  • use the INavigationContentLoader interface and MEF Metadata to share the same container for the various “MEF Modules”;
  • use the new Cosmopolitan theme available for Silverlight Navigation applications;
  • refactor the code of the ViewModel base class using the one available in the latest Prism drops;
  • refactor unit tests inserting an apposite Mock service.

MEFMVVMRIA
The source code is available for download on Codeplex.

Happy Silverlighting!

Silverlight 3 Beta and Binary message encoding

Silverlight 3 Beta uses Binary message encoding as a default WCF binding option, this is also the methodology used in the “Silverlight-enabled WCF Service” item template of Visual Studio.

John Papa has posted a nice article explaining the advantages of this binding instead of the “usual” BasicHttpBinding used in Silverlight 2 (other details available here and here), what about the client side? How can I use this new Binding?

These are the steps required for explicitely specifying the new binding in the code:

  • add a “Service Reference” from Visual Studio;
  • initialize and call the service in this way
EndpointAddress address = new EndpointAddress("<Your Service Uri Here>");

CustomBinding binding = new CustomBinding(
new BinaryMessageEncodingBindingElement(),
new HttpTransportBindingElement());

YourServiceRef.ServiceClient svc = new YourServiceRef.ServiceClient(binding, address);

Download the Visual Studio 2008 solution (also tested on Visual Studio 2010 Beta 1:)

Silverlight 3 Duplex Wrap-up

I’ve already blogged about the new Silverlight 3 Beta Duplex support here. In these days I’ve found some interesting articles and tips about this topic, so this is a list of links I’ve found useful:

Silverlight 3 Beta Duplex support

I’m testing the updated Duplex support available in Silverlight 3 Beta, the important news is the possibility to simplify and reduce the code in the client:

  • now it’s possible to use the “Add Service Reference” functionality of Visual Studio to consume the service;
  • in this way you the use of channels can be avoided by simply attaching a callback to an event.

I’ve prepared an example based on the material available on the official documentation, download the complete solution from here.

Silverlight, SOAP Headers, WCF and asmx services

As reported by the Web Services Team, Silverlight 2 supports custom SOAP headers.

A good working example can be found here, but it only uses WCF services, what about the “old” asmx ones?

I’ve modified the “SilverlightHeaders” solution to use both WCF and asmx, using OperationContext in the first case and HttpContext in the last, click here to download the complete solution.

WCF DataContract Serializer and IsReference property

One of the new features of .NET framework 3.5 SP1 is the possibility to serialize an object graph with circular references by using the standard xsd:ID/xsd:IDREF attributes.

Just mark your DataContract attribute with the IsReference=true property: