[Remoting series] 12: Configuration File

Source: Internet
Author: User
Replacing hard encoding with configuration files can make applications more flexible. Especially for distributed systems, this means that we can easily adjust the configuration of distributed objects. The remoting configuration file is relatively simple. For details, refer to msdn.

MS - Help: // Ms. msdnqtr. v80.chs/ms. msdn. v80/ms. netdevfx. v1_chs/dv_fxgenref/html/52ebd450-de87-4a87-8bb9-6b13108fbc63.htm

The following is a simple example, including Sao / Configuration example of Cao.

Server. CS
Binaryclientformattersinkprovider cbin =   New Binaryclientformattersinkprovider ();
Binaryserverformattersinkprovider sbin =   New Binaryserverformattersinkprovider ();
Sbin. typefilterlevel = Typefilterlevel. Full;

Hashtable Properties =   New Hashtable ();
Properties [ " Port " ] =   801 ;

Tcpchannel Channel =   New Tcpchannel (properties, cbin, sbin );
Channelservices. registerchannel (channel, False );

Remotingconfiguration. registerwellknownservicetype ( Typeof (Data ), " Data " , Wellknownobjectmode. Singleton );
Remotingconfiguration. applicationname =   " Test " ;
Remotingconfiguration. registeractivatedservicetype ( Typeof (Data2 ));

Client. CS
Tcpchannel Channel =   New Tcpchannel ();
Channelservices. registerchannel (channel, False );
Remotingconfiguration. registerwellknownclienttype ( Typeof (Data ), " TCP: // localhost: 801/Data " );
Remotingconfiguration. registeractivatedclienttype ( Typeof (Data2 ), " TCP: // localhost: 801/test " );

Data data =   New Data ();
Data. Test ();

Data2 data2 =   New Data2 ();
Data2.test ();

Change to the corresponding configuration file.

Server. config
<? XML version = " 1.0 " Encoding = " UTF-8 "   ?>
< Configuration >
< System. runtime. remoting >
< Application name = " Test " >
< Channels >
< Channel Ref = " TCP " Port = " 801 " >
< Clientproviders >
< Formatter Ref = " Binary " />
</ Clientproviders >
< Serverproviders >
< Formatter Ref = " Binary " Typefilterlevel = " Full "   />
</ Serverproviders >
</ Channel >
</ Channels >
< Service >
< Wellknown Mode = " Singleton " Type = " Learn. Library. remoting. Data, learn. Library " Objecturi = " Data "   />
< Activated type = " Learn. Library. remoting. data2, learn. Library "   />
</ Service >
</ Application >
</ System. runtime. remoting >
</ Configuration >

Client. config
<? XML version = " 1.0 " Encoding = " UTF-8 "   ?>
< Configuration >
< System. runtime. remoting >
< Application >
< Channels >
< Channel Ref = " TCP " >
< Clientproviders >
< Formatter Ref = " Binary " />
</ Clientproviders >
</ Channel >
</ Channels >
< Client URL = " TCP: // localhost: 801/test " >
< Wellknown type = " Learn. Library. remoting. Data, learn. Library " URL = " TCP: // localhost: 801/Data "   />
< Activated type = " Learn. Library. remoting. data2, learn. Library "   />
</ Client >
</ Application >
</ System. runtime. remoting >
</ Configuration >

Server. CS
Remotingconfiguration. Configure ( " Server. config " , False );

Client. CS
Remotingconfiguration. Configure ( " Client. config " , False );

Data data =   New Data ();
Data. Test ();

Data2 data2 =   New Data2 ();
Data2.test ();
[Last modified by yuyun

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.