【问题标题】:Error in Windows service While starting the serviceWindows 服务错误 启动服务时
【发布时间】:2011-07-25 05:37:20
【问题描述】:

我已经创建了一个 Windows 服务。

当我在本地计算机上安装服务后尝试启动服务时,出现错误。

我的其他 windows 服务运行良好,只有这个特定的服务给出了这个错误,所以问题与 windows 无关,而与我的服务有关。

可能出了什么问题?

这是我的 Windows 服务:

namespace TempWindowService
{
    public partial class Service1 : ServiceBase
    {
        System.Threading.Thread _thread;
        public Service1()
        {
            InitializeComponent();
        }
       // System.Timers.Timer tm = new System.Timers.Timer(10000);
        protected override void OnStart(string[] args)
        {
            TempWindowService.MyServ.MyServSoapClient newService = new TempWindowService.MyServ.MyServSoapClient();
             //newService.BatchProcess();
             _thread = new Thread(new ThreadStart(newService.BatchProcess));
             _thread.Start();

           // tm.Interval = 1000;
           //tm.Elapsed += new ElapsedEventHandler(TimerElapsedEvent);
           // tm.AutoReset = true;
           // tm.Enabled = true;

        }

        public void StartNew()
        {
            TempWindowService.MyServ.MyServSoapClient newService = new    TempWindowService.MyServ.MyServSoapClient();
            newService.BatchProcess();
        }
        private static void TimerElapsedEvent(object source, ElapsedEventArgs e)
        {

        }


        protected override void OnStop()
        {

        }
    }
}

我通过添加服务引用从 windows 服务调用 web 服务

这就是错误在 EventViewer 中显示的内容

Service cannot be started. System.InvalidOperationException: An endpoint configuration section for contract 'MyServ.MyServSoap' could not be loaded because more than one endpoint configuration for that contract was found. Please indicate the preferred endpoint configuration section by name.
   at System.ServiceModel.Description.ConfigLoader.LookupChannel(String configurationName, String contractName, Boolean wildcard)

可能出了什么问题?

【问题讨论】:

  • 检查事件查看器中是否记录了任何错误。
  • 如果服务在您能够附加调试器之前停止,请查看this question on how to break 的答案。
  • @Sachin 和@Ole_Brun:感谢您的意见。我已将 eventViewer 错误添加到我的问题中。请检查一下,请告诉我可能出了什么问题?

标签: .net .net-3.5 windows-services service


【解决方案1】:

这行很可能抛出异常:

TempWindowService.MyServ.MyServSoapClient newService = new TempWindowService.MyServ.MyServSoapClient();

检查您的配置文件是否存在且正确;事件日志查看器会让您知道问题所在。

考虑使用trycatch 查找启动错误并以有用的方式报告它们。

【讨论】:

  • 感谢您的意见。如何查看事件日志?甚至如何在上面的行中使用try catch?你能用一点代码解释一下吗?
  • 我已将 eventViewer 错误添加到我的问题中。请检查一下,请告诉我可能出了什么问题?
  • 检查您的配置文件,它对服务不正确。检查您是否有一个配置文件,尝试重新创建 Web 服务引用,或者使用服务调用创建控制台应用程序失败,调试它(更容易),然后再次将其变为服务。
【解决方案2】:

看看 EventViewer,我敢肯定,它会包含一些与此错误相关的有用信息。此外,您可以使用以下所示的方法对其进行调试:

How to: Debug Windows Service Applications

您可以在以下位置找到有关此错误的大量信息:

http://www.google.com/#sclient=psy&hl=en&site=&source=hp&q=An+endpoint+configuration+section+for+contract+could+not+be+loaded+because+more+than+one+endpoint+configuration+for+that+contract+was+found

【讨论】:

  • 如何查看 EventViewer?它位于哪里?我是新手,对它了解不多
  • 计算机-->管理-->事件查看器
  • 感谢您的意见。我已将 eventViewer 错误添加到我的问题中。请检查一下,请告诉我出了什么问题?
  • @DevExpress 团队:可能是您提供了错误的链接。您为我提供了重定向到 www.google.co.in 的链接。
  • 只需在 google.com 中输入错误文本。我的链接应该将您重定向到 google.com 页面
【解决方案3】:

如果 EventViewer 对您没有帮助,您应该尝试使用以下方法之一对其进行调试:

  • 在 OnStart 下放置一个“Debugger.Break”并与调试器连接。
  • 在 OnStart 下休眠 10 秒,并在延迟期间连接调试器。

【讨论】:

  • 这有点随机。相反,我建议:while (!Debugger.IsAttached) { Thread.Sleep(1000); } Debugger.Break(); 这样它会等到调试器被附加
  • 好电话@Debugger.IsAttached :)
  • 只记得在部署时取出该代码,否则您的服务将等待调试器附加。最好将其设为 .config 选项、WaitForDebugger 等
【解决方案4】:

如果您的服务的配置文件中有多个具有相同合同类型的端点,则需要指定您感兴趣的端点:

TempWindowService.MyServ.MyServSoapClient newService = new TempWindowService.MyServ.MyServSoapClient("EndPointName");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-16
    • 1970-01-01
    • 2019-09-25
    • 1970-01-01
    • 2010-09-18
    • 1970-01-01
    相关资源
    最近更新 更多