Communication Between Local Silverlight Applications using LocalMessageSender and LocalMessageReceiver


This makes it extremely easy to communicate between two different Silverlight applications. Granted, you could communicate between Silverlight instances before, but you had to use Javascript as a go-between. Now, it is much, much simpler, and as an added bonus, Silverlight apps can communicate from different browser pages! An app loaded in one browser tab can (with the right permissions) communicate to one on a different tab.

We have 2 examples here.

image

  • The 1st example – A Silverlight app which has a table of employees. This Table View communicates back and forth with another Detail View Silverlight App. When you select an employee in the Table View, it populates the Detail View. In the Detail View, you can edit the employee and save it, or you can "add as new" which will communicates back to the Table View add a new employee to the table. This sample use a JSON Serializer (DataContractJsonSerializer) to serialize/deserialize the business object and use that as a payload for communication.
  • Local Connections (2)

  • The 2nd example is an old MFC Scribble like Silverlight Application. You can start each page in a different browser instance and draw in the sender and see your strokes duplicated in the receiver. The screen shot below was taken with the sender running in IE, and the receiver running in Firefox–two different browsers and two different processes.

The keys here are the LocalMessageReceiver and the LocalMessageSender. As you might guess, the receiver listens for messages, and the sender sends messages. If you want your Silverlight application to receive messages, you need to create a LocalMessageReceiver with some name, and tell the receiver to listen.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s