I'm learning about MsmqIntegrationBinding. All the samples and guidelines I've seen so far were covering scenario where, there is just one operation with one data contract. I tried to add another contract and the service started successfully. However I cannot figure out how to reach the second operation. Is such thing even possible with this binding?
[ServiceContract]
[ServiceKnownType(typeof(Data1))]
[ServiceKnownType(typeof(Data2))]
public interface ISampleService
{
[OperationContract(IsOneWay = true, Action = "*")]
void Operation1(MsmqMessage<Data1> msg);
[OperationContract(IsOneWay = true)]
void Operation2(MsmqMessage<Data2> msg);
}
public class SampleService : ISampleService
{
[OperationBehavior(TransactionScopeRequired = true, TransactionAutoComplete = true)]
public void Operation1(MsmqMessage<Data1> msg)
{
var data = msg.Body;
}
[OperationBehavior(TransactionScopeRequired = true, TransactionAutoComplete = true)]
public void Operation2(MsmqMessage<Data2> msg)
{
var data = msg.Body;
}
}
Calling code
var queue = new MessageQueue(@".\private$\samplequeue");
var body = new Data1() { Data = "some data" };
var message = new Message(body);
message.Label = "some label";
queue.Send(body, MessageQueueTransactionType.Single);
This will fire the Operation1 which has Action set to "*".
This is a very interesting question.
The Action OperationContractAttribute is normally used by the WCF stack to populate the WS-Addressing soap headers. It's use is obviously overridden in some way by the queued bindings.
It is possible that there is an undocumented feature of WCF which allows for some mapping of msmq message headers to the operation based on the Action attribute acting like a filter, but if there is I don't know what form it would take.
I think the simplest explanation is: no, it's not possible, and the reason for that is that the msmqIntegrationBinding is exactly what it says on the tin: it's about interop over functionality.
Because you are forced to call the operation with a MsmqMessage wrapper it kind of makes this binding semantically one-dimensional, and this lends to my theory that it is intended to wrap a single endpoint operation to support interop with legacy COM and ActiveX clients.
Anyhow, there's no law saying that a binding must support multiple operations, just like certain bindings don't support callbacks, and certain others only one-way operations.
Appreciate this doesn't answer your question directly.