spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / programming / csharp / webservices / chap6 / 2 To page 1current pageTo page 3To page 4To page 5To page 6To page 7To page 8
[previous] [next]

Professional C# Web Services

Sr Instructional Designer D2L-Moodle,Clearance
WSI Nationwide, Inc.
US-NJ-Fort Monmouth

Justtechjobs.com Post A Job | Post A Resume
Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs


Nothing has really changed with the server and the remote object, so we can use the same client application we created earlier to communicate with the new server. To complete the picture, we will change the client code as can be seen below:

// SimpleClient.cs

using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
namespace Wrox.Samples
{
   class SimpleClient
   {
      static void Main(string[] args)
      {

         // Create and register the client channel

         TcpClientChannel channel = new TcpClientChannel();
         ChannelServices.RegisterChannel(channel);

         // Register the name and port of the remote object

         WellKnownClientTypeEntry entry = new WellKnownClientTypeEntry(
            typeof(MyRemoteObject), 
            "tcp://localhost:9000/SimpleServer/MyRemoteObject");
         RemotingConfiguration.RegisterWellKnownClientType(entry);

Now a client channel from the class TcpClientChannel is instantiated and registered. We use the WellKnownClientTypeEntry class to define the remote object. In contrast to the server version of this class, the complete path to the remote object must be specified here as we have to know the server name in the client, but the mode is not specified because this is defined from the server. The RemotingConfiguration class is then used to register this remote object in the remoting runtime.

As we saw earlier, the remote object can be instantiated with the new operator. To demonstrate that a well-known object gets activated with every method call, the method Hello() is now called five times in a for loop:

         MyRemoteObject obj = new MyRemoteObject(); 
         for (int i=0; i < 5; i++)
            Console.WriteLine(obj.Hello());
      }
   }
}

Running this program we can see in the output of the server (see screenshot below) that a new instance of the remote object is not created by calling the new operator in the client code, but with every method call instead. Well-known objects could also be called server-activated objects as compared to client-activated objects. With client-activated objects a new object gets instantiated on the server when the client invokes the new operator:

results of example code run

One important fact that we should remember with well-known objects:

A well-known object doesn't have state. A new instance is created with every method call.


home / programming / csharp / webservices / chap6 / 2 To page 1current pageTo page 3To page 4To page 5To page 6To page 7To page 8
[previous] [next]

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Enterprise 2.0: Social Networking in the Cloud · BroadSoft Marketplace Hastens Pace of Telephony Innovation · Review: HTC Hero for Sprint

Created: February 25, 2002
Revised: February 25, 2002


URL: http://webreference.com/programming/csharp/webservices/chap6/2/2.html