|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
Note: This is an unedited contribution. If this article is inappropriate,
needs attention or copies someone else's work without reference then please
Report This Article
IntroductionDot Net Remoting is a simple programming model/framework which allows objects from different machines/processes/app-domains to communicate each other. It allows the flexibility of using different types of communication protocols (tcp, http etc..) and message formatters (binary, SOAP etc..). Communication among different app-domains is facilitated by Remoting objects. Remoting objects can be hosted using Managed Executables/IIS/.Net Component Services. It is also possible for .Net applications running on different machines to share the same instance of a remoting object hosted on a server. This document demonstrates how to handle events from a remote object using a real time ‘Message and file transfer’ application. Technologies covered in this document
This document demonstrates the following pattern and technologies. · Publisher listener design pattern · Server activated singleton objects · Marshal by reference remote object access · Raising events from remote objects · Use of binary format over TCP channel Publisher-Listener Design pattern.Design patterns are an efficient way of reusing and sharing solutions to repeating problems. ‘Publisher-Listener’ is a behavioral design pattern. It is also known as ‘observer’ pattern. By definition, a ‘Publisher-listener’ pattern establishes a one-to-many dependency between objects so that when one object changes state , all it’s dependents are notified and updated automatically.
As shown in the above diagram, in a ‘Publisher-Listener’ design pattern, when a publisher post a message, all the listeners are automatically get updated with the message. A publisher and listener can be the same object. There can be so many publishers and listeners. All the listeners have to register to the server to make them enable to listen to the messages.
Dot Net Remoting terminologies
Server-Activated ObjectsServer-activated objects are objects whose lifetimes are controlled by the server. They are created by the server only as needed when the client invokes the first method on the object. Server-activated objects only support default constructors. To use a remote object with parameterized constructors you can use client activation or dynamic publication (see below). Server-activated objects are also referred to as well-known object types, as their location (URL) is published and known in advance. There are two activation modes for server-activated objects, Singleton and SingleCall, both of which are described below. Single Call
Single Call objects service one and only one request coming in. Single Call objects are useful in scenarios where the objects are required to do a finite amount of work. Single Call objects are usually not required to store state information, and they cannot hold state information between method calls. However, Single Call objects can be configured in a load-balanced fashion. Singleton Objects
Singleton objects are those objects that service multiple clients and hence share data by storing state information between client invocations. They are useful in cases in which data needs to be shared explicitly between clients and also in which the overhead of creating and maintaining objects is substantial. For example, the following code snippet depicts a server-activated (wellknown) type with activation mode set to SingleCall.
Client-Activated Objects (CAO)Client-activated objects (CAO) are server-side objects that are activated upon request from the client. When the client submits a request for a server object using "new" operator or Activator.CreateInstance(), an activation request message is sent to the remote application. The server then creates an instance of the requested class and returns an ObjRef back to the client application that invoked it. A proxy is then created on the client side using the ObjRef. The client's method calls will be executed on the proxy. Client-activated objects can store state information between method calls for its specific client and not across different client objects. Each invocation of "new" returns a proxy to an independent instance of the server type. For example, the following code snippet depicts a ClientActivated type. Note that we no longer need an URL, as for client-activated types the type alone is sufficient for activation. Also, the wellknown tag has been replaced by the activated tag.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
<configuration> <system.runtime.remoting> <application> <lifetime leaseTime="20D" sponsorshipTimeout="1H" renewOnCallTime="1D" leaseManagerPollTime="1H" /> <service> <wellknown mode="Singleton" type="MessageShare.SharedMessage,MessageShare" objectUri="SharedMessage"/> </service> <channels> <channel ref = "tcp" port = "8080"> <serverProviders> <formatter ref="binary" typeFilterLevel="Full" /> </serverProviders> </channel> </channels> </application> </system.runtime.remoting> </configuration> |
|
<configuration> <system.runtime.remoting> <application> <lifetime leaseTime="20D" sponsorshipTimeout="1H" renewOnCallTime="1D" leaseManagerPollTime="1H" /> <client> <wellknown type="MessageShare.SharedMessage,MessageShare" url="tcp://10.201.33.229:8080/SharedMessage" /> </client> <channels> <channel ref="tcp" port="0" clientConnectionLimit="20" > </channel> </channels> </application> </system.runtime.remoting> <appSettings> <add key="RemotingUrl" value="tcp://10.201.33.229:8080/SharedMessage"></add> </appSettings> </configuration> |
Please note to change the IP address and port number - tcp://10.201.33.229:8080 to that of the server machine where the server application is running. The port number should be same as that configured in the server configuration file.
Download sourcecode - RemotingClassSource.zip
Download sourcecode - ClientAppSource.Zip
· Please note to change the IP address and port number - tcp://10.201.33.229:8080 in the client configuration file to that of the server machine where the server application is running.
· The port number in the client configuration file should be same as that configured in the server configuration file.
· Manually start the server application (executable console application)
· Use the client application only after ensuring the following
o The configuration files are updated properly
o The server application is started.
· An Introduction to Microsoft .NET Remoting Framework
· Format for .NET Remoting Configuration Files
|
Abbreviation |
Expansion |
|
MBV |
Marshal By Value |
|
MBR |
Marshal By Reference |
|
CAO |
Client Activated Objects |
|
SOAP |
Simple Object Access Protocol |
|
IIS |
Internet Information Services |
| You must Sign In to use this message board. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 14 May 2006 Editor: |
Copyright 2006 by josekonoor Everything else Copyright © CodeProject, 1999-2008 Web10 | Advertise on the Code Project |