我使用 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 description) 在 System.ServiceModel.Description.DispatcherBuilder.InitializeServiceHost(ServiceDescription description, ServiceHostBase serviceHost) 在 System.ServiceModel.ServiceHostBase.InitializeRuntime() 在 System.ServiceModel.ServiceHostBase.OnBeginOpen( ) 在 System.ServiceModel.ServiceHostBase。