WCF using windows service
Posted
by Lijo
on Stack Overflow
See other posts from Stack Overflow
or by Lijo
Published on 2010-05-22T09:37:46Z
Indexed on
2010/05/22
9:40 UTC
Read the original article
Hit count: 312
wcfservice
Hi,
I am creating a WCF service which is to be hosted in Windows Service. I created a console application as follows
I went to management console (services.msc) and started the service. But I got the following error "The LijosWindowsService service on Local Computer started and then stopped. Some services stop automatically if they have no work to do, for example, the Performance Logs and Alerts service"
I went to the event viewer and got the following "Service cannot be started. System.InvalidOperationException: Service 'Lijo.Samples.WeatherService' has zero application (non-infrastructure) endpoints. This might be because no configuration file was found for your application, or because no service element matching the service name could be found in the configuration file, or because no endpoints were defined in the service element."
Could you please let me know what is the missing link here?
File name [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>
Thanks
Lijo
© Stack Overflow or respective owner