如何在WCF中使用MSMQ?

发布于 2024-08-31 07:07:12 字数 1756 浏览 4 评论 0原文

我可以使用许多 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>

I can work with many WCF bindings, except netMsmqBinding. All I get is:

CommunicationObjectFaultedException: "The communication object, System.ServiceModel.ServiceHost, cannot be used for communication because it is in the Faulted state."

at System.ServiceModel.Channels.CommunicationObject.Close(TimeSpan timeout)

I tried it in a Windows Server 2008 R2 with the following features installed

  • Message Queueing
  • Message Queueing Services
  • Message Queueing Server
  • Message Queueing Triggers
  • HTTP Support
  • Multicasting Support
  • Message Queueing DCOM Proxy

I tried also to add manually a private Message Queue in the Server Manager but it didn't work.

I am using a Windows Service to host my MSMQ.
My Service Contract is

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; }
}
}

And my app.config contains

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

and

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一世旳自豪 2024-09-07 07:07:12

最好的起点是 Tom Hollander 的三部分博客文章:

并仔细查看 WCF 中的队列 - 那里也有很多东西!

您收到的错误表明通信通道存在问题 - 出现问题,通道已“故障”,即变得不可用。可能发生的原因有很多,在没有任何信息的情况下很难从远处诊断。

查看资源,看看这是否可以帮助您前进一两步 - 如果没有,我们将不得不从您那里获得更多信息!

The best starting point would be Tom Hollander's three part blog post:

and have a good look at the MSDN docs on Queues in WCF - lots of stuff there, too!

The error you're getting would indicate some problem with the communication channel - something went wrong, the channel has been "faulted", i.e. rendered unusable. There's a ton of reasons that might happen, that's really hard to diagnose from afar with hardly any info.

Check out the resources and see if that helps you a step or two further - if not, we'll have to get a lot more info from you!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文