Communication between Silverlight-based local applications

Source: Internet
Author: User
Tags silverlight

With local messaging, you can create a communication channel between multiple Silverlight Plug-ins running on a single computer. You typically host these plug-ins in a single Web page and use local messaging to coordinate their behavior. This allows you to create complex layouts that combine multiple Silverlight-based applications with content based on other technologies.

For example, suppose you want to provide a Silverlight based navigation system for an html-based Web site. You can use Silverlight to create menu bars and sidebar, and use local messaging to keep their state synchronized. Another scenario is to create a Silverlight-based banner ad with animation effects across sidebar ads, and use local messaging to coordinate transitions. You can also use local messaging to establish communications between a Silverlight-based application in a Web page and other applications running outside the browser.

Configuring local message sinks and senders

To establish a local messaging channel, create a Localmessagereceiver object in one application and create the corresponding Localmessagesender object in another application. The transmitter always sends the first message, but the receiver may respond and implement bidirectional communication. You can also create both the transmitter and receiver objects in two applications so that one of them can send the first message.

When you create a sink, you must give it either a unique name in the global scope or a unique name within the host domain of the receiving application. If you specify only a name, the scope is limited to the domain by default. When you create a transmitter, you must identify the appropriate sink. If you specify only a name, the transmitter will assume that the receiver is hosted in the same domain and is using a domain-wide name.

The name range ensures that the receiver will receive only the messages it expects. If you do not want to limit your application to a specific domain, you can use a global scope. However, doing so increases the likelihood of name collisions unless you choose a name that may be unique. If you are familiar with all Silverlight-based applications that are hosted in a domain, domain scope allows you to choose a simpler receiver name.

The following code example demonstrates a basic configuration in which both the receiving application and the sending application are hosted in the same domain.

Vb

' In the receiving application:
Dim messageReceiver As New LocalMessageReceiver("receiver")

' In the sending application:
Dim messageSender As New LocalMessageSender("receiver")

You can create multiple sinks and transmitter objects. Each receiver can receive messages from any number of senders. However, each transmitter can only send messages to the receiver identified in its constructor. In addition, you can configure the receiver to receive only messages from the specified sender domain, or to receive messages from any domain.

The following example shows a more complex configuration in which both the receiving application and the sending application can be hosted in the same domain or in a different domain.

Vb

' In the receiving application:
Dim messageReceiver As New LocalMessageReceiver("receiver", _
     ReceiverNameScope.Global, LocalMessageReceiver.AnyDomain)
' In the sending application:
Dim messageSender As New LocalMessageSender( _
     "receiver", LocalMessageSender.Global)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.