The following example class RemotePerson will provide comparisons for DCOM and .NET remoting.
// compile with: /LD /clr
#using <mscorlib.dll>
#using <System.dll>
using namespace System;
public __gc class RemotePerson : public MarshalByRefObject
{
public:
RemotePerson()
{
firstName = "JohnMBR";
lastName = "DoeMBR";
age = 30;
Console::WriteLine("RemotePerson c'tor");
}
RemotePerson(String* fname,String* lname,int age)
{
firstName = fname;
lastName = lname;
this->age = age;
Console::WriteLine("RemotePerson 3 arg c'tor");
}
__property int get_Age()
{
Console::WriteLine(__box(age));
return age;
}
void HaveBirthday()
{
Console::WriteLine("HaveBirthday");
age++;
}
__property String* get_FirstName()
{
Console::WriteLine("firstName");
return firstName;
}
__property void set_FirstName(String* fname)
{ firstName = fname; }
__property String* get_LastName()
{
Console::WriteLine("lastName");
return lastName;
}
__property void set_LastName(String* lname)
{ lastName = lname; }
private:
String* firstName;
String* lastName;
int age;
}; The code demonstrates the following concepts:
- The
RemotePerson class derives from the class System::MarshalByRefObject. In all other respects, RemotePerson is a regular managed class. For more information, see Activation Options.
In the next step, you will instantiate the class in a server process and invoke its methods. You will then try different .NET remoting features to enhance the client and server.
Go to the next step | Go to the previous step
See Also
Managed Extensions for C++ and .NET Remoting Tutorial