{"id":91,"date":"2006-02-08T21:12:41","date_gmt":"2006-02-09T04:12:41","guid":{"rendered":"http:\/\/kennyw.com\/indigo\/91"},"modified":"2006-02-08T21:12:41","modified_gmt":"2006-02-09T04:12:41","slug":"large-messages-and-wcf","status":"publish","type":"post","link":"https:\/\/kennyw.com\/?p=91","title":{"rendered":"Large Messages and WCF"},"content":{"rendered":"<p>CLR typed objects (and buffered messages) are great for a large breadth of applications.  Sometimes though, you just want to push bytes.   WCF provides a convenient way of doing so with &#8220;streamed methods&#8221;.<\/p>\n<p>To use WCF&#8217;s &#8220;Streaming API&#8221; you write an operation with an input and\/or output of type <code class=\"classname\">System.IO.Stream<\/code>.  Because the Stream parameter utilizes the entire body, if an input or an output (i.e. <code class=\"keyword\">ref<\/code> parameter, <code class=\"keyword\">out<\/code> parameter, or return value) is of type <code class=\"classname\">Stream<\/code> then it must be the only input\/output specified in your <code class=\"classname\">OperationContract<\/code>.<\/p>\n<p>When using a Streaming method, you need to pass in a <code class=\"classname\">Stream<\/code> object that provides data incrementally from its <code>Read()<\/code> method.  One common area of confusion is that your return <code class=\"classname\">Stream<\/code> must also be written with the <code>Read()<\/code> method providing the data. The mental model is that the client is &#8220;reading&#8221; the return value, and not that the server is &#8220;writing&#8221; the result.<\/p>\n<p>Now that your operation has been architected so that it no longer requires buffering, you have to choose a binding that is compatible with moving a lot of bytes around.  <a href=\"http:\/\/blogs.msdn.com\/yassers\/\">Yasser<\/a> wrote a nice post on this topic <a href=\"http:\/\/blogs.msdn.com\/yassers\/archive\/2006\/01\/21\/515887.aspx\">here<\/a>.  In a nutshell you need to:<\/p>\n<ul>\n<li>Pick an encoding (<a href=\"http:\/\/windowssdk.msdn.microsoft.com\/library\/default.asp?url=\/library\/en-us\/cpref20\/html\/T_System_ServiceModel_BinaryMessageEncodingBindingElement.asp\">Binary<\/a> for Indigo< ->Indigo scenarios or <a href=\"http:\/\/windowssdk.msdn.microsoft.com\/library\/default.asp?url=\/library\/en-us\/cpref20\/html\/T_System_ServiceModel_MtomMessageEncodingBindingElement.asp\">MTOM<\/a> if you require interop)<\/li>\n<li>Enable streaming on your binding (either through <code class=\"classname\">TransferMode.Streamed<\/code> on a transport or by using <a href=\"http:\/\/kennyw.com\/indigo\/53\">chunking<\/a> at the top of your binding stack)<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>CLR typed objects (and buffered messages) are great for a large breadth of applications. Sometimes though, you just want to push bytes. WCF provides a convenient way of doing so with &#8220;streamed methods&#8221;. To use WCF&#8217;s &#8220;Streaming API&#8221; you write an operation with an input and\/or output of type System.IO.Stream. Because the Stream parameter utilizes [&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-91","post","type-post","status-publish","format-standard","hentry","category-indigo"],"_links":{"self":[{"href":"https:\/\/kennyw.com\/index.php?rest_route=\/wp\/v2\/posts\/91","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=91"}],"version-history":[{"count":0,"href":"https:\/\/kennyw.com\/index.php?rest_route=\/wp\/v2\/posts\/91\/revisions"}],"wp:attachment":[{"href":"https:\/\/kennyw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=91"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kennyw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=91"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kennyw.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=91"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}