{"id":119,"date":"2006-05-23T10:05:32","date_gmt":"2006-05-23T17:05:32","guid":{"rendered":"http:\/\/kennyw.com\/indigo\/119"},"modified":"2006-05-23T10:05:32","modified_gmt":"2006-05-23T17:05:32","slug":"ireplychannel-and-null-replies","status":"publish","type":"post","link":"https:\/\/kennyw.com\/?p=119","title":{"rendered":"IReplyChannel and &quot;null&quot; replies"},"content":{"rendered":"<p>I mentioned in an <a href=\"http:\/\/kennyw.com\/indigo\/63\">earlier post<\/a> how the Service Model Runtime normalizes different channel shapes based on the requirements of your OperationContract. One of the adaptations the Service Model Runtime provides is the ability to use one-way methods over <a href=\"http:\/\/kennyw.com\/channelinterfaces#irequestchannel\"><code class=\"classname\">IRequestChannel<\/code><\/a> and <a href=\"http:\/\/kennyw.com\/channelinterfaces#ireplychannel\"><code class=\"classname\">IReplyChannel<\/code><\/a>.<\/p>\n<p>For example, let&#8217;s say you have method such as:<\/p>\n<div class=\"code\">[<code class=\"classname\">OperationContract<\/code>(IsOneWay=<code class=\"keyword\">true<\/code>]<br \/>\n<code class=\"keyword\">void<\/code> SendUpdate(<code class=\"keyword\">string<\/code> update);<\/div>\n<p>If you want to expose this method over <code class=\"classname\">BasicHttpBinding<\/code>, how does that work? HTTP is fundamentally request-reply based, and as such offers up only <code class=\"classname\">IRequestChannel<\/code> and <code class=\"classname\">IReplyChannel<\/code>.<\/p>\n<p>To address this scenario, part of the model for request-reply is a paradigm whereby a channel can optionally support &#8220;null&#8221; responses. This is exposed through the programming model by calling <code class=\"classname\">IRequestContext<\/code><code>.[Begin]Reply(<\/code><code class=\"keyword\">null<\/code><code>)<\/code>. As an additional convenience, if you call <code class=\"classname\">IRequestContext<\/code><code>.Close()<\/code> without having sent a reply we will call <code>Reply(<\/code><code class=\"keyword\">null<\/code><code>)<\/code> on your behalf.<\/p>\n<p>HTTP signals a &#8220;null&#8221; response on the wire by sending a &#8220;202 Accepted&#8221; with no entity body.  Note that for interop purposes we are lax on the client and allow any 200-level response without an entity body to signal null response. TCP\/Pipes send a .Net Framing ACK with no entity body. A message-level protocol for request reply can designate a particular schema\/action for an &#8220;ACK Message&#8221; to signal a null response.<\/p>\n<p>On the client you should check for a <code class=\"keyword\">null<\/code> return value from <code class=\"classname\">IRequestChannel<\/code><code>.SendRequest()<\/code>. For example:<\/p>\n<div class=\"code\">\n<pre>\n<code class=\"classname\">Message<\/code> reply = requestChannel.SendRequest(request);\n<code class=\"keyword\">if<\/code> (reply == <code class=\"keyword\">null<\/code>)\n{\n    <code class=\"classname\">Console<\/code>.WriteLine(\"Called a one-way method.\");\n}\n<code class=\"keyword\">else<\/code>\n{\n    <code class=\"classname\">Console<\/code>.WriteLine(\"Called a two-way method.\");\n}\n<\/pre>\n<\/div>\n<p>ServiceModel, as well as our forthcoming <code class=\"classname\">OneWayBindingElement<\/code> leverage the &#8220;null&#8221; response in order to achieve mapping request-response message exchanges to one-way.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I mentioned in an earlier post how the Service Model Runtime normalizes different channel shapes based on the requirements of your OperationContract. One of the adaptations the Service Model Runtime provides is the ability to use one-way methods over IRequestChannel and IReplyChannel. For example, let&#8217;s say you have method such as: [OperationContract(IsOneWay=true] void SendUpdate(string update); [&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-119","post","type-post","status-publish","format-standard","hentry","category-indigo"],"_links":{"self":[{"href":"https:\/\/kennyw.com\/index.php?rest_route=\/wp\/v2\/posts\/119","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=119"}],"version-history":[{"count":0,"href":"https:\/\/kennyw.com\/index.php?rest_route=\/wp\/v2\/posts\/119\/revisions"}],"wp:attachment":[{"href":"https:\/\/kennyw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=119"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kennyw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=119"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kennyw.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=119"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}