C# Windows服务启动后立即停止(代码问题?)
我使用WCF创建了以下服务,并按照MSDN“”教程中指定的方式进行安装,但每次启动该服务时,都会弹出一个窗口,说明该服务已启动和停止。我想知道为什么会发生这种情况,以及如何纠正它 服务代码:C# Windows服务启动后立即停止(代码问题?),c#,visual-studio-2010,wcf,windows-services,C#,Visual Studio 2010,Wcf,Windows Services,我使用WCF创建了以下服务,并按照MSDN“”教程中指定的方式进行安装,但每次启动该服务时,都会弹出一个窗口,说明该服务已启动和停止。我想知道为什么会发生这种情况,以及如何纠正它 服务代码: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.Linq; using System.
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.Collections.Generic;
使用系统组件模型;
使用系统数据;
使用系统诊断;
使用System.Linq;
使用System.ServiceProcess;
使用系统文本;
使用System.ServiceModel;
使用System.ServiceModel.Description;
使用RemoteArchiversService;
命名空间或服务
{
公共部分类或服务:ServiceBase
{
专用服务主机;
公共或服务()
{
初始化组件();
}
启动时受保护的覆盖无效(字符串[]args)
{
if(ORAHost!=null)
{
ORAHost.Close();
}
//打开ServiceHostBase以开始侦听命令
ORAHost=新的服务主机(typeof(OrionWCF));
ORAHost.Open();
}
受保护的覆盖void OnStop()
{
ORAHost.Close();//停止侦听
}
}
[ServiceContract(命名空间=”http://Blah.Blargh.ServiceBase")]
公共接口IRemoteArchive
{
//功能
[经营合同]
void collectFileAsync(日期时间开始,日期时间结束);
[经营合同]
无效更改到期检查(int DAYSTOKEP);
[经营合同]
无效更新活动配置文件(配置文件P,bool AddRemove);
[经营合同]
作废更新配置文件列表(配置文件P,bool AddRemove);
}
部分类OrWCF:IRemoteArchive
{
私有列表ProfileList=新列表();
私有列表ActiveProfiles=新列表();
私有int DAYSTOKEPDATA=30;
公共无效更新配置文件列表(配置文件P,bool AddRemove)
{
...
}
公共无效更新活动配置文件(配置文件P,bool AddRemove)
{
...
}
公共无效更改过期检查(int DAYSTOKEP)
{
...
}
public void collectFileAsync(日期时间开始,日期时间结束)
{
...
}
}
}
日志读数:
服务无法启动。System.InvalidOperationException:服务
“RemoteService.OrWCF”没有应用程序
(非基础设施)端点。这可能是因为没有配置
找不到应用程序的文件,或者因为没有服务元素
在配置文件中可以找到匹配的服务名称,或者
因为服务元素中未定义终结点。在
System.ServiceModel.Description.DispatcherBuilder.EnsureThereArea应用程序点(ServiceDescription
说明)在
System.ServiceModel.Description.DispatcherBuilder.InitializeServiceHost(ServiceDescription
说明,ServiceHostBase(serviceHost)位于
System.ServiceModel.ServiceHostBase.InitializeRuntime()位于
System.ServiceModel.ServiceHostBase.OnBeginOpen()位于
位于的System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan超时)
System.ServiceModel.Channel.CommunicationObject.Open(时间跨度
超时)在System.ServiceModel.Channels.CommunicationObject.Open()处
在C:\Us中的RemoteService.ORservice.OnStart(字符串[]args)处
启用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>
根据新信息编辑:
在App.Config文件中找不到WCF服务端点配置,请参阅。应用程序日志中怎么说?运行eventvwr以了解。。。然后告诉我们。编辑以包含日志信息您的配置是否正常?你能加上吗?你用什么装订?终点是什么?弄清楚了。我没有实现任何hostingI只是在事件查看器中添加了日志问题(如果有用的话)