Remoting's understanding of "passed references"

Source: Internet
Author: User

WCF is a mass integrator and has many other Microsoft technologies, among which remoting is widely used in distributed architecture. Therefore, it is helpful to understand the concept of remoting.

When remoting is mentioned, it has to involve the marshalbyrefobject object. The explanation of the word on the network is very vague. In particular, "cross-origin access, remoting is a reference transfer, not a value transfer ", instead, I didn't talk about what the "reference transfer" is. In some cases, I did talk about how to pass all the content that requires interaction through the objref object, however, we do not have a clear understanding of "reference transfer", or we use other methods to understand "reference transfer" rather than "reference transfer" to better understand remoting, this logical way of thinking is especially prone to vague concepts, which seem to be clear, but actually do not understand.

An example is written to understand the reference transfer, which may help you understand the code.

Define Interface

public interface IPersonService    {        String HelloMethod(String name);    }

Define implement

public class PersonService : MarshalByRefObject, IPersonService{    public String HelloMethod(String name)    {        Console.WriteLine(            "Server Hello.HelloMethod : {0}", name);        return "Hi there " + name;    }}

Define Service
Static void main (string [] ARGs) {// tcpchannel chan1 = new tcpchannel (8085 ); // for remote calls, the client channel httpchannel chan2 = new httpchannel (8086) that uses http to transmit messages ); // provides static methods to help you remotely process channel registration, resolution, and URL discovery. This class of channelservices cannot be inherited. registerchannel (chan1, false); channelservices. registerchannel (chan2, false); // provides a variety of static methods for remote Structure Configuration remotingconfiguration. registerwellknownservicetype (// typeof (helloserver), typeof (personservice), "sayhello", wellknownobjectmode. singleton); system. console. writeline ("Press ENTER key to exit"); system. console. readline ();}
Define Client
Class program {static void main (string [] ARGs) {tcpchannel chan1 = new tcpchannel (); channelservices. registerchannel (chan1, false); // activator contains specific methods for creating object types locally or remotely, or obtaining references to existing remote objects. Unable to inherit this class ipersonservice obj1 = (ipersonservice) activator. getObject (typeof (ipersonservice), // typeof (helloserver), "TCP: // localhost: 8085/sayhello"); If (obj1 = NULL) {system. console. writeline ("cocould not locate TCP server");} // use the HTTP channel to obtain the remote object httpchannel chan2 = new httpchannel (); channelservices. registerchannel (chan2, false); ipersonservice obj2 = (ipersonservice) activator. getObject (typeof (ipersonservice), // typeof (helloserver), "http: // localhost: 8086/sayhello"); If (obj2 = NULL) {system. console. writeline ("cocould not locate HTTP server");} console. writeline ("Client1 TCP hellomethod {0}", obj1.hellomethod ("caveman1"); console. writeline ("Client2 HTTP hellomethod {0}", obj2.hellomethod ("caveman2"); console. readline ();}}

Note that the "ipersonservice" interface used by the client does not know the instance class of the interface for the client,

Client method calls only package the call information and link information through the proxy object generated by activator,

After receiving the packaged information, the server performs operations on the corresponding classes and methods based on the packaging information, such as creating (calling) service entities and calling methods, package the returned values and transmit them to the client. Further research is required on the specific logic.

Here, I just want to explain what the meaning of "remoting transmission reference" means, so as not to misunderstand it.

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.