【发布时间】:2011-06-30 05:20:02
【问题描述】:
我尝试使用 Windows 服务项目托管 WCF 库服务,我安装了该服务,但是,当我在 services.msc 中启动该服务时,该服务立即启动并关闭。按照显示的消息:
Local 上的 Servicel 服务 计算机启动然后停止。 某些服务会自动停止,如果 它们未被其他服务使用 或程序。
wcf和windows服务项目的App.config文件相同,如下:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<compilation debug="true" />
</system.web>
<!-- When deploying the service library project, the content of the config file must be added to the host's
app.config file. System.Configuration does not support config files for libraries. -->
<system.serviceModel>
<services>
<service name="WorkMateWCF.Service1">
<endpoint address="" binding="netTcpBinding" bindingConfiguration=""
contract="WorkMateWCF.IService1">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexTcpBinding" bindingConfiguration=""
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8523/WorkMate1" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
整个项目/解决方案可在此处下载:https://skydrive.live.com/?cid=d358d316fa2c3a37&sc=documents&uc=1&id=D358D316FA2C3A37%21135#
请您指导我如何进一步进行。谢谢。
附加信息: 以下是windows服务项目中service1.cs文件的代码。
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 WorkMateWCF;
namespace WorkMateWinService
{
public partial class Service1 : ServiceBase
{
internal static ServiceHost MyServiceHost = null;
public Service1()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
if (MyServiceHost != null)
{
MyServiceHost.Close();
}
MyServiceHost=new ServiceHost(typeof( Service1));
MyServiceHost.Open();
}
protected override void OnStop()
{
if (MyServiceHost != null)
{
MyServiceHost.Close();
MyServiceHost = null;
}
}
}
}
【问题讨论】:
-
您需要在帖子中提供有关此问题的更多信息,而不是依赖可下载的项目。这个问题及其答案应该对所有人都有益。
-
你能告诉我还需要什么信息吗,因为我想我提到了这个问题,我是编码新手,请告诉我还需要什么信息。谢谢。
-
一个好的开始是在服务的 Start 方法中显示代码。欢迎提供任何其他相关信息。
-
谢谢 Roy Dictus,我已经添加了。
标签: wcf windows-services