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

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

Rate me:
Please Sign up or sign in to vote.
3.38/5 (8 votes)
26 Jun 20032 min read 68.1K   1.3K   20   10
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.

XML
<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.

XML
<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


Written By
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 Pin
voorugonda prashanth12-Jul-07 3:27
voorugonda prashanth12-Jul-07 3:27 
Generalsocket address Pin
lexx_debug20-Dec-05 4:38
lexx_debug20-Dec-05 4:38 
AnswerRe: socket address Pin
sameh_serag8-Nov-06 20:59
sameh_serag8-Nov-06 20:59 
GeneralException Error Pin
jchsiung214-Aug-05 9:26
jchsiung214-Aug-05 9:26 
GeneralRe: Exception Error Pin
kamil nowicki18-Apr-06 0:33
kamil nowicki18-Apr-06 0:33 
QuestionInterface? Pin
mikasa9-Dec-03 2:43
mikasa9-Dec-03 2:43 
GeneralThank you for solving my problem! Pin
Marc Clifton30-Nov-03 9:28
mvaMarc Clifton30-Nov-03 9:28 
GeneralRe: Thank you for solving my problem! Pin
danielibarnes21-Mar-06 6:02
danielibarnes21-Mar-06 6:02 
GeneralClient Pin
hlbcal19-Jul-03 18:44
hlbcal19-Jul-03 18:44 
AnswerRe: Client Pin
sameh_serag8-Nov-06 21:05
sameh_serag8-Nov-06 21:05 
1-make sure your config file states the correct address of the server
2- make sure you attach the config file with the application by using
RemotingConfiguration.Configure("your configuration file name")

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.