I'm trying to create a MSMQ WCF service, although I'm having troubles running the code. It fails when trying to create an instance of the service. I have MSMQ installed, and can confirm there is a private created called 'servicemodelsamples'
When running the service, I received the following error;
Service cannot be started. System.InvalidOperationException: There was an error opening the queue. Ensure that MSMQ is installed and running, the queue exists and has proper authorization to be read from. The inner exception may contain additional information. ---> System.ServiceModel.MsmqException: An error occurred while opening the queue:Unrecognized error -1072824283 (0xc00e0025). The message cannot be sent or received from the queue. Ensure that MSMQ is installed and running. Also ensure that the queue is available to open with the required access mode and authorization.
Control Service Interface and Implementation.
[ServiceContract()]
public interface IControlService
{
[OperationContract(IsOneWay = true)]
void PricingAlert(int eventid, int marketid);
}
public class ControlService : IControlService
{
public ControlService()
{ }
public void PricingAlert(int eventid, int marketid)
{
Console.WriteLine("Acknowledged");
}
}
Service1.cs Service starting code.
protected override void OnStart(string[] args)
{
Thread.Sleep(10000);
string queueName = Settings.Default["queueName"].ToString();
if (!MessageQueue.Exists(queueName))
MessageQueue.Create(queueName, true);
if (myServiceHost != null)
{
myServiceHost.Close();
}
myServiceHost = new ServiceHost(typeof(ControlService));
myServiceHost.Open(); // *** Code Fails Here
}
The application config;
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="ControlService.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<system.web>
<compilation debug="true" />
</system.web>
<system.serviceModel>
<bindings>
<netMsmqBinding>
<binding name="netMsmqBindingConfig">
<security mode="None">
</security>
</binding>
</netMsmqBinding>
</bindings>
<services>
<service name="TheControlService.ControlService" behaviorConfiguration="MSMQBindingBehaviour">
<endpoint address="net.msmq://172.26.2.11/private/ServiceModelSamples"
binding="netMsmqBinding" bindingConfiguration="netMsmqBindingConfig"
contract="TheControlService.IControlService" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MSMQBindingBehaviour">
<serviceMetadata httpGetEnabled="true" httpGetUrl="http://localhost:8000/Hello/" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<system.diagnostics>
<trace autoflush="true" />
<sources>
<source name="System.ServiceModel"
switchValue="Information, ActivityTracing"
propagateActivity="true">
<listeners>
<add name="sdt"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData="controlserviceerrors.svclog" />
</listeners>
</source>
</sources>
</system.diagnostics>
<applicationSettings>
<ControlService.Properties.Settings>
<setting name="queueName" serializeAs="String">
<value>.\private$\ServiceModelSamples</value>
</setting>
</ControlService.Properties.Settings>
</applicationSettings>
</configuration>
Any ideas? I suspect it might because I've based the code on an example which was a winforms application.