<xmp>
remoting一般宿主在windows服务里.
新建一个windows服务,在OnStart方法里写入如下代码:
protected override void OnStart(string[] args)
{
// TODO: 在此处添加代码以启动服务。
EventLog myLog=new EventLog();
myLog.Source="MonthListService";
bool failed=false;
try
{
RemotingConfiguration.Configure(@"MonthService.exe.config");
myLog.WriteEntry("从配置文件MontService.exe.config配置成功!");
}
catch(Exception ex)
{
myLog.WriteEntry("配置失败"+ex.Message,EventLogEntryType.Error);
failed=true;
}
if(failed==true)
{
//MessageBox.
}
}
配置文件MonthService.exe.config的内容如下,因为Machine.config里有已经配置好的channel等,所以用channel ref="tcp server" port="8085"来引用Machine.config里的设置.
<configuration>
<system.runtime.remoting>
<application name="VersionHost">
<channels>
<channel ref="tcp server" port="8085"/>
</channels>
<service>
<wellknown displayName="MyService" type="VersionDemo.VersionServer,VersionServer,Version=2.0.0.0" mode="SingleCall" objectUri="Version"/>
</service>
</application>
<debug loadType="true"/>
</system.runtime.remoting>
</configuration>
使用installunit exeFilePath来注册到windows服务即可.
</xmp>
本文地址:http://com.8s8s.com/it/it42515.htm