. NET Remoting (1)--starting point, starting from the example

Source: Internet
Author: User

. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.