MSMQ and Duplex

One of the nifty features in Windows Communication Foundation is duplex requests. To define a duplex request you need to create two interfaces, both with their OperationContract marked with IsOneWay:=True. The request interface also contains a CallbackContract with the response interface.

<ServiceContract(CallbackContract:=GetType(IDuplexResponse))> _

Public Interface IDuplexRequest

    <OperationContract(IsOneWay:=True)> _

    Sub SendRequest(ByVal data As String)

End Interface


<ServiceContract()> _

Public Interface IDuplexResponse

    <OperationContract(IsOneWay:=True)> _

    Sub SendResponse(ByVal data As String)

End Interface


Now in the request implementation you can use the OperationContext to retrieve the callback interface using OperationContext.Current.GetCallbackChannel(Of IDuplexResponse)().

Public Class DuplexRequest

    Implements IDuplexRequest


    Public Sub SendRequest(ByVal data As String) Implements IDuplexRequest.SendRequest

        Dim responseChannel As IDuplexResponse = OperationContext.Current.GetCallbackChannel(Of IDuplexResponse)()

        responseChannel.SendResponse(String.Format(“I received ‘{0}’.”, data))

    End Sub

End Class


So far so good. Now with all the operations marked as one way and seem a perfect fit for a netMsmqBinding implementation. Unfortunately this doesn’t seem to work though, or otherwise I could not figure out how to get this to work [:(]. Even though all operations are one way the channel still needs to be a duplex channel and as the netMsmqBinding is a simple binding instead of a duplex binding this just doesn’t work.

This is unfortunate because the sample Microsoft released showing duplex communication is very primitive and in fact strongly coupled to netMsmqBinding as it requires passing the address as a normal piece of data to the client. Because of this it doesn’t seem to be in the “spirit” of WCF [:(]. BTW you can find the Microsoft sample at:

If anyone has OperationContext.Current.GetCallbackChannel() working with netMsmqBinding I would appreciate the information on how to do this.


One thought on “MSMQ and Duplex

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>