【问题标题】:Failing to get MSMQ WCF Window Service to function无法让 MSMQ WCF 窗口服务运行
【发布时间】:2012-02-22 16:56:25
【问题描述】:

我正在尝试创建一个 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 应用程序的示例。

【问题讨论】:

  • 上次发生在我身上的这件事实际上一个安全问题。在某些操作系统中,默认权限不允许您从队列中读取。
  • 您找到解决方案了吗?我有一个类似的问题;从 Visual Studio 运行集成测试有效,但在构建服务器上运行它们(代理在我的计算机上),我收到相同的异常消息。
  • 我们遇到了这个问题,并通过删除和重新添加队列找到了解决方法。我怀疑这可能是一个红鲱鱼,但你可以试试。此外,this MSMQ FAQ 提到这可能是 Active Directory 问题。

标签: c# wcf msmq netmsmqbinding


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-18
    • 2012-03-16
    • 2015-08-20
    • 1970-01-01
    相关资源
    最近更新 更多