Application Space with Silverlight

Despite of some small differences, the functionality of the appspace version for Silverlight is nearly the same as in the standard version. The main differences are:
  • TCP transport only (any other transport services are currently not supported)
  • The filter functionality of the publish/subscribe feature is not available (this is because of limitations in Silverlight concerning reflection and code generation)

Despite of that, you won't see any notable differences. You can find a small Silverlight demo application with client/server communication in the usage demos!

Silverlight Application

This is how instantiating an AppSpace and connecting to a worker looks like in Silverlight:

var space = new XcoAppSpace("tcp.port=0"):
var worker = space.ConnectWorker<PWorker>("serveraddr:8000/myworker");
...
You see that there is no difference to the standard version of the AppSpace - just start the appspace, connect to your worker and start sending messages!

Server for Silverlight Clients

There are a few things that you need to think of when preparing your server space:
  • Communication is only possible with the TCP transport service - so your server space needs one installed (remember that you can also use multiple transport services in one space instance, if you need to)
  • Note that Silverlight only allows communication on a very limited number of TCP ports (4502-4534), so you need to use one of those ports.
  • Also, for a Silverlight client to be able to connect to the port on the server, you need to have a policy in place that allows this connection. To get the policy information, the client will place a request at port 943 on the same server - this means you need to have a policy server running at this port that tells incoming silverlight clients what they are allowed to do. The appspace distribution contains a simple policy server (PolicyServer.exe) which you can run either from code or as console window. See here for further explanation, and an example policy server implementation. Look at the usage demos to see how to use and configure the policy server.
  • It is important to notice that when communicating with a silverlight client, the server cannot initiate the communication (since the client doesn't have a static address, and there is no possibility in Silverlight to open a tcp port for listening). So the server must wait for the client to send a message before something can be sent to the client. Especially in a scenario with Silverlight clients that need to be notified by the server, it can therefore be helpful to increase the connection lifetime (default is 1 minute) to prevent the need for sending alive message. See the tcp transport service configuration for more information on configuring the connection lifetime. Note that the lifetime needs to be configured on both client and server side.
  • For serialization the default binary serializer is not suitable - you need to use the XcoJsonSerializer which serializes messages in Json format. The Silverlight version automatically uses this serializer.

var space = new XcoAppSpace("tcp.port=8000;serializer=json");
space.RunWorker<PWorker, Worker>("myworker");
...

Contract

You may wonder how to best define a contract in such a scenario. Normally you would define a contract assembly and add a reference to this assembly to the client and server project. In this case, where client and server projects are using different framework versions, you have two possibilities:
  • Link the contract code files into the different assemblies
  • Use a portable library project. A portable library can be referenced in both projects, you can create such a library with Visual Studio 2010 when you install the Portable Library Tools extension, in VS11 this is already built in.

Last edited Dec 21, 2012 at 1:25 PM by thomass, version 4

Comments

No comments yet.