This is a mirror of official site: http://jasper-net.blogspot.com/

Silverlight: Interprocess Communication from Silverlight Application

| Thursday, June 16, 2011
Summary: The article shows how to implement communication between Silverlight application and some non-Silverlight application by using Eneter.Messaging.Framework. The example shows Silverlight client invoking requests to the console application. The request can be paused, resumed or cancelled.

There are not many possibilities if you need to implement the communication between Silverlight application and some non-Silverlight application (e.g. standard desktop application).
Basically, you can choose sockets to implement your own communication based on TCP or you can choose WCF to communicate via remote calls.

Another option you can consider is to useEneter.Messaging.Framework. The framework enables you to implement the message based communication scenarios. E.g. Silverlight client can invoke a request and manipulate it with 'pause', 'resume' and 'cancel'. It means the request being processed in the console application can be paused, resumed or cancelled from Silverlight client.

The example below shows how to implement the Silverlight client invoking a request to the non-Silverlight application that can be 'paused', 'resumed' or 'cancelled'.

1. Create Server - Standard Console Application

Create standard console application in Visual Studio and add Eneter.Messaging.Framework.dll to references.
(Full, not limited and for non-commercial usage free version of the framework can be downloaded from www.eneter.net.)

Implement the main method in the following way:

using Eneter.Messaging.MessagingSystems.MessagingSystemBase;

using Eneter.Messaging.MessagingSystems.TcpMessagingSystem;

namespace TcpCommandServer
{
    class Program
    {
        static void Main(string[] args)
        {
            // Start policy server to allow the communication with the Silverlight client.
            TcpPolicyServer aPolicyServer = 
new TcpPolicyServer(System.Net.IPAddress.Loopback);
            aPolicyServer.StartPolicyServer();

            // Create the communication based on Tcp.
            // Note: Silverlight clients can communicate 
            // on the following ports: 4502 - 4532.
            IMessagingSystemFactory aMessagingFactory = new TcpMessagingSystemFactory();
            IDuplexInputChannel aDuplexInputChannel = 
aMessagingFactory.CreateDuplexInputChannel("127.0.0.1:4530");

            // Start listening for requests.
            CommandReceiver aCommandReceiver = new CommandReceiver();
            aCommandReceiver.StartCommandReceiver(aDuplexInputChannel);
        }
    }
}

Note: The policy server listens to port 943 and returns XML telling Silverlight that communication is allowed. The framework returns a basic XML but you can also set your own if it is needed.

Read more: Codeproject

Posted via email from Jasper-net

0 comments: