{"id":113,"date":"2006-05-03T17:46:29","date_gmt":"2006-05-04T00:46:29","guid":{"rendered":"http:\/\/kennyw.com\/indigo\/113"},"modified":"2006-05-03T17:46:29","modified_gmt":"2006-05-04T00:46:29","slug":"exposing-capabilities-on-your-binding","status":"publish","type":"post","link":"https:\/\/kennyw.com\/?p=113","title":{"rendered":"Exposing Capabilities on your Binding"},"content":{"rendered":"<p><a href=\"http:\/\/kennyw.com\/indigo\/38\">Bindings<\/a> represent a wide variety of functionality. Everything from different transports, to different security mechanisms, delivery mechanisms, transactions, and custom protocols.  Nonetheless, there are times where you want to make a decision based on a binding&#8217;s capabilities.<\/p>\n<p>For example: &#8220;Does this binding support ordered delivery?&#8221;<br \/>\nOr: &#8220;Does this binding support both client and server authentication?&#8221;<\/p>\n<p>WCF has a polymorphic way of making such inquiries of a Binding, though there are a few subtleties involved.<\/p>\n<p>The first pivot point is to decide whether the capability is a property of the actual Binding, or a property exposed by the stack of Binding Elements.  For example, supporting client authentication is a property of the underlying stack.  It can be added at different layers (e.g. transport, WS-Security, etc), and can even be removed by some layers. These capabilities are accessed though a method on the Binding:<\/p>\n<div class=\"indent1\"><code>T GetProperty&lt;T&gt;()<\/code><\/div>\n<p>As in: <\/p>\n<div class=\"code\"><code class=\"classname\">ISecurityCapabilities<\/code> s = binding.GetProperty&lt;<code class=\"classname\">ISecurityCapabilities<\/code>&gt;();<\/div>\n<p>GetProperty&lt;T&gt; simply constructs a Binding Context representing the stack of Binding Elements, and queries them through:<\/p>\n<div class=\"indent1\"><code>T GetProperty&lt;T&gt;(<\/code><code class=\"classname\">BindingContext<\/code> context)<\/div>\n<p>Each individual Binding Element can handle the inquiry itself, delegate the inquiry, or a combination of the two. GetProperty is also supported by the runtime objects (IChannelFactory, IChannelListener, IChannel, etc).<\/p>\n<p>Conversely, if a Binding claims to support <a href=\"http:\/\/www.ws-i.org\/Profiles\/BasicProfile-1.0-2004-04-16.html\">Basic Profile 1.0<\/a>, that is a claim about a particular coordination and configuration of binding elements. Therefore, this is not a feature to expose through <code>T GetProperty&lt;T&gt;()<\/code>. The Binding should instead implement the capability directly. For example:<\/p>\n<div class=\"code\"><code class=\"keyword\">public class<\/code> MyBasicProfileBinding : <code class=\"classname\">IBasicProfile10Binding<\/code><\/div>\n<p>Where <code class=\"classname\">IBasicProfile10Binding<\/code> is an agreed upon interface. It is queried as &#8220;<code class=\"keyword\">if<\/code> <code>(binding<\/code> <code class=\"keyword\">is<\/code> <code class=\"classname\">IBasicProfile10Binding<\/code><code>)<\/code>&#8221;<\/p>\n<p>Lastly, there are a handful of cases where a particular property is applicable to <strong>all<\/strong> bindings. In that case, we use the traditional approach of a strongly typed property on our base class. For example:<\/p>\n<div class=\"indent1\">\n<code class=\"keyword\">public abstract string<\/code><code> Scheme {<\/code> <code class=\"keyword\">get<\/code><code>; }<\/code>\n<\/div>\n<p>To re-cap: for polymorphic properties, use GetProperty&lt;T&gt;. For capabilities of the binding element stack, and interface implementation for composite capabilities provided by the concrete binding.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Bindings represent a wide variety of functionality. Everything from different transports, to different security mechanisms, delivery mechanisms, transactions, and custom protocols. Nonetheless, there are times where you want to make a decision based on a binding&#8217;s capabilities. For example: &#8220;Does this binding support ordered delivery?&#8221; Or: &#8220;Does this binding support both client and server authentication?&#8221; [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"class_list":["post-113","post","type-post","status-publish","format-standard","hentry","category-indigo"],"_links":{"self":[{"href":"https:\/\/kennyw.com\/index.php?rest_route=\/wp\/v2\/posts\/113","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kennyw.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kennyw.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kennyw.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/kennyw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=113"}],"version-history":[{"count":0,"href":"https:\/\/kennyw.com\/index.php?rest_route=\/wp\/v2\/posts\/113\/revisions"}],"wp:attachment":[{"href":"https:\/\/kennyw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=113"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kennyw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=113"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kennyw.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=113"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}