WCF hosted in Windows Service


K

Karch

I am writing a WCF Service using MSMQ hosted in a Windows Service on Windows
XP. All the required components are installed (.NET3, MSMQ, etc).

For some reason my service tries to start and then stops right away. I have
looked at everything and can't see anything wrong - in fact, I started this
a few weeks ago and I swear it was running at one point.

I have included the app.config and service code below - any idea why my
service will not stay running? Thanks!

<?xml version="1.0" encoding="utf-8" ?>

<configuration>

<appSettings>

<!-- use appSetting to configure MSMQ queue name -->

<add key="queueTarget" value=".\private$\NodeManagerXact" />

</appSettings>

<system.serviceModel>

<services>

<service name="Node.Manager.MessagingService"

behaviorConfiguration="MessagingServiceBehavior">

<host>

<baseAddresses>

<add baseAddress="http://localhost:8000/Node.Manager/service"/>

</baseAddresses>

</host>

<!-- Define NetMsmqEndpoint -->

<endpoint address="net.msmq://localhost/private/NodeManagerXact"

binding="netMsmqBinding"

contract="Node.Manager.IMessenger" />

<endpoint address=""

binding="wsHttpBinding"

contract="Node.Manager.IMessenger" />

<endpoint address="mex"

binding="mexHttpBinding"

contract="IMetadataExchange" />

</service>

</services>

<!--For debugging purposes set the includeExceptionDetailInFaults attribute
to true-->

<behaviors>

<serviceBehaviors>

<behavior name="MessagingServiceBehavior">

<serviceMetadata httpGetEnabled="True"/>

<serviceDebug includeExceptionDetailInFaults="False" />

</behavior>

</serviceBehaviors>

</behaviors>

</system.serviceModel>

</configuration>



[RunInstaller(true)]

public class NodeManagerInstaller : Installer

{

private ServiceProcessInstaller process;

private ServiceInstaller service;

public NodeManagerInstaller()

{

process = new ServiceProcessInstaller();

process.Account = ServiceAccount.LocalSystem;

service = new ServiceInstaller();

service.ServiceName = "NodeManagerService";

Installers.Add(process);

Installers.Add(service);

}

}





public partial class NodeManagerService : ServiceBase

{

public ServiceHost serviceHost = null;

public static void Main()

{

// Get MSMQ queue name from appsettings in configuration.

string queueName = ConfigurationManager.AppSettings["queueTarget"];

// Create the transacted MSMQ queue if necessary.

if (!MessageQueue.Exists(queueName))

MessageQueue.Create(queueName, true);

ServiceBase.Run(new NodeManagerService());

}

public NodeManagerService()

{

InitializeComponent();

ServiceName = "NodeManagerService";

}

protected override void OnStart(string[] args)

{

if (serviceHost != null)

{

serviceHost.Close();

}

serviceHost = new ServiceHost(typeof(MessagingService));

serviceHost.Open();

}

protected override void OnStop()

{

if (serviceHost != null)

{

serviceHost.Close();

serviceHost = null;

}

}

}
 
Ad

Advertisements

K

Karch

Nevermind - I found the problem. I was specifying MSMQ binding which doesn't
support the two-way communication specified in my contract. Thanks anyway -
hopefully this helps someone else. :)

Karch said:
I am writing a WCF Service using MSMQ hosted in a Windows Service on
Windows XP. All the required components are installed (.NET3, MSMQ, etc).

For some reason my service tries to start and then stops right away. I
have looked at everything and can't see anything wrong - in fact, I
started this a few weeks ago and I swear it was running at one point.

I have included the app.config and service code below - any idea why my
service will not stay running? Thanks!

<?xml version="1.0" encoding="utf-8" ?>

<configuration>

<appSettings>

<!-- use appSetting to configure MSMQ queue name -->

<add key="queueTarget" value=".\private$\NodeManagerXact" />

</appSettings>

<system.serviceModel>

<services>

<service name="Node.Manager.MessagingService"

behaviorConfiguration="MessagingServiceBehavior">

<host>

<baseAddresses>

<add baseAddress="http://localhost:8000/Node.Manager/service"/>

</baseAddresses>

</host>

<!-- Define NetMsmqEndpoint -->

<endpoint address="net.msmq://localhost/private/NodeManagerXact"

binding="netMsmqBinding"

contract="Node.Manager.IMessenger" />

<endpoint address=""

binding="wsHttpBinding"

contract="Node.Manager.IMessenger" />

<endpoint address="mex"

binding="mexHttpBinding"

contract="IMetadataExchange" />

</service>

</services>

<!--For debugging purposes set the includeExceptionDetailInFaults
attribute to true-->

<behaviors>

<serviceBehaviors>

<behavior name="MessagingServiceBehavior">

<serviceMetadata httpGetEnabled="True"/>

<serviceDebug includeExceptionDetailInFaults="False" />

</behavior>

</serviceBehaviors>

</behaviors>

</system.serviceModel>

</configuration>



[RunInstaller(true)]

public class NodeManagerInstaller : Installer

{

private ServiceProcessInstaller process;

private ServiceInstaller service;

public NodeManagerInstaller()

{

process = new ServiceProcessInstaller();

process.Account = ServiceAccount.LocalSystem;

service = new ServiceInstaller();

service.ServiceName = "NodeManagerService";

Installers.Add(process);

Installers.Add(service);

}

}





public partial class NodeManagerService : ServiceBase

{

public ServiceHost serviceHost = null;

public static void Main()

{

// Get MSMQ queue name from appsettings in configuration.

string queueName = ConfigurationManager.AppSettings["queueTarget"];

// Create the transacted MSMQ queue if necessary.

if (!MessageQueue.Exists(queueName))

MessageQueue.Create(queueName, true);

ServiceBase.Run(new NodeManagerService());

}

public NodeManagerService()

{

InitializeComponent();

ServiceName = "NodeManagerService";

}

protected override void OnStart(string[] args)

{

if (serviceHost != null)

{

serviceHost.Close();

}

serviceHost = new ServiceHost(typeof(MessagingService));

serviceHost.Open();

}

protected override void OnStop()

{

if (serviceHost != null)

{

serviceHost.Close();

serviceHost = null;

}

}

}
 

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