[英]How to use MSMQ in WCF?
I can work with many WCF bindings, except netMsmqBinding
. 除了
netMsmqBinding
之外,我可以使用许多WCF绑定。 All I get is: 我得到的是:
CommunicationObjectFaultedException: "The communication object, System.ServiceModel.ServiceHost, cannot be used for communication because it is in the Faulted state."
CommunicationObjectFaultedException:“通信对象System.ServiceModel.ServiceHost不能用于通信,因为它处于Faulted状态。”
at System.ServiceModel.Channels.CommunicationObject.Close(TimeSpan timeout)
在System.ServiceModel.Channels.CommunicationObject.Close(TimeSpan超时)处
I tried it in a Windows Server 2008 R2 with the following features installed 我在安装了以下功能的Windows Server 2008 R2中进行了尝试
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. 我正在使用Windows服务来托管我的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 而我的app.config包含
<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>
The best starting point would be Tom Hollander's three part blog post: 最好的起点是汤姆·霍兰德(Tom Hollander)的三部分博客文章:
and have a good look at the MSDN docs on Queues in WCF - lots of stuff there, too! 并仔细阅读WCF中关于队列的MSDN文档-还有很多东西!
The error you're getting would indicate some problem with the communication channel - something went wrong, the channel has been "faulted", ie 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! 查看资源,看看是否可以帮助您进一步前进一两个步骤-如果没有,我们将向您提供更多信息!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.