我正在创建一个要在Windows服务中托管的WCF服务。我创建了一个控制台应用程序,如下所示使用Windows服务的WCF
我去了管理控制台(services.msc)并启动了服务。但我得到了以下错误
上 本地计算机LijosWindowsService服务启动后又停止 。一些服务自动停止 如果他们没有工作 做,例如,性能日志 和警报服务
我去的事件查看器,并得到了以下
服务不能启动。 System.InvalidOperationException: 服务'Lijo.Samples.WeatherService' 没有应用程序 (非基础设施)端点。这 可能是因为没有配置文件 发现你的应用程序,或 因为匹配 服务名称没有服务元素可以在 配置文件中找到,或者因为没有 终点在服务 元素定义。
您能否让我知道这里缺少的链接是什么?
文件名[LijosService.cs]
using System.ComponentModel;
using System.ServiceModel;
using System.ServiceProcess;
using System.Configuration;
using System.Configuration.Install;
namespace Lijo.Samples
{
[ServiceContract(Namespace = "http://Lijo.Samples")]
public interface IWeather
{
[OperationContract]
double Add(double n1, double n2);
}
public class WeatherService : IWeather
{
public double Add(double n1, double n2)
{
double result = n1 + n2;
return result;
}
}
public class MyWindowsService : ServiceBase
{
public ServiceHost serviceHost = null;
public MyWindowsService()
{
// Windows Service name
ServiceName = "LijosWindowsService";
}
public static void Main()
{
ServiceBase.Run(new MyWindowsService());
}
protected override void OnStart(string[] args)
{
if (serviceHost != null)
{
serviceHost.Close();
}
serviceHost = new ServiceHost(typeof(WeatherService));
serviceHost.Open();
}
protected override void OnStop()
{
if (serviceHost != null)
{
serviceHost.Close();
serviceHost = null;
}
}
}
// ProjectInstaller
[RunInstaller(true)]
public class ProjectInstaller : Installer
{
private ServiceProcessInstaller myProcess;
private ServiceInstaller myService;
public ProjectInstaller()
{
myProcess = new ServiceProcessInstaller();
myProcess.Account = ServiceAccount.LocalSystem;
myService = new ServiceInstaller();
myService.ServiceName = "LijosWindowsService";
Installers.Add(myProcess);
Installers.Add(myService);
}
}
}
的App.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<service name="Lijo.Samples.WeatherService"
behaviorConfiguration="WeatherServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8000/ServiceModelSamples/LijosService"/>
</baseAddresses>
</host>
<endpoint address=""
binding="wsHttpBinding"
contract="Lijo.Samples.IWeather" />
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="WeatherServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="False"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
感谢
Lijo
你的配置和代码看起来不错 - 你肯定**有一个'(yourapplication).exe.config'文件在'(yourapplication)相同的目录中。 exe'位于您的服务推出的位置? – 2010-05-22 10:16:10
谢谢....当我将exe.config放入所需文件夹时,一切正常。 – Lijo 2010-05-22 10:42:04