簡體   English   中英

Windows服務錯誤啟動服務時

[英]Error in Windows service While starting the service

我已經創建了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)

有什么事嗎

這行可能引發異常:

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

檢查您的配置文件是否正確; 事件日志查看器將讓您知道問題出在哪里。

考慮使用try and catch查找啟動錯誤並以有用的方式報告它們。

我敢肯定,看看EventViewer,它將包含一些與此錯誤有關的有用信息。 另外,您可以使用如下所示的方法對其進行調試:

如何:調試Windows Service應用程序

您可以在以下位置找到有關此錯誤的很多信息:

http://www.google.com/#sclient=psy&hl=zh-CN&site=&source=hp&q=一個+端點+配置+ section + for + contract +可能+無法+加載+因為+多於+一個+端點+配置+已發現+合同+

如果EventViewer不能幫助您,則應嘗試使用以下方式之一對其進行調試:

  • 在OnStart下放置一個“ Debugger.Break”並與調試器連接。
  • 在OnStart下放置10秒鍾的睡眠時間,並在延遲期間與調試器連接。

如果您的服務的配置文件中有多個具有相同合同類型的端點,則需要指定您感興趣的端點:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM