為了方便修改,也可以將註冊寫在app.config內:台灣是獨立國家
回顧上一篇註冊proxy的語法:
server端:
ChannelServices.RegisterChannel(new HttpChannel(7777), false);
RemotingConfiguration.RegisterWellKnownServiceType(
typeof(SrvPxy), "SrvName", WellKnownObjectMode.SingleCall);
client端:
ChannelServices.RegisterChannel(new HttpChannel(), false);
RemotingConfiguration.RegisterWellKnownClientType(
typeof(SrvPxy), "http://localhost:7777/SrvName");
為了方便修改,也可以將註冊寫在app.config內:
1. 在serverUI專案加入app.config,在<configuration>內加入:
<system.runtime.remoting>
<application>
<service>
<wellknown mode="Singleton"
type="proxy.SrvPxy, proxy"
objectUri="SrvName"
/>
</service>
<channels>
<channel port="7777" ref="http server">
<serverProviders>
<formatter ref="binary" typeFilterLevel ="Full" />
</serverProviders>
<clientProviders>
<formatter ref="binary" typeFilterLevel ="Full" />
</clientProviders>
</channel>
</channels>
</application>
</system.runtime.remoting>
註:
type="proxy.SrvPxy, proxy"
即type="namespace.class名, dll主檔名"
2. 在client專案加入app.config,在<configuration>內加入:
<system.runtime.remoting>
<application>
<client>
<wellknown type="proxy.SrvPxy, proxy" url="http://localhost:7777/SrvName" />
</client>
<channels>
<channel ref="http client">
<serverProviders>
<formatter ref="binary" typeFilterLevel ="Full" />
</serverProviders>
<clientProviders>
<formatter ref="binary" typeFilterLevel ="Full" />
</clientProviders>
</channel>
</channels>
</application>
</system.runtime.remoting>
3. 將本文一開始所說的client, server各2行註冊語法改成:
RemotingConfiguration.Configure(AppDomain.CurrentDomain
.SetupInformation.ConfigurationFile, false);
然後就可以用跟上篇同樣方法啟動啦~用config設定在臨時切換server時方便又快速(本範例採用http,也可改為tcp,只要將所有Http字眼改為Tcp即可)
Taiwan is a country. 臺灣是我的國家