{"id":8,"date":"2015-06-28T15:10:00","date_gmt":"2015-06-28T15:10:00","guid":{"rendered":""},"modified":"2016-01-30T22:39:54","modified_gmt":"2016-01-30T22:39:54","slug":"wcf-exposing-metadata-over-tcp","status":"publish","type":"post","link":"https:\/\/tpodolak.com\/blog\/2015\/06\/28\/wcf-exposing-metadata-over-tcp\/","title":{"rendered":"WCF &#8211; exposing metadata over TCP"},"content":{"rendered":"<p>I think that everyone who has ever been working with <i>WCF<\/i> knows that we can enable metadata exchange by adding <i>ServiceMetadataBehavior<\/i> to <i>App.config<\/i> file<\/p>\n<pre lang=\"xml\">\r\n<behaviors>\r\n     <serviceBehaviors>\r\n       <behavior>\r\n         <serviceMetadata httpGetEnabled=\"true\"><\/serviceMetadata>\r\n       <\/behavior>\r\n     <\/serviceBehaviors>\r\n<\/behaviors>\r\n<\/pre>\n<p>Up until yesterday the build in solution works fine for me. However recently I&#8217;ve had to expose metadata over <i>TCP<\/i> protocol. <i>ServiceMetadataBehavior<\/i> doesn&#8217;t have something like <i>TcpGetEnabled<\/i> property so in order to expose metadata over other protocols (in my case <i>TCP<\/i>) it is necessary to add custom <i>MEX<\/i> endpoint.<\/p>\n<pre lang=\"xml\">\r\n<system.serviceModel>\r\n    <services>\r\n          <service name=\"AudioLib.Services.AudioService\">\r\n            <endpoint address=\"AudioService\/MEX\" binding=\"mexTcpBinding\" contract=\"IMetadataExchange\">\r\n    <!-- application endpoints -->\r\n            <host>\r\n              <baseAddresses>\r\n                <add baseAddress=\"net.tcp:\/\/localhost:8080\"><\/add>\r\n              <\/baseAddresses>\r\n            <\/host>\r\n          <\/endpoint>\r\n        <\/service>\r\n    <\/services> \r\n    <!-- rest of the config -->\r\n<\/system.serviceModel>\r\n<\/pre>\n<p>The endpoint configuration has to have a specific binding &#8211; in my case <i>mexTcpBinding<\/i> (there are of course <i>MEX<\/i> bindings available for other protocols). What is more, the contract has to be set to <i>IMetadataExchange<\/i>. The address value is up to us, we can use full blown address as well as leverage base address. At this point if we run service we will get the exception<br \/>\n<a href=\"http:\/\/tpodolak.com\/blog\/wp-content\/uploads\/2015\/06\/wcf-exposing-metadata-over-tcp\/Exception.png\" rel=\"attachment wp-att-260\"><img decoding=\"async\" src=\"http:\/\/tpodolak.com\/blog\/wp-content\/uploads\/2015\/06\/wcf-exposing-metadata-over-tcp\/Exception.png\" alt=\"Exception\" width=\"600\" class=\"aligncenter size-full wp-image-260\" srcset=\"https:\/\/tpodolak.com\/blog\/wp-content\/uploads\/2015\/06\/wcf-exposing-metadata-over-tcp\/Exception.png 456w, https:\/\/tpodolak.com\/blog\/wp-content\/uploads\/2015\/06\/wcf-exposing-metadata-over-tcp\/Exception-150x67.png 150w, https:\/\/tpodolak.com\/blog\/wp-content\/uploads\/2015\/06\/wcf-exposing-metadata-over-tcp\/Exception-300x134.png 300w\" sizes=\"(max-width: 456px) 100vw, 456px\" \/><\/a><br \/>\nEven though we added custom endpoint for metadata exchange we still have to use <i>ServiceMetadataBehavior<\/i>. This time however we can skip <i>httpGetEnabled<\/i> property<\/p>\n<pre lang=\"xml\">\r\n<!-- rest of the config -->\r\n<serviceBehaviors>\r\n        <behavior>\r\n          <serviceMetadata httpgetenabled=\"true\"><\/serviceMetadata>\r\n        <\/behavior>\r\n<\/serviceBehaviors>\r\n<!-- rest of the config -->\r\n<\/pre>\n<p>From now on we can access metadata over <i>TCP<\/i><br \/>\n<a href=\"http:\/\/tpodolak.com\/blog\/wp-content\/uploads\/2015\/06\/wcf-exposing-metadata-over-tcp\/audioservicetcpmex.png\" rel=\"attachment wp-att-259\"><img decoding=\"async\" src=\"http:\/\/tpodolak.com\/blog\/wp-content\/uploads\/2015\/06\/wcf-exposing-metadata-over-tcp\/audioservicetcpmex.png\" alt=\"metadata over TCP\" width=\"600\" class=\"aligncenter size-full wp-image-259\" srcset=\"https:\/\/tpodolak.com\/blog\/wp-content\/uploads\/2015\/06\/wcf-exposing-metadata-over-tcp\/audioservicetcpmex.png 646w, https:\/\/tpodolak.com\/blog\/wp-content\/uploads\/2015\/06\/wcf-exposing-metadata-over-tcp\/audioservicetcpmex-150x122.png 150w, https:\/\/tpodolak.com\/blog\/wp-content\/uploads\/2015\/06\/wcf-exposing-metadata-over-tcp\/audioservicetcpmex-300x244.png 300w\" sizes=\"(max-width: 646px) 100vw, 646px\" \/><\/a><br \/>\nSource code for this post can be found <a href=\"https:\/\/github.com\/tpodolak\/Blog\/tree\/master\/WCFExposingServiceMetadataOverTCP\">here<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I think that everyone who has ever been working with WCF knows that we can enable metadata exchange by adding ServiceMetadataBehavior to App.config file Up until yesterday the build in solution works fine for me. However recently I&#8217;ve had to expose metadata over TCP protocol. ServiceMetadataBehavior doesn&#8217;t have something like TcpGetEnabled property so in order [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,12],"tags":[159,167],"class_list":["post-8","post","type-post","status-publish","format-standard","hentry","category-c","category-wcf","tag-c","tag-wcf"],"_links":{"self":[{"href":"https:\/\/tpodolak.com\/blog\/wp-json\/wp\/v2\/posts\/8","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tpodolak.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tpodolak.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tpodolak.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tpodolak.com\/blog\/wp-json\/wp\/v2\/comments?post=8"}],"version-history":[{"count":8,"href":"https:\/\/tpodolak.com\/blog\/wp-json\/wp\/v2\/posts\/8\/revisions"}],"predecessor-version":[{"id":522,"href":"https:\/\/tpodolak.com\/blog\/wp-json\/wp\/v2\/posts\/8\/revisions\/522"}],"wp:attachment":[{"href":"https:\/\/tpodolak.com\/blog\/wp-json\/wp\/v2\/media?parent=8"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tpodolak.com\/blog\/wp-json\/wp\/v2\/categories?post=8"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tpodolak.com\/blog\/wp-json\/wp\/v2\/tags?post=8"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}