簡體   English   中英

Windows服務啟動,然后立即停止(代碼問題?)

[英]Windows Service starts then immediately stops (code issue?)

我使用WCF制作了以下服務,並按照MSDN“ 制作Windows服務 ”教程中的指定方式進行了安裝,但是每次我啟動該服務時,都會彈出一個對話框 ,指出該服務已啟動和停止。 我想知道為什么會這樣以及如何糾正它。

服務代碼:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.ServiceModel;
using System.ServiceModel.Description;
using RemoteArchiverService;
namespace ORService
{
    public partial class ORservice : ServiceBase
    {
        private ServiceHost ORAHost;
        public ORservice()
        {
            InitializeComponent();
        }
        protected override void OnStart(string[] args)
        {
            if (ORAHost != null)
            {
                ORAHost.Close();
            }
            // Open the ServiceHostBase to start listening for commands
            ORAHost = new ServiceHost(typeof(OrionWCF));
            ORAHost.Open();
        }
        protected override void OnStop()
        {
            ORAHost.Close();//stop listening
        }
    }
    [ServiceContract(Namespace = "http://Blah.Blargh.ServiceBase")]
    public interface IRemoteArchive
    {
        //functions
        [OperationContract]
        void CollectFilesAsync(DateTime start, DateTime end);
        [OperationContract]
        void ChangeExpireCheck(int daysToKeep);
        [OperationContract]
        void UpdateActiveProfiles(Profile P, bool AddRemove);
        [OperationContract]
        void UpdateProfileList(Profile P, bool AddRemove);
    }
    partial class OrWCF : IRemoteArchive
    {
        private List<Profile> ProfileList = new List<Profile>();
        private List<Profile> ActiveProfiles = new List<Profile>();
        private int DaysToKeepData = 30;

        public void UpdateProfileList(Profile P, bool AddRemove)
        {
            ...
        }
        public void UpdateActiveProfiles(Profile P, bool AddRemove)
        {
            ...
        }
        public void ChangeExpireCheck(int daysToKeep)
        {
            ...
        }
        public void CollectFilesAsync(DateTime start, DateTime end)
        {
            ...
        }
    }
}

日志讀取:

服務無法啟動。 System.InvalidOperationException:服務'RemoteService.OrWCF'的應用程序端點(非基礎結構)為零。 這可能是因為沒有為您的應用程序找到配置文件,或者是因為在配置文件中找不到與服務名稱匹配的服務元素,或者因為在服務元素中未定義端點。 在System.ServiceModel.Description.DispatcherBuilder.EnsureThereAreApplicationEndpoints(ServiceDescription描述)在System.ServiceModel.Description.DispatcherBuilder.InitializeServiceHost(ServiceDescription描述,ServiceHostBase serviceHost)在System.ServiceModel.ServiceHostBase.InitializeRuntime()在System.ServiceModel.ServiceHostBase.OnBeginOpen() )在System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan超時)在System.ServiceModel.Channels.CommunicationObject.Open()在RemoteService.ORservice.OnStart(String [] args )在C:\\ Us ...

啟用WCF跟蹤以查看有關問題的詳細信息。

<configuration>
   <system.diagnostics>
      <sources>
            <source name="System.ServiceModel" 
                    switchValue="Information, ActivityTracing"
                    propagateActivity="true">
            <listeners>
               <add name="traceListener" 
                   type="System.Diagnostics.XmlWriterTraceListener" 
                   initializeData= "c:\log\Traces.svclog" />
            </listeners>
         </source>
      </sources>
   </system.diagnostics>
</configuration>

有關WCF配置的詳細信息,請參見MSDN

根據新信息進行編輯:無法在App.Config文件中找到WCF服務端點配置,請參閱http://msdn.microsoft.com/zh-cn/library/ms733932.aspx

暫無
暫無

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

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