. NET Remoting

Source: Internet
Author: User
Tags soap

. NET Remoting is Microsoft's early distributed communications technology, although Microsoft later through the WCF Common basic communication framework is integrated, but through the review of learning remoting, in turn, learning to understand WCF is also very helpful. At the same time through the study of this blog, you can see the charm of remoting technology.

Let's look at a wiki Wikipedia overview of WCF technology. It mentions the technologies of WCF, Web Service, Remoting, socket, and so on. As I mention these nouns, you should be aware of these techniques and know the level at which they are located.

Windows Communication Foundation (WCF) is an application development interface for a set of data communications developed by Microsoft, and it is. NET Framework 3.0, introduced with the Windows Presentation Foundation and Windows Workflow Foundation parallel is a new generation of Windows operating systems and three major application development libraries for WinFX.

In the. NET Framework 2.0 and previous releases, Microsoft developed a Web Service (SOAP with HTTP communication),. NET Remoting (tcp/http/pipeline Communication), as well as basic Winsock communication support, because each communication method is designed differently, and each other also has overlapping with each other (for example,. NET Remoting can develop soap, HTTP communication), for developers, Different options will have different program design models, and must be re-learned, so that developers have a lot of inconvenience to the user. At the same time, service-oriented Architecture (service-oriented Architecture) is also beginning to prevail in the software industry, so Microsoft has re-viewed these communication methods and designed a unified program development model, Provides the most basic and resilient support for data communication, which is the Windows Communication Foundation.

In the early days, there were other communication technologies, such as MSMQ (Message Queuing), COM, COM +, DCOM, and so on. COM is a major invention of Microsoft, which encapsulates complex communication details into a single COM component, allowing. NET programmers to interoperate without having to worry about complex communication details, using only the operational communication model.

A brief introduction to this, looking back at Remoting's communication architecture diagram:

As you can see from the schema diagram, remoting can manipulate the server-side objects directly in the way that the object is proxied.

The following is a basic project to demonstrate the use of remoting.

Let's look at the architecture of the project:

Remotingserver is a remoting server-side console project; Remotingclient is a remoting client console project; Remotingservice is a class library project.

Both Remotingserver and remotingclient need to refer to the System.Runtime.Remoting component. and reference Remotingservice this class library project.

Code in Remotingserver:

      Static voidMain (string[] args) {TcpServerChannel Channel=NewTcpServerChannel (8888); ChannelServices.RegisterChannel (channel,false); RemotingConfiguration.RegisterWellKnownServiceType (typeof(Personidconverter),"Hi", WellKnownObjectMode.SingleCall); Console.WriteLine ("Remoting Service has been started");        Console.ReadLine (); }

Code in Remotingclient:

      Static voidMain (string[] args) {ChannelServices.RegisterChannel (NewTcpClientChannel (),false); Personidconverter Service= (Personidconverter) Activator.GetObject (typeof(Personidconverter),"Tcp://localhost:8888/hi"); if(!Object. Equals (Service,NULL) {Console.WriteLine (service. Personid15to18 ("130503670401001"));//Test ID Number} console.readline (); }

Code in Personidconverter:

    /// <summary>    ///remote service class, inherited from MarshalByRefObject/// </summary>     Public classPersonidconverter:marshalbyrefobject {/// <summary>        ///ID 15 ext. 18 Bit/// </summary>        /// <param name= "id" >15-digit ID number</param>        /// <returns>18-digit ID number</returns>         Public stringPersonid15to18 (stringID) {intis =0; int[] IW =New int[] {7,9,Ten,5,8,4,2,1,6,3,7,9,Ten,5,8,4,2};//weighted Factor constants            stringLastcode ="10x98765432";//Check Code Constants            stringNewId;//New ID NumberNewId = ID. Substring (0,6); NewId+=" +";//Fill in 6th and 7th place ' 1 ', ' 9 ' two digitsNewId + = ID. Substring (6,9); //make a weighted sum             for(inti =0; I < -; i++) { is+=int. Parse (Newid.substring (i,1)) *Iw[i]; }            intIY = is% One;//Modulo operation to get modulo valueNewId + = lastcode.substring (IY,1);//The value of modulo as the index number is obtained from the Lastcode, which is added to the last one of the ID card, which is the new ID number.             returnnewId; }    }

This provides a 15-bit ID to 18-bit service.

The runtime starts the Remotingserver project and then runs the Remotingclient project.

After the server is running:

After the client runs:

You can see that the 15-bit ID number has been successfully converted to 18-bit and the remoting call succeeds.

For more details, refer to the official website: http://msdn.microsoft.com/zh-cn/library/xws7132e (v=vs.100). aspx

. NET Remoting

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.