Click here to Skip to main content
Click here to Skip to main content

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

By , 31 Mar 2004
 

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

 <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

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

Client side configuration

   <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

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

Activate through code

Server side

    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

    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

About the Author

Cohen Shwartz Oren
Israel Israel
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralMy vote of 2memberngoj29 Dec '09 - 14:22 
QuestionBug Remoting by TCP channel in VistamemberZapfchen7 Jul '09 - 3:57 
AnswerRe: Bug Remoting by TCP channel in VistamemberZapfchen9 Jul '09 - 2:36 
The problem is solved.
MS Remoting conflicts with MS Firewall Client for ISA Server v 4.0
 
BTW, WCF also hangs on Vista with ISA Client present
 
We need a patch for ISA !!!
GeneralServer Raise Eventmembertbman16 Jan '09 - 14:54 
GeneralHi Thanks! HttpChannel is working now!memberjayzonpanget21 Oct '08 - 19:02 
GeneralSame problem in HttpChannelmemberjayzonpanget21 Oct '08 - 18:56 
GeneralExcellent article, got exactly what I wantedmemberebranson196912 May '08 - 8:43 
GeneralThanks a lot!membersidkud24 Dec '07 - 12:53 
GeneralWMI versus .Net Remotingmemberpuromtec19 Aug '07 - 6:36 
GeneralRe: WMI versus .Net RemotingmemberCohen Shwartz Oren13 Aug '07 - 0:25 
GeneralRe: WMI versus .Net Remoting [modified]memberpuromtec114 Aug '07 - 4:42 
GeneralNicely DonememberChristopher G. Lasater23 May '07 - 8:30 
GeneralRe: Nicely DonememberCohen Shwartz Oren23 May '07 - 9:30 
GeneralExample fails using HttpChannelmemberrcarsten14 Nov '06 - 22:13 
GeneralRe: Example fails using HttpChannelmemberjayzonpanget21 Oct '08 - 19:03 
QuestionRetrieving events in VBAmemberJEBond24 Oct '06 - 5:46 
GeneralThanks a lotmemberNehal Kanani20 Jan '06 - 0:05 
GeneralRe: Thanks a lotmemberCohen Shwartz Oren12 May '07 - 6:14 
GeneralEventssussHector Caban2 Apr '05 - 0:27 
GeneralRe: EventsmemberCohen Shwartz Oren12 May '07 - 6:13 
GeneralRe: EventsmemberChris Zubriski16 Sep '08 - 8:03 
Generalnew cool stuffmemberAlex Sivokho3 Feb '05 - 23:23 
GeneralRe: new cool stuffmemberCohen Shwartz Oren17 Mar '05 - 2:20 
GeneralRe: new cool stuffmemberajn999917 Mar '05 - 18:40 
GeneralSome Remoting Exceptions and how to deal with themmemberCohen Shwartz Oren18 Oct '04 - 0:08 
GeneralPermission problem - DelegateSerializationHoldermemberCohen Shwartz Oren18 Oct '04 - 0:09 
GeneralBecause of security restrictions, the type System. Runtime.Remoting.ObjRef cannot be accessedmemberCohen Shwartz Oren18 Oct '04 - 0:10 
GeneralThe constructor to desterilize an object of type MYException was not found.&#8221;memberCohen Shwartz Oren18 Oct '04 - 0:11 
GeneralOverloading problemmemberCohen Shwartz Oren18 Oct '04 - 0:12 
GeneralAn unhandled exception of type 'System.Runtime.Remoting.RemotingException' Occurred in mscorlib.dllmemberCohen Shwartz Oren18 Oct '04 - 0:13 
GeneralSerialize object to the clients failsmemberCohen Shwartz Oren18 Oct '04 - 0:14 
GeneralEx: &#8220;Server encountered an internal error. For more information, turn on custom Errors in the server&#8217;s .config file.&#8221;memberCohen Shwartz Oren18 Oct '04 - 0:15 
General: &quot;The underlying connection was closed: Unable to connect to the remotememberCohen Shwartz Oren18 Oct '04 - 0:15 
Generalgetting reconnected to the same old clientmemberCohen Shwartz Oren18 Oct '04 - 0:16 
General[Msg Deleted]memberandre.pietsch25 Aug '05 - 2:49 
GeneralThanksmemberAndreas Nolte12 Oct '04 - 4:20 
GeneralProgrammatically configure serverProviders and clientprovidermemberchalama2 Sep '04 - 6:22 
General&quot;Serialization will not deserialize delegates to non-public methods.&quot;memberNeil de Weerdt26 Jul '04 - 1:50 
GeneralRe: &quot;Serialization will not deserialize delegates to non-public methods.&quot;memberCohen Shwartz Oren26 Jul '04 - 2:18 
GeneralServer encountered an internal error. For more information, turn on customErrors in the server’s .config file.”memberCohen Shwartz Oren19 Jul '04 - 5:13 
GeneralRe: Server encountered an internal error. For more information, turn on customErrors in the server’s .config file.”memberCohen Shwartz Oren19 Jul '04 - 5:21 
GeneralRe: Server encountered an internal error. For more information, turn on customErrors in the server&#8217;s .config file.&#8221;sussAnthonyVO10 Feb '05 - 16:16 
GeneralRe: Server encountered an internal error. For more information, turn on customErrors in the server&#8217;s .config file.&#8221;memberCohen Shwartz Oren12 Feb '05 - 20:20 
GeneralRe: Server encountered an internal error. For more information, turn on customErrors in the server&#8217;s .config file.&#8221;memberAnthonyVO14 Feb '05 - 2:21 
GeneralRe: Server encountered an internal error. For more information, turn on customErrors in the server&#8217;s .config file.&#8221;memberCohen Shwartz Oren14 Feb '05 - 2:31 
General.NET Remoting on Linuxmemberjrpally1 Jul '04 - 7:45 
GeneralThank You :)memberbzchai14 Jun '04 - 3:45 
GeneralThank You :)sussAnonymous14 Jun '04 - 3:45 
GeneralServer encountered an internal error. For more information, turn on customErrors in the server's config filememberRamesh1104667 May '04 - 9:39 
GeneralRe: Server encountered an internal error. For more information, turn on customErrors in the server's config filememberCohen Shwartz Oren8 May '04 - 20:40 

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

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130516.1 | Last Updated 1 Apr 2004
Article Copyright 2004 by Cohen Shwartz Oren
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid