Mono WCF Advent Day 3: Binding basics

| 1 Comment | No TrackBacks

Before starting today's post, let me clarify some strangeness for a couple of posts from now on. I originally wanted to write about Moonlight and MonoTouch support as Day 3, but turned out the order of the topics was sort of wrong and I needed to introduce some more, before talking about them. Hence, there will be some mention on Moonlight and MonoTouch support before introducing them, but please be patient to wait for them.

so-called ABC of WCF

In many introductions to WCF, there is "ABC" of WCF: address, binding and contract. While in my opinion ABC is not really important...

  • [A]ddress for most of WCF consumers is just an URI.
  • I gave a very short introduction to [C]ontract at Day 1, and I won't have to explain about it until I introduce our NetTcpBinding support.
  • ... so, today I'll mostly explain [B]indings.

Binding is a customized set of BindingElements, which in turn is to represent communication capabilities for each. Primary ones are:

  • MessageEncodingBindingElement, to represent a message encoder capabilities, which is used to serialize and deserialize service calls to and from Stream.
  • TransportBindingElement, to provide channels to transmit messages.
  • SecurityBindingElement, to provide security capabilities.

There is a lot more binding elements (the examples above are actually all abstract) that for each represent several capabilities. I don't explain a lot.

Another important concept for client and service interoperability is "message version" a.k.a MessageVersion. MessageVersion is used to adjust which SOAP version and WS-Addressing version are used. While it indicates a WS-Addressing version, it is not part of EndpointAddress, and is rather tied to Binding.

BasicHttpBinding

BasicHttpBinding is one of the supported binding in Mono 2.6, and the only supported binding in Moonlight and MonoTouch (except for CustomBinding which is explained later). It consists of two binding elements:

  • TextMessageEncodingBindingElement: supports XML message encoding.
  • HttpTransportBindingElement: supports message transport via HTTP.

BasicHttpBinding by default uses MessageVersion.Soap11 (which is, SOAP 1.1 with no WS-Addressing).

CustomBinding

Most of WCF consumers would use HTTP transport, which is HttpTransportBindingElement (or HttpsTransportBindingElement). There is also TcpTransportBindingElement, which is used in NetTcpBinding and other couple of bindings. In BasicHttpBinding, text XML message encoding is used, which is provided by TextMessageEncodingBindingElement, but there is also BinaryMessageEncodingBindingElement, which is to use "binary" message format.

I'll explain about them in the other day, but what I would note here is that you can mix a couple of binding elements by using CustomBinding. For example, it is possible to use binary message encoding over HTTP transport. Try it by modifying the Day 1 example by changing

    var binding = new BasicHttpBinding ();

to

    var binding = new CustomBinding (
      new BinaryMessageEncodingBindingElement (),
      new HttpTransportBindingElement ());

(Note: I noticed such mixed usage did not work in Mono due to some regressions, and fixed it in trunk. So it won't work under current 2.6 release.)

More to come later

We have a few more bindings in our .NET profile. I'll lave them for later days.

No TrackBacks

TrackBack URL: http://veritas-vos-liberabit.com/monogatari/mt-tb.cgi/86

1 Comment

I don't know actually what are these stuff means. Can you add further key points? Anyway, as I was reading your post they are all very informative, Thank you.

Anna Marie

Blog: treuil électrique 

Leave a comment