Protocol Channel Example: Chunking

In my quick PDC recap I promised to post Yasser‘s demo code. So before I digress: here is the code for a protocol chunking channel.

There is a lot more refinement to be added in order to make this production-level, but it’s a great illustration of the power and flexibility of a layered channel model. We have streaming over some Indigo transports (TCP/Named Pipe datagram, and HTTP requests and responses). However, these streams suffer from connections getting dropped mid-message, and need to be secured, routed, etc at the transport layer.

Yasser’s chunking channel nicely sidesteps all of these issues. By fragmenting/reassembling at the SOAP layer, each SOAP “chunk message” can be secured using WS-Security, reliably sent using WS-RM, and even transacted using WS-Transactions. Even better, this solution works for streaming a Message over any arbitrary transport. Which means you can write a simple streaming media server by adapting the chunking channel and using it in conjunction with a Udp multicast transport. Maybe I’ll mock one up next week even 🙂

For those not on commnet, I’ve posted the slides from my PDC talk here. Enjoy!

10 thoughts on “Protocol Channel Example: Chunking

  1. Pingback: kennyw.com » Blog Archive » Large Messages and WCF

  2. John

    Hi Kenny.
    I’m writing a custom HTTP binding. Would you know if the following channel stack yields an IDuplexSessionChannel shape?
    ReliableSessionBindingElement
    TextMessageEncodingBindingElement
    HttpTransportBindingElement
    I’m implementing a WsHTTP custom binding for the chunking sample, but it fails with when I add the ChunkingBindingElement to the top of the BindingElementCollection. The error is “’WsHttpChunkingBinding’ doesn’t support creating any channel types”. The CanBuildChannelFactory and CanBuildChannelListener functions in ChunkingBindingElement always return false. I suspect the binding elements I have chosen for my test binding don’t support the IDuplexSessionChannel shape. I also get the same problem when I remove the ChunkingBindingElement and add a CompositeDuplexBindingElement element. Cheers.

    Reply
  3. Kenny

    In order to get duplex session from RM on top of HTTP you need to layer CompositeDuplex and OneWayBindingElement in between (see what WsDualHttpBinding generates for example). You can setup this binding stack for IDuplexSessionChannel over HTTP:
    ReliableSessionBindingElement
    CompositeDuplexBindingElement
    OneWayBindingElement
    TextMessageEncodingBindingElement
    HttpTransportBindingElement

    Reply
  4. Guillaume

    Hello Kenny,

    I’m trying to integrate ChunkingChannel with WsFederationHttpBinding.

    Is it my stack:

    …….

    But it fails. Is it possible to do what I would?

    Thanks in advance

    Reply
  5. Ksenia

    Hello Kenny,

    I have the same problem as guys had. I try to use chunking for WSDualHttpBinding. I create binding elements from in the following way:
    public override BindingElementCollection CreateBindingElements()
    {
    WSDualHttpBinding wsHttpBinding = new WSDualHttpBinding();
    BindingElementCollection beCollection = wsHttpBinding.CreateBindingElements();
    beCollection.Insert(6, be);
    return beCollection;

    //BindingElementCollection col = new BindingElementCollection();
    //col.Add(new TransactionFlowBindingElement());
    //col.Add(rsbe);
    ////col.Add(new TransportSecurityBindingElement());
    //col.Add(SecurityBindingElement.CreateAnonymousForCertificateBindingElement());
    //col.Add(cdbe);
    //col.Add(owbe);
    //col.Add(new WindowsStreamSecurityBindingElement());
    //col.Add(encbe);
    //col.Add(be);
    //col.Add(httpbe);
    //return col;
    }

    Reply
  6. Pingback: kennyw.com » Blog Archive » Security and Streamed Messages

  7. Supriya

    Is it possible to make Chunking for WSHttpBinding, work without CompositeDuplexBindingElement
    ?Eventhough i dont want any reply from service, it is prompting for ClientBaseAddress.I tried to remove CompositeDuplexBindingElement from binding elements. Getting Channel Stack order error.

    Reply
  8. Alisa

    Hi Kenney,

    I would like to use your grate Chunking channel with MemoryStream. In case of MemoryStream some not implemented methods in ChunkingWriter and ChunkingReader are called (for example WriteStartAttribut, WriteString, WriteEndAttribut). When I look for a caller of this not-implemented methods there is only “External call” to see in stack trace. I have some questions:

    1. What is the difference in the MemoryStream handling in comparison with FileStream? Could you describe a workflow in ChunkingWriter/ChunkingReader?
    2. How do I need to implement these not-implemented methods that will be called by handling of MemoryStream?

    Thanks
    Alisa.

    Reply

Leave a Reply

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