How do I use MSMQ in WCF?
I can work with many WCF bindings besides netMsmqBinding
. All I get is this:
CommunicationObjectFaultedException: "The System.ServiceModel.ServiceHost communication object cannot be used for communication because it is in the Faulted state."
at System.ServiceModel.Channels.CommunicationObject.Close (timed out TimeSpan)
I tried it on Windows Server 2008 R2 with below features installed
- Message queue
- Message Queuing Services
- Message Queuing Server
- Message Queue Triggers
- HTTP support
- Multicast support
- Message Queuing DCOM Proxy
I also tried manually adding a separate message queue in Server Manager, but that didn't work.
I am using windows service to host my MSMQ. My service contract
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>
a source to share
The best starting point would be that Tom Hollander posted three blog posts:
- MSMQ, WCF and IIS: Making Them Play Well (Part 1)
- MSMQ, WCF and IIS: Making Them Play Well (Part 2)
- MSMQ, WCF and IIS: Making Them Play Well (Part 3)
and have a good look at the MSDN docs on Queues in WCF - there's a lot there too!
The error you are receiving indicates some problem with the communication channel - something went wrong, the channel was "out of order," meaning it was unusable. There are tons of reasons that can happen that are very difficult to diagnose from afar with hardly any information.
Check out the resources and see if one more step helps you - if not, we need to get more information from you.
a source to share