Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WCF Windows服务无法启动,引发System.IO.FileNotFoundException_C#_.net_Wcf_Windows Services - Fatal编程技术网

C# WCF Windows服务无法启动,引发System.IO.FileNotFoundException

C# WCF Windows服务无法启动,引发System.IO.FileNotFoundException,c#,.net,wcf,windows-services,C#,.net,Wcf,Windows Services,我已经为一个问题争论了好几天了。在我们的解决方案中,我们有一个老化的整体,包括各种ASP.NET技术、一个WCF服务和一些其他Windows服务。一切都是为我的同事构建的,服务也都正确启动。我已经有一段时间没有在巨石上工作了,当我把注意力转向它时,我经历了各种各样的错误,包括一个我仍然没有解决的错误。为了让我们的WCF工作,我们必须运行一个充当WCF主机的Windows服务。当我尝试启动此服务时,它爆炸了,弹出以下对话框: Windows无法在本地计算机上启动{name of service}服

我已经为一个问题争论了好几天了。在我们的解决方案中,我们有一个老化的整体,包括各种ASP.NET技术、一个WCF服务和一些其他Windows服务。一切都是为我的同事构建的,服务也都正确启动。我已经有一段时间没有在巨石上工作了,当我把注意力转向它时,我经历了各种各样的错误,包括一个我仍然没有解决的错误。为了让我们的WCF工作,我们必须运行一个充当WCF主机的Windows服务。当我尝试启动此服务时,它爆炸了,弹出以下对话框:

Windows无法在本地计算机上启动{name of service}服务。 错误1064:处理控制请求时,服务中发生异常

通过检查事件查看器,我在Windows日志/应用程序中发现此.NET运行时错误:

Application: {redacted full path/name of WCF service host}.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.IO.FileNotFoundException

Exception Info: System.IO.FileNotFoundException
   at System.ServiceModel.Channels.HttpChannelListener..ctor(System.ServiceModel.Channels.HttpTransportBindingElement, System.ServiceModel.Channels.BindingContext)
   at System.ServiceModel.Channels.HttpChannelListener`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]..ctor(System.ServiceModel.Channels.HttpTransportBindingElement, System.ServiceModel.Channels.BindingContext)
   at System.ServiceModel.Channels.HttpTransportBindingElement.BuildChannelListener[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]](System.ServiceModel.Channels.BindingContext)
   at System.ServiceModel.Channels.Binding.BuildChannelListener[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]](System.Uri, System.String, System.ServiceModel.Description.ListenUriMode, System.ServiceModel.Channels.BindingParameterCollection)
   at System.ServiceModel.Description.ServiceMetadataExtension.CreateGetDispatcher(System.Uri, System.ServiceModel.Channels.Binding, System.String)
   at System.ServiceModel.Description.ServiceMetadataExtension.EnsureGetDispatcher(System.Uri, Boolean)
   at System.ServiceModel.Description.ServiceMetadataBehavior.EnsureGetDispatcher(System.ServiceModel.ServiceHostBase, System.ServiceModel.Description.ServiceMetadataExtension, System.Uri, System.String)
   at System.ServiceModel.Description.ServiceMetadataBehavior.CreateHttpGetEndpoints(System.ServiceModel.Description.ServiceDescription, System.ServiceModel.ServiceHostBase, System.ServiceModel.Description.ServiceMetadataExtension)
   at System.ServiceModel.Description.DispatcherBuilder.InitializeServiceHost(System.ServiceModel.Description.ServiceDescription, System.ServiceModel.ServiceHostBase)
   at System.ServiceModel.ServiceHostBase.InitializeRuntime()
   at System.ServiceModel.ServiceHostBase.OnOpen(System.TimeSpan)
   at System.ServiceModel.Channels.CommunicationObject.Open(System.TimeSpan)
   at {elided - a few more stack trace lines referring to our custom code}
同样在同一个事件查看器日志中,我有此应用程序错误(紧跟在.NET运行时错误之后):

在过去的一年半里,我一直在使用VS2019的.NETCore中工作,所以我想可能框架所需的一些配置或SDK已经丢失了。我的机器上还有2017年,这也是我的同事们更喜欢使用的单片解决方案。现在,在这几天里,我做了以下工作:

  • 已卸下和/或安装各种SDK和瞄准包
  • 修复VS 2017
  • 已卸载并重新安装VS 2017
  • 修复VS 2019
  • 已卸载并重新安装VS 2019
  • 多次卸载并重新安装Windows服务

我从我头上的网络搜索结果中得到了最模糊的提示,一些绑定重定向可能有问题。起初我可以发誓我看到了FileNotFound存在于System.Net.Http中的证据,但现在我似乎找不到任何对我有指示意义的东西。在这一点上,我完全被它烧坏了,我正在考虑擦除整个系统,然后从一个干净的Windows安装开始。如果我不得不那样做,那真是太遗憾了。如果您对要查找的位置或尝试的内容有最模糊的提示,我们将不胜感激。

这可能是因为服务启动时找不到WCF配置文件,而WCF配置文件无法正常启动

您需要检查服务名称的值,服务名称不是随机设置的,这是服务接口的实现类

上图是WCF服务的接口和实现类

有关在windows服务中托管WCF的更多详细信息,请参阅以下链接:


是的。事实证明,必须在所有app.cong文件中手动更改System.Net.Http的绑定重定向。我不知道为什么,但它奏效了。不过,我想说的是,你的回答可能会对处于类似情况的其他人有所帮助。
Faulting application name: {service name}.exe, version: 4.2.0.0, time stamp: 0x5f0f45ce
Faulting module name: KERNELBASE.dll, version: 10.0.18362.815, time stamp: 0xb89efff3
Exception code: 0xe0434352
Fault offset: 0x000000000003a799
Faulting process id: 0xd84
Faulting application start time: 0x01d65ad32192a62b
Faulting application path: {full service path/name}.exe
Faulting module path: C:\WINDOWS\System32\KERNELBASE.dll
Report Id: 1db8e59a-b3a0-47e3-bb0f-5d8c6e2f8ed5
Faulting package full name: 
Faulting package-relative application ID: