Freigeben über


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.

NoteNote

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

  • Define a class that derives from the MarshalByRefObject class.

   Public Class RemotableType
      Inherits MarshalByRefObject
    …
End Class
public class RemotableType : MarshalByRefObject
{
    …
}

Example

' RemotableType.vb
Imports System

Public Class RemotableType
   Inherits MarshalByRefObject 
   Public Function SayHello() As String
      Console.WriteLine("RemotableType.SayHello() was called!")
      Return "Hello, world"
   End Function 
End Class 
// RemotableType.cs
using System;
public class RemotableType : MarshalByRefObject
{
    public string SayHello()
    {
        Console.WriteLine("RemotableType.SayHello() was called!");
        return "Hello, world";
    }
}

See Also

Tasks

How to: Build a Hosting Application
How to: Build a Client Application

Reference

Remoting Settings Schema

Concepts

Configuration of Remote Applications
Server Activation

Other Resources

Building a Basic .NET Framework Remoting Application