How to: Host WCF in a Windows Service Using TCP

P

Peter

I am trying to host WCF in a Windows Service, and I have created an example
form http://msdn.microsoft.com/en-us/library/cc949080.aspx#
but I am still getting an error message when I try to start the servrice

What am I doing wrong?

Thank You

Peter

Here's the error:

"The Service1 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"

Here's the error from the Application Event Viewer

Event Type: Error
Event Source: Service1
Event Category: None
Event ID: 0
Date: 10/29/2009
Time: 2:31:35 PM
User: N/A
Computer: DEVCON1
Description:
Service cannot be started. System.InvalidOperationException: Service
'WindowsService1.Service1' 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.
at
System.ServiceModel.Description.DispatcherBuilder.EnsureThereAreNonMexEndpoints(ServiceDescription
description)
at
System.ServiceModel.Description.DispatcherBuilder.InitializeServiceHost(ServiceDescription
description, ServiceHostBase serviceHost)
at System.ServiceModel.ServiceHostBase.InitializeRuntime()
at System.ServiceModel.ServiceHostBase.OnBeginOpen()
at System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan
timeout)
at System.ServiceModel.Channels.CommunicationObject.Open()
at WindowsService1.Service1.OnStart(String[] args) in C:\Program
Files\...
 
P

Peter

That's what I am doing trying to start the WCF in OnStart method, and it's
failing on myServiceHost.Open();

protected override void OnStart(string[] args)
{
if (myServiceHost != null)
{
myServiceHost.Close();
}
myServiceHost = new ServiceHost(typeof(Service1));
myServiceHost.Open();

}

Mr. Arnold said:
Peter said:
I am trying to host WCF in a Windows Service, and I have created an
example form http://msdn.microsoft.com/en-us/library/cc949080.aspx#
but I am still getting an error message when I try to start the servrice

What am I doing wrong?

Thank You

Peter

Here's the error:

"The Service1 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"

The NT service can stop if it is hosting something and it aborted.
Here's the error from the Application Event Viewer

Event Type: Error
Event Source: Service1
Event Category: None
Event ID: 0
Date: 10/29/2009
Time: 2:31:35 PM
User: N/A
Computer: DEVCON1
Description:
Service cannot be started. System.InvalidOperationException: Service
'WindowsService1.Service1' 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.
at
System.ServiceModel.Description.DispatcherBuilder.EnsureThereAreNonMexEndpoints(ServiceDescription
description)
at
System.ServiceModel.Description.DispatcherBuilder.InitializeServiceHost(ServiceDescription
description, ServiceHostBase serviceHost)
at System.ServiceModel.ServiceHostBase.InitializeRuntime()
at System.ServiceModel.ServiceHostBase.OnBeginOpen()
at System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan
timeout)
at System.ServiceModel.Channels.CommunicationObject.Open()
at WindowsService1.Service1.OnStart(String[] args) in C:\Program
Files\...

It looks like the WCF service is aborting the NT service at NT service
OnStart() due to the WCF service cannot find its endpoints.


If the WCF was being hosted by IIS as a WCF Web service, WCF Console
application or WCF standalone exe, then a Web or App.config would be used
by the WCF service application that would have the serviceEnd points in
the config file required by the WCF servic.

I don't know if you can have an generated WCF.config file connected to a
NT service application that's hosting a WCF service.

If that's the case, then you would programmically set the service
endpoints via the WCF service at WCF service start-up when the NT service
started. I would suspect on the NT service OnStart().
 
M

Mr. Arnold

<snipped>

I would say look at the example in the link and take note on the app.config
that's being deployed to the Bin directory where the NTservice.exe would be
located so that it can find the app.config that has the end points for the
WCF service.

http://msdn.microsoft.com/en-us/library/ms733069(loband).aspx

I would say make this one work and then go back to your other example and
make necessary adjustments.


__________ Information from ESET NOD32 Antivirus, version of virus signature database 4556 (20091029) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
 
P

Peter

Mr. Arnold said:
<snipped>

I would say look at the example in the link and take note on the
app.config that's being deployed to the Bin directory where the
NTservice.exe would be located so that it can find the app.config that has
the end points for the WCF service.

http://msdn.microsoft.com/en-us/library/ms733069(loband).aspx

I would say make this one work and then go back to your other example and
make necessary adjustments.

__________ Information from ESET NOD32 Antivirus, version of virus
signature database 4556 (20091029) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

I am getting the same error in both examples.
 
M

Mr. Arnold

Peter said:
I am getting the same error in both examples.

I don't know man. I took that example I gave you and followed it to the 'T',
built/compiled the project, installed the NTservice, and started the
service. The service started with no problems and is running on my Vista
machine.


__________ Information from ESET NOD32 Antivirus, version of virus signature database 4559 (20091030) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
 
P

Peter

Mr. Arnold said:
I don't know man. I took that example I gave you and followed it to the
'T', built/compiled the project, installed the NTservice, and started the
service. The service started with no problems and is running on my Vista
machine.


__________ Information from ESET NOD32 Antivirus, version of virus
signature database 4559 (20091030) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
Thanks for your help

I deleted the project and recreated it and it's working now, so obviously I
had something wrong.
And the project at http://msdn.microsoft.com/en-us/library/cc949080.aspx#
has wrong reference

the reference should be
myServiceHost = new ServiceHost(typeof(WcfServiceLibrary1.Service1));

Not
myServiceHost = new ServiceHost(typeof(Service1));
 
R

rani iyer

Hi Peter,

Try to do this in the OnStart() method

myServiceHost = new ServiceHost(typeof(WcfServiceLibrary1.Service1));

The reason for this is both the WcfService and Windows Service contains class as Service1 and if you use the Service1 as given in the link, it refers to WindowsService class file.

