Click here to Skip to main content
15,867,488 members
Articles / Programming Languages / C#
Article

.NET Remoting: Passing through the obstacles path from version 1.0 to 1.1

Rate me:
Please Sign up or sign in to vote.
4.73/5 (68 votes)
31 Mar 20042 min read 219.7K   3.3K   40   64
Houston, we have a problem. One small step for mankind, one Giant irritation for developers.

Introduction

The following article's aim is to help those of you who want to use .NET Remoting on Framework 1.1*. This article will not teach you Remoting, mainly because I am not an expert on that field. Furthermore, my CodeProject colleagues published some useful and nice to read articles on that issue (see links below). The attached projects were kept simple as possible to allow you to overcome the changes presented by Framework 1.1*. It handles the maladies of security exception, serialization and delegates issues.

Background

Recently, I have faced the challenge of exposing objects via .NET Remoting. Like the most of you, I have started with the MSDN, and of course CodeProject, but all the examples were suited for Framework 1.0 only. Attempts to run 1.0 project on a 1.1 Framework ends with lots of exceptions.

  • Type System.DelegateSerializationHolder and the types derived from it (such as System.DelegateSerializationHolder) are not permitted to be deserialized at this security level.
  • Because of security restrictions, the type System.Runtime.Remoting.ObjRef cannot be accessed.
  • This remoting proxy has no channel sink which means either the server has no registered server channels that are listening, or this application has no suitable client channel to talk to the server.

The web is full of developers' complaints on the very same problems but I have not found a simple, corrective and comprehensive example. So there you have it!.

Code snippets

Activate through Config files

Server side configuration

XML
 <system.runtime.remoting>
    <application name="ServerAssembly" >
     <service>
          <!-- type: is the full type name 
(type the class that inherit from MBR,assembly) of the 
object-->
          <!-- objectUri - alias -->
          <!-- Server tells remoting Here's a type 
Here's how and when to instantiate the type
Here's the name (end point) a client will use to contact the type
            -->            
  
        <wellknown mode="Singleton" 
            type="SharedAssembly.SharedObj, SharedAssembly" 

objectUri="ParachuteExample" />
           </service>
         <channels>
            <channel ref="tcp" port="6123">    
                <serverProviders>            
                    <formatter ref="binary" typeFilterLevel="Full" />
                </serverProviders>                
            </channel>    
         </channels>     
    </application>
  </system.runtime.remoting>

Server side code

C#
RemotingConfiguration.Configure ("ServerAssembly.exe.config");

Client side configuration

XML
<system.runtime.remoting>
   <application>
      <client>
         <wellknown
            type="SharedAssembly.SharedObj, SharedAssembly"
            url="tcp://localhost:6123/ParachuteExample"
         />
      </client>
    <channels>
 <channel ref="tcp" port="0">
  <clientProviders>
   <formatter ref="binary" />
  </clientProviders>
  <serverProviders>
   <formatter ref="binary" typeFilterLevel="Full" />
  </serverProviders>
 </channel>
</channels>

   </application>

Client side code

C#
RemotingConfiguration.Configure ("ClientAssembly.exe.config");
SharedObj remObject = new SharedObj();

Activate through code

Server side

C#
BinaryClientFormatterSinkProvider clientProvider = null;
BinaryServerFormatterSinkProvider serverProvider =
   new BinaryServerFormatterSinkProvider();
serverProvider.TypeFilterLevel =

System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;

IDictionary props = new Hashtable();
props["port"] = 6123;
props["typeFilterLevel"] = TypeFilterLevel.Full;
TcpChannel chan = new TcpChannel(
props,clientProvider,serverProvider);

ChannelServices.RegisterChannel(chan);

RemotingConfiguration.RegisterWellKnownServiceType(typeof(SharedObj),
                "ParachuteExample",
                WellKnownObjectMode.Singleton);

Client Side

C#
BinaryClientFormatterSinkProvider clientProvider =
   new BinaryClientFormatterSinkProvider();
BinaryServerFormatterSinkProvider serverProvider =
   new BinaryServerFormatterSinkProvider();
serverProvider.TypeFilterLevel =

System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;

IDictionary props = new Hashtable();
props["port"] = 0;
string s = System.Guid.NewGuid().ToString();
props["name"] = s;
props["typeFilterLevel"] = TypeFilterLevel.Full;
TcpChannel chan = new TcpChannel(
props,clientProvider,serverProvider);

ChannelServices.RegisterChannel(chan);


Type typeofRI = typeof(IParachute);
IParachute remObject = (IParachute)Activator.GetObject(    typeofRI,
                "tcp://localhost:6123/ParachuteExample");

Using the code

Since some of you like configuration files while others like to connect and create the well known object via code, I have included two projects accordingly. Both projects, codeActivationExample.zip and configFileExample.zip, include the same assemblies as follows:

  • ClientAssembly
  • ServerAssembly
  • SharedAssembly

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Israel Israel
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralEvents Pin
Hector Caban2-Apr-05 0:27
Hector Caban2-Apr-05 0:27 
GeneralRe: Events Pin
Cohen Shwartz Oren12-May-07 6:13
Cohen Shwartz Oren12-May-07 6:13 
GeneralRe: Events Pin
Chris Zubriski16-Sep-08 8:03
Chris Zubriski16-Sep-08 8:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.