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

Delegate Remotable Objects in Simple English (Really, it's that simple)

, 26 Jun 2003
Rate this:
Please Sign up or sign in to vote.
Made easy: How to solve the FileNotFoundException error when Remoting.

Sample Image - DelegateRemotable.gif

Introduction

If you recall my last article, which was about a simple remoting chat program (on the .NET Framework SDK v1.0, VB.NET), it had a problem... You could only start the Client.exe from the same directory as the Server.exe. This requirement was because the Client requires some metadata of the Server's assembly to create a proxy version of the Server. Once that is done, only can you start Clients in directories other than the Server. Although the bug was corrected on the .NET Framework SDK, and the solution explained in KB312114 (meant for V1.0), it was rather cryptic. Although they have provided a fix for their console chat program, I would like to present a clearer explanation of what the solution requires and how to do it in C#, on the .NET Framework SDK v1.1.

Cause

In simple English, delegates require that the receiving object (our ClientUI) be able to obtain the type information from the Server assembly.

Solution

Solution design

The fix requires a design which would look a bit like above.

  • STEP 1: Create an abstract class, make sure its accessible from both ClientUI and Server.

    To make remoted delegates work on our remoting chat, an abstract class (in this case, RemotelyDelegatableObject) that contains the callback function must be placed in a common assembly (Manager.dll, under InBetween namespace) that both client and server have access to (i.e. Manager.dll will be placed in the same directory as the ClientUI and Server).

  • STEP 2: Implement the abstract class

    The solution requires that our client (ClientUI) derives a custom class (OurCallBack class) from this abstract class (RemotelyDelegatableObject) to implement the logic in the callback.

  • STEP 3: Create a public function (OurInternalCallback) for the callback that is final (cannot be overridden)

    Using the function, forward all calls to a protected abstract function (private, abstract, OurInternalCallback) that is overridden in the derived client class, ClientUI. This allows the delegate to bind to a concrete implementation of the callback function (OurInternalCallback), and this implementation must not be overridable.

Note: SubmitEventArgs was inherited from EventArgs just to allow us to pass in more custom information.

Adapting to V1.1

Adapting to V1.1 requires a minor change to our config files.

We need to add the typeFilterLevel to the Formatter tag.

Shown below is our .config for ClientUI.exe.

<configuration>

      <system.runtime.remoting>

          <application>

              <client>

              <!-- TODO: Change the host and port name -->

              <wellknown 

                  type="InBetween.Manager, Manager"

                  url="http://UP:12345/RemotingChat"

              />

              </client>

              <channels>

                  <channel 

                      ref="http" 

                      name="ClientRemotingChatChannel"

                      port="8888">

                  <clientProviders> 

                      <formatter ref="soap" />

                  </clientProviders>

                  <serverProviders> 

                      <formatter ref="soap" typeFilterLevel="Full" />

                  </serverProviders> 

                  </channel>

              </channels>

          </application>

      </system.runtime.remoting>

  </configuration>

Shown below is our .config for Server.exe.

<configuration>

      <system.runtime.remoting>

          <application>

              <service>

              <wellknown 

              type="InBetween.Manager, Manager" 

              objectUri="RemotingChat"

              mode="Singleton" 

              />

              </service>

          <channels>

              <channel 

              ref="http server" 

              name="RemotingChatChannel"

              port="12345">

              <serverProviders> 

                  <provider ref="wsdl" /> 

                  <formatter ref="soap" typeFilterLevel="Full" />

                  <formatter ref="binary" typeFilterLevel="Full" />

              </serverProviders> 

              </channel>

          </channels>

          </application>

      </system.runtime.remoting>

  </configuration>

History

Friday 27, June 2003: Uploaded first version.

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

Share

About the Author

Daniel Ang Chee Meng
Web Developer
Malaysia Malaysia
The author has been developing software on a freelance basis and is currently employed by a consulting firm, having just finished his Bsc in Computing (Uni. of Staffordshire, UK). He is residing in Asia and holds among other qualifications, the MCSD.net and MCAD.net charter membership. He has a deep interest in the .Net platform. His previous exposure was in Java. One of his biggest 'concerns' is that one day the world might be blown off orbit by some mad scientist...
NOTE: The author apologises for looking very scary. He's not, in real life...
 
oMCSD (.Net) Charter member
oMCAD (.Net) Charter member
oMCSE (Microsoft Windows 2000)
oMCSA (Microsoft Windows 2000)
oMCDBA (Microsoft SQL 2000)
oMicrosoft Certified Professional
 

Comments and Discussions

 
GeneralNot able to run multiple clients Pinmembervoorugonda prashanth12-Jul-07 3:27 
Generalsocket address Pinmemberlexx_debug20-Dec-05 4:38 
AnswerRe: socket address Pinmembersameh_serag8-Nov-06 20:59 
GeneralException Error Pinmemberjchsiung214-Aug-05 9:26 
GeneralRe: Exception Error Pinmemberkamil nowicki18-Apr-06 0:33 
QuestionInterface? Pinmembermikasa9-Dec-03 2:43 
GeneralThank you for solving my problem! PineditorMarc Clifton30-Nov-03 9:28 
GeneralRe: Thank you for solving my problem! Pinmemberdanielibarnes21-Mar-06 6:02 
GeneralClient Pinmemberhlbcal19-Jul-03 18:44 
AnswerRe: Client Pinmembersameh_serag8-Nov-06 21:05 

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

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

| Advertise | Privacy | Mobile
Web03 | 2.8.140814.1 | Last Updated 27 Jun 2003
Article Copyright 2003 by Daniel Ang Chee Meng
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid