Export (0) Print
Expand All

How to: Build a Remotable Type

This topic is specific to a legacy technology that is retained for backward compatibility with existing applications and is not recommended for new development. Distributed applications should now be developed using the  Windows Communication Foundation (WCF).

To enable objects in other application domains to use an instance of your class, your class must inherit from MarshalByRefObject. The following procedure describes how to create a basic object that can be created and invoked from objects executing in another application domain.

txct33xt.note(en-us,VS.90).gifNote:
See How to: Compile and Run a Basic Remoting Application for complete instructions on how to build and run this sample.

To build a remotable type

  1. Define a class that derives from the MarshalByRefObject class.

    public class RemotableType : MarshalByRefObject
    {
        …
    }
    
  2. Implement the methods and properties for that class as you would for a non-remotable type. A call is made to Console.WriteLine to have the listener display a string. This is used later to demonstrate that the remote object was called.

    Public Function SayHello() As String
       Console.WriteLine("RemotableType.SayHello() was called!")
       Return "Hello, world"
    End Function 'StringMethod
    

    public string SayHello(){
       Console.WriteLine("RemotableType.SayHello() was called!");
       return "Hello, world";
    }
    
  3. Create a directory named remoting\type and save the class as RemotableType.cs or RemotingType.vb, in the new directory. Open a command-prompt and navigate to the remoting\type directory and type the following command:

    csc /noconfig /t:library RemotableType.cs
    
    

Example

// RemotableType.cs
using System;
public class RemotableType : MarshalByRefObject
{
    public string SayHello()
    {
        Console.WriteLine("RemotableType.SayHello() was called!");
        return "Hello, world";
    }
}

See Also



Copyright © 2007 by Microsoft Corporation. All rights reserved.

Community Additions

Show:
© 2014 Microsoft