Regards,
Rani



Peter wrote:

How to: Host WCF in a Windows Service Using TCP
29-Oct-09

I am trying to host WCF in a Windows Service, and I have created an exampl
form http://msdn.microsoft.com/en-us/library/cc949080.aspx
but I am still getting an error message when I try to start the servric

What am I doing wrong

Thank Yo

Pete

Here is the error

"The Service1 service on Local Computer started and then stopped. Som
services stop automatically if they have no work to do, for example, th
Performance Logs and Alerts service

Here is the error from the Application Event Viewe

Event Type: Erro
Event Source: Service
Event Category: Non
Event ID:
Date: 10/29/200
Time: 2:31:35 P
User: N/
Computer: DEVCON
Description
Service cannot be started. System.InvalidOperationException: Servic
'WindowsService1.Service1' has zero application (non-infrastructure
endpoints. This might be because no configuration file was found for you
application, or because no service element matching the service name coul
be found in the configuration file, or because no endpoints were defined i
the service element
a
System.ServiceModel.Description.DispatcherBuilder.EnsureThereAreNonMexEndpoints(ServiceDescriptio
description
a
System.ServiceModel.Description.DispatcherBuilder.InitializeServiceHost(ServiceDescriptio
description, ServiceHostBase serviceHost
at System.ServiceModel.ServiceHostBase.InitializeRuntime(
at System.ServiceModel.ServiceHostBase.OnBeginOpen(
at System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout
at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpa
timeout
at System.ServiceModel.Channels.CommunicationObject.Open(
at WindowsService1.Service1.OnStart(String[] args) in C:\Progra
Files\...

Previous Posts In This Thread:

How to: Host WCF in a Windows Service Using TCP
I am trying to host WCF in a Windows Service, and I have created an exampl
form http://msdn.microsoft.com/en-us/library/cc949080.aspx
but I am still getting an error message when I try to start the servric

What am I doing wrong

Thank Yo

Pete

Here is the error

"The Service1 service on Local Computer started and then stopped. Som
services stop automatically if they have no work to do, for example, th
Performance Logs and Alerts service

Here is the error from the Application Event Viewe

Event Type: Erro
Event Source: Service
Event Category: Non
Event ID:
Date: 10/29/200
Time: 2:31:35 P
User: N/
Computer: DEVCON
Description
Service cannot be started. System.InvalidOperationException: Servic
'WindowsService1.Service1' has zero application (non-infrastructure
endpoints. This might be because no configuration file was found for you
application, or because no service element matching the service name coul
be found in the configuration file, or because no endpoints were defined i
the service element
a
System.ServiceModel.Description.DispatcherBuilder.EnsureThereAreNonMexEndpoints(ServiceDescriptio
description
a
System.ServiceModel.Description.DispatcherBuilder.InitializeServiceHost(ServiceDescriptio
description, ServiceHostBase serviceHost
at System.ServiceModel.ServiceHostBase.InitializeRuntime(
at System.ServiceModel.ServiceHostBase.OnBeginOpen(
at System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout
at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpa
timeout
at System.ServiceModel.Channels.CommunicationObject.Open(
at WindowsService1.Service1.OnStart(String[] args) in C:\Progra
Files\...

Peter wrote:The NT service can stop if it is hosting something and it aborted.
Peter wrote

The NT service can stop if it is hosting something and it aborted

It looks like the WCF service is aborting the NT service at NT service
OnStart() due to the WCF service cannot find its endpoints.


If the WCF was being hosted by IIS as a WCF Web service, WCF Console
application or WCF standalone exe, then a Web or App.config would be
used by the WCF service application that would have the serviceEnd
points in the config file required by the WCF servic.

I do not know if you can have an generated WCF.config file connected to a
NT service application that is hosting a WCF service.

If that is the case, then you would programmically set the service
endpoints via the WCF service at WCF service start-up when the NT
service started. I would suspect on the NT service OnStart().

That's what I am doing trying to start the WCF in OnStart method, and it
That's what I am doing trying to start the WCF in OnStart method, and it is
failing on myServiceHost.Open();

protected override void OnStart(string[] args)
{
if (myServiceHost != null)
{
myServiceHost.Close();
}
myServiceHost = new ServiceHost(typeof(Service1));
myServiceHost.Open();

}

<snipped>I would say look at the example in the link and take note on the app.
<snipped>

I would say look at the example in the link and take note on the app.config
that is being deployed to the Bin directory where the NTservice.exe would be
located so that it can find the app.config that has the end points for the
WCF service.

http://msdn.microsoft.com/en-us/library/ms733069(loband).aspx

I would say make this one work and then go back to your other example and
make necessary adjustments.


__________ Information from ESET NOD32 Antivirus, version of virus signature database 4556 (20091029) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

I am getting the same error in both examples.
I am getting the same error in both examples.

I do not know man.
I do not know man. I took that example I gave you and followed it to the 'T',
built/compiled the project, installed the NTservice, and started the
service. The service started with no problems and is running on my Vista
machine.


__________ Information from ESET NOD32 Antivirus, version of virus signature database 4559 (20091030) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

Thanks for your helpI deleted the project and recreated it and it is working
Thanks for your help

I deleted the project and recreated it and it is working now, so obviously I
had something wrong.
And the project at http://msdn.microsoft.com/en-us/library/cc949080.aspx#
has wrong reference

the reference should be
myServiceHost = new ServiceHost(typeof(WcfServiceLibrary1.Service1));

Not
myServiceHost = new ServiceHost(typeof(Service1));

EggHeadCafe - Software Developer Portal of Choice
MDI .NET Forms Include Docked Controls And Smaller MDIClient
http://www.eggheadcafe.com/tutorial...84-57049e53b8c5/mdi-net-forms-include-do.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top