Windows服务托管一个WCF服务立即关闭
我试着托管一个WCF图书馆服务与Windows服务项目,我安装了服务,但是,当我启动service.msc服务,服务启动和立即关闭。继显示的消息之后:Windows服务托管一个WCF服务立即关闭
本地的Servicel服务 计算机已启动,然后停止。 如果 某些服务未被其他服务 或程序使用,某些服务会自动停止。
的App.config
文件WCF和Windows服务项目是相同的,其计算方法如下:
<?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 service项目中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;
}
}
}
}
得到了问题,当我回顾我的事件日志,我发现这一点:
"Service cannot be started. System.InvalidOperationException: The HttpGetEnabled property of ServiceMetadataBehavior is set to true and the HttpGetUrl property is a relative address, but there is no http base address. Either supply an http base address or set HttpGetUrl to an absolute address.
at System.ServiceModel.Description.ServiceMetadataBehavior.EnsureGetDispatcher(ServiceHostBase host, ServiceMetadataExtension mex, Uri url, String scheme)
at System.ServiceModel.Description.ServiceMetadataBehavior.CreateHttpGetEndpoints(ServiceDescription description, ServiceHostBase host, ServiceMetadataExtension mex)
at System.ServiceModel.Description.ServiceMetadataBehavior.ApplyBehavior(ServiceDescription description, ServiceHostBase host)
at System.ServiceModel.Description.ServiceMetadataBehavior.System.ServiceModel.Description.IServiceBehavior.ApplyDispatchBehavior(ServiceDescription description, ServiceHostBase serviceHostBase)
at System.ServiceModel.Description.DispatcherBuilder.InitializeServiceHost(ServiceDescript..."
然后彻底审查后,问题是,我没有HTTPSGETENABLED假只有一个,事实上有两种,使后另一个的变化,应用程序开始像魅力工作。
我特
我发现了什么非常混乱(也可能是.NET运行时,太)是事实,你的Windows服务被称为Service1
,而WCF服务也被称为Service1
(没有命名空间或任何东西) 。
那么这两个Service1
类类型中的哪一个将在这里使用???
MyServiceHost = new ServiceHost(typeof(Service1));
我不知道 - 我恐怕这将是错误类(在Windows NT服务类)。
你应该给你的东西更有意义的名字,并保持这些东西分开(按名称)!
谢谢marc_s,我想在这种情况下运行wcf。你能告诉我怎么做这个改变。非常感谢让我理解错误。我试图从http://msdn.microsoft.com/en-us/library/ff649818执行。aspx,我不擅长c# – surpavan
@surpavan:只需将WCF服务类重命名为MyWCFService,然后使用MyServiceHost = new ServiceHost(typeof(MyWCFService));'。这样,你有两个不同的名字 - 'Service1'是你的主机,NT服务,而'MyWCFService'是WCF服务(顾名思义) –
我很抱歉说我无法做到这一点,这对我来说很让人困惑,你能否做出这样的改变并给我一些文件/文件,以便我能比较和理解它在哪里或者它是什么。感谢一切,直到现在。 – surpavan
您需要在您的帖子中提供有关此问题的更多信息,而不是依赖可下载的项目。问题及其答案应该对所有人都有益。 –
可否请你告诉我需要更多的信息,因为我认为我提到了这个问题,我是新来的编码,请让我知道什么是更多的信息是必需的。谢谢。 – surpavan
一个好的开始是在服务的Start方法中显示代码。任何其他可能相关的信息都是值得欢迎的。 –