【问题标题】:How to use MSMQ in WCF?如何在 WCF 中使用 MSMQ?
【发布时间】:2010-05-04 21:25:47
【问题描述】:

我可以使用许多 WCF 绑定,netMsmqBinding 除外。我得到的只是:

CommunicationObjectFaultedException:“通信对象 System.ServiceModel.ServiceHost 无法用于通信,因为它处于故障状态。”

在 System.ServiceModel.Channels.CommunicationObject.Close(TimeSpan 超时)

我在安装了以下功能的 Windows Server 2008 R2 中尝试过

  • 消息队列
  • 消息队列服务
  • 消息队列服务器
  • 消息队列触发器
  • HTTP 支持
  • 多播支持
  • 消息队列 DCOM 代理

我也尝试在服务器管理器中手动添加私有消息队列,但没有成功。

我正在使用 Windows 服务来托管我的 MSMQ。 我的服务合同是

namespace MyCompany.Services
{
[ServiceContract(Name = "ServiceName",
                     Namespace = "http://MyCompany/ServiceName")]
public interface IServiceName
{
    [OperationContract(IsOneWay = true)]
    void Insert(MyData[] data);
}
[DataContract]
public class MyData
{
    [DataMember]
    public DateTime DateTime { get; set; }
    [DataMember]
    public double Lat { get; set; }
    [DataMember]
    public double Lon { get; set; }
    [DataMember]
    public TimeSpan Timespan { get; set; }
    [DataMember]
    public Guid Id { get; set; }
    [DataMember(IsRequired = false)]
    public int? Category { get; set; }
}
}

我的 app.config 包含

  <endpoint
      address="net.msmq://localhost/private/ServiceName"
      binding="netMsmqBinding"
      contract="MyCompany.Services.IServiceName"
      bindingConfiguration="tolerant"
      behaviorConfiguration="tolerant"
      />

<netMsmqBinding>
  <binding name="tolerant"
         maxReceivedMessageSize="2147483647"
         >
    <readerQuotas maxArrayLength="2147483647" />
    <security mode="None"/>
  </binding>
</netMsmqBinding>

【问题讨论】:

    标签: wcf msmq netmsmqbinding


    【解决方案1】:

    最好的起点是 Tom Hollander 的三篇博文:

    并仔细查看 Queues in WCF 上的 MSDN 文档 - 那里也有很多东西!

    您遇到的错误表明通信通道存在问题 - 出现问题,通道已“出现故障”,即无法使用。可能发生的原因有很多,几乎没有任何信息很难从远处诊断。

    查看资源,看看这是否对您有帮助 - 如果没有,我们将不得不从您那里获得更多信息!

    【讨论】:

    • 我没有按照帖子中的说明安装MSMQ Active Directory Domain。我希望它在没有安全性的情况下工作
    • 我终于安装了它,但它没有帮助。我想我会停止尝试将它托管在 Windows 服务上,我最终会将它移至 IIS。
    猜你喜欢
    • 2012-05-02
    • 2010-11-21
    • 1970-01-01
    • 2012-01-05
    • 2012-11-05
    • 1970-01-01
    • 1970-01-01
    • 2011-11-02
    • 2011-12-05
    相关资源
    最近更新 更多