我正在尝试创建一个MSMQ WCF服务,尽管我遇到了运行代码的麻烦。尝试创建服务实例时失败。我安装了MSMQ,并且可以确认有一个名为' servicemodelsamples '的私有创建
运行服务时,我收到以下错误;
无法启动服务。 System.InvalidOperationException:有 打开队列时出错。确保已安装并运行MSMQ, 队列存在并具有可读取的适当授权。该 内部异常可能包含其他信息。 ---> System.ServiceModel.MsmqException:打开时出错 queue:无法识别的错误-1072824283(0xc00e0025)。消息不能 从队列中发送或接收。确保已安装MSMQ 运行。还要确保队列可以打开 所需的访问模式和授权。
控制服务接口和实施。
[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服务启动代码。
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
}
应用程序配置;
<?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>
有什么想法吗?我怀疑它可能是因为我将代码基于一个winforms应用程序的示例。
答案 0 :(得分:1)
检查运行服务的用户。手动将权限添加到队列中。
如果队列中断了权限,则应使用记事本在C:\Windows\System32\msmq\storage\lqs
中手动重置权限。