. NET Remoting application instance

Source: Internet
Author: User

Preface used in the project. NET Remoting. I also read it some time ago. NET Remoting related information, I feel that I should write an instance to sort it out. NET Remoting. If you have any questions, please correct them. A brief introduction is an ASP. NET web application developed using Visual Studio 2010 in the. NET Framework 4.0 Framework. Use IIS 7.5. The basic idea is to build the following solutions based on your application in the project. Buseniess: business logic layer MyInterface: interface, similar to the Contract NetRemotingWeb in WCF: performance Layer RemotingClient: client RemotingServer: Basic Principle of the server: implementation process 1. the server is on the web. config to configure the channel and property copy Code <system. runtime. remoting> <application> <service> <wellknown mode = "Singleton" type = "RemotingServer. myServer, RemotingServer "objectUri =" MyServer. rem "/> </service> <channels> <channel ref =" http "> <serverProviders> <formatter ref =" binary "typeFilterLevel =" Full "/> </ServerProviders> <clientProviders> <formatter ref = "binary"/> </clientProviders> </channel> </channels> </application> <customErrors mode = "off "/> </system. runtime. remoting> copy the code objectUri to point to MyServer. In MyServer, you can simply copy the code public class MyServer: externalbyrefobject, IMyInterface {public string sayHello (string name) {return "Hello: "+ name ;}} to remotely call the copied code, you must inherit MarshalByRefObject and expose an interface in IMyInte In rface. 2. the client must reference the following namespace using System. runtime. remoting. channels; using System. runtime. remoting. channels. http; using System. runtime. remoting; using System. runtime. remoting. lifetime; using System. collections. specialized; server address const string OBJECT_URL = "MyServer. rem "; const string REMOTING_URL =" http://127.0.0.1:8039/ "; In fact, you can configure it in the config file. Here, I will write it in the program. Define the channel and instantiate the proxy copy code if (ChannelServices. getChannel ("DataProClient") = null) {ListDictionary channelProperties = new ListDictionary (); channelProperties. add ("port", 0); channelProperties. add ("name", "DataProClient"); channelProperties. add ("timeout",-1); channelProperties. add ("proxyName", ""); BinaryServerFormatterSinkProvider provider = new BinaryServerFormatterSinkProvider (); provider. typeFilterLev El = System. runtime. serialization. formatters. typeFilterLevel. full; HttpChannel channel = new HttpChannel (channelProperties, new BinaryClientFormatterSinkProvider (), provider); ChannelServices. registerChannel (channel, false);} client_server = (MyInterface. IMyInterface) RemotingServices. connect (typeof (MyInterface. IMyInterface), strUri); copy the code strUri = REMOTING_URL + OBJECT_URL; here, it is necessary to check whether the channel is empty, and it may cause "the connection Channel occupied "causes the channel creation to fail. Call the server's public string say (string name) {string word = client_server.sayHello (name); return word;} 3. the business logic layer instantiates the Client to call its method public string sayHello (string name) {client Client = new client (); string s = Client. say (name); return s ;}

Related Article

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.