15.02.2015 Views

C# 4 and .NET 4

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

OC228 ❘ ChaPTer 54 .net remOtinG<br />

server<br />

The server is implemented within a console application. With RemotingConfiguration.Configure(), the<br />

configuration file is read <strong>and</strong> thus the channel <strong>and</strong> remote objects are set up. With the Console.ReadLine()<br />

the server waits until the user stops the application:<br />

using System;<br />

using System.Runtime.Remoting;<br />

namespace Wrox.ProCSharp.Remoting<br />

{<br />

class Server<br />

{<br />

static void Main()<br />

{<br />

RemotingConfiguration.Configure("Server.exe.config", true);<br />

Console.WriteLine("press return to exit");<br />

Console.ReadLine();<br />

}<br />

}<br />

}<br />

server Configuration file<br />

code snippet RemotingAndEvents/RemoteServer/Program.cs<br />

The server configuration file, Server.exe.config, is also created as already discussed. There is just one<br />

important point: the remote object must keep state for the client because the client at first registers the<br />

event h<strong>and</strong>ler <strong>and</strong> calls the remote method afterward. You cannot use single-call objects with events,<br />

so the RemoteObject class is configured as a client-activated type. Also, to support delegates, you have<br />

to enable full serialization by specifying the typeFilterLevel attribute with the element:<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

event sink<br />

code snippet RemotingAndEvents/RemoteServer/app.config<br />

An event sink library is required for use by the client <strong>and</strong> is invoked by the server. The event sink<br />

implements the h<strong>and</strong>ler StatusH<strong>and</strong>ler() that’s defined with the delegate. As previously noted, the method<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!