. NET Remoting is used for communication between applications.
Let's start with a simple example:
Prepare three items.
(i) Remote Objects
Newly created Class Library project: Selfremote
public class Selfremoteobject:marshalbyrefobject
{
public int Plus (int a, int b)
{
Console.WriteLine ("Client Request call: A={0},b={1}", b);
Console.WriteLine ("Computed Result: a+b={0}, returned to client call", A + B);
return a + B;
}
}
Derive from MarshalByRefObject, and then complete a service (method) that can be called remotely. The library file is then generated and the library file is used as the reference library on both sides of the server and client.
(ii) Service Side
Establish a console application for registering the channel. (Add a reference to the remote object build library)
static void Main (string[] args)
{
HttpChannel _channel = new HttpChannel (10001);
ChannelServices.RegisterChannel (_channel,false);
Console.WriteLine ("HTTP channel remoting service begins ...");
RemotingConfiguration.RegisterWellKnownServiceType
(typeof (Selfremoteobject), "Selfremoteobject",
Wellknownobjectmode.singleton);
Console.read ();
}
Establishing an HTTP channel
(iii) Client
To add a reference to the remote object build library
public void Test ()
{
Selfremoteobject app =
(Selfremoteobject) Activator.GetObject (typeof (Selfremoteobject),
"Http://localhost:10001/selfRemoteObject");
Console.WriteLine (App. Plus (1,3));
Console.ReadLine ();
}
(iv) Test
Console:
Client Request Call: A=1,b=3
Calculation result: A+b=3, returned to client call
Client:
4
The implementation of remoting is demonstrated in a simple example.
• In this example, create a library file for the Selfremote class library of the remote remoting object to be referenced at both ends.
• Configuration for both ends can be done programmatically, or in the same way as the configuration file.
Blog Park Avenue to Jane
http://www.cnblogs.com/jams742003/
Reprint Please specify: Blog Park
. NET Remoting (1)--starting point, starting from the example