remoting作成windows服务后一直无法读取配置文件,可能的原因之一。

当然在这个无法读取配置文件,无法启动通道之前,你必须确认你的配置文件是正确的。正确的动态配置remoting的格式是:

<configuration>  
  
<system.runtime.remoting>
    
<application>
      
<service>
        
<wellknown type="HappyWeb.BLL.PublishNewsClass,HappyWeb.BLL" objectUri="HappyWeb.BLL.PublishNewsClass"
                    mode
="Singleton" />
        
<wellknown type="HappyWeb.BLL.MemberLoginCheck,HappyWeb.BLL" objectUri="HappyWeb.BLL.MemberLoginCheck"
                    mode
="Singleton" />
        
<wellknown type="HappyWeb.BLL.PublishPartsNews,HappyWeb.BLL" objectUri="HappyWeb.BLL.PublishPartsNews"
                    mode
="Singleton" />
      
</service>
      
<channels>
        
<channel ref="tcp" port="9999">
          
<serverProviders>
            
<formatter ref="binary" typeFilterLevel="Full" />
          
</serverProviders>
        
</channel>
      
</channels>
    
</application>
  
</system.runtime.remoting>
</configuration>

里面type的格式是 <namespace>.<class>, <assembly>

无法启动服务。System.Runtime.Remoting.RemotingException: 因发生异常“System.IO.FileNotFoundException: 系统找不到指定的文件。 (异常来自 HRESULT:0x80070002)
   在 System.ConfigServer.RunParser(IConfigHandler factory, String fileName)
   在 System.ConfigTreeParser.Parse(String fileName, String configPath, Boolean skipSecurityStuff)
   在 System.Runtime.Remoting.RemotingConfigHandler.LoadConfigurationFromXmlFile(String filename)”而无法成功读取 .Config 文件“xxx.WindowsService.exe.config”。
   在 System.Runtime.Remoting.RemotingConfigHandler.LoadConfigurationFromXmlFile(String filename)
   在 System.Runtime.Remoting.RemotingConfigHandler.DoConfiguration(String filename, Boolean ensureSecurity)
   在 System.Runtime.Remoting.RemotingConfiguration.Configure(String filename, Boolean ensureSecurity)
   在 xxxx.WindowsService.srvMain.OnStart(String[] args)
   在 System.ServiceProcess.ServiceBase.ServiceQueuedMainCallback(Object state)




因为我的软件服务端先是做成应用程序,后面才转Windows服务,

所以我可以确认我的代码是没错的,同样REMOTING的配置也是没问题的。

后面用监控WINDOWS文件读取工具,发现里面有一条记录
CreateFile
C:\WINDOWS\system32\HappyWeb.WindowsService.exe.config
NAME NOT FOUND

我猜测着是不是配置文件要放这,想不到还真是。

可是我在GOOGLE上一直搜索不到这种结果,

而网上同学的提示一直是config文件要和exe放在一起,

我想可能是个例吧,如果你也碰到同样的怪事,希望这能帮助到你。

另外也希望高手能解析下为什么。

posted on 2008-06-30 08:59  Blackie  阅读(2875)  评论(3编辑  收藏  举报

导航