【问题标题】:How to use msmq between WCF Router and WCF Service hosted in a Windows Service如何在 WCF 路由器和 Windows 服务中托管的 WCF 服务之间使用 msmq
【发布时间】:2011-12-26 13:31:17
【问题描述】:

在我当前的系统中,我有一个路由器服务和十几个(大约一半使用 msmq,其余使用 tcp)通过 IIS 托管的 WCF 服务。我的任务是将除路由器之外的所有服务移至 Windows 服务。这已使用与使用 IIS web.config 文件相同的配置来完成。这是之前配置的 sn-p(服务的公共队列:myservices/wcfservice):

  <!--Router Service web.config-->
  <client>
    <endpoint address="net.msmq://localhost/MyServices/WCFService.svc" binding="netMsmqBinding" contract="*" name="IWCFService_Msmq" />
  </client>

  <!--Services web.config-->
  <service behaviorConfiguration="SomeServiceBehavior" name="WCFService">
    <endpoint binding="netMsmqBinding" name="IWCFService_Msmq"
      contract="IWCFService" />
    <host>
      <baseAddresses>
        <add baseAddress="net.msmq://localhost/MyServices/WCFService" />
      </baseAddresses>
    </host>
  </service>

我很困惑为什么会这样,因为服务有一个 net.tcp 绑定,而路由器有 msmq,当我四处询问时,我被告知这是“神奇的”。我尝试使用类似的配置对我的设置(路由器到 Windows 服务)执行相同的操作,但收到错误消息:

<!--Router Service web.config-->
  <client>
    <endpoint address="net.msmq://localhost/MyServices/WCFService" binding="netMsmqBinding" contract="*" name="IWCFService_Msmq" />
  </client>

  <!--One "other" Services hosted in Windows Service app.config-->
  <service behaviorConfiguration="SomeServiceBehavior" name="WCFService">
    <endpoint binding="netMsmqBinding" name="IWCFService_Msmq"
      contract="IWCFService" />
    <host>
      <baseAddresses>
        <add baseAddress="net.tcp://localhost/MyServices/WCFService" />
      </baseAddresses>
    </host>
  </service>

这对我所有使用 tcp 的服务都很好,但是当我尝试使用 msmq 并尝试启动 windows 服务时,我在事件查看器中收到以下错误:

Service cannot be started. System.InvalidOperationException: Could not find a base address that matches scheme net.msmq for the endpoint with binding NetMsmqBinding. Registered base address schemes are [net.tcp].

我是 msmq 的新手,因此不胜感激。谢谢!

更新:

我已更新服务 app.config 中的基地址以匹配路由器 web.config 中的地址。我以前试过这个,但没有奏效。后来我发现这是因为我没有使 msmq 本身成为“事务队列”(我们的设置需要它)。完成后,一切顺利!

<!--One "other" Services hosted in Windows Service app.config-->
  <service behaviorConfiguration="SomeServiceBehavior" name="WCFService">
    <endpoint binding="netMsmqBinding" name="IWCFService_Msmq"
      contract="IWCFService" />
    <host>
      <baseAddresses>
        <add baseAddress="net.msmq://localhost/MyServices/WCFService" />
      </baseAddresses>
    </host>
  </service>

【问题讨论】:

    标签: wcf windows-services web-config msmq


    【解决方案1】:

    为什么不给所有的 MSMQ 服务自己的配置,给所有的 tcp 服务自己的呢?问题显然是当您选择绑定为 msmq 时它会查找基地址,并且找不到 msmq 绑定,因为您提供的只是 tcp 基地址绑定。当然,您也可以在 baseaddresses 节点中添加另一个使用 net.msmq 的基地址。

    【讨论】:

      【解决方案2】:

      从 InvalidOperationException 的错误消息来看,“net.tcp”似乎是您在 IIS 中托管的应用程序的高级设置中唯一启用的协议。

      “net.msmq”是启用的协议吗?

      1. 打开 IIS 管理器
      2. 选择您的应用程序
      3. 单击操作列表中的高级设置
      4. 将“net.msmq”添加到行为 - 启用协议

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-06-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多