3

我正在尝试创建一个 MSMQ WCF 服务,尽管我在运行代码时遇到了麻烦。尝试创建服务实例时失败。我安装了 MSMQ,并且可以确认有一个名为“ servicemodelsamples ”的私有创建

运行服务时,我收到以下错误;

无法启动服务。System.InvalidOperationException:打开队列时出错。确保 MSMQ 已安装并正在运行,队列存在并且具有适当的读取权限。内部异常可能包含附加信息。---> System.ServiceModel.MsmqException:打开队列时出错:无法识别的错误-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 应用程序的示例。

4

1 回答 1

1

检查运行服务的用户。手动向队列添加权限。C:\Windows\System32\msmq\storage\lqs如果队列的权限被破坏,您应该使用记事本手动重置权限。

于 2013-12-02T21:34:50.753 回答