宿主程序为windows服务的remoting

 1<xmp>   
 2remoting一般宿主在windows服务里.   
 3新建一个windows服务,在OnStart方法里写入如下代码:   
 4protected override void OnStart(string[] args)   
 5{   
 6// TODO: 在此处添加代码以启动服务。   
 7EventLog myLog=new EventLog();   
 8myLog.Source="MonthListService";   
 9bool failed=false;   
10try   
11{   
12RemotingConfiguration.Configure(@"MonthService.exe.config");   
13myLog.WriteEntry("从配置文件MontService.exe.config配置成功!");   
14}   
15catch(Exception ex)   
16{   
17myLog.WriteEntry("配置失败"+ex.Message,EventLogEntryType.Error);   
18failed=true;   
19}   
20if(failed==true)   
21{   
22//MessageBox.   
23}   
24}   
25配置文件MonthService.exe.config的内容如下,因为Machine.config里有已经配置好的channel等,所以用channel ref="tcp server" port="8085"来引用Machine.config里的设置.   
26<configuration>
27<system.runtime.remoting>
28<application name="VersionHost">
29<channels>
30<channel port="8085" ref="tcp server"></channel>
31</channels>
32<service>
33<wellknown displayname="MyService" mode="SingleCall" objecturi="Version" type="VersionDemo.VersionServer,VersionServer,Version=2.0.0.0"></wellknown>
34</service>
35</application>
36<debug loadtype="true"></debug>
37</system.runtime.remoting>
38</configuration>   
39  
40  
41使用installunit exeFilePath来注册到windows服务即可.   
42</xmp>
Published At
Categories with Web编程
Tagged with
comments powered by Disqus