15.02.2015 Views

C# 4 and .NET 4

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

OC200 ❘ ChaPTer 54 .net remOtinG<br />

static void Main()<br />

{<br />

Console.WriteLine("Press return after the server is started");<br />

Console.ReadLine();<br />

}<br />

}<br />

}<br />

ChannelServices.RegisterChannel(new TcpClientChannel(), true);<br />

Hello obj = (Hello)Activator.GetObject(<br />

typeof(Hello), "tcp://localhost:8086/Hi");<br />

if (obj == null)<br />

{<br />

Console.WriteLine("could not locate server");<br />

return;<br />

}<br />

for (int i=0; i < 5; i++)<br />

{<br />

Console.WriteLine(obj.Greeting("Stephanie"));<br />

}<br />

code snippet RemoteHello/HelloClient/Program.cs<br />

A proxy is an object used by the client application in place of the remote object. Proxies<br />

that are used in Chapter 55 have a similar functionality to the proxies in this chapter.<br />

The implementation of proxies for Web services <strong>and</strong> proxies for .<strong>NET</strong> Remoting is<br />

very different.<br />

Now you can start the server <strong>and</strong> then the client. Within the client console, the text Hello, Stephanie<br />

appears fi ve times. With your server console window you can see the output shown. With every method call<br />

a new instance gets created because the WellKnownObjectMode.SingleCall activation mode was selected:<br />

Press return to exit<br />

Constructor called<br />

Greeting called<br />

Constructor called<br />

Greeting called<br />

Constructor called<br />

Greeting called<br />

Constructor called<br />

Greeting called<br />

Constructor called<br />

Greeting called<br />

.neT remoTing arChiTeCTure<br />

Now that you ’ ve seen a simple client <strong>and</strong> server application in action, let ’ s take a look at the .<strong>NET</strong> Remoting<br />

architecture before we dive into the details. Based on the previously created program, you look at the<br />

architecture <strong>and</strong> the mechanisms for extensibility.<br />

This section explores the following topics:<br />

➤<br />

➤<br />

➤<br />

The functionality of a channel <strong>and</strong> how a channel can be confi gured<br />

Formatters <strong>and</strong> how they are used<br />

The utility classes ChannelServices <strong>and</strong> RemotingConfiguration<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!