5,667,575 members and growing! (9,214 online)
Email Password   helpLost your password?
General Programming » Internet / Network » Remoting     Intermediate

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

By Cohen Shwartz Oren

Houston, we have a problem. One small step for mankind, one Giant irritation for developers.
C#, Windows, .NET 1.1, .NETVisual Studio, VS.NET2003, Dev

Posted: 30 Mar 2004
Updated: 31 Mar 2004
Views: 111,095
Bookmarked: 30 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
64 votes for this Article.
Popularity: 8.03 Rating: 4.45 out of 5
5 votes, 7.8%
1
1 vote, 1.6%
2
1 vote, 1.6%
3
2 votes, 3.1%
4
55 votes, 85.9%
5

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


Oren, lives in Israel and work as R&D Manager in Applicure Technologies. A company that develop a software-based products for web application security.

Since the .Net kickoff he lives the .NET world and managed and develops in various aspects of its technologists: .Net Remoting, Web services, Reflection WMI Management, Ajax and Web Forms.

His Software engineering experience includes:
* Design of complex large scale client-server architectures with emphasis on performance issues.
* Design Windows and Web Applications with emphasis on User Experience and Usability.
* Migration of C++ and COM Software projects to .Net.
* Frameworks like: MFC, ATL and .Net

For Oren computer programming is not only a job but also a hobby he developed some useful
freeware
. Apart from programming, he is practicing skydiving and snowboarding.


Blog: Blog:The RnD Manager
.
Occupation: Other
Company: Applicure
Location: Israel Israel

Other popular Internet / Network articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 25 of 60 (Total in Forum: 60) (Refresh)FirstPrevNext
GeneralHi Thanks! HttpChannel is working now!memberjayzonpanget20:02 21 Oct '08  
GeneralSame problem in HttpChannelmemberjayzonpanget19:56 21 Oct '08  
GeneralExcellent article, got exactly what I wantedmemberebranson19699:43 12 May '08  
GeneralThanks a lot!membersidkud13:53 24 Dec '07  
GeneralWMI versus .Net Remotingmemberpuromtec17:36 9 Aug '07  
GeneralRe: WMI versus .Net RemotingmemberCohen Shwartz Oren1:25 13 Aug '07  
GeneralRe: WMI versus .Net Remoting [modified]memberpuromtec15:42 14 Aug '07  
GeneralNicely DonememberChristopher G. Lasater9:30 23 May '07  
GeneralRe: Nicely DonememberCohen Shwartz Oren10:30 23 May '07  
GeneralExample fails using HttpChannelmemberrcarsten23:13 14 Nov '06  
GeneralRe: Example fails using HttpChannelmemberjayzonpanget20:03 21 Oct '08  
QuestionRetrieving events in VBAmemberJEBond6:46 24 Oct '06  
GeneralThanks a lotmemberNehal Kanani1:05 20 Jan '06  
GeneralRe: Thanks a lotmemberCohen Shwartz Oren7:14 12 May '07  
GeneralEventssussHector Caban1:27 2 Apr '05  
GeneralRe: EventsmemberCohen Shwartz Oren7:13 12 May '07  
GeneralRe: EventsmemberChris Zubriski9:03 16 Sep '08  
Generalnew cool stuffmemberAlex Sivokho0:23 4 Feb '05  
GeneralRe: new cool stuffmemberCohen Shwartz Oren3:20 17 Mar '05  
GeneralRe: new cool stuffmemberajn999919:40 17 Mar '05  
GeneralSome Remoting Exceptions and how to deal with themmemberCohen Shwartz Oren1:08 18 Oct '04  
GeneralPermission problem - DelegateSerializationHoldermemberCohen Shwartz Oren1:09 18 Oct '04  
GeneralBecause of security restrictions, the type System. Runtime.Remoting.ObjRef cannot be accessedmemberCohen Shwartz Oren1:10 18 Oct '04  
GeneralThe constructor to desterilize an object of type MYException was not found.”memberCohen Shwartz Oren1:11 18 Oct '04  
GeneralOverloading problemmemberCohen Shwartz Oren1:12 18 Oct '04  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 31 Mar 2004
Editor: Smitha Vijayan
Copyright 2004 by Cohen Shwartz Oren
Everything else Copyright © CodeProject, 1999-2008
Web20 | Advertise on the Code Project