wcfmsmqnetmsmqbinding

How to use MSMQ in WCF?


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

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>

Solution

  • 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!