<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><title>Ido Flatow&amp;#39;s Blog&lt;h3&gt;Veni Vidi Scripsi&lt;/h3&gt;</title><link>http://blogs.microsoft.co.il/blogs/idof/</link><description /><dc:language>en</dc:language><generator>CommunityServer 2007.1 (Build: 20917.1142)</generator><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/IdoFlatowsBlog" /><feedburner:info uri="idoflatowsblog" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item><title>Hi, my name is Ido Flatow, and in this session we will talk about…</title><link>http://feedproxy.google.com/~r/IdoFlatowsBlog/~3/5GaPKJdoMd8/hi-my-name-is-ido-flatow-and-in-this-session-we-will-talk-about.aspx</link><pubDate>Thu, 22 Mar 2012 22:23:00 GMT</pubDate><guid isPermaLink="false">b5c4f5bc-c09b-4439-a595-91a98c1847df:1040404</guid><dc:creator>Ido Flatow</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://blogs.microsoft.co.il/blogs/idof/rsscomments.aspx?PostID=1040404</wfw:commentRss><comments>http://blogs.microsoft.co.il/blogs/idof/archive/2012/03/23/hi-my-name-is-ido-flatow-and-in-this-session-we-will-talk-about.aspx#comments</comments><description>&lt;p&gt;In the next couple of months, I’m going to say that phrase many times. &lt;/p&gt;
&lt;p&gt;My &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/2011/10/02/the-month-of-october-bears-good-news.aspx"&gt;speaking&lt;/a&gt; engagements last year at VSLive in &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/2011/10/20/my-mvc-jquery-razor-nuget-iis-express-session-at-vs-live-2011-redmond.aspx"&gt;Redmond&lt;/a&gt; and &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/2011/12/07/slide-decks-and-demo-code-from-my-visual-studio-live-2011-orlando-sessions.aspx"&gt;Orlando&lt;/a&gt;, and in the North-American MCT Summit in San-Francisco marked my first steps into the world of becoming an international speaker. Until that time, most of my speaker experience came from speaking back home in Israel in courses and conferences, and here and there teaching a course abroad in Sela’s &lt;a href="http://sela.co.il/?CategoryID=464"&gt;branches&lt;/a&gt; in the world. Speaking in a conference is somewhat similar to a course, only 10x times the size of the audience, and more pressure since you only have one hour to make a good impression instead of an entire week.&lt;/p&gt;
&lt;p&gt;And now it’s time for the 2012 conferences. These next couple of months are going to be quite hectic, with conferences worldwide, and me skipping from one continent to the other. So here is my appearance list, just in case you are one of my groupies and wish to attend each of my sessions &lt;img style="BORDER-BOTTOM-STYLE:none;BORDER-LEFT-STYLE:none;BORDER-TOP-STYLE:none;BORDER-RIGHT-STYLE:none;" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://blogs.microsoft.co.il/blogs/idof/wlEmoticon-smile_3A9971BD.png" /&gt;.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/idof/image_27784511.png"&gt;&lt;img style="BACKGROUND-IMAGE:none;BORDER-BOTTOM:0px;BORDER-LEFT:0px;PADDING-LEFT:0px;PADDING-RIGHT:0px;DISPLAY:inline;BORDER-TOP:0px;BORDER-RIGHT:0px;PADDING-TOP:0px;" title="image" border="0" alt="image" src="http://blogs.microsoft.co.il/blogs/idof/image_thumb_1851406A.png" width="769" height="209" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;March 25-29 – &lt;a href="http://www.sela.co.il/s/SDP2012/index.html"&gt;Sela Developer Practice&lt;/a&gt; (SDP). Sela, Israel.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;In our annual conference I will deliver two workshops:&lt;/p&gt;
&lt;p&gt;1. &lt;strong&gt;Advanced WCF&lt;/strong&gt; – In this 1-day workshop I will show monitoring techniques for WCF, discuss about WCF performance, demonstrate various WCF security concepts, and show some useful tips for accessing WCF from client applications. In addition, I will demonstrate how to extend WCF by creating custom behaviors.&lt;/p&gt;
&lt;p&gt;2. &lt;strong&gt;Debugging the web with Fiddler&lt;/strong&gt; – In this 1-day workshop I will show you how to use Fiddler from bottom to top: how to inspect sessions, filter requests and responses, check statistics and timeline, use the composer and auto-responder, and how to create your own inspector and custom handler for Fiddler.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/idof/gids_346E1123.jpg"&gt;&lt;img style="BACKGROUND-IMAGE:none;BORDER-BOTTOM:0px;BORDER-LEFT:0px;PADDING-LEFT:0px;PADDING-RIGHT:0px;DISPLAY:inline;BORDER-TOP:0px;BORDER-RIGHT:0px;PADDING-TOP:0px;" title="gids" border="0" alt="gids" src="http://blogs.microsoft.co.il/blogs/idof/gids_thumb_63704CFA.jpg" width="769" height="238" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;April 17-20 - &lt;a href="http://www.developermarch.com/developersummit/"&gt;Great Indian Developer Summit&lt;/a&gt; (GIDS). Bangalore, India.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This will be my first appearance in GIDS, and my first time to India, so I’m twice as happy to speak at the conference. In GIDS I will have four sessions:&lt;/p&gt;
&lt;p&gt;1. &lt;strong&gt;What’s new in WCF 4&lt;/strong&gt; – simplified configuration, better IIS hosting, routing and discovery services and more. Many groups are still in the process of migrating from previous versions of .NET (1.1, 2, 3.5) to .NET 4, so if you are migrating to WCF 4, or already using it and want to learn more about it, this session is for you.&lt;/p&gt;
&lt;p&gt;2. &lt;strong&gt;What’s new in WCF 4.5&lt;/strong&gt; – UDP transport, WebSocket support, configuration Intellisense, streaming improvements, etc.. If you want to learn about the new features which will be available late this year in .NET 4.5 you should definitely come (or at the least start by &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/tags/WCF+4.5/default.aspx"&gt;reading&lt;/a&gt; my posts about it).&lt;/p&gt;
&lt;p&gt;3. &lt;strong&gt;ASP.NET MVC Razor And jQuery: The New Face Of ASP.NET&lt;/strong&gt; – so many new frameworks and concept that will make every web developer’s head spin. Unfortunately this is only a 1-hour session, so we won’t be able to touch ground on all the technologies, but at least we will have enough time to talk about MVC, jQuery, and Razor, as the new way for building web applications.&lt;/p&gt;
&lt;p&gt;4. &lt;strong&gt;Introducing The Windows Azure HPC Scheduler – &lt;/strong&gt;doing HPC using Windows HPC Server? with the new release of the Windows Azure HPC Scheduler, you can migrate your entire solution to the cloud without using any local cluster, and use the Windows Azure cloud elasticity to increase/reduce resources as needed. &lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/idof/image_0DFC080B.png"&gt;&lt;img style="BACKGROUND-IMAGE:none;BORDER-BOTTOM:0px;BORDER-LEFT:0px;PADDING-LEFT:0px;PADDING-RIGHT:0px;DISPLAY:inline;BORDER-TOP:0px;BORDER-RIGHT:0px;PADDING-TOP:0px;" title="image" border="0" alt="image" src="http://blogs.microsoft.co.il/blogs/idof/image_thumb_0EA4BE35.png" width="676" height="148" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;May 14-17 – &lt;a href="http://vslive.com/Events/New-York-2012/Home.aspx"&gt;Visual Studio Live&lt;/a&gt; (VSLive). New York, USA.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This will be my third appearance at VSLive, but I’m as excited as ever, as I will be presenting three sessions, back-to-back, all of them about WCF:&lt;/p&gt;
&lt;p&gt;1. &lt;strong&gt;What&amp;#39;s new in WCF 4 &lt;/strong&gt;– as mentioned before, a very useful session if you are currently migrating to .NET 4.&lt;/p&gt;
&lt;p&gt;2. &lt;strong&gt;What’s new in WCF 4.5&lt;/strong&gt; – just imagine being in a conference room and listening to 2 hours of new WCF features (4 &amp;amp; 4.5). If I were you, I would just wait to get back to the office to try it out.&lt;/p&gt;
&lt;p&gt;3. &lt;strong&gt;Monitoring and troubleshooting WCF services – &lt;/strong&gt;trace files, message logs, ETW, WMI, performance counters, AppFabric monitoring … Come and see all the ways for monitoring your WCF services. In addition we will discuss various aspects of instance modes and concurrency in WCF, and go over many of the settings in WCF that can affect the performance of your services.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/idof/NDC_logo_date_2012_260F4C99.jpg"&gt;&lt;img style="BACKGROUND-IMAGE:none;BORDER-BOTTOM:0px;BORDER-LEFT:0px;PADDING-LEFT:0px;PADDING-RIGHT:0px;DISPLAY:inline;BORDER-TOP:0px;BORDER-RIGHT:0px;PADDING-TOP:0px;" title="NDC_logo_date_2012" border="0" alt="NDC_logo_date_2012" src="http://blogs.microsoft.co.il/blogs/idof/NDC_logo_date_2012_thumb_473F4275.jpg" width="464" height="243" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;June 6-8 – &lt;a href="http://www.ndcoslo.com/"&gt;Norwegian Developers Conference&lt;/a&gt; (NDC). Oslo, Norway.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;First time to NDC, but this time I will not fly alone. My colleague, &lt;a href="http://blogs.microsoft.co.il/blogs/roadan"&gt;Yaniv Rodenski&lt;/a&gt;, is also a speaker at NDC where he will have a session on Hadoop on Windows Azure. As for me, I will only have one session this time, so I’ll have more time to visit Oslo:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Debugging the Web with Fiddler&lt;/strong&gt; – learn to use Fiddler, the famous Web debugger, to inspect requests and response, catch message as they pass and alter them, create responses without ever reaching the server, and write your own extensions to Fiddler. I recommend you install &lt;a href="http://www.fiddler2.com/fiddler2/version.asp"&gt;Fiddler&lt;/a&gt; on your laptop prior to the session so you can try it out during my talk.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/idof/image_72A3636F.png"&gt;&lt;img style="BACKGROUND-IMAGE:none;BORDER-BOTTOM:0px;BORDER-LEFT:0px;PADDING-LEFT:0px;PADDING-RIGHT:0px;DISPLAY:inline;BORDER-TOP:0px;BORDER-RIGHT:0px;PADDING-TOP:0px;" title="image" border="0" alt="image" src="http://blogs.microsoft.co.il/blogs/idof/image_thumb_1B121FB7.png" width="790" height="108" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;August 6-10 – &lt;a href="http://vslive.com/Events/Redmond-2012/Home.aspx"&gt;Visual Studio Live&lt;/a&gt; (VSLive). Redmond, WA, USA.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Back again to the Microsoft campus on Redmond, this will be my fourth VSLive conference, and second time as a speaker in the Redmond event. Luckily for me, I will not have to endure the 16 hours of flight (not including layovers) alone, since I will be accompanied by &lt;a href="http://blogs.microsoft.co.il/blogs/gilf/"&gt;Gil Fink&lt;/a&gt;, another one of my colleagues, who is also speaking at VSLive on HTML5 and Entity Framework. As for me, my sessions are:&lt;/p&gt;
&lt;p&gt;1. &lt;strong&gt;Building secured, scalable, low-latency web applications with the Windows Azure Platform – &lt;/strong&gt;in the past years, whenever you saw a session about Web apps in Windows Azure, you always got a lot of slides, and a bit of demo code. Well no more! this is a 1-hour code only session where I will show how to create a Web application for Windows Azure that utilizes everything Azure has to offer – compute, storage, CDN, ACS, AppFabric Cache, SQL Azure, Full IIS, WCF worker roles and more. &lt;/p&gt;
&lt;p&gt;2. &lt;strong&gt;Embracing HTTP with ASP.NET Web APIs – &lt;/strong&gt;although I’ve always been the “WCF guy”, I’m in the business of Web technologies, and you can’t build proper Web apps without harnessing the full power of the HTTP protocol. In this session I will show you what the new ASP.NET Web API is all about, and how you can use it to build HTTP services.&lt;/p&gt;
&lt;p&gt;That’s the agenda for now, and I guess that there will be more updates in the next couple of weeks. My calendar for September-December is still opened, so if you want to book me for a conference, let me know.&lt;/p&gt;
&lt;p&gt;I will also tweet with live updates from the conferences, so don’t forget to follow me @IdoFlatow&lt;/p&gt;
&lt;div style="PADDING-BOTTOM:0px;MARGIN:0px;PADDING-LEFT:0px;PADDING-RIGHT:0px;PADDING-TOP:0px;" class="wlWriterHeaderFooter"&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http://blogs.microsoft.co.il/blogs/idof/archive/2012/03/23/hi-my-name-is-ido-flatow-and-in-this-sessions-we-will-talk-about.aspx"&gt;&lt;img border="0" alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://blogs.microsoft.co.il/blogs/idof/archive/2012/03/23/hi-my-name-is-ido-flatow-and-in-this-sessions-we-will-talk-about.aspx&amp;amp;bgcolor=6600FF" /&gt;&lt;/a&gt; &lt;a href="http://dotnetshoutout.com/Submit?url=http://blogs.microsoft.co.il/blogs/idof/archive/2012/03/23/hi-my-name-is-ido-flatow-and-in-this-sessions-we-will-talk-about.aspx"&gt;&lt;img style="BORDER-BOTTOM:0px;BORDER-LEFT:0px;BORDER-TOP:0px;BORDER-RIGHT:0px;" alt="Shout it" src="http://dotnetshoutout.com/image.axd?url=http://blogs.microsoft.co.il/blogs/idof/archive/2012/03/23/hi-my-name-is-ido-flatow-and-in-this-sessions-we-will-talk-about.aspx" /&gt;&lt;/a&gt; 
&lt;div class="addthis_toolbox addthis_default_style "&gt;&lt;a class="addthis_button_preferred_1"&gt;&lt;/a&gt;&lt;a class="addthis_button_preferred_2"&gt;&lt;/a&gt;&lt;a class="addthis_button_preferred_3"&gt;&lt;/a&gt;&lt;a class="addthis_button_preferred_4"&gt;&lt;/a&gt;&lt;a class="addthis_button_compact"&gt;&lt;/a&gt;&lt;a class="addthis_counter addthis_bubble_style"&gt;&lt;/a&gt;&lt;/div&gt;
&lt;script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=ra-4f27f7864794397c"&gt;&lt;/script&gt;
&lt;/div&gt;&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=1040404" width="1" height="1"&gt;</description><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/SDP/default.aspx">SDP</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/DEV/default.aspx">DEV</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/Speaker/default.aspx">Speaker</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/GIDS/default.aspx">GIDS</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/NDC/default.aspx">NDC</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/VSLive/default.aspx">VSLive</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/Conferences/default.aspx">Conferences</category><feedburner:origLink>http://blogs.microsoft.co.il/blogs/idof/archive/2012/03/23/hi-my-name-is-ido-flatow-and-in-this-session-we-will-talk-about.aspx</feedburner:origLink></item><item><title>What’s new in WCF 4.5? WebSocket support (Part 2 of 2)</title><link>http://feedproxy.google.com/~r/IdoFlatowsBlog/~3/TXhxD1rOShs/what-s-new-in-wcf-4-5-websocket-support-part-2-of-2.aspx</link><pubDate>Tue, 06 Mar 2012 13:57:14 GMT</pubDate><guid isPermaLink="false">b5c4f5bc-c09b-4439-a595-91a98c1847df:1027907</guid><dc:creator>Ido Flatow</dc:creator><slash:comments>2</slash:comments><wfw:commentRss>http://blogs.microsoft.co.il/blogs/idof/rsscomments.aspx?PostID=1027907</wfw:commentRss><comments>http://blogs.microsoft.co.il/blogs/idof/archive/2012/03/06/what-s-new-in-wcf-4-5-websocket-support-part-2-of-2.aspx#comments</comments><description>&lt;p&gt;It’s time for post No. 12 in the WCF 4.5 series. Part 1 of 2 was about WebSocket support with SOAP-based messages. Part 2 is about WebSocket support with plain text messages that enables the interaction between web browsers and WCF.&lt;/p&gt;  &lt;p&gt;Previous posts:&lt;/p&gt;  &lt;p&gt;1. &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/2011/09/16/what-s-new-in-wcf-4-5-let-s-start-with-wcf-configuration.aspx"&gt;What’s new in WCF 4.5? let’s start with WCF configuration&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;2. &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/2011/09/17/what-s-new-in-wcf-4-5-a-single-wsdl-file.aspx"&gt;What’s new in WCF 4.5? a single WSDL file&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;3. &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/2011/09/19/what-s-new-in-wcf-4-5-configuration-tooltips-and-intellisense-in-config-files.aspx"&gt;What’s new in WCF 4.5? Configuration tooltips and intellisense in config files&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;4. &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/2011/09/25/what-s-new-in-wcf-4-5-configuration-validations.aspx"&gt;What’s new in WCF 4.5? Configuration validations&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;5. &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/2011/09/25/what-s-new-in-wcf-4-5-multiple-authentication-support-on-a-single-endpoint-in-iis.aspx"&gt;What’s new in WCF 4.5? Multiple authentication support on a single endpoint in IIS&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;6. &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/2011/10/05/what-s-new-in-wcf-4-5-automatic-https-endpoint-for-iis.aspx"&gt;What’s new in WCF 4.5? Automatic HTTPS endpoint for IIS&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;7. &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/2011/10/10/what-s-new-in-wcf-4-5-basichttpsbinding.aspx"&gt;What’s new in WCF 4.5? BasicHttpsBinding&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;8. &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/2011/10/31/what-s-new-in-wcf-4-5-changed-default-for-asp-net-compatibility-mode.aspx"&gt;What’s new in WCF 4.5? Changed default for ASP.NET compatibility mode&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;9. &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/2012/01/17/what-s-new-in-wcf-4-5-improved-streaming-in-iis-hosting.aspx"&gt;What’s new in WCF 4.5? Improved streaming in IIS hosting&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;10. &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/2012/02/15/what-s-new-in-wcf-4-5-udp-transport-support.aspx"&gt;What’s new in WCF 4.5? UDP transport support&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;11. &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/2012/03/01/what-s-new-in-wcf-4-5-websocket-support-part-1-of-2.aspx"&gt;What’s new in WCF 4.5? WebSocket support (Part 1 of 2)&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;If you haven’t read &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/2012/03/01/what-s-new-in-wcf-4-5-websocket-support-part-1-of-2.aspx"&gt;part 1&lt;/a&gt;, please go over it first so you can get the gist about WebSockets, NetHttpBinding, and how it is used in WCF.&lt;/p&gt;  &lt;p&gt;In part 1 I demonstrated how to create both binary encoded SOAP bindings and text encoded SOAP bindings with WebSockets. Problem is that in JavaScript it can get difficult to create and parse SOAP messages - this is why we tend to use XML/JSON based bindings (such as WebHttpBinding) instead of SOAP-based bindings (BasicHttpBinding/WsHttpBinding) when calling WCF services from JavaScript.&lt;/p&gt;  &lt;p&gt;Creating a duplex service with WebSockets, NetHttpBinding, and plain text messages, is just like creating any other WCF service:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Define the contract and callback contract &lt;/li&gt;    &lt;li&gt;Implement the service &lt;/li&gt;    &lt;li&gt;Configure the host &lt;/li&gt;    &lt;li&gt;Consume the service from a client app &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;First we will create our contract. Since we need to receive and send messages, we will create a duplex contract, each contract with a single method which we will mark with &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.operationcontractattribute.action.aspx"&gt;action=”*”&lt;/a&gt;:&lt;/p&gt;  &lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:facbda8f-f54c-4f54-b436-105ea3b11442" class="wlWriterSmartContent"&gt; &lt;div style="border:#000080 1px solid;color:#000;font-family:&amp;#39;Courier New&amp;#39;, Courier, Monospace;font-size:10pt;"&gt; &lt;div style="background:#000080;color:#fff;font-family:Verdana, Tahoma, Arial, sans-serif;font-weight:bold;padding:2px 5px;"&gt;Contracts&lt;/div&gt; &lt;div style="background:#ddd;max-height:300px;overflow:auto;"&gt; &lt;ol style="background:#ffffff;margin:0 0 0 2.5em;padding:0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;[&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;ServiceContract&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;]&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;public&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;interface&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;IWebSocketEchoCallback&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;{        &lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;    &lt;span style="background:#ffffff;color:#000000;"&gt;[&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;OperationContract&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;(IsOneWay = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;true&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;, Action = &lt;/span&gt;&lt;span style="background:#ffffff;color:#800000;"&gt;&amp;quot;*&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;)]        &lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;void&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; Send(&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;Message&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; message);&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;[&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;ServiceContract&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;(CallbackContract = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;typeof&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;(&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;IWebSocketEchoCallback&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;))]&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;public&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;interface&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;IWebSocketEcho&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000;"&gt;[&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;OperationContract&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;(IsOneWay = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;true&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;, Action = &lt;/span&gt;&lt;span style="background:#ffffff;color:#800000;"&gt;&amp;quot;*&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;)]&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;    &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;void&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; Receive(&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;Message&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; message);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;The echo service itself is a simple implementation that receives the message and sends it back to the client:&lt;/p&gt;  &lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:2adb4134-f483-4804-aa6b-575eac755b7a" class="wlWriterSmartContent"&gt; &lt;div style="border:#000080 1px solid;color:#000;font-family:&amp;#39;Courier New&amp;#39;, Courier, Monospace;font-size:10pt;"&gt; &lt;div style="background:#000080;color:#fff;font-family:Verdana, Tahoma, Arial, sans-serif;font-weight:bold;padding:2px 5px;"&gt;EchoService&lt;/div&gt; &lt;div style="background:#ddd;overflow:auto;"&gt; &lt;ol style="background:#ffffff;margin:0 0 0 2.5em;padding:0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;public&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;class&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;EchoService&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; : &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;IWebSocketEcho&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;    &lt;span style="background:#ffffff;color:#000000;"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;IWebSocketEchoCallback&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; _callback = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;null&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;public&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; EchoService()&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;        &lt;span style="background:#ffffff;color:#000000;"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000;"&gt;_callback =&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;                &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;OperationContext&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;.Current.GetCallbackChannel&amp;lt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;IWebSocketEchoCallback&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;&amp;gt;();&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000;"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;        &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;public&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;void&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; Receive(&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;Message&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; message)&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000;"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;            &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; (message == &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;null&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;)&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000;"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;                &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;throw&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;ArgumentNullException&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;(&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000;"&gt;&amp;quot;message&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000;"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;WebSocketMessageProperty&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; property = &lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;                &lt;span style="background:#ffffff;color:#000000;"&gt;(&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;WebSocketMessageProperty&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;)message.Properties[&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000;"&gt;&amp;quot;WebSocketMessageProperty&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;];&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;WebSocketContext&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; context = property.WebSocketContext;&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;            &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; queryParameters = &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;HttpUtility&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;.ParseQueryString(context.RequestUri.Query);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;string&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; content = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;string&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;.Empty;&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; (!message.IsEmpty)&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;            &lt;span style="background:#ffffff;color:#000000;"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;byte&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;[] body = message.GetBody&amp;lt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;byte&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;[]&amp;gt;();&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;                &lt;span style="background:#ffffff;color:#000000;"&gt;content = &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;Encoding&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;.UTF8.GetString(body);                &lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000;"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#008000;"&gt;// Do something with the content/queryParams&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;            &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#008000;"&gt;// ...&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;            &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;string&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; str = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;null&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; (&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;string&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;.IsNullOrEmpty(content)) &lt;/span&gt;&lt;span style="background:#ffffff;color:#008000;"&gt;// Connection open message&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;            &lt;span style="background:#ffffff;color:#000000;"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="background:#ffffff;color:#000000;"&gt;str = &lt;/span&gt;&lt;span style="background:#ffffff;color:#800000;"&gt;&amp;quot;Opening connection from user &amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; + &lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;                    &lt;span style="background:#ffffff;color:#000000;"&gt;queryParameters[&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000;"&gt;&amp;quot;Name&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;].ToString();                &lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000;"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;            &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;else&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#008000;"&gt;// Message received from client&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000;"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;                &lt;span style="background:#ffffff;color:#000000;"&gt;str = &lt;/span&gt;&lt;span style="background:#ffffff;color:#800000;"&gt;&amp;quot;Received message: &amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; + content;                &lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000;"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000;"&gt;_callback.Send(CreateMessage(str));            &lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;        &lt;span style="background:#ffffff;color:#000000;"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;        &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;private&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;Message&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; CreateMessage(&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;string&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; content)&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000;"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;            &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;Message&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; message = &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;ByteStreamMessage&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;.CreateMessage(&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;ArraySegment&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;byte&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;&amp;gt;(&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;                    &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;Encoding&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;.UTF8.GetBytes(content)));&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000;"&gt;message.Properties[&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000;"&gt;&amp;quot;WebSocketMessageProperty&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;] =&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;                &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;WebSocketMessageProperty&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="background:#ffffff;color:#000000;"&gt;{ MessageType = &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;WebSocketMessageType&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;.Text };&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;                        &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; message;&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;        &lt;span style="background:#ffffff;color:#000000;"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000;"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;The &lt;strong&gt;Receive &lt;/strong&gt;method handles two types of calls:&lt;/p&gt;  &lt;p&gt;1. The first “connection upgrade” message – when the client first connects to the service and tries to upgrade the connection from HTTP to WebSocket. In this call the request is sent using HTTP GET, and therefore there is no body, but we can access the URL’s query string.&lt;/p&gt;  &lt;p&gt;2. The second message and on are the messages being sent by the client over the WebSocket transport – these messages contain a message body, with no special query string.&lt;/p&gt;  &lt;p&gt;Line 5-9 shows how to create a standard duplex service by storing the callback channel in a local variable. The callback channel will be used later on in the code in order to send messages back to the client. The service uses the default instancing mode which is PerSession, so a new instance will be created for each client, and the local variable will point to a different callback channel in each service instance.&lt;/p&gt;  &lt;p&gt;Lines 17-27 demonstrates the technique of parsing the message – either by checking its query string or by reading the byte array from the message and transforming it to a string.&lt;/p&gt;  &lt;p&gt;Lines 32-43 checks which type of message is being handled, the first connection request, or a consequent message from the client. In each case the service responds by echoing the message back to the client.&lt;/p&gt;  &lt;p&gt;Line 46-56 demonstrates how to create a Message object with a simple string content when using the byte stream encoding.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: to use the &lt;strong&gt;ByteStreamMessage &lt;/strong&gt;type, add a reference to the &lt;strong&gt;System.ServiceModel.Channels&lt;/strong&gt; assembly.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: WebSocket messages can be either text or binary, so if you are planning on using binary messages you will need to change the code to work with byte arrays instead of strings.&lt;/p&gt;  &lt;p&gt;Now that we have the contracts and the service, we need to define our host and endpoint. In this example I will use IIS as the host and I will use the routing mechanism of ASP.NET to create a service URL address that doesn’t contain the annoying “.svc” extension. The following global.asax code shows how to do that:&lt;/p&gt;  &lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:a7dabbd6-e54f-4812-9f2d-50147332dc56" class="wlWriterSmartContent"&gt; &lt;div style="border:#000080 1px solid;color:#000;font-family:&amp;#39;Courier New&amp;#39;, Courier, Monospace;font-size:10pt;"&gt; &lt;div style="background:#000080;color:#fff;font-family:Verdana, Tahoma, Arial, sans-serif;font-weight:bold;padding:2px 5px;"&gt;Global.Asax&lt;/div&gt; &lt;div style="background:#ddd;max-height:300px;overflow:auto;"&gt; &lt;ol style="background:#ffffff;margin:0 0 0 2.5em;padding:0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;public&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;class&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;Global&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; : System.Web.&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;HttpApplication&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;protected&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;void&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; Application_Start(&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;object&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; sender, &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;EventArgs&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; e)&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;    &lt;span style="background:#ffffff;color:#000000;"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;RouteTable&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;.Routes.Add(&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;ServiceRoute&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;(&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000;"&gt;&amp;quot;echo&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;,&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;            &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;ServiceHostFactory&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;(),&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;typeof&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;(&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;EchoService&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;)));&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;    &lt;span style="background:#ffffff;color:#000000;"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;And now for the endpoint configuration. Since NetHttpBinding uses SOAP messages, and there is no “WebSocketHttpBinding” for passing plain byte streams, we need to create a custom binding that will allow us to receive messages over WebSocket where the message can either be a text message or a binary message (the WebSocket API supports both types).&lt;/p&gt;  &lt;p&gt;The standard encodings of WCF - text, binary, and MTOM, will not enable us to receive non-SOAP byte streams, that is why we need to use a new encoding which was introduced in WCF 4 – the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.channels.bytestreammessageencodingbindingelement.aspx"&gt;ByteStreamMessageEncoding&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;The following endpoint and binding configuration will allow us to open a WebSocket listener that receives simple byte streams:&lt;/p&gt;  &lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:137d57bc-f4a5-4838-9de4-223ab6db75bf" class="wlWriterSmartContent"&gt; &lt;div style="border:#000080 1px solid;color:#000;font-family:&amp;#39;Courier New&amp;#39;, Courier, Monospace;font-size:10pt;"&gt; &lt;div style="background:#000080;color:#fff;font-family:Verdana, Tahoma, Arial, sans-serif;font-weight:bold;padding:2px 5px;"&gt;Service Configuration&lt;/div&gt; &lt;div style="background:#ddd;overflow:auto;"&gt; &lt;ol style="background:#ffffff;margin:0 0 0 2.5em;padding:0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt; &amp;lt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515;"&gt;system.serviceModel&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;    &lt;span style="background:#ffffff;color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515;"&gt;serviceHostingEnvironment&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#ff0000;"&gt;aspNetCompatibilityEnabled&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;=&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;true&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt; &lt;/span&gt;&lt;/li&gt; &lt;li&gt;                               &lt;span style="background:#ffffff;color:#0000ff;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#ff0000;"&gt;multipleSiteBindingsEnabled&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;=&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;true&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt; /&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;    &lt;span style="background:#ffffff;color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515;"&gt;services&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;      &lt;span style="background:#ffffff;color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515;"&gt;service&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#ff0000;"&gt;name&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;=&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;UsingWebSockets.EchoService&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;        &lt;span style="background:#ffffff;color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515;"&gt;endpoint&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#ff0000;"&gt;address&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;=&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt; &lt;/span&gt;&lt;/li&gt; &lt;li&gt;                  &lt;span style="background:#ffffff;color:#0000ff;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#ff0000;"&gt;binding&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;=&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;customBinding&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt; &lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;                  &lt;span style="background:#ffffff;color:#0000ff;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#ff0000;"&gt;bindingConfiguration&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;=&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;webSocket&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;&amp;quot;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                  &lt;span style="background:#ffffff;color:#0000ff;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#ff0000;"&gt;contract&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;=&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;UsingWebSockets.IWebSocketEcho&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt; /&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;      &lt;span style="background:#ffffff;color:#0000ff;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515;"&gt;service&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#0000ff;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515;"&gt;services&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;    &lt;span style="background:#ffffff;color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515;"&gt;bindings&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;      &lt;span style="background:#ffffff;color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515;"&gt;customBinding&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;        &lt;span style="background:#ffffff;color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515;"&gt;binding&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#ff0000;"&gt;name&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;=&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;webSocket&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;&amp;gt;          &lt;/span&gt;&lt;/li&gt; &lt;li&gt;          &lt;span style="background:#ffffff;color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515;"&gt;byteStreamMessageEncoding&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;/&amp;gt;            &lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;          &lt;span style="background:#ffffff;color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515;"&gt;httpTransport&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;&amp;gt;            &lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515;"&gt;webSocketSettings&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#ff0000;"&gt;transportUsage&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;=&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;Always&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt; &lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;                               &lt;span style="background:#ffffff;color:#0000ff;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#ff0000;"&gt;createNotificationOnConnection&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;=&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;true&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;/&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;          &lt;span style="background:#ffffff;color:#0000ff;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515;"&gt;httpTransport&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;        &lt;span style="background:#ffffff;color:#0000ff;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515;"&gt;binding&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;      &lt;span style="background:#ffffff;color:#0000ff;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515;"&gt;customBinding&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;    &lt;span style="background:#ffffff;color:#0000ff;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515;"&gt;bindings&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;  &lt;span style="background:#ffffff;color:#0000ff;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515;"&gt;system.serviceModel&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;The important part in the configuration is lines 13-21:&lt;/p&gt;  &lt;p&gt;1. We set the &lt;strong&gt;transportUsage &lt;/strong&gt;to &lt;strong&gt;Always &lt;/strong&gt;to force the usage of WebSocket rather than HTTP.&lt;/p&gt;  &lt;p&gt;2. We set the &lt;strong&gt;createNotificationOnConnection&lt;/strong&gt; to &lt;strong&gt;true&lt;/strong&gt; to allow our Receive method to be invoked for the connection request message (the first GET request which is sent to the service).&lt;/p&gt;  &lt;p&gt;3. We use the &lt;strong&gt;byteStreamMessageEncoding&lt;/strong&gt; which allows the service to receive simple byte streams as input instead of complex SOAP structures.&lt;/p&gt;  &lt;p&gt;To test our code we can add an HTML page to our project. The following code is based on the StockTicker demo from the HTML5 Labs &lt;a href="http://html5labs.interoperabilitybridges.com/prototypes/websockets/websockets/info"&gt;website&lt;/a&gt;:&lt;/p&gt;  &lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:d186c6f8-332f-4049-a5a4-b65694fda42a" class="wlWriterSmartContent"&gt; &lt;div style="border:#000080 1px solid;color:#000;font-family:&amp;#39;Courier New&amp;#39;, Courier, Monospace;font-size:10pt;"&gt; &lt;div style="background:#000080;color:#fff;font-family:Verdana, Tahoma, Arial, sans-serif;font-weight:bold;padding:2px 5px;"&gt;Echo Client&lt;/div&gt; &lt;div style="background:#ddd;overflow:auto;"&gt; &lt;ol style="background:#ffffff;margin:0 0 0 2.5em;padding:0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;&amp;lt;!&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000;"&gt;DOCTYPE&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#ff0000;"&gt;html&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000;"&gt;html&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#ff0000;"&gt;xmlns&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;=&amp;quot;http://www.w3.org/1999/xhtml&amp;quot;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000;"&gt;head&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;    &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000;"&gt;title&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;Echo Demo&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000;"&gt;title&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000;"&gt;script&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#ff0000;"&gt;src&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;=&amp;quot;Scripts/jquery-1.4.1.js&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#ff0000;"&gt;type&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;=&amp;quot;text/javascript&amp;quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000;"&gt;script&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;    &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000;"&gt;script&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;        &lt;span style="background:#ffffff;color:#000000;"&gt;$(document).ready(&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; () {&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; (!window.WebSocket &amp;amp;&amp;amp; window.MozWebSocket) {&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;                &lt;span style="background:#ffffff;color:#000000;"&gt;window.WebSocket = window.MozWebSocket;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000;"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000;"&gt;$(&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000;"&gt;&amp;#39;#echoForm&amp;#39;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;).submit(&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; (event) {&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;                &lt;span style="background:#ffffff;color:#000000;"&gt;$(&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000;"&gt;&amp;#39;#echoForm&amp;#39;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;)&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                    &lt;span style="background:#ffffff;color:#000000;"&gt;.add(&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000;"&gt;&amp;#39;#echoForm &amp;gt; *&amp;#39;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;)&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;                    &lt;span style="background:#ffffff;color:#000000;"&gt;.attr(&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000;"&gt;&amp;#39;disabled&amp;#39;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;, &lt;/span&gt;&lt;span style="background:#ffffff;color:#800000;"&gt;&amp;#39;disabled&amp;#39;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;                &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; uri = &lt;/span&gt;&lt;span style="background:#ffffff;color:#800000;"&gt;&amp;#39;ws://&amp;#39;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; + window.location.hostname +&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                    &lt;span style="background:#ffffff;color:#000000;"&gt;window.location.pathname.replace(&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000;"&gt;&amp;#39;EchoDemo.html&amp;#39;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;, &lt;/span&gt;&lt;span style="background:#ffffff;color:#800000;"&gt;&amp;#39;echo&amp;#39;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;) +&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;                    &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000;"&gt;&amp;#39;?Name=&amp;#39;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; + $(&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000;"&gt;&amp;quot;#name&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;).val();&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="background:#ffffff;color:#000000;"&gt;connect(uri);&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;                &lt;span style="background:#ffffff;color:#000000;"&gt;event.preventDefault();&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000;"&gt;});&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000;"&gt;});&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; connect(uri) {&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;            &lt;span style="background:#ffffff;color:#000000;"&gt;$(&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000;"&gt;&amp;#39;#messages&amp;#39;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;).prepend(&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000;"&gt;&amp;#39;&amp;lt;div&amp;gt;Connecting...&amp;lt;/div&amp;gt;&amp;#39;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;            &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; websocket = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; WebSocket(uri);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;            &lt;span style="background:#ffffff;color:#000000;"&gt;websocket.onopen = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; () {&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="background:#ffffff;color:#000000;"&gt;window.focus();&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;                &lt;span style="background:#ffffff;color:#000000;"&gt;$(&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000;"&gt;&amp;#39;#echoForm&amp;#39;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;).hide();&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="background:#ffffff;color:#000000;"&gt;$(&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000;"&gt;&amp;#39;#outputArea&amp;#39;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;).show();&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;                &lt;span style="background:#ffffff;color:#000000;"&gt;window.setInterval(&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;()&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="background:#ffffff;color:#000000;"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;                   &lt;span style="background:#ffffff;color:#000000;"&gt;websocket.send(&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000;"&gt;&amp;quot;the time is &amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; + &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; Date());&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="background:#ffffff;color:#000000;"&gt;}, 1000);                &lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;                &lt;span style="background:#ffffff;color:#000000;"&gt;$(&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000;"&gt;&amp;#39;#messages&amp;#39;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;).html(&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                    &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000;"&gt;&amp;#39;&amp;lt;div&amp;gt;Connected. Waiting for messages...&amp;lt;/div&amp;gt;&amp;#39;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;);&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;            &lt;span style="background:#ffffff;color:#000000;"&gt;};&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;            &lt;span style="background:#ffffff;color:#000000;"&gt;websocket.onclose = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; () {&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; (document.readyState == &lt;/span&gt;&lt;span style="background:#ffffff;color:#800000;"&gt;&amp;quot;complete&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;) {&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;                    &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; warn = $(&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000;"&gt;&amp;#39;&amp;lt;div&amp;gt;&amp;#39;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;).html(&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                        &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000;"&gt;&amp;#39;Connection lost. Refresh the page to start again.&amp;#39;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;).&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;                        &lt;span style="background:#ffffff;color:#000000;"&gt;css(&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000;"&gt;&amp;#39;color&amp;#39;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;, &lt;/span&gt;&lt;span style="background:#ffffff;color:#800000;"&gt;&amp;#39;red&amp;#39;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                    &lt;span style="background:#ffffff;color:#000000;"&gt;$(&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000;"&gt;&amp;#39;#messages&amp;#39;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;).append(warn);&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;                &lt;span style="background:#ffffff;color:#000000;"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000;"&gt;};&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000;"&gt;websocket.onmessage = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;function&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; (event) {&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;                &lt;span style="background:#ffffff;color:#000000;"&gt;$(&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000;"&gt;&amp;quot;#messages&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;).append(event.data + &lt;/span&gt;&lt;span style="background:#ffffff;color:#800000;"&gt;&amp;quot;&amp;lt;br&amp;gt;&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="background:#ffffff;color:#000000;"&gt;};&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;        &lt;span style="background:#ffffff;color:#000000;"&gt;};&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000;"&gt;script&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000;"&gt;head&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000;"&gt;body&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000;"&gt;form&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#ff0000;"&gt;id&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;=&amp;quot;echoForm&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#ff0000;"&gt;action&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;=&amp;quot;&amp;quot;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;    &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000;"&gt;input&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#ff0000;"&gt;type&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;=&amp;quot;text&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#ff0000;"&gt;id&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;=&amp;quot;name&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#ff0000;"&gt;placeholder&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;=&amp;quot;type your name&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;/&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000;"&gt;form&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;        &lt;span style="background:#ffffff;color:#000000;"&gt;    &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000;"&gt;div&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#ff0000;"&gt;id&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;=&amp;quot;outputArea&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#ff0000;"&gt;style&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;=&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#ff0000;"&gt;display&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;: &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;none&amp;quot;&amp;gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000;"&gt;div&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#ff0000;"&gt;id&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;=&amp;quot;messages&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#ff0000;"&gt;style&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;=&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#ff0000;"&gt;height&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;: &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;80%&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;; &lt;/span&gt;&lt;span style="background:#ffffff;color:#ff0000;"&gt;overflow&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;: &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;hidden&amp;quot;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;        &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000;"&gt;div&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000;"&gt;div&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000;"&gt;body&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000;"&gt;html&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;Most of the above code is jQuery stuff to handle the incoming message, so let’s point out the important parts:&lt;/p&gt;  &lt;p&gt;Lines 18-20 – In these lines we create the URI of the service. Note the use of the ws:// scheme – this is the scheme of WebSocket, but it works just fine even when our service base address is set to HTTP.&lt;/p&gt;  &lt;p&gt;Lines 27-56 – the &lt;strong&gt;connect&lt;/strong&gt; function basically does all the rest. The WebSocket functions are based on the &lt;a href="http://dev.w3.org/html5/websockets/"&gt;WebSocket API&lt;/a&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Line 30 – create the WebSocket object &lt;/li&gt;    &lt;li&gt;Lines 32-42 – open the connection &lt;/li&gt;    &lt;li&gt;Lines 36-49 – run a function every 1 second that sends the current time to the service &lt;/li&gt;    &lt;li&gt;Lines 44-51 – handle the WebSocket channel closing &lt;/li&gt;    &lt;li&gt;Lines 53-55 – handle a received message (a message sent from the service to the client) &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Running the client will show the following output:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/idof/image_22337674.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://blogs.microsoft.co.il/blogs/idof/image_thumb_109365DC.png" width="464" height="261" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;To conclude, in order to create a service that can receive and send message to browsers using WebSockets we need to do the following:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Create the duplex contract which contains a simple Receive and Send methods (or any other names you like). &lt;/li&gt;    &lt;li&gt;Implement the contract in a service like you’ll implement any other duplex service. The only thing you need to take care of is how to read and write the message. &lt;/li&gt;    &lt;li&gt;Create an endpoint which uses a custom binding which supports WebSockets and simple byte-stream encoding. &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;Although the above works quite well, there is another way to create this type of service – by creating a service class that inherits from the &lt;strong&gt;Microsoft.WebSockets.WebSocketService&lt;/strong&gt; type. The Microsoft.WebSockets &lt;a href="http://nuget.org/packages/Microsoft.WebSockets/0.2"&gt;package&lt;/a&gt;, available from NuGet, enables the creation of WebSocket-based services. Once inheriting your service from &lt;strong&gt;WebSocketService&lt;/strong&gt;, you can override methods such as &lt;strong&gt;OnMessage&lt;/strong&gt;, &lt;strong&gt;OnOpen&lt;/strong&gt;, &lt;strong&gt;OnClose&lt;/strong&gt;, and &lt;strong&gt;OnError&lt;/strong&gt;. Working with these methods is quite easy, as demonstrated in the following code:&lt;/p&gt;  &lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:1bcd6442-2779-4eb1-a715-885571ccfc01" class="wlWriterSmartContent"&gt; &lt;div style="border:#000080 1px solid;color:#000;font-family:&amp;#39;Courier New&amp;#39;, Courier, Monospace;font-size:10pt;"&gt; &lt;div style="background:#000080;color:#fff;font-family:Verdana, Tahoma, Arial, sans-serif;font-weight:bold;padding:2px 5px;"&gt;EchoService2&lt;/div&gt; &lt;div style="background:#ddd;overflow:auto;"&gt; &lt;ol style="background:#ffffff;margin:0 0 0 2.5em;padding:0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;public&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;class&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;EchoService2&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; : &lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;     &lt;span style="background:#ffffff;color:#000000;"&gt;Microsoft.ServiceModel.WebSockets.&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;WebSocketService&lt;/span&gt;&lt;/li&gt; &lt;li&gt; &lt;span style="background:#ffffff;color:#000000;"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;     &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;public&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;override&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;void&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; OnMessage(&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;string&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; message)&lt;/span&gt;&lt;/li&gt; &lt;li&gt;     &lt;span style="background:#ffffff;color:#000000;"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;         &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;string&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; str = &lt;/span&gt;&lt;span style="background:#ffffff;color:#800000;"&gt;&amp;quot;Received message: &amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; + message;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;         &lt;span style="background:#ffffff;color:#000000;"&gt;Send(str);&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;     &lt;span style="background:#ffffff;color:#000000;"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;     &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;     &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;public&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;override&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;void&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; OnOpen()&lt;/span&gt;&lt;/li&gt; &lt;li&gt;     &lt;span style="background:#ffffff;color:#000000;"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;         &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; queryParameters = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;this&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;.QueryParameters;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;         &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;string&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; str = &lt;/span&gt;&lt;span style="background:#ffffff;color:#800000;"&gt;&amp;quot;Opening connection from user &amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; +&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;             &lt;span style="background:#ffffff;color:#000000;"&gt;queryParameters[&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000;"&gt;&amp;quot;Name&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;].ToString();&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;          &lt;span style="background:#ffffff;color:#000000;"&gt;Send(str);                        &lt;/span&gt;&lt;/li&gt; &lt;li&gt;     &lt;span style="background:#ffffff;color:#000000;"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;     &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;protected&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;override&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;void&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; OnClose()&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;     &lt;span style="background:#ffffff;color:#000000;"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;         &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;base&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;.OnClose();            &lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;     &lt;span style="background:#ffffff;color:#000000;"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;     &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;protected&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;override&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;void&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; OnError()&lt;/span&gt;&lt;/li&gt; &lt;li&gt;     &lt;span style="background:#ffffff;color:#000000;"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;         &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;base&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;.OnError();            &lt;/span&gt;&lt;/li&gt; &lt;li&gt;     &lt;span style="background:#ffffff;color:#000000;"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt; &lt;span style="background:#ffffff;color:#000000;"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;As you can see, in this case you don’t have to work directly with byte arrays. In order to host this service you also don’t need to define a special endpoint configuration, as this package includes a &lt;strong&gt;WebSocketHost&lt;/strong&gt; class that automatically creates and configures a WebSocket endpoint. To create a WebSocketHost and provide it to IIS, we need to create a class that inherits from ServiceHostFactory, as demonstrated in the following code :&lt;/p&gt;  &lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:b0326016-ebdb-440c-9870-49a91d3cbc4c" class="wlWriterSmartContent"&gt; &lt;div style="border:#000080 1px solid;color:#000;font-family:&amp;#39;Courier New&amp;#39;, Courier, Monospace;font-size:10pt;"&gt; &lt;div style="background:#000080;color:#fff;font-family:Verdana, Tahoma, Arial, sans-serif;font-weight:bold;padding:2px 5px;"&gt;WebSocketServiceHostFactory&lt;/div&gt; &lt;div style="background:#ddd;max-height:300px;overflow:auto;"&gt; &lt;ol style="background:#ffffff;margin:0 0 0 2.5em;padding:0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;public&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;class&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;WebSocketServiceHostFactory&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; : &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;ServiceHostFactory&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;  &lt;span style="background:#ffffff;color:#000000;"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;      &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;protected&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;override&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;ServiceHost&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; CreateServiceHost(&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;Type&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; serviceType, &lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;          &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;Uri&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;[] baseAddresses)&lt;/span&gt;&lt;/li&gt; &lt;li&gt;      &lt;span style="background:#ffffff;color:#000000;"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;          &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; host = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;WebSocketHost&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;(serviceType, baseAddresses);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;          &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;          &lt;span style="background:#ffffff;color:#000000;"&gt;host.AddWebSocketEndpoint();&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;          &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; host;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;      &lt;span style="background:#ffffff;color:#000000;"&gt;}        &lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;  &lt;span style="background:#ffffff;color:#000000;"&gt;}    &lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: the ServiceHostFactory is declared in the &lt;strong&gt;System.ServiceModel.Activation&lt;/strong&gt; assembly, so don’t forget to add a reference to it.&lt;/p&gt;  &lt;p&gt;Once we have the new factory, we can register it with the routing mechanism (lines 5-7):&lt;/p&gt;  &lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:ebdbe2b5-625a-48c5-a4dd-9fce6a7f0774" class="wlWriterSmartContent"&gt; &lt;div style="border:#000080 1px solid;color:#000;font-family:&amp;#39;Courier New&amp;#39;, Courier, Monospace;font-size:10pt;"&gt; &lt;div style="background:#000080;color:#fff;font-family:Verdana, Tahoma, Arial, sans-serif;font-weight:bold;padding:2px 5px;"&gt;Global.Asax&lt;/div&gt; &lt;div style="background:#ddd;overflow:auto;"&gt; &lt;ol style="background:#ffffff;margin:0 0 0 2.5em;padding:0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;public&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;class&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;Global&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; : System.Web.&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;HttpApplication&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;  &lt;span style="background:#ffffff;color:#000000;"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;      &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;protected&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;void&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; Application_Start(&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;object&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; sender, &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;EventArgs&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; e)&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;      &lt;span style="background:#ffffff;color:#000000;"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;          &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;RouteTable&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;.Routes.Add(&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;ServiceRoute&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;(&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000;"&gt;&amp;quot;echo2&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;,&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;              &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;WebSocketServiceHostFactory&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;(),&lt;/span&gt;&lt;/li&gt; &lt;li&gt;              &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;typeof&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;(&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;EchoService2&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;)));&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;          &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;RouteTable&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;.Routes.Add(&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;ServiceRoute&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;(&lt;/span&gt;&lt;span style="background:#ffffff;color:#800000;"&gt;&amp;quot;echo&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;,&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;              &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;ServiceHostFactory&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;(),&lt;/span&gt;&lt;/li&gt; &lt;li&gt;              &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;typeof&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;(&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;EchoService&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;)));&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;      &lt;span style="background:#ffffff;color:#000000;"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;  &lt;span style="background:#ffffff;color:#000000;"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;All is left is to change the client HTML code in line 19 to call the ‘echo2’ service instead of ‘echo’.&lt;/p&gt;  &lt;p&gt;You can see more examples on how to use this package in Paul Batum’s &lt;a href="http://www.paulbatum.com/2011/09/getting-started-with-websockets-in.html"&gt;blog post&lt;/a&gt;, and in his //BUILD &lt;a href="http://channel9.msdn.com/Events/BUILD/BUILD2011/SAC-807T"&gt;session&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;So as you can see, it is quite easy to create a WCF service that can receive messages from a browser and push messages to a browser by using WebSockets. Farewell long polling, I hope we never meet again &lt;img style="border-bottom-style:none;border-left-style:none;border-top-style:none;border-right-style:none;" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://blogs.microsoft.co.il/blogs/idof/wlEmoticon-smile_58B0FBEB.png" /&gt;&lt;/p&gt;  &lt;p&gt;You can download the above code (both versions) from my &lt;a href="https://skydrive.live.com/redir.aspx?cid=5ef5be1ab30a6056&amp;amp;resid=5EF5BE1AB30A6056!490&amp;amp;parid=5EF5BE1AB30A6056!129"&gt;SkyDrive&lt;/a&gt;. The source code also includes a sample self-hosted WebSocket service and an HTML page that uses it instead of the IIS-hosted service.&lt;/p&gt;&lt;div class="wlWriterHeaderFooter" style="margin:0px;padding:0px 0px 0px 0px;"&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http://blogs.microsoft.co.il/blogs/idof/archive/2012/03/06/what-s-new-in-wcf-4-5-websocket-support-part-2-of-2.aspx"&gt;&lt;img border="0" alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://blogs.microsoft.co.il/blogs/idof/archive/2012/03/06/what-s-new-in-wcf-4-5-websocket-support-part-2-of-2.aspx&amp;amp;bgcolor=6600FF" /&gt;&lt;/a&gt; &lt;a href="http://dotnetshoutout.com/Submit?url=http://blogs.microsoft.co.il/blogs/idof/archive/2012/03/06/what-s-new-in-wcf-4-5-websocket-support-part-2-of-2.aspx"&gt;&lt;img alt="Shout it" src="http://dotnetshoutout.com/image.axd?url=http://blogs.microsoft.co.il/blogs/idof/archive/2012/03/06/what-s-new-in-wcf-4-5-websocket-support-part-2-of-2.aspx" style="border:0px;" /&gt;&lt;/a&gt; 			  &lt;div class="addthis_toolbox addthis_default_style "&gt; &lt;a class="addthis_button_preferred_1"&gt;&lt;/a&gt; &lt;a class="addthis_button_preferred_2"&gt;&lt;/a&gt; &lt;a class="addthis_button_preferred_3"&gt;&lt;/a&gt; &lt;a class="addthis_button_preferred_4"&gt;&lt;/a&gt; &lt;a class="addthis_button_compact"&gt;&lt;/a&gt; &lt;a class="addthis_counter addthis_bubble_style"&gt;&lt;/a&gt; &lt;/div&gt; &lt;script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=ra-4f27f7864794397c"&gt;&lt;/script&gt; &lt;a href="http://www.codeproject.com/script/Articles/BlogFeedList.aspx?amid=2199681" rel="tag" style="display:none;"&gt;CodeProject&lt;/a&gt; &lt;/div&gt;&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=1027907" width="1" height="1"&gt;</description><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/DEV/default.aspx">DEV</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/What_2700_s+new/default.aspx">What's new</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/WCF+4.5/default.aspx">WCF 4.5</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/websocket/default.aspx">websocket</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/browser/default.aspx">browser</category><feedburner:origLink>http://blogs.microsoft.co.il/blogs/idof/archive/2012/03/06/what-s-new-in-wcf-4-5-websocket-support-part-2-of-2.aspx</feedburner:origLink></item><item><title>WCF or ASP.NET Web APIs? My two cents on the subject</title><link>http://feedproxy.google.com/~r/IdoFlatowsBlog/~3/0XosiLVKySw/wcf-or-asp-net-web-apis-my-two-cents-on-the-subject.aspx</link><pubDate>Mon, 05 Mar 2012 11:39:12 GMT</pubDate><guid isPermaLink="false">b5c4f5bc-c09b-4439-a595-91a98c1847df:1027021</guid><dc:creator>Ido Flatow</dc:creator><slash:comments>12</slash:comments><wfw:commentRss>http://blogs.microsoft.co.il/blogs/idof/rsscomments.aspx?PostID=1027021</wfw:commentRss><comments>http://blogs.microsoft.co.il/blogs/idof/archive/2012/03/05/wcf-or-asp-net-web-apis-my-two-cents-on-the-subject.aspx#comments</comments><description>&lt;p&gt;A couple of weeks ago (around Feb. 16) the WCF WebAPIs - a framework for building RESTful/Hypermedia/HTTP services, which was in development over the past 1.5 years as a side-project on &lt;a href="http://wcf.codeplex.com/"&gt;CodePlex&lt;/a&gt;, has been formally &lt;a href="http://wcf.codeplex.com/wikipage?title=WCF%20Web%20API%20is%20now%20ASP.NET%20Web%20API"&gt;integrated&lt;/a&gt; into ASP.NET and its name changed to the ASP.NET Web API.&lt;/p&gt;  &lt;p&gt;These past two weeks, there has been a lot of questions among WCF developers: What does it mean that the Web APIs are no longer a part of WCF – is WCF dead? Has SOAP gone bankrupted? is HTTP the new way to go for interoperability? &lt;/p&gt;  &lt;p&gt;To get a better understanding of what happened and what is the way to go, we need to answer a couple of questions:&lt;/p&gt;  &lt;p&gt;1. What is the purpose of the WebAPIs?&lt;/p&gt;  &lt;p&gt;2. Why do we need &lt;strike&gt;REST&lt;/strike&gt; HTTP services? What’s wrong with SOAP-over-HTTP? &lt;/p&gt;  &lt;p&gt;3. Why did the WebAPIs move from WCF to ASP.NET MVC?&lt;/p&gt;  &lt;p&gt;4. Is there still a use for WCF? When should I choose Web APIs over WCF?&lt;/p&gt;  &lt;p&gt;&lt;u&gt;What is the purpose of the WebAPIs?&lt;/u&gt;&lt;/p&gt;  &lt;p&gt;When WCF was conceived back in its Indigo and .NET 3 days, the main goal was to support SOAP + WS-* over a wide variety of transports. However, over time it became clear that although SOAP is wide spread and supported on many platforms, it is not the only way to go when creating services. There is also a need to also support non-SOAP services, especially over HTTP, where you can harness the power of the HTTP protocol to create HTTP services: services that are activated by simple GET requests, or by passing plain XML over POST, and respond with non-SOAP content such as plain XML, a JSON string, or any other content that can be used by the consumer. Support for non-SOAP services was very much needed in WCF back then, mostly because some clients, such as web browsers, were not that suitable to handle SOAP messages (plenty of XML parsing and DOM manipulation).&lt;/p&gt;  &lt;p&gt;So in WCF 3.5 we got the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.webhttpbinding.aspx"&gt;WebHttpBinding&lt;/a&gt; – a new binding that helped us create this kind of non-SOAP service over HTTP, better known as a RESTful service.&lt;/p&gt;  &lt;p&gt;The WebHttpBinding was not enough, and after WCF 3.5 was released, a new set of tools was created – the &lt;a href="http://msdn.microsoft.com/en-us/library/ee391967.aspx"&gt;WCF REST Starter Kit&lt;/a&gt;. The REST starter kit was an attempt to enrich the support of WCF 3.5 for HTTP services – add better client-side support for .NET apps, extend the server side support for other content types, enable response and request caching, inspection of messages and so forth. Unfortunately, this great toolkit was never officially released and ended its product cycle as “Preview 2”, although it’s still being used today in some of Microsoft’s products that are built with .NET 3.5.&lt;/p&gt;  &lt;p&gt;Although not released, some of the service-side features of the REST starter kit were &lt;a href="http://blogs.msdn.com/b/endpoint/archive/2010/01/06/introducing-wcf-webhttp-services-in-net-4.aspx"&gt;integrated into WCF 4&lt;/a&gt; – we didn’t get any of the client-side libraries, but we did get most of the service-side features (excluding the new inspectors). Some were well-integrated into WCF while others required the use of ASP.NET (by turning on the ASP.NET compatibility mode).&lt;/p&gt;  &lt;p&gt;So with WCF 4 we had some support for “Web” HTTP services, but it wasn’t that perfect – to get some of the features you needed IIS hosting and ASP.NET, not all types of requests were supported easily (ever tried posting HTML form data to a WCF HTTP service?), the overuse of CLR attributes to define the POST/GET/PUT/DELETE was tedious, not to mention the configuration required to create this type of services with all of the endpoint behavior. And even after all of that we didn’t actually get full control over the HTTP messages.&lt;/p&gt;  &lt;p&gt;That was the main goal of the Web APIs, known back then as the WCF Web APIs: to stop looking at HTTP through the eyes of WCF - as just a transport protocol to pass requests. Rather, it allows us to look at it as the real application-level protocol it is – a rich, interoperable, resource-oriented protocol. The purpose of the Web APIs was to properly use URIs, HTTP headers, and body to create HTTP services for the web, and for everyone else that wished to embrace HTTP as its protocol and lifelong friend.&lt;/p&gt;  &lt;p&gt;&lt;u&gt;Why do we need &lt;strike&gt;REST&lt;/strike&gt; HTTP services? What’s wrong with SOAP-over-HTTP? &lt;/u&gt;&lt;/p&gt;  &lt;p&gt;The world of SOAP and the world of HTTP services are very different. SOAP allows us to place all the knowledge required by our service in the message itself, disregarding its transport protocol, whether it is TCP, HTTP, UDP, PGM, Named Pipes… But unlike TCP, UDP and the other &lt;a href="http://en.wikipedia.org/wiki/OSI_model"&gt;level 4-5&lt;/a&gt; protocols, HTTP is an application-level protocol, and as such it offers a wide variety of features:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;It supports verbs that define the action - query information using GET, place new information and update existing using POST or PUT, remove information using DELETE etc. &lt;/li&gt;    &lt;li&gt;It contains message headers that are very meaningful and descriptive - headers that suggest the content type of the message’s body, headers that explain how to cache information, how to secure it etc. &lt;/li&gt;    &lt;li&gt;It contains a body that can be used for any type of content, not just XML content as SOAP enforces (and if you want something else – encode it to base64 strings and place it in the SOAP’s XML content). The body of HTTP messages can be anything you want – HTML, plain XML, JSON, binary files (images, videos, documents…) … &lt;/li&gt;    &lt;li&gt;It uses URIs for identifying both information paths (resources) and actions – the &lt;a href="http://tools.ietf.org/html/draft-gregorio-uritemplate-08"&gt;URI templates&lt;/a&gt; initiative is catching on and is rapidly becoming the standard way of representing requests for resources and &lt;a href="http://codebetter.com/glennblock/2011/05/09/hypermedia-and-forms/"&gt;hypermedia&lt;/a&gt; URIs. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;The use of HTTP has evolved over the years. Application-level protocol architectural styles such as &lt;strike&gt;REST&lt;/strike&gt; &lt;a href="http://blog.steveklabnik.com/posts/2012-02-23-rest-is-over"&gt;Hypermedia APIs&lt;/a&gt; have emerged on top of HTTP. These, in turn, harness the power of HTTP to create resource-oriented services, and better define the stateless interaction between clients and services.&lt;/p&gt;  &lt;p&gt;The Web APIs therefore were intended to allow all of these approaches – you can use it to create HTTP services that only use the standard HTTP concepts (URIs and verbs), and to to create services that use more advanced HTTP features – request/response headers, hypermedia concepts etc.&lt;/p&gt;  &lt;p&gt;So HTTP is a lot more than a transport protocol. It is an application-level protocol, and the fact is that although many platforms know how to use SOAP, many more platforms know how to use HTTP! among the HTTP supporting platforms which do not support SOAP that well are the browsers – probably the most important platforms for web developers (and users). And if you don’t believe me that REST and hypermedia are useful, maybe Martin Fowler can &lt;a href="http://martinfowler.com/articles/richardsonMaturityModel.html"&gt;convince you&lt;/a&gt; better than me.&lt;/p&gt;  &lt;p&gt;This, of course, does not mean that SOAP is redundant – SOAP is still useful for building messages when you don’t have an alternative application-level protocol at your disposal, or when you want to use SOAP across the board while considering HTTP as no more than another way to pass messages (for example, use HTTP because it can cross firewalls more easily than TCP).&lt;/p&gt;  &lt;p&gt;&lt;u&gt;Why did the WebAPIs move from WCF to ASP.NET MVC?&lt;/u&gt;&lt;/p&gt;  &lt;p&gt;Back to the story of WCF and the WCF Web APIs (we are still before the merger). Another goal of the WCF Web APIs was to incorporate known concepts that would help developers to overcome some of the drawbacks they faced with WCF, such as huge configurations, overuse of attributes, and the WCF infrastructure that did not support testing well. Thus the Web APIs used IoC, enabled convention-over-configuration, and tried to offer simpler configuration environment.&lt;/p&gt;  &lt;p&gt;The problem was that at that point in time there were several approaches for constructing HTTP services:&lt;/p&gt;  &lt;p&gt;1. WCF with the WebHttp binding and REST support.&lt;/p&gt;  &lt;p&gt;2. The new WCF Web APIs, soon to be ASP.NET Web APIs.&lt;/p&gt;  &lt;p&gt;3. A not-so-new framework, ASP.NET MVC, which took a break from being HTML-oriented (getting requests from HTML pages and returning HTML/JSON) to being &lt;a href="http://iwantmymvc.com/rest-service-mvc3"&gt;Resource-oriented&lt;/a&gt; – people started realizing that they can consider controllers as services and use the MVC infrastructure to define the control requests, responses, and better control the HTTP message.&lt;/p&gt;  &lt;p&gt;4. Open source frameworks such as &lt;a href="http://serialseb.blogspot.com/2008/12/openrasta-is-available.html"&gt;OpenRasta&lt;/a&gt; and &lt;a href="https://github.com/ServiceStack/ServiceStack"&gt;ServiceStack&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;In addition to that, as time passed, the WCF Web APIs had a lot of trouble adapting WCF to the “native” HTTP world. As WCF was primarily designed for SOAP-based XML messages, and the “open-heart” surgery that was required to make the Web API work as part of WCF was a bit too much (or so I understand from people who were involved in creating the Web APIs). On the other hand, the ASP.NET MVC infrastructure with its elegant handling of HTTP requests and responses, and its support of easy-to-create controllers seemed like the proper way to go for creating this new type of services.&lt;/p&gt;  &lt;p&gt;So the fact was we had too many options and therefore too much confusion. What were we to do? We merge teams! (Kind of reminds us of the time of LINQ-to-SQL and Entity Framework, WCF and Ado.Net Data Services and other such examples). So the WCF team and the ASP.NET team joined forces and created a new framework focused on the world of REST/Hypermedia/HTTP services for the web world and thus came out the ASP.NET Web APIs.&lt;/p&gt;  &lt;p&gt;I’m still not so sure about the choice of names, as the new Web APIs can also work outside of ASP.NET with the use of WCF, but I guess that the name “WCF ASP.NET Web API” was a bit long. Maybe “WASP Web API”? “WAWAPI” (Wcf Aspnet Web API)? Or maybe simply call it “Hypermedia Web API”?&lt;/p&gt;  &lt;p&gt;So this merger is intended to reduce confusion, not induce it. I guess that if it was explained at that time, it might have caused less confusion over time (see the &lt;a href="http://blogs.msdn.com/b/silverlight/archive/2010/11/01/pdc-and-silverlight.aspx"&gt;Silverlight is dead&lt;/a&gt; slip of PDC 2010). Does Microsoft need a new DevDiv PR team?&lt;/p&gt;  &lt;p&gt;&lt;u&gt;Is there still use for WCF? when should I choose Web APIs over WCF?&lt;/u&gt;&lt;/p&gt;  &lt;p&gt;Recall my points from before - HTTP is a lot more than a transport protocol; use SOAP across the board and consider HTTP as no more than another way to pass messages.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;If your intention is to create services that support special scenarios – one way messaging, message queues, duplex communication etc, then you’re better of picking WCF &lt;/li&gt;    &lt;li&gt;If you want to create services that can use fast transport channels when available, such as TCP, Named Pipes, or maybe even UDP (in WCF 4.5), and you also want to support HTTP when all other transports are unavailable, then you’re better off with WCF and using both SOAP-based bindings and the WebHttp binding. &lt;/li&gt;    &lt;li&gt;If you want to create resource-oriented services over HTTP that can use the full features of HTTP – define cache control for browsers, versioning and concurrency using ETags, pass various content types such as images, documents, HTML pages etc., use URI templates to include Task URIs in your responses, then the new Web APIs are the best choice for you. &lt;/li&gt;    &lt;li&gt;If you want to create a multi-target service that can be used as both resource-oriented service over HTTP and as RPC-style SOAP service over TCP – talk to me first, so I’ll give you some pointers. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;I hope this helped you removing some of the confusion over this topic.&lt;/p&gt;&lt;div class="wlWriterHeaderFooter" style="margin:0px;padding:0px 0px 0px 0px;"&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http://blogs.microsoft.co.il/blogs/idof/archive/2012/03/05/wcf-or-asp-net-web-apis-my-two-cents-on-the-subject.aspx"&gt;&lt;img border="0" alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://blogs.microsoft.co.il/blogs/idof/archive/2012/03/05/wcf-or-asp-net-web-apis-my-two-cents-on-the-subject.aspx&amp;amp;bgcolor=6600FF" /&gt;&lt;/a&gt; &lt;a href="http://dotnetshoutout.com/Submit?url=http://blogs.microsoft.co.il/blogs/idof/archive/2012/03/05/wcf-or-asp-net-web-apis-my-two-cents-on-the-subject.aspx"&gt;&lt;img alt="Shout it" src="http://dotnetshoutout.com/image.axd?url=http://blogs.microsoft.co.il/blogs/idof/archive/2012/03/05/wcf-or-asp-net-web-apis-my-two-cents-on-the-subject.aspx" style="border:0px;" /&gt;&lt;/a&gt; 			  &lt;div class="addthis_toolbox addthis_default_style "&gt; &lt;a class="addthis_button_preferred_1"&gt;&lt;/a&gt; &lt;a class="addthis_button_preferred_2"&gt;&lt;/a&gt; &lt;a class="addthis_button_preferred_3"&gt;&lt;/a&gt; &lt;a class="addthis_button_preferred_4"&gt;&lt;/a&gt; &lt;a class="addthis_button_compact"&gt;&lt;/a&gt; &lt;a class="addthis_counter addthis_bubble_style"&gt;&lt;/a&gt; &lt;/div&gt; &lt;script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=ra-4f27f7864794397c"&gt;&lt;/script&gt; &lt;a href="http://www.codeproject.com/script/Articles/BlogFeedList.aspx?amid=2199681" rel="tag" style="display:none;"&gt;CodeProject&lt;/a&gt; &lt;/div&gt;&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=1027021" width="1" height="1"&gt;</description><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/WCF/default.aspx">WCF</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/DEV/default.aspx">DEV</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/REST/default.aspx">REST</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/Hypermedia/default.aspx">Hypermedia</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/Web+API/default.aspx">Web API</category><feedburner:origLink>http://blogs.microsoft.co.il/blogs/idof/archive/2012/03/05/wcf-or-asp-net-web-apis-my-two-cents-on-the-subject.aspx</feedburner:origLink></item><item><title>What’s new in WCF 4.5? WebSocket support (Part 1 of 2)</title><link>http://feedproxy.google.com/~r/IdoFlatowsBlog/~3/Cw5NT1etqaM/what-s-new-in-wcf-4-5-websocket-support-part-1-of-2.aspx</link><pubDate>Thu, 01 Mar 2012 14:12:43 GMT</pubDate><guid isPermaLink="false">b5c4f5bc-c09b-4439-a595-91a98c1847df:1023699</guid><dc:creator>Ido Flatow</dc:creator><slash:comments>1</slash:comments><wfw:commentRss>http://blogs.microsoft.co.il/blogs/idof/rsscomments.aspx?PostID=1023699</wfw:commentRss><comments>http://blogs.microsoft.co.il/blogs/idof/archive/2012/03/01/what-s-new-in-wcf-4-5-websocket-support-part-1-of-2.aspx#comments</comments><description>&lt;p&gt;This is the 11th post in the WCF 4.5 series. The previous post was about the new UDP transport support, and this new post is also about new transports – the WebSocket transport.&lt;/p&gt;  &lt;p&gt;This post is part 1 of 2. This post will be about the WebSocket support between .NET apps using WCF (SOAP-based), and the next post will be about using WebSockets between browsers and WCF (non-SOAP).&lt;/p&gt;  &lt;p&gt;Previous posts:&lt;/p&gt;  &lt;p&gt;1. &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/2011/09/16/what-s-new-in-wcf-4-5-let-s-start-with-wcf-configuration.aspx"&gt;What’s new in WCF 4.5? let’s start with WCF configuration&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;2. &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/2011/09/17/what-s-new-in-wcf-4-5-a-single-wsdl-file.aspx"&gt;What’s new in WCF 4.5? a single WSDL file&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;3. &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/2011/09/19/what-s-new-in-wcf-4-5-configuration-tooltips-and-intellisense-in-config-files.aspx"&gt;What’s new in WCF 4.5? Configuration tooltips and intellisense in config files&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;4. &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/2011/09/25/what-s-new-in-wcf-4-5-configuration-validations.aspx"&gt;What’s new in WCF 4.5? Configuration validations&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;5. &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/2011/09/25/what-s-new-in-wcf-4-5-multiple-authentication-support-on-a-single-endpoint-in-iis.aspx"&gt;What’s new in WCF 4.5? Multiple authentication support on a single endpoint in IIS&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;6. &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/2011/10/05/what-s-new-in-wcf-4-5-automatic-https-endpoint-for-iis.aspx"&gt;What’s new in WCF 4.5? Automatic HTTPS endpoint for IIS&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;7. &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/2011/10/10/what-s-new-in-wcf-4-5-basichttpsbinding.aspx"&gt;What’s new in WCF 4.5? BasicHttpsBinding&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;8. &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/2011/10/31/what-s-new-in-wcf-4-5-changed-default-for-asp-net-compatibility-mode.aspx"&gt;What’s new in WCF 4.5? Changed default for ASP.NET compatibility mode&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;9. &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/2012/01/17/what-s-new-in-wcf-4-5-improved-streaming-in-iis-hosting.aspx"&gt;What’s new in WCF 4.5? Improved streaming in IIS hosting&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;10. &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/2012/02/15/what-s-new-in-wcf-4-5-udp-transport-support.aspx"&gt;What’s new in WCF 4.5? UDP transport support&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;A (very) short introduction to WebSockets&lt;/strong&gt; – WebSocket is a bi-directional (two-way), full-duplex channel. WebSocket channels start as normal HTTP channels, and then use handshakes to upgrade the channel to WebSocket, allowing two-way TCP communication between client and server, thus overcoming several limitations enforced by firewalls. In order not to repeat all that is already written about WebSockets, I suggest you check the following websites:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://en.wikipedia.org/wiki/WebSocket"&gt;http://en.wikipedia.org/wiki/WebSocket&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://websocket.org/"&gt;http://websocket.org/&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="https://datatracker.ietf.org/doc/rfc6455/"&gt;https://datatracker.ietf.org/doc/rfc6455/&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Note: This post was written according to the WebSocket support of WCF 4.5 with .NET 4.5 Beta and Visual Studio 11 Beta. If you are still using the Developer Preview version, you might see some different configuration sections and different behavior of the “Add Service Reference” feature.&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;The support of WebSocket in WCF 4.5 is achieved through the new NetHttpBinding. The NetHttpBinding was first introduced in the &lt;a href="http://msdn.microsoft.com/en-us/library/aa395198.aspx"&gt;WCF 4 samples&lt;/a&gt; as a custom binding that uses binary-encoded SOAP messages over HTTP(S). The NetHttpBinding in WCF 4.5 is an improved binding that uses binary-encoded SOAP messages over HTTP(S) or WebSocket transports. The NetHttpBinding can be used in any of the following ways:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;&lt;strong&gt;Request-Response over HTTP.&lt;/strong&gt; This mode does not use WebSockets, but rather a simple HTTP/HTTPS channel with binary-encoded SOAP messages.       &lt;br /&gt;This mode is the default mode when using the binding without a duplex contract. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Duplex over WebSocket&lt;/strong&gt;. This mode uses WebSockets, and allows two-way communication between client and service.       &lt;br /&gt;This mode is automatically used when you declare your service contract with a callback contract (duplex). &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Request-Response over WebSocket&lt;/strong&gt;. This mode uses WebSockets, but it does not take advantage of the two-way communication support of the channel (since we still use the request-response pattern).       &lt;br /&gt;This mode is used when doing one of the following:       &lt;ol&gt;       &lt;li&gt;Changing the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.servicecontractattribute.sessionmode.aspx"&gt;SessionMode&lt;/a&gt; of the contract to &lt;strong&gt;Required&lt;/strong&gt;. The binding will upgrade automatically from HTTP to WebSocket, since HTTP is not sessionful and WebSocket is. &lt;/li&gt;        &lt;li&gt;Manually forcing WebSocket by changing the binding configuration and setting the WebSocket transport usage to &lt;strong&gt;Always&lt;/strong&gt;. &lt;/li&gt;     &lt;/ol&gt;   &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;Since &lt;strong&gt;WebSocket is sessionful&lt;/strong&gt;, you automatically get &lt;strong&gt;session support&lt;/strong&gt; in your service, if you haven’t changed the instance context mode from the default PerSession setting. If you’ve ever needed a sessionful HTTP channel and had to use WsHttpBinding with WS-ReliableMessaging, you now have another option which doesn’t require passing extra WS-RM messages.&lt;/p&gt;  &lt;p&gt;NetHttpBinding with WebSocket can in fact replace the use of WsDualHttpBinding, since WebSocket provides a duplex channel which also supports sessions – this is better than WsDualHttpBinding which uses two channels, and require the use of WS-ReliableMessaging for session management.&lt;/p&gt;  &lt;p&gt;All three modes of the binding are non-interoperable, because they use binary-encoded SOAP messages which is a proprietary Microsoft encoding technique. If you want to learn more about binary encoding, I suggest you read Nicholas Allen’s &lt;a href="http://bitly.com/bundles/idof/3"&gt;posts&lt;/a&gt; on the subject. However, this does not mean we cannot use WebSockets as an interoperable transport with text-based SOAP messages – we can change the binding configuration to use text instead of binary, thus making in interoperable, as shown later on.&lt;/p&gt;  &lt;p&gt;To demonstrate the usage of NetHttpBinding, I’ve created a simple duplex contract:&lt;/p&gt;  &lt;pre class="csharpcode"&gt;[ServiceContract(CallbackContract=&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(IDuplexCallbackContract))]
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;interface&lt;/span&gt; IDuplexContract
{
    [OperationContract]
    &lt;span class="kwrd"&gt;string&lt;/span&gt; SayHelloDuplex(&lt;span class="kwrd"&gt;string&lt;/span&gt; name);
}

[ServiceContract]
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;interface&lt;/span&gt; IDuplexCallbackContract
{
    [OperationContract]
    &lt;span class="kwrd"&gt;void&lt;/span&gt; SayingHello(&lt;span class="kwrd"&gt;string&lt;/span&gt; message);
}&lt;/pre&gt;
And a service that implements the contract: 

&lt;pre class="csharpcode"&gt;[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Reentrant)]
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; WebSocketSampleService : IRegularContract, IDuplexContract
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; SayHelloDuplex(&lt;span class="kwrd"&gt;string&lt;/span&gt; name)
    {
        OperationContext.Current.
            GetCallbackChannel&amp;lt;IDuplexCallbackContract&amp;gt;().
            SayingHello(&lt;span class="str"&gt;&amp;quot;Hello &amp;quot;&lt;/span&gt; + name + &lt;span class="str"&gt;&amp;quot; by WebSockets&amp;quot;&lt;/span&gt;);

        &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="str"&gt;&amp;quot;Hello &amp;quot;&lt;/span&gt; + name;
    }
}&lt;/pre&gt;

&lt;p&gt;The endpoint configuration is quite simple:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;endpoint&lt;/span&gt; &lt;span class="attr"&gt;address&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;http://localhost:8083&amp;quot;&lt;/span&gt;
          &lt;span class="attr"&gt;binding&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;netHttpBinding&amp;quot;&lt;/span&gt;
          &lt;span class="attr"&gt;contract&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Contracts.IDuplexContract&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;Note: &lt;/strong&gt;It appear that the WCF Service Configuration Editor doesn’t recognize the NetHttpBinding’s WebSocket configuration, so you’ll need to use Visual Studio’s XML editor (the binding configuration is supported from VS11 Beta).&lt;/p&gt;

&lt;p&gt;And as for the client-side code, just add a service reference and call the service:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;Services.IDuplexContract duplexProxy;
Console.WriteLine(&lt;span class="str"&gt;&amp;quot;Press enter when service is ready&amp;quot;&lt;/span&gt;);
Console.ReadLine();

&lt;span class="rem"&gt;// Use the generated proxy class&lt;/span&gt;
duplexProxy = &lt;span class="kwrd"&gt;new&lt;/span&gt; Services.DuplexContractClient(
    callbackContext,
    &lt;span class="str"&gt;&amp;quot;DuplexContract&amp;quot;&lt;/span&gt;);
Console.WriteLine(&lt;span class="str"&gt;&amp;quot;Calling the duplex contract:&amp;quot;&lt;/span&gt;);
Console.WriteLine(duplexProxy.SayHelloDuplex(&lt;span class="str"&gt;&amp;quot;ido&amp;quot;&lt;/span&gt;));

&lt;span class="rem"&gt;// Or use a DuplexChannelFactory&lt;/span&gt;
DuplexChannelFactory&amp;lt;Services.IDuplexContract&amp;gt; dchf =
    &lt;span class="kwrd"&gt;new&lt;/span&gt; DuplexChannelFactory&amp;lt;Services.IDuplexContract&amp;gt;(
        callbackContext,
        &lt;span class="kwrd"&gt;new&lt;/span&gt; NetHttpBinding(),&lt;br /&gt;        &lt;span class="kwrd"&gt;new&lt;/span&gt; EndpointAddress(&lt;span class="str"&gt;&amp;quot;http://localhost:8083/&amp;quot;&lt;/span&gt;));
duplexProxy = dchf.CreateChannel();
Console.WriteLine(&lt;span class="str"&gt;&amp;quot;Calling the duplex contract using text encoded messages:&amp;quot;&lt;/span&gt;);
Console.WriteLine(duplexProxy.SayHelloDuplex(&lt;span class="str"&gt;&amp;quot;ido&amp;quot;&lt;/span&gt;));&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: When specifying the endpoint address in the service, you need to use the http:// scheme, but on the client-side you can use either http:// or ws://. When generating a service reference, the client configuration will use the ws:// scheme.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: If your service endpoint uses NetHttpBinding but you contract is a non-duplex service contract (without a callback contract), you can still use NetHttpBinding, but the channel will be HTTP and not WebSockets – in this case the generated client configuration will create a custom binding instead of NetHttpBinding. The custom binding is a perfect match of the NetHttpBinding so things will still work, but it may be a bit confusing the first time you see it. I hope this will be resolved in the RTM version of VS 11. &lt;/p&gt;

&lt;p&gt;When you add a service reference to the service, the client side configuration will be generated with a custom binding instead of the NetHttpBinding - you can either leave it as-is, or remove the custom binding and rewrite the configuration to use the NetHttpBinding (of course you might need to do it again when you update the service reference).&lt;/p&gt;

&lt;p&gt;It is also quite easy to define a new service endpoint which uses the NetHttpBinding with text-based SOAP messages instead of binary:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;service&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Host.WebSocketSampleService&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;endpoint&lt;/span&gt; &lt;span class="attr"&gt;address&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;http://localhost:8084&amp;quot;&lt;/span&gt;
              &lt;span class="attr"&gt;binding&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;netHttpBinding&amp;quot;&lt;/span&gt;
              &lt;span class="attr"&gt;bindingConfiguration&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;TextOverWebSockets&amp;quot;&lt;/span&gt;
              &lt;span class="attr"&gt;contract&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Contracts.IDuplexContract&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;service&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;bindings&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;netHttpBinding&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;binding&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;TextOverWebSockets&amp;quot; &lt;span class="attr"&gt;messageEncoding&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Text&amp;quot;&lt;/span&gt;/&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;netHttpBinding&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;bindings&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;So as you can see, we have the ability to use both binary and text, but how can we be sure it actually passes text instead of binary? for that we need a network sniffer that can show us the WebSocket messages. You can use Wireshark or any other TCP sniffer to check that, however I always found those sniffers to be a bit hard to manage, especially for localhost communication. Luckily for us, we can use Fiddler, the famous HTTP sniffer, which now supports WebSocket messages (although &lt;a href="http://blogs.msdn.com/b/fiddler/archive/2011/11/22/fiddler-and-websockets.aspx"&gt;only for watching&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;This is how the binary message looks like when sent over WebSockets:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/idof/image_122B477B.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://blogs.microsoft.co.il/blogs/idof/image_thumb_01569F29.png" width="604" height="400" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And this is how the text message looks like:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/idof/image_100534DE.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://blogs.microsoft.co.il/blogs/idof/image_thumb_1426E4A5.png" width="604" height="399" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And this is the HTTP connection upgrade request:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/idof/image_44E53C77.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://blogs.microsoft.co.il/blogs/idof/image_thumb_53C85792.png" width="604" height="535" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;(notice the GET request for WebSocket upgrade, and the corresponding HTTP 101 – Switching Protocols response)&lt;/p&gt;

&lt;p&gt;If you want to use WebSockets for a simple Request-Response contract, you can also do that, but you’ll need to set the binding configuration of your endpoint to require WebSocket communication:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;bindings&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;netHttpBinding&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;binding&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;ReqResWithWebSockets&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
             &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;webSocketSettings&lt;/span&gt; &lt;font color="#ff0000"&gt;transportUsage&lt;/font&gt;&lt;span class="kwrd"&gt;=&amp;quot;Always&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;binding&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;netHttpBinding&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;      
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;bindings&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;You can download the sample code from my &lt;a href="https://skydrive.live.com/redir.aspx?cid=5ef5be1ab30a6056&amp;amp;resid=5EF5BE1AB30A6056!481&amp;amp;parid=5EF5BE1AB30A6056!129"&gt;SkyDrive&lt;/a&gt; which demonstrates all of the above including duplex, request-response, sessions, forcing WebSockets, and text encoded messages.&lt;/p&gt;

&lt;p&gt;When considering the use of WebSocket via NetHttpBinding for duplex communication vs. WsDualHttpBinding and NetTcpBinding, the benefits of NetHttpBindings are:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Like NetTcp it requires one channel instead of two, as in the case of WsDualHttp. &lt;/li&gt;

  &lt;li&gt;Like NetTcp it has a sessionful channel, unlike WsDualHttp which requires the use of WS-ReliableMessaging. &lt;/li&gt;

  &lt;li&gt;Like NetTcp, it uses binary encoding which reduces the message size, unlike the text encoding of WsDualHttp. &lt;/li&gt;

  &lt;li&gt;Unlike NetTcp, it can &lt;a href="http://www.infoq.com/articles/Web-Sockets-Proxy-Servers"&gt;overcome&lt;/a&gt; some firewall restrictions that prohibit TCP communication. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;As we’ve seen so far, the WebSocket support in WCF 4.5 uses SOAP-based messages. In the next post I will cover how to use WebSockets in WCF 4.5 to communicate with non-SOAP clients, such as web browsers, using simple text over WebSockets.&lt;/p&gt;&lt;div class="wlWriterHeaderFooter" style="margin:0px;padding:0px 0px 0px 0px;"&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http://blogs.microsoft.co.il/blogs/idof/archive/2012/03/01/what-s-new-in-wcf-4-5-websocket-support-part-1-of-2.aspx"&gt;&lt;img border="0" alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://blogs.microsoft.co.il/blogs/idof/archive/2012/03/01/what-s-new-in-wcf-4-5-websocket-support-part-1-of-2.aspx&amp;amp;bgcolor=6600FF" /&gt;&lt;/a&gt; &lt;a href="http://dotnetshoutout.com/Submit?url=http://blogs.microsoft.co.il/blogs/idof/archive/2012/03/01/what-s-new-in-wcf-4-5-websocket-support-part-1-of-2.aspx"&gt;&lt;img alt="Shout it" src="http://dotnetshoutout.com/image.axd?url=http://blogs.microsoft.co.il/blogs/idof/archive/2012/03/01/what-s-new-in-wcf-4-5-websocket-support-part-1-of-2.aspx" style="border:0px;" /&gt;&lt;/a&gt; 			

&lt;div class="addthis_toolbox addthis_default_style "&gt;
&lt;a class="addthis_button_preferred_1"&gt;&lt;/a&gt;
&lt;a class="addthis_button_preferred_2"&gt;&lt;/a&gt;
&lt;a class="addthis_button_preferred_3"&gt;&lt;/a&gt;
&lt;a class="addthis_button_preferred_4"&gt;&lt;/a&gt;
&lt;a class="addthis_button_compact"&gt;&lt;/a&gt;
&lt;a class="addthis_counter addthis_bubble_style"&gt;&lt;/a&gt;
&lt;/div&gt;
&lt;script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=ra-4f27f7864794397c"&gt;&lt;/script&gt;
&lt;a href="http://www.codeproject.com/script/Articles/BlogFeedList.aspx?amid=2199681" rel="tag" style="display:none;"&gt;CodeProject&lt;/a&gt; &lt;/div&gt;&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=1023699" width="1" height="1"&gt;</description><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/WCF/default.aspx">WCF</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/DEV/default.aspx">DEV</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/fiddler/default.aspx">fiddler</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/What_2700_s+new/default.aspx">What's new</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/WCF+4.5/default.aspx">WCF 4.5</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/websocket/default.aspx">websocket</category><feedburner:origLink>http://blogs.microsoft.co.il/blogs/idof/archive/2012/03/01/what-s-new-in-wcf-4-5-websocket-support-part-1-of-2.aspx</feedburner:origLink></item><item><title>What’s new in WCF 4.5? UDP transport support</title><link>http://feedproxy.google.com/~r/IdoFlatowsBlog/~3/_0pCx4IhyUQ/what-s-new-in-wcf-4-5-udp-transport-support.aspx</link><pubDate>Wed, 15 Feb 2012 20:50:00 GMT</pubDate><guid isPermaLink="false">b5c4f5bc-c09b-4439-a595-91a98c1847df:1014306</guid><dc:creator>Ido Flatow</dc:creator><slash:comments>3</slash:comments><wfw:commentRss>http://blogs.microsoft.co.il/blogs/idof/rsscomments.aspx?PostID=1014306</wfw:commentRss><comments>http://blogs.microsoft.co.il/blogs/idof/archive/2012/02/15/what-s-new-in-wcf-4-5-udp-transport-support.aspx#comments</comments><description>&lt;p&gt;This is the tenth post in the WCF 4.5 series. I’ve started this series of posts 4 months ago when &lt;a href="http://msdn.microsoft.com/en-us/netframework/hh403373"&gt;.NET 4.5 developer preview&lt;/a&gt; was announced; The Beta/RC/RTM version is still to come, but hopefully it will be available soon, and you will be able to use the new WCF 4.5 features in your projects.&lt;/p&gt;
&lt;p&gt;Until now, I’ve shown new features in configuration easiness and hosting improvements. In this post and the next one I will cover new transport features, starting with the support for the UDP transport.&lt;/p&gt;
&lt;p&gt;Previous posts:&lt;/p&gt;
&lt;p&gt;1. &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/2011/09/16/what-s-new-in-wcf-4-5-let-s-start-with-wcf-configuration.aspx"&gt;What’s new in WCF 4.5? let’s start with WCF configuration&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;2. &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/2011/09/17/what-s-new-in-wcf-4-5-a-single-wsdl-file.aspx"&gt;What’s new in WCF 4.5? a single WSDL file&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;3. &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/2011/09/19/what-s-new-in-wcf-4-5-configuration-tooltips-and-intellisense-in-config-files.aspx"&gt;What’s new in WCF 4.5? Configuration tooltips and intellisense in config files&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;4. &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/2011/09/25/what-s-new-in-wcf-4-5-configuration-validations.aspx"&gt;What’s new in WCF 4.5? Configuration validations&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;5. &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/2011/09/25/what-s-new-in-wcf-4-5-multiple-authentication-support-on-a-single-endpoint-in-iis.aspx"&gt;What’s new in WCF 4.5? Multiple authentication support on a single endpoint in IIS&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;6. &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/2011/10/05/what-s-new-in-wcf-4-5-automatic-https-endpoint-for-iis.aspx"&gt;What’s new in WCF 4.5? Automatic HTTPS endpoint for IIS&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;7. &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/2011/10/10/what-s-new-in-wcf-4-5-basichttpsbinding.aspx"&gt;What’s new in WCF 4.5? BasicHttpsBinding&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;8. &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/2011/10/31/what-s-new-in-wcf-4-5-changed-default-for-asp-net-compatibility-mode.aspx"&gt;What’s new in WCF 4.5? Changed default for ASP.NET compatibility mode&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;9. &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/2012/01/17/what-s-new-in-wcf-4-5-improved-streaming-in-iis-hosting.aspx"&gt;What’s new in WCF 4.5? Improved streaming in IIS hosting&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I’ve been teaching WCF for several years now, and almost every time I explain to people about the different types of bindings and supported transports someone asks me if there is a built-in support for a UDP transport. Until now my answer was “It isn’t supported out-of-the-box, but there is a &lt;a href="http://msdn.microsoft.com/en-us/library/ms751494.aspx"&gt;UDP transport sample&lt;/a&gt; in the &lt;a href="http://www.microsoft.com/download/en/details.aspx?displaylang=en&amp;amp;id=21459"&gt;WCF/WF samples&lt;/a&gt;”. From now on my new answer is “In WCF 4/3.5 there is a sample implementation, but it is now out-of-the-box in WCF 4.5”.&lt;/p&gt;
&lt;p&gt;You can get some basic info about the binding in the &lt;a href="http://msdn.microsoft.com/en-us/library/ms730879(v=vs.110).aspx"&gt;System-Provided Bindings&lt;/a&gt; page on MSDN (make sure you look at the 4.5 version), unfortunately there is no documentation on the UdpBinding type yet, but hopefully MS will create it by the time WCF 4.5 is released.&lt;/p&gt;
&lt;p&gt;Declaring an endpoint that uses UDP is quite simple:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;endpoint&lt;/span&gt; &lt;span class="attr"&gt;address&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;soap.udp://localhost:8080/&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;binding&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;udpBinding&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;contract&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;UdpHost.IService&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;Some facts about the new UDP binding:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;The address scheme for this binding is &lt;strong&gt;soap.udp://&lt;/strong&gt; &lt;/li&gt;
&lt;li&gt;The binding is supported only&amp;nbsp;by .NET (since it does uses text encoding for the SOAP messages, it can be considered interoperable, although currently no other SOAP-based services technology support UDP)&lt;/li&gt;
&lt;li&gt;Security is not supported (neither transport or message) &lt;/li&gt;
&lt;li&gt;Sessions, transactions, streaming, and duplex are not supported (I was hoping for a duplex UDP using one-way messages) &lt;/li&gt;
&lt;li&gt;Supported encoding is text &lt;/li&gt;
&lt;li&gt;The binding can be used in code by adding a reference to the System.ServiceModel.Channels assembly &lt;/li&gt;
&lt;li&gt;The binding is not supported in IIS/WAS, since there is still no UDP shared listener for WAS&lt;/li&gt;
&lt;li&gt;In the case of One-Way messages, this is a true one-way unidirectional call - the client won’t throw an exception if the service is unavailable &lt;/li&gt;
&lt;li&gt;If you specify a &lt;a href="http://en.wikipedia.org/wiki/Multicast_address"&gt;multicast address&lt;/a&gt; in the endpoint, such as 224.0.0.1 or 239.255.255.255 (the later is used by UDP discovery endpoints), you can create multiple listeners on the same address+protocol even from different machines – one client can send a single message that will be received by multiple listeners – this can be a great way to synchronize server state, do pub-sub (notification) calls etc...&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;Using a multicast listening address is also quite simple:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;endpoint&lt;/span&gt; &lt;span class="attr"&gt;address&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;soap.udp://239.255.255.255:8083/&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;binding&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;udpBinding&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;contract&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;UdpHost.IService&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;As for performance, I’ve create a simple client which sends 5000 messages using request-response and one-way (simple and multicast), with HTTP (basicHttp), TCP, and UDP bindings. For the purpose of the test I’ve removed all security settings from the NetTcp binding. The result is shown below:&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Calling 5000 iterations one way using UDP &lt;br /&gt;One-way using UDP took 0 seconds, average is 0.1792ms&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Calling 5000 iterations one way using HTTP &lt;br /&gt;One-way using HTTP took 6 seconds, average is 1.3ms&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Calling 5000 iterations one way using TCP &lt;br /&gt;One-way using TCP took 2 seconds, average is 0.5876ms&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Calling 5000 iterations one way using UDP Multicast &lt;br /&gt;One-way using UDP Multicast took 3 seconds, average is 0.736ms&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Calling 5000 iterations of request-response using UDP &lt;br /&gt;Request-response using UDP took 7 seconds, average is 1.4738ms&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Calling 5000 iterations of request-response using HTTP &lt;br /&gt;Request-response using HTTP took 8 seconds, average is 1.7784ms&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Calling 5000 iterations of request-response using TCP &lt;br /&gt;Request-response using TCP took 4 seconds, average is 0.9518ms&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Conclusions:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;One-way messages are fast when using UDP – about 7 times faster than HTTP, and 3 times faster than TCP. I assume this is because when using UDP we don’t need to wait for the TCP &lt;a href="http://en.wikipedia.org/wiki/Acknowledgement_(data_networks)"&gt;ACK&lt;/a&gt; (also used in HTTP).&lt;/li&gt;
&lt;li&gt;One-way multicast messages in UDP are slower than direct messages – about 4 times slower&lt;/li&gt;
&lt;li&gt;Request-response message in UDP are slower than TCP, but faster than HTTP. I assume the reason for being slower than TCP is that UDP uses two channels to create request-response whereas TCP requires only one channel.&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;Trying to run the same sample when the server has not been started produces the following results:&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Calling 5000 iterations one way using UDP &lt;br /&gt;One-way using UDP took 0 seconds, average is 0.1216ms&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Calling 5000 iterations one way using HTTP &lt;br /&gt;One-way using HTTP failed&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Calling 5000 iterations one way using TCP &lt;br /&gt;One-way using TCP failed&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Calling 5000 iterations one way using UDP Multicast &lt;br /&gt;One-way using UDP Multicast took 1 seconds, average is 0.376ms&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Calling 5000 iterations of request-response using UDP &lt;br /&gt;Request-response using UDP failed&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Calling 5000 iterations of request-response using HTTP &lt;br /&gt;Request-response using HTTP failed&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Calling 5000 iterations of request-response using TCP &lt;br /&gt;Request-response using TCP failed&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;As you can see, UDP one-way messages are unidirectional!!!&lt;/p&gt;
&lt;p&gt;The sample code is available on my &lt;a href="https://skydrive.live.com/redir.aspx?cid=5ef5be1ab30a6056&amp;amp;resid=5EF5BE1AB30A6056!467&amp;amp;parid=5EF5BE1AB30A6056!129"&gt;SkyDrive&lt;/a&gt;.&lt;/p&gt;
&lt;div style="PADDING-BOTTOM:0px;MARGIN:0px;PADDING-LEFT:0px;PADDING-RIGHT:0px;PADDING-TOP:0px;" class="wlWriterHeaderFooter"&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http://blogs.microsoft.co.il/blogs/idof/archive/2012/02/15/what-s-new-in-wcf-4-5-udp-transport-support.aspx"&gt;&lt;img border="0" alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://blogs.microsoft.co.il/blogs/idof/archive/2012/02/15/what-s-new-in-wcf-4-5-udp-transport-support.aspx&amp;amp;bgcolor=6600FF" /&gt;&lt;/a&gt; &lt;a href="http://dotnetshoutout.com/Submit?url=http://blogs.microsoft.co.il/blogs/idof/archive/2012/02/15/what-s-new-in-wcf-4-5-udp-transport-support.aspx"&gt;&lt;img style="BORDER-BOTTOM:0px;BORDER-LEFT:0px;BORDER-TOP:0px;BORDER-RIGHT:0px;" alt="Shout it" src="http://dotnetshoutout.com/image.axd?url=http://blogs.microsoft.co.il/blogs/idof/archive/2012/02/15/what-s-new-in-wcf-4-5-udp-transport-support.aspx" /&gt;&lt;/a&gt; 
&lt;div class="addthis_toolbox addthis_default_style "&gt;&lt;a class="addthis_button_preferred_1"&gt;&lt;/a&gt;&lt;a class="addthis_button_preferred_2"&gt;&lt;/a&gt;&lt;a class="addthis_button_preferred_3"&gt;&lt;/a&gt;&lt;a class="addthis_button_preferred_4"&gt;&lt;/a&gt;&lt;a class="addthis_button_compact"&gt;&lt;/a&gt;&lt;a class="addthis_counter addthis_bubble_style"&gt;&lt;/a&gt;&lt;/div&gt;
&lt;script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=ra-4f27f7864794397c"&gt;&lt;/script&gt;
&lt;a style="DISPLAY:none;" href="http://www.codeproject.com/script/Articles/BlogFeedList.aspx?amid=2199681" rel="tag"&gt;CodeProject&lt;/a&gt; &lt;/div&gt;&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=1014306" width="1" height="1"&gt;</description><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/WCF/default.aspx">WCF</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/DEV/default.aspx">DEV</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/What_2700_s+new/default.aspx">What's new</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/WCF+4.5/default.aspx">WCF 4.5</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/UDP/default.aspx">UDP</category><feedburner:origLink>http://blogs.microsoft.co.il/blogs/idof/archive/2012/02/15/what-s-new-in-wcf-4-5-udp-transport-support.aspx</feedburner:origLink></item><item><title>Calling a WCF service from a client without having the contract interface</title><link>http://feedproxy.google.com/~r/IdoFlatowsBlog/~3/thl6VlxselA/calling-a-wcf-service-from-a-client-without-having-the-contract-interface.aspx</link><pubDate>Thu, 09 Feb 2012 22:47:00 GMT</pubDate><guid isPermaLink="false">b5c4f5bc-c09b-4439-a595-91a98c1847df:1010779</guid><dc:creator>Ido Flatow</dc:creator><slash:comments>1</slash:comments><wfw:commentRss>http://blogs.microsoft.co.il/blogs/idof/rsscomments.aspx?PostID=1010779</wfw:commentRss><comments>http://blogs.microsoft.co.il/blogs/idof/archive/2012/02/10/calling-a-wcf-service-from-a-client-without-having-the-contract-interface.aspx#comments</comments><description>&lt;p&gt;I was asked yesterday in the Hebrew C#/.NET Framework MSDN forums a &lt;a href="http://social.msdn.microsoft.com/Forums/he-IL/nethe/thread/1678e16f-877c-44c9-9ccf-9b9c39bc51b4"&gt;tough question&lt;/a&gt; – is it possible to dynamically call a WCF service using only the contract name, operation name, and metadata address?&lt;/p&gt;
&lt;p&gt;At first I agreed with the answer given in the forum – move from SOAP bindings to WebHttpBinding (“REST”). This of course makes things a lot easier, only requiring you to create a WebHttpRequest and parse the response. However the question remains - is it possible to do this in the case of a SOAP-based service endpoint? &lt;/p&gt;
&lt;p&gt;The short answer is – YES! &lt;/p&gt;
&lt;p&gt;The full answer is – YES, but you’ll need to do a lot of coding to make it work properly, and even more coding for complex scenarios (who said passing a data contract?)&lt;/p&gt;
&lt;p&gt;How is it done you ask?&lt;/p&gt;
&lt;p&gt;First let’s start with the contract – you have a simple contract that looks like so:&lt;/p&gt;
&lt;div class="csharpcode"&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;[ServiceContract]&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;interface&lt;/span&gt; ICalculator&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;{&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;  [OperationContract]&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;  &lt;span class="kwrd"&gt;double&lt;/span&gt; Add(&lt;span class="kwrd"&gt;double&lt;/span&gt; n1, &lt;span class="kwrd"&gt;double&lt;/span&gt; n2);&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;  [OperationContract]&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;  &lt;span class="kwrd"&gt;double&lt;/span&gt; Subtract(&lt;span class="kwrd"&gt;double&lt;/span&gt; n1, &lt;span class="kwrd"&gt;double&lt;/span&gt; n2);&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;  [OperationContract]&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;  &lt;span class="kwrd"&gt;double&lt;/span&gt; Multiply(&lt;span class="kwrd"&gt;double&lt;/span&gt; n1, &lt;span class="kwrd"&gt;double&lt;/span&gt; n2);&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;  [OperationContract]&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  11:  &lt;/span&gt;  &lt;span class="kwrd"&gt;double&lt;/span&gt; Divide(&lt;span class="kwrd"&gt;double&lt;/span&gt; n1, &lt;span class="kwrd"&gt;double&lt;/span&gt; n2);&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  12:  &lt;/span&gt;}&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;At this point the implementation doesn’t matter, but you can assume the service compiles and loads successfully.&lt;/p&gt;
&lt;p&gt;Second, make sure your service has either a MEX endpoint or metadata exposed over HTTP GET. Read &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/2011/08/10/wsdl-vs-mex-knockout-or-tie.aspx"&gt;here&lt;/a&gt; for more info about the difference between the two.&lt;/p&gt;
&lt;p&gt;Third – do the client coding!!! to create the client code I took some ideas from the following links:&lt;/p&gt;
&lt;p&gt;&lt;a title="http://msdn.microsoft.com/en-us/library/ms733780.aspx" href="http://msdn.microsoft.com/en-us/library/ms733780.aspx"&gt;http://msdn.microsoft.com/en-us/library/ms733780.aspx&lt;/a&gt; – generating client-side type information for WCF contracts &lt;/p&gt;
&lt;p&gt;&lt;a title="http://www.codeproject.com/Articles/42278/Call-a-Web-Service-Without-Adding-a-Web-Reference" href="http://www.codeproject.com/Articles/42278/Call-a-Web-Service-Without-Adding-a-Web-Reference"&gt;http://www.codeproject.com/Articles/42278/Call-a-Web-Service-Without-Adding-a-Web-Reference&lt;/a&gt; – the same concept of dynamic calls, but for ASP.NET web services (ASMX).&lt;/p&gt;
&lt;div class="csharpcode"&gt;
&lt;div class="csharpcode"&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Collections.Generic;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Linq;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.ServiceModel;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.ServiceModel.Description;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Globalization;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Collections.ObjectModel;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.CodeDom.Compiler;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;&lt;span class="kwrd"&gt;namespace&lt;/span&gt; Client&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  11:  &lt;/span&gt;{&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  12:  &lt;/span&gt;    &lt;span class="kwrd"&gt;class&lt;/span&gt; Program&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  13:  &lt;/span&gt;    {&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  14:  &lt;/span&gt;        &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Main(&lt;span class="kwrd"&gt;string&lt;/span&gt;[] args)&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  15:  &lt;/span&gt;        {&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  16:  &lt;/span&gt;            &lt;span class="rem"&gt;// Define the metadata address, contract name, operation name, and parameters. &lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  17:  &lt;/span&gt;            &lt;span class="rem"&gt;// You can choose between MEX endpoint and HTTP GET by changing the address and enum value.&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  18:  &lt;/span&gt;            Uri mexAddress = &lt;span class="kwrd"&gt;new&lt;/span&gt; Uri(&lt;span class="str"&gt;&amp;quot;http://localhost:8732/CalculatorService/?wsdl&amp;quot;&lt;/span&gt;);&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  19:  &lt;/span&gt;            &lt;span class="rem"&gt;// For MEX endpoints use a MEX address and a mexMode of .MetadataExchange&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  20:  &lt;/span&gt;            MetadataExchangeClientMode mexMode = MetadataExchangeClientMode.HttpGet;            &lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  21:  &lt;/span&gt;            &lt;span class="kwrd"&gt;string&lt;/span&gt; contractName = &lt;span class="str"&gt;&amp;quot;ICalculator&amp;quot;&lt;/span&gt;;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  22:  &lt;/span&gt;            &lt;span class="kwrd"&gt;string&lt;/span&gt; operationName = &lt;span class="str"&gt;&amp;quot;Add&amp;quot;&lt;/span&gt;;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  23:  &lt;/span&gt;            &lt;span class="kwrd"&gt;object&lt;/span&gt;[] operationParameters = &lt;span class="kwrd"&gt;new&lt;/span&gt; &lt;span class="kwrd"&gt;object&lt;/span&gt;[] { 1, 2 };&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  24:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  25:  &lt;/span&gt;            &lt;span class="rem"&gt;// Get the metadata file from the service.&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  26:  &lt;/span&gt;            MetadataExchangeClient mexClient = &lt;span class="kwrd"&gt;new&lt;/span&gt; MetadataExchangeClient(mexAddress, mexMode);&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  27:  &lt;/span&gt;            mexClient.ResolveMetadataReferences = &lt;span class="kwrd"&gt;true&lt;/span&gt;;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  28:  &lt;/span&gt;            MetadataSet metaSet = mexClient.GetMetadata();&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  29:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  30:  &lt;/span&gt;            &lt;span class="rem"&gt;// Import all contracts and endpoints&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  31:  &lt;/span&gt;            WsdlImporter importer = &lt;span class="kwrd"&gt;new&lt;/span&gt; WsdlImporter(metaSet);&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  32:  &lt;/span&gt;            Collection&amp;lt;ContractDescription&amp;gt; contracts = importer.ImportAllContracts();&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  33:  &lt;/span&gt;            ServiceEndpointCollection allEndpoints = importer.ImportAllEndpoints();&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  34:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  35:  &lt;/span&gt;            &lt;span class="rem"&gt;// Generate type information for each contract&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  36:  &lt;/span&gt;            ServiceContractGenerator generator = &lt;span class="kwrd"&gt;new&lt;/span&gt; ServiceContractGenerator();&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  37:  &lt;/span&gt;            var endpointsForContracts = &lt;span class="kwrd"&gt;new&lt;/span&gt; Dictionary&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;, IEnumerable&amp;lt;ServiceEndpoint&amp;gt;&amp;gt;();&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  38:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  39:  &lt;/span&gt;            &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (ContractDescription contract &lt;span class="kwrd"&gt;in&lt;/span&gt; contracts)&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  40:  &lt;/span&gt;            {&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  41:  &lt;/span&gt;                generator.GenerateServiceContractType(contract);&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  42:  &lt;/span&gt;                &lt;span class="rem"&gt;// Keep a list of each contract&amp;#39;s endpoints&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  43:  &lt;/span&gt;                endpointsForContracts[contract.Name] = allEndpoints.Where(&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  44:  &lt;/span&gt;                    se =&amp;gt; se.Contract.Name == contract.Name).ToList();&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  45:  &lt;/span&gt;            }&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  46:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  47:  &lt;/span&gt;            &lt;span class="kwrd"&gt;if&lt;/span&gt; (generator.Errors.Count != 0)&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  48:  &lt;/span&gt;                &lt;span class="kwrd"&gt;throw&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; Exception(&lt;span class="str"&gt;&amp;quot;There were errors during code compilation.&amp;quot;&lt;/span&gt;);&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  49:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  50:  &lt;/span&gt;            &lt;span class="rem"&gt;// Generate a code file for the contracts &lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  51:  &lt;/span&gt;            CodeGeneratorOptions options = &lt;span class="kwrd"&gt;new&lt;/span&gt; CodeGeneratorOptions();&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  52:  &lt;/span&gt;            options.BracingStyle = &lt;span class="str"&gt;&amp;quot;C&amp;quot;&lt;/span&gt;;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  53:  &lt;/span&gt;            CodeDomProvider codeDomProvider = CodeDomProvider.CreateProvider(&lt;span class="str"&gt;&amp;quot;C#&amp;quot;&lt;/span&gt;);&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  54:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  55:  &lt;/span&gt;            &lt;span class="rem"&gt;// Compile the code file to an in-memory assembly&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  56:  &lt;/span&gt;            &lt;span class="rem"&gt;// Don&amp;#39;t forget to add all WCF-related assemblies as references&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  57:  &lt;/span&gt;            CompilerParameters compilerParameters = &lt;span class="kwrd"&gt;new&lt;/span&gt; CompilerParameters(&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  58:  &lt;/span&gt;                &lt;span class="kwrd"&gt;new&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt;[] { &lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  59:  &lt;/span&gt;                    &lt;span class="str"&gt;&amp;quot;System.dll&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;System.ServiceModel.dll&amp;quot;&lt;/span&gt;, &lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  60:  &lt;/span&gt;                    &lt;span class="str"&gt;&amp;quot;System.Runtime.Serialization.dll&amp;quot;&lt;/span&gt; });&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  61:  &lt;/span&gt;            compilerParameters.GenerateInMemory = &lt;span class="kwrd"&gt;true&lt;/span&gt;;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  62:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  63:  &lt;/span&gt;            CompilerResults results = codeDomProvider.CompileAssemblyFromDom(&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  64:  &lt;/span&gt;                compilerParameters, generator.TargetCompileUnit);&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  65:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  66:  &lt;/span&gt;            &lt;span class="kwrd"&gt;if&lt;/span&gt; (results.Errors.Count &amp;gt; 0)&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  67:  &lt;/span&gt;            {&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  68:  &lt;/span&gt;                &lt;span class="kwrd"&gt;throw&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; Exception(&lt;span class="str"&gt;&amp;quot;There were errors during generated code compilation&amp;quot;&lt;/span&gt;);&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  69:  &lt;/span&gt;            }&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  70:  &lt;/span&gt;            &lt;span class="kwrd"&gt;else&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  71:  &lt;/span&gt;            {&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  72:  &lt;/span&gt;                &lt;span class="rem"&gt;// Find the proxy type that was generated for the specified contract&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  73:  &lt;/span&gt;                &lt;span class="rem"&gt;// (identified by a class that implements the contract and ICommunicationbject)&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  74:  &lt;/span&gt;                Type clientProxyType = results.CompiledAssembly.GetTypes().First(&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  75:  &lt;/span&gt;                    t =&amp;gt; t.IsClass &amp;amp;&amp;amp;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  76:  &lt;/span&gt;                        t.GetInterface(contractName) != &lt;span class="kwrd"&gt;null&lt;/span&gt; &amp;amp;&amp;amp;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  77:  &lt;/span&gt;                        t.GetInterface(&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(ICommunicationObject).Name) != &lt;span class="kwrd"&gt;null&lt;/span&gt;);&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  78:  &lt;/span&gt;                        &lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  79:  &lt;/span&gt;                &lt;span class="rem"&gt;// Get the first service endpoint for the contract&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  80:  &lt;/span&gt;                ServiceEndpoint se = endpointsForContracts[contractName].First();                    &lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  81:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  82:  &lt;/span&gt;                &lt;span class="rem"&gt;// Create an instance of the proxy&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  83:  &lt;/span&gt;                &lt;span class="rem"&gt;// Pass the endpoint&amp;#39;s binding and address as parameters&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  84:  &lt;/span&gt;                &lt;span class="rem"&gt;// to the ctor&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  85:  &lt;/span&gt;                &lt;span class="kwrd"&gt;object&lt;/span&gt; instance = results.CompiledAssembly.CreateInstance(&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  86:  &lt;/span&gt;                    clientProxyType.Name, &lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  87:  &lt;/span&gt;                    &lt;span class="kwrd"&gt;false&lt;/span&gt;, &lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  88:  &lt;/span&gt;                    System.Reflection.BindingFlags.CreateInstance, &lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  89:  &lt;/span&gt;                    &lt;span class="kwrd"&gt;null&lt;/span&gt;,&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  90:  &lt;/span&gt;                    &lt;span class="kwrd"&gt;new&lt;/span&gt; &lt;span class="kwrd"&gt;object&lt;/span&gt;[] { se.Binding, se.Address }, &lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  91:  &lt;/span&gt;                    CultureInfo.CurrentCulture, &lt;span class="kwrd"&gt;null&lt;/span&gt;);&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  92:  &lt;/span&gt;                &lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  93:  &lt;/span&gt;                &lt;span class="rem"&gt;// Get the operation&amp;#39;s method, invoke it, and get the return value&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  94:  &lt;/span&gt;                &lt;span class="kwrd"&gt;object&lt;/span&gt; retVal = instance.GetType().GetMethod(operationName).&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  95:  &lt;/span&gt;                    Invoke(instance, operationParameters);&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  96:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  97:  &lt;/span&gt;                Console.WriteLine(retVal.ToString());&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  98:  &lt;/span&gt;            }&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  99:  &lt;/span&gt;        }&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt; 100:  &lt;/span&gt;    }&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt; 101:  &lt;/span&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;I’ve placed comments that describe the code, but basically it imports the WSDL, generates types for the contract (service + data), generates C# code from it, compiles it, and uses reflection to create a proxy and invoke the correct method.&lt;/p&gt;
&lt;p&gt;If you want to use this technique to call methods that require a data contract, you will need some extra work to create the correct type and initialize it.&lt;/p&gt;
&lt;p&gt;A compiled and running version of this code (+ the service) can be found here: &lt;a title="https://skydrive.live.com/redir.aspx?cid=5ef5be1ab30a6056&amp;amp;resid=5EF5BE1AB30A6056!466&amp;amp;parid=5EF5BE1AB30A6056!129" href="https://skydrive.live.com/redir.aspx?cid=5ef5be1ab30a6056&amp;amp;resid=5EF5BE1AB30A6056!466&amp;amp;parid=5EF5BE1AB30A6056!129"&gt;https://skydrive.live.com/redir.aspx?cid=5ef5be1ab30a6056&amp;amp;resid=5EF5BE1AB30A6056!466&amp;amp;parid=5EF5BE1AB30A6056!129&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Hope you find this piece of code useful.&lt;/p&gt;
&lt;p&gt;Feb-12:&lt;/p&gt;
&lt;p&gt;Just found out this great blog post that uses the same implementation only to enable calling WCF services from PowerShell.&amp;nbsp; &lt;br /&gt;&lt;a title="http://www.justaprogrammer.net/2012/02/11/using-powershell-to-call-a-wcf-service/" href="http://www.justaprogrammer.net/2012/02/11/using-powershell-to-call-a-wcf-service/"&gt;http://www.justaprogrammer.net/2012/02/11/using-powershell-to-call-a-wcf-service/&lt;/a&gt;&lt;/p&gt;
&lt;div style="PADDING-BOTTOM:0px;MARGIN:0px;PADDING-LEFT:0px;PADDING-RIGHT:0px;PADDING-TOP:0px;" class="wlWriterHeaderFooter"&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http://blogs.microsoft.co.il/blogs/idof/archive/2012/02/10/calling-a-wcf-service-from-a-client-without-having-the-contract-interface.aspx"&gt;&lt;img border="0" alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://blogs.microsoft.co.il/blogs/idof/archive/2012/02/10/calling-a-wcf-service-from-a-client-without-having-the-contract-interface.aspx&amp;amp;bgcolor=6600FF" /&gt;&lt;/a&gt; &lt;a href="http://dotnetshoutout.com/Submit?url=http://blogs.microsoft.co.il/blogs/idof/archive/2012/02/10/calling-a-wcf-service-from-a-client-without-having-the-contract-interface.aspx"&gt;&lt;img style="BORDER-BOTTOM:0px;BORDER-LEFT:0px;BORDER-TOP:0px;BORDER-RIGHT:0px;" alt="Shout it" src="http://dotnetshoutout.com/image.axd?url=http://blogs.microsoft.co.il/blogs/idof/archive/2012/02/10/calling-a-wcf-service-from-a-client-without-having-the-contract-interface.aspx" /&gt;&lt;/a&gt; 
&lt;div class="addthis_toolbox addthis_default_style "&gt;&lt;a class="addthis_button_preferred_1"&gt;&lt;/a&gt;&lt;a class="addthis_button_preferred_2"&gt;&lt;/a&gt;&lt;a class="addthis_button_preferred_3"&gt;&lt;/a&gt;&lt;a class="addthis_button_preferred_4"&gt;&lt;/a&gt;&lt;a class="addthis_button_compact"&gt;&lt;/a&gt;&lt;a class="addthis_counter addthis_bubble_style"&gt;&lt;/a&gt;&lt;/div&gt;
&lt;script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=ra-4f27f7864794397c"&gt;&lt;/script&gt;
&lt;a style="DISPLAY:none;" href="http://www.codeproject.com/script/Articles/BlogFeedList.aspx?amid=2199681" rel="tag"&gt;CodeProject&lt;/a&gt; &lt;/div&gt;&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=1010779" width="1" height="1"&gt;</description><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/WCF/default.aspx">WCF</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/CodeDom/default.aspx">CodeDom</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/DEV/default.aspx">DEV</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/mex/default.aspx">mex</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/WsdlImporter/default.aspx">WsdlImporter</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/WCF+Client/default.aspx">WCF Client</category><feedburner:origLink>http://blogs.microsoft.co.il/blogs/idof/archive/2012/02/10/calling-a-wcf-service-from-a-client-without-having-the-contract-interface.aspx</feedburner:origLink></item><item><title>WCF/ASMX Interoperability – Removing the Annoying xxxSpecified when Adding a Web Reference to a WCF Service</title><link>http://feedproxy.google.com/~r/IdoFlatowsBlog/~3/a3wsKWQIq2M/wcf-asmx-interoperability-removing-the-annoying-xxxspecified-when-adding-a-web-reference-to-a-wcf-service.aspx</link><pubDate>Tue, 31 Jan 2012 18:22:00 GMT</pubDate><guid isPermaLink="false">b5c4f5bc-c09b-4439-a595-91a98c1847df:1003550</guid><dc:creator>Ido Flatow</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://blogs.microsoft.co.il/blogs/idof/rsscomments.aspx?PostID=1003550</wfw:commentRss><comments>http://blogs.microsoft.co.il/blogs/idof/archive/2012/01/31/wcf-asmx-interoperability-removing-the-annoying-xxxspecified-when-adding-a-web-reference-to-a-wcf-service.aspx#comments</comments><description>&lt;p&gt;Today I answered a &lt;a href="http://social.msdn.microsoft.com/Forums/he-IL/nethe/thread/53c28854-d853-4713-a389-132a28dd0297"&gt;question&lt;/a&gt; in the Hebrew MSDN forums about consuming WCF from a .NET 2 client, using the “Add Web Reference” option of Visual Studio.&lt;/p&gt;
&lt;p&gt;Just in case you don’t know Hebrew I’ll sum it up for you – when adding a web reference to a WCF service that exposes a method of the following sort:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;int&lt;/span&gt; UseScalarTypes(&lt;span class="kwrd"&gt;int&lt;/span&gt; value1, &lt;span class="kwrd"&gt;int&lt;/span&gt; value2)&lt;/pre&gt;
&lt;p&gt;The generated method signature in the client app will look like so:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; UseScalarTypes(
  &lt;span class="kwrd"&gt;int&lt;/span&gt; value1, &lt;span class="kwrd"&gt;bool&lt;/span&gt; value1Specified, 
  &lt;span class="kwrd"&gt;int&lt;/span&gt; value2, &lt;span class="kwrd"&gt;bool&lt;/span&gt; value2Specified, 
  &lt;span class="kwrd"&gt;out&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; UseScalarTypesResult, &lt;span class="kwrd"&gt;out&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; UseScalarTypesResultSpecified)&lt;/pre&gt;
&lt;p&gt;The question was why this happens and how this can be fixed to look like the service’s method signature.&lt;/p&gt;
&lt;p&gt;Before we continue to see why this happens and how to fix it, the short answer is – Yes, you can make it look like the original contract by using message contracts. Continue reading to see how.&lt;/p&gt;
&lt;p&gt;Why this happens:&lt;/p&gt;
&lt;p&gt;In WCF the WSDL generated for the above method looks like so:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;xs:element&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;UseScalarTypes&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;xs:complexType&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;xs:sequence&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;xs:element&lt;/span&gt; &lt;span class="attr"&gt;minOccurs&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;0&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;value1&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;xs:int&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt; 
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;xs:element&lt;/span&gt; &lt;span class="attr"&gt;minOccurs&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;0&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;value2&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;xs:int&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt; 
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;xs:sequence&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;xs:complexType&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;xs:element&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;Notice the &lt;strong&gt;minOccurs&lt;/strong&gt;? int is a value type which means it doesn’t accept null values, but still WCF marks it as optional. When you use the “Add Service Reference” option of WCF in Visual Studio, the generator ignores that attribute and creates the method declaration in the client side the same way it is declared in the service contract. However, if you use the old “Add Web Reference” option, the generator checks the minOccurs, realizes that the variable is optional, and since this is a value type, it translates the optional into a set of variables: value + xxxSpecified.&lt;/p&gt;
&lt;p&gt;By the way, this is how the WSDL is created for the same method declaration when it is used in an ASMX-style web service:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;s:element&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;UseScalarTypes&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;s:complexType&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;s:sequence&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;s:element&lt;/span&gt; &lt;span class="attr"&gt;minOccurs&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;1&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;maxOccurs&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;1&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;value1&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;s:int&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt; 
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;s:element&lt;/span&gt; &lt;span class="attr"&gt;minOccurs&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;1&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;maxOccurs&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;1&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;value2&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;s:int&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt; 
  &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;s:sequence&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;s:complexType&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;s:element&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Note 1&lt;/strong&gt;: With ASMX web service, the minOccurs/maxOccurs is set properly because the “Add Web Reference” expects that, and therefore we don’t see this behavior with ASMX web service + add web reference. &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Note 2&lt;/strong&gt;: Since WCF ignores the minOccurs, using the “Add Service Reference” to consume that ASMX web service will result in a client-side method with the same signature as declared in the service (without the xxxSpecified).&lt;/p&gt;
&lt;p&gt;So now that we know why this happens, let’s see how to fix it.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Step 1&lt;/strong&gt;: Create a set of message contracts, one for the request and one for the response (if you have one). &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Step 2&lt;/strong&gt;: In the request message contract class, apply the &lt;strong&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms586728.aspx"&gt;MessageContract&lt;/a&gt;&lt;/strong&gt; attribute and set the &lt;strong&gt;IsWrapped&lt;/strong&gt; parameter to &lt;strong&gt;false&lt;/strong&gt;, like so: &lt;/p&gt;&lt;pre class="csharpcode"&gt;[MessageContract(IsWrapped = &lt;span class="kwrd"&gt;false&lt;/span&gt;)]
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; UseScalarTypesRequest&lt;/pre&gt;
&lt;p&gt;Setting the IsWrapped to false will create the XML without a wrapping element, making the properties look like they are actually method parameters.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Step 3&lt;/strong&gt;: Add each parameter of the method to the class as a property, and apply the &lt;strong&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.messagebodymemberattribute.aspx"&gt;MessageBodyMember&lt;/a&gt;&lt;/strong&gt; attribute to it. You can use this step to rename the property to use the naming convention of parameters by using the &lt;strong&gt;Name&lt;/strong&gt; parameter in the attribute. The result should look like so:&lt;/p&gt;&lt;pre class="csharpcode"&gt;[MessageContract(IsWrapped = &lt;span class="kwrd"&gt;false&lt;/span&gt;)]
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; UseScalarTypesRequest
{
  [MessageBodyMember(Name = &lt;span class="str"&gt;&amp;quot;value1&amp;quot;&lt;/span&gt;)]
  &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; Value1 { get; set; }
  [MessageBodyMember(Name = &lt;span class="str"&gt;&amp;quot;value2&amp;quot;&lt;/span&gt;)]
  &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; Value2 { get; set; }
}&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Step 4&lt;/strong&gt;: Do the same for the response message contract, this time you just need one property for the return type of the method, for example:&lt;/p&gt;&lt;pre class="csharpcode"&gt;[MessageContract(IsWrapped = &lt;span class="kwrd"&gt;false&lt;/span&gt;)]
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; UseScalarTypesResponse
{
  [MessageBodyMember]
  &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; Result { get; set; }
}&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Step 5&lt;/strong&gt;: Change the method signature in the contract and service from using parameters to using the message contracts you’ve created, like so:&lt;/p&gt;&lt;pre class="csharpcode"&gt;UseScalarTypesResponse UseScalarTypes(UseScalarTypesRequest parameters)&lt;/pre&gt;
&lt;p&gt;Of course the immediate step will be to also change the implementation of your code to reflect the parameters being moved to a wrapper object - for convenience, you can leave your existing code in the service as is, change the contract, and then create the new methods which will simply call the older ones, like so:&lt;/p&gt;&lt;pre class="csharpcode"&gt;UseScalarTypesResponse UseScalarTypes(UseScalarTypesRequest parameters)
{
  UseScalarTypesResponse result = &lt;span class="kwrd"&gt;new&lt;/span&gt; UseScalarTypesResponse();
  result.Result = UseScalarTypes(parameters.Value1, parameters.Value2);
  &lt;span class="kwrd"&gt;return&lt;/span&gt; result;
}&lt;/pre&gt;
&lt;p&gt;That’s it, update your web reference in the client side, and watch how the method signature in the client side is without the xxxSpecified.&lt;/p&gt;
&lt;div style="PADDING-BOTTOM:0px;MARGIN:0px;PADDING-LEFT:0px;PADDING-RIGHT:0px;PADDING-TOP:0px;" class="wlWriterHeaderFooter"&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http://blogs.microsoft.co.il/blogs/idof/archive/2012/01/31/wcf-asmx-interoperability-removing-the-annoying-xxxspecified-when-adding-a-web-reference-to-a-wcf-service.aspx"&gt;&lt;img border="0" alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://blogs.microsoft.co.il/blogs/idof/archive/2012/01/31/wcf-asmx-interoperability-removing-the-annoying-xxxspecified-when-adding-a-web-reference-to-a-wcf-service.aspx&amp;amp;bgcolor=6600FF" /&gt;&lt;/a&gt; &lt;a href="http://dotnetshoutout.com/Submit?url=http://blogs.microsoft.co.il/blogs/idof/archive/2012/01/31/wcf-asmx-interoperability-removing-the-annoying-xxxspecified-when-adding-a-web-reference-to-a-wcf-service.aspx"&gt;&lt;img style="BORDER-BOTTOM:0px;BORDER-LEFT:0px;BORDER-TOP:0px;BORDER-RIGHT:0px;" alt="Shout it" src="http://dotnetshoutout.com/image.axd?url=http://blogs.microsoft.co.il/blogs/idof/archive/2012/01/31/wcf-asmx-interoperability-removing-the-annoying-xxxspecified-when-adding-a-web-reference-to-a-wcf-service.aspx" /&gt;&lt;/a&gt; 
&lt;div class="addthis_toolbox addthis_default_style "&gt;&lt;a class="addthis_button_preferred_1"&gt;&lt;/a&gt;&lt;a class="addthis_button_preferred_2"&gt;&lt;/a&gt;&lt;a class="addthis_button_preferred_3"&gt;&lt;/a&gt;&lt;a class="addthis_button_preferred_4"&gt;&lt;/a&gt;&lt;a class="addthis_button_compact"&gt;&lt;/a&gt;&lt;a class="addthis_counter addthis_bubble_style"&gt;&lt;/a&gt;&lt;/div&gt;
&lt;script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=ra-4f27f7864794397c"&gt;&lt;/script&gt;
&lt;a style="DISPLAY:none;" href="http://www.codeproject.com/script/Articles/BlogFeedList.aspx?amid=2199681" rel="tag"&gt;CodeProject&lt;/a&gt; &lt;/div&gt;&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=1003550" width="1" height="1"&gt;</description><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/WCF/default.aspx">WCF</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/DEV/default.aspx">DEV</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/Interoperability/default.aspx">Interoperability</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/ASMX/default.aspx">ASMX</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/IsSpecified/default.aspx">IsSpecified</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/web+services/default.aspx">web services</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/add+web+reference/default.aspx">add web reference</category><feedburner:origLink>http://blogs.microsoft.co.il/blogs/idof/archive/2012/01/31/wcf-asmx-interoperability-removing-the-annoying-xxxspecified-when-adding-a-web-reference-to-a-wcf-service.aspx</feedburner:origLink></item><item><title>פורום חדש לתחום ווב נפתח בפורומי מיקרוסופט ישראל</title><link>http://feedproxy.google.com/~r/IdoFlatowsBlog/~3/ZMslrFLE5wU/1000453.aspx</link><pubDate>Sat, 28 Jan 2012 19:40:39 GMT</pubDate><guid isPermaLink="false">b5c4f5bc-c09b-4439-a595-91a98c1847df:1000453</guid><dc:creator>Ido Flatow</dc:creator><slash:comments>2</slash:comments><wfw:commentRss>http://blogs.microsoft.co.il/blogs/idof/rsscomments.aspx?PostID=1000453</wfw:commentRss><comments>http://blogs.microsoft.co.il/blogs/idof/archive/2012/01/28/1000453.aspx#comments</comments><description>&lt;div dir="rtl"&gt;   &lt;p&gt;לפני מספר חודשים נפתחו באתר מיקרוסופט MSDN ישראל פורומים לפיתוח ו-IT. בחודש האחרון חל שינוי בפורומים, בקטלוג שלהם, וברשימת מנהלי הפורומים. כחלק מהשינוי אני שמח לבשר לכם על פתיחתו של &lt;a href="http://social.msdn.microsoft.com/Forums/he-IL/webdevhe/threads"&gt;פורום חדש&lt;/a&gt; לתחום הווב בניהולם של &lt;a href="http://blogs.microsoft.co.il/blogs/shlomo"&gt;שלמה גולדברג&lt;/a&gt; (הרב דוטנט) ועבדכם הנאמן.&lt;/p&gt;    &lt;p&gt;בפורום ננסה לתת מענה לשאלות בנושאי פיתוח לעולמות הווב של מיקרוסופט – ASP.NET, ASP.NET MVC, Web Services, WCF, IIS, HTML/JS ועוד.&lt;/p&gt;    &lt;p&gt;להבדיל מהפורומים של MSDN, הפורומים במיקרוסופט ישראל מיועדים לקהל הישראלי, כתובים בעברית, ומעודדים כתיבה בעברית של שאלות ותשובות.&lt;/p&gt;    &lt;p&gt;למה בעברית? למה פורומים נוספים על אלו של MSDN? ובכן:&lt;/p&gt;    &lt;p&gt;1. אנחנו לא היחידים – להרבה מדינות יש פורומים &lt;a href="http://msdn.microsoft.com/he-IL/ms376821"&gt;מקומיים&lt;/a&gt;, בשפה מקומית, שמיועדים לקהל המקומי.&lt;/p&gt;    &lt;p&gt;2. עברית כשפת אם - לחלקנו קל להתבטא יותר בעברית במקום באנגלית. אני מכיר מפתחים מצויינים שעדין משתמשים בבודק איות לפני שליחת מייל באנגלית. כתיבה בעברית גם מאפשרת גישה לפורומים לקהל היותר צעיר של מפתחים.&lt;/p&gt;    &lt;p&gt;3. יצירת קהילה – השתתפות בפורום תאפשר שיתוף פעולה יותר הדוק בין הקהל הישראלי והנציגים בארץ של מיקרוסופט. דרך הפורום נוכל ליידע אתכם על הרצאות בבתים פתוחים, כנסים בארץ,קורסים והכשרות. במקרים מסוימים ייתכן ואף נוכל לבצע אסקלציה של שאלות לגורמים במיקרוסופט ישראל ואף יותר מכך.&lt;/p&gt;    &lt;p&gt;לצערנו, עד כמה שנרצה, פורום לא יכול להסתמך אך ורק על המנהלים שלו שיענו, ולכן ההשתתפות שלהם חיונית להצלחת הפורום. אז גם אם אין לכם שאלה ספציפית, אתם מוזמנים להכנס &lt;a href="http://social.msdn.microsoft.com/Forums/he-IL/webdevhe/threads"&gt;לפורום&lt;/a&gt; מדי פעם, להגיב על שאלות, ללמוד משאלות של אחרים, וגם לספר לנו על משהו מעניין שמצאתם שאולי יכול לשמש אנשים אחרים. אם אתם נוהגים לעבוד עם RSS, אתם מוזמנים להוסיף את לינק ה-&lt;a href="http://social.msdn.microsoft.com/Forums/he-IL/webdevhe/threads?outputAs=rss"&gt;RSS&lt;/a&gt; של הפורום לרשימות שלכם.&lt;/p&gt;    &lt;p&gt;אז נתראה &lt;a href="http://social.msdn.microsoft.com/Forums/he-IL/webdevhe/threads"&gt;בפורום&lt;/a&gt;, &lt;a href="http://blogs.microsoft.co.il/blogs/idof"&gt;בבלוג&lt;/a&gt;, &lt;a href="http://twitter.com/IdoFlatow"&gt;בטוויטר&lt;/a&gt; ובאירועים השונים השנה.&lt;/p&gt;     &lt;/div&gt;&lt;div class="wlWriterHeaderFooter" style="margin:0px;padding:0px 0px 0px 0px;"&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http://blogs.microsoft.co.il/blogs/idof/archive/2012/01/28/1000453.aspx"&gt;&lt;img border="0" alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://blogs.microsoft.co.il/blogs/idof/archive/2012/01/28/1000453.aspx&amp;amp;bgcolor=6600FF" /&gt;&lt;/a&gt; &lt;a href="http://dotnetshoutout.com/Submit?url=http://blogs.microsoft.co.il/blogs/idof/archive/2012/01/28/1000453.aspx"&gt;&lt;img alt="Shout it" src="http://dotnetshoutout.com/image.axd?url=http://blogs.microsoft.co.il/blogs/idof/archive/2012/01/28/1000453.aspx" style="border:0px;" /&gt;&lt;/a&gt; &lt;/div&gt;&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=1000453" width="1" height="1"&gt;</description><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/DEV/default.aspx">DEV</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/forum/default.aspx">forum</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/webdev/default.aspx">webdev</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/msdn/default.aspx">msdn</category><feedburner:origLink>http://blogs.microsoft.co.il/blogs/idof/archive/2012/01/28/1000453.aspx</feedburner:origLink></item><item><title>What’s new in WCF 4.5? Improved streaming in IIS hosting</title><link>http://feedproxy.google.com/~r/IdoFlatowsBlog/~3/l-t0Ip8a7k0/what-s-new-in-wcf-4-5-improved-streaming-in-iis-hosting.aspx</link><pubDate>Tue, 17 Jan 2012 20:36:00 GMT</pubDate><guid isPermaLink="false">b5c4f5bc-c09b-4439-a595-91a98c1847df:990797</guid><dc:creator>Ido Flatow</dc:creator><slash:comments>8</slash:comments><wfw:commentRss>http://blogs.microsoft.co.il/blogs/idof/rsscomments.aspx?PostID=990797</wfw:commentRss><comments>http://blogs.microsoft.co.il/blogs/idof/archive/2012/01/17/what-s-new-in-wcf-4-5-improved-streaming-in-iis-hosting.aspx#comments</comments><description>&lt;p&gt;As promised in my &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/2012/01/16/dear-blog-it-s-been-a-while-since-my-last-post.aspx"&gt;previous post&lt;/a&gt;, I’m continuing my mission to inform you of new changes in WCF 4.5.&lt;/p&gt;
&lt;p&gt;This is the ninth post in the WCF 4.5 series. This post continues the previous posts on web-hosting features, and this time it is about the improved streaming capabilities of WCF when it is hosted in IIS.&lt;/p&gt;
&lt;p&gt;Previous posts:&lt;/p&gt;
&lt;p&gt;1. &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/2011/09/16/what-s-new-in-wcf-4-5-let-s-start-with-wcf-configuration.aspx"&gt;What’s new in WCF 4.5? let’s start with WCF configuration&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;2. &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/2011/09/17/what-s-new-in-wcf-4-5-a-single-wsdl-file.aspx"&gt;What’s new in WCF 4.5? a single WSDL file&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;3. &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/2011/09/19/what-s-new-in-wcf-4-5-configuration-tooltips-and-intellisense-in-config-files.aspx"&gt;What’s new in WCF 4.5? Configuration tooltips and intellisense in config files&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;4. &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/2011/09/25/what-s-new-in-wcf-4-5-configuration-validations.aspx"&gt;What’s new in WCF 4.5? Configuration validations&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;5. &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/2011/09/25/what-s-new-in-wcf-4-5-multiple-authentication-support-on-a-single-endpoint-in-iis.aspx"&gt;What’s new in WCF 4.5? Multiple authentication support on a single endpoint in IIS&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;6. &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/2011/10/05/what-s-new-in-wcf-4-5-automatic-https-endpoint-for-iis.aspx"&gt;What’s new in WCF 4.5? Automatic HTTPS endpoint for IIS&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;7. &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/2011/10/10/what-s-new-in-wcf-4-5-basichttpsbinding.aspx"&gt;What’s new in WCF 4.5? BasicHttpsBinding&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;8. &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/2011/10/31/what-s-new-in-wcf-4-5-changed-default-for-asp-net-compatibility-mode.aspx"&gt;What’s new in WCF 4.5? Changed default for ASP.NET compatibility mode&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;If you’ve ever tried creating a WCF service that uses streamed requests (for example a file upload service) and host it in IIS, you may have noticed a strange behavior in your WCF service – it would seem that WCF is late in receiving the request, as if it was entirely loaded into the memory, and then passed to WCF. So is it streamed? or is it actually buffered? well, it’s both.&lt;/p&gt;
&lt;p&gt;When you host a WCF service in IIS you also get a bit of the ASP.NET pipeline on the side, even if you don’t use the ASP.NET compatibility mode, this is documented in the &lt;a href="http://msdn.microsoft.com/en-us/library/aa702682.aspx"&gt;WCF Services and ASP.NET&lt;/a&gt; article on MSDN (look for the part about the PostAuthenticateRequest event). In .NET 4, there is a design flaw in ASP.NET which causes the requests sent to WCF to be buffered in ASP.NET. This buffering behavior causes several major side-effects:&lt;/p&gt;
&lt;p&gt;1. There is a latency between the time the streamed message is received by ASP.NET and the time the WCF service method is actually invoked.&lt;/p&gt;
&lt;p&gt;2. There is some memory consumption due to the buffering – the exact amount of memory consumed depends on the size of the message sent by the client, but it can even get to several hundred MBs if you increase the &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.configuration.httpruntimesection.maxrequestlength.aspx"&gt;MaxRequestLength&lt;/a&gt; of ASP.NET, the &lt;a href="http://www.iis.net/ConfigReference/system.webServer/security/requestFiltering/requestLimits"&gt;MaxAllowedContentLength&lt;/a&gt; of IIS 7, and of course the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.wshttpbindingbase.maxreceivedmessagesize.aspx"&gt;MaxReceivedMessageSize&lt;/a&gt; and &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.channels.httptransportbindingelement.maxbuffersize.aspx"&gt;MaxBufferSize&lt;/a&gt; of WCF.&lt;/p&gt;
&lt;p&gt;3. When ASP.NET buffers the request, it uses both memory and disk. The &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.configuration.httpruntimesection.requestlengthdiskthreshold.aspx"&gt;requestLengthDiskThreshold&lt;/a&gt; configuration setting of ASP.NET controls when ASP.NET starts to use the disk. If you upload multiple files to WCF at once, you will start to see some delays due to multiple files being written to the disk at once. BTW, the files are written to an “upload” folder under the web application’s temporary asp.net folder (under c:\windows\Microsoft.NET\Framework\vX.X.XXXX\Temporary ASP.NET Files\) and are removed after the request is handled.&lt;/p&gt;
&lt;p&gt;To show this behavior, I have created a client application that uploads a 500MB file to a WCF service. The WCF service is hosted in IIS and is set to a streamed request (you can download the StreamingInIIS sample solution from &lt;font style="BACKGROUND-COLOR:#ffffff;"&gt;&lt;a href="https://skydrive.live.com/redir.aspx?cid=5ef5be1ab30a6056&amp;amp;resid=5EF5BE1AB30A6056!460&amp;amp;parid=5EF5BE1AB30A6056!129"&gt;here&lt;/a&gt;&lt;/font&gt;). The following output shows some information about the time it took for the service to receive and handle the request, and the consumed memory:&lt;/p&gt;
&lt;p&gt;1 Client started upload on 17/01/2012 19:03:25 &lt;br /&gt;2 Available memory before starting is: 2701MB &lt;br /&gt;3 Client finished upload on 17/01/2012 19:03:44 &lt;br /&gt;4 Available memory after finishing is: 2699MB &lt;br /&gt;5 Available memory on ASP.NET is: 2701MB &lt;br /&gt;6 ASP.NET received upload at: 17/01/2012 19:03:28 &lt;br /&gt;7 Available memory on WCF is: 2122MB &lt;br /&gt;8 WCF started receiving file at: 17/01/2012 19:03:38 &lt;br /&gt;9 WCF finished receiving file at: 17/01/2012 19:03:43 &lt;br /&gt;File size is: 524288000 &lt;br /&gt;Press any key to continue . . .&lt;/p&gt;
&lt;p&gt;Some things to note about these results:&lt;/p&gt;
&lt;p&gt;1. Client started / Client finished (line 1+3) – the &lt;strong&gt;total time&lt;/strong&gt; the client waited for the service was &lt;strong&gt;19 seconds&lt;/strong&gt;; this includes the upload time, the buffering time of ASP.NET, and the time WCF handled the received stream.&lt;/p&gt;
&lt;p&gt;2. &lt;strong&gt;ASP.NET started receiving&lt;/strong&gt; the stream &lt;strong&gt;3 seconds &lt;/strong&gt;after the client began sending it (line 6).&lt;/p&gt;
&lt;p&gt;3. &lt;strong&gt;WCF started receiving&lt;/strong&gt; the stream &lt;strong&gt;10 seconds&lt;/strong&gt; after ASP.NET received started receiving it, and a total of &lt;strong&gt;13 seconds&lt;/strong&gt; from the time the client started sending it (line 8). In total, it took WCF &lt;strong&gt;5 seconds &lt;/strong&gt;to &lt;strong&gt;read the entire stream&lt;/strong&gt; from ASP.NET (line 8+9).&lt;/p&gt;
&lt;p&gt;4. Before the client sent the message, the &lt;strong&gt;available memory&lt;/strong&gt; in the machine was &lt;strong&gt;2701MB&lt;/strong&gt;, which is also the available memory when ASP.NET first received the message. By the time WCF got the request and started handling it, the available memory was &lt;strong&gt;2122MB&lt;/strong&gt; – about &lt;strong&gt;580MB were consumed from the memory&lt;/strong&gt; for this operation (lines 2, 5, and 7).&lt;/p&gt;
&lt;p&gt;5. As for the generated temp file, here is a screenshot of the temporary ASP.NET folder content:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/idof/image_415EBE7C.png"&gt;&lt;img style="BACKGROUND-IMAGE:none;BORDER-BOTTOM:0px;BORDER-LEFT:0px;PADDING-LEFT:0px;PADDING-RIGHT:0px;DISPLAY:inline;BORDER-TOP:0px;BORDER-RIGHT:0px;PADDING-TOP:0px;" title="image" border="0" alt="image" src="http://blogs.microsoft.co.il/blogs/idof/image_thumb_451C634C.png" width="682" height="191" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: to show the ASP.NET information I used the ASP.NET compatibility mode. You can turn it off in the sample code if you want to verify that the problem also exists when we don’t use the compatibility mode (look at the difference between the time the client sent the request and the time WCF actually started handling the request – there should be a big latency).&lt;/p&gt;
&lt;p&gt;So we get that WCF 4 doesn’t handle well streamed content over IIS, but what about WCF 4.5? what has changed?&lt;/p&gt;
&lt;p&gt;In WCF 4.5 this just doesn’t happen – with .NET 4.5, ASP.NET doesn’t buffer the request, but rather forwards it directly to WCF, so we don’t get any latency, no memory consumption, and no disk usage.&lt;/p&gt;
&lt;p&gt;Want to see some proof? I ran the same demo code in Windows Server 8 with WCF 4.5 over IIS. I used a smaller file size (200MB), since this is a VM with less memory, however you can still see the difference quite clearly:&lt;/p&gt;
&lt;p&gt;1 Client started upload on 11/27/2011 7:23:18 AM &lt;br /&gt;2 Available memory before starting is: 942MB &lt;br /&gt;3 Client finished upload on 11/27/2011 7:23:46 AM &lt;br /&gt;4 Available memory after finishing is: 942MB &lt;br /&gt;5 Available memory on ASP.NET is: 941MB &lt;br /&gt;6 ASP.NET received upload at: 11/27/2011 7:23:20 AM &lt;br /&gt;7 Available memory on WCF is: 942MB &lt;br /&gt;8 WCF started receiving file at: 11/27/2011 7:23:20 AM &lt;br /&gt;9 WCF finished receiving file at: 11/27/2011 7:23:46 AM &lt;br /&gt;File size is: 209715200 &lt;br /&gt;Press any key to continue . . .&lt;/p&gt;
&lt;p&gt;First thing to note – memory consumption hasn’t changed throughout the execution – remains &lt;strong&gt;steady at ~942MB&lt;/strong&gt; (lines 2+4+5+7).&lt;/p&gt;
&lt;p&gt;As for the latency – &lt;strong&gt;WCF received the request &lt;/strong&gt;at the &lt;strong&gt;same time ASP.NET received it&lt;/strong&gt; (lines 6+8), which is &lt;strong&gt;2 seconds after the client &lt;/strong&gt;begins sending it.&lt;/p&gt;
&lt;p&gt;Oh, and since ASP.NET passed the stream directly to WCF, &lt;strong&gt;no temp file was created &lt;/strong&gt;!!&lt;/p&gt;
&lt;p&gt;So there you have it – proper streaming in WCF 4.5 over IIS.&lt;/p&gt;
&lt;p&gt;Stay tuned for more posts about the new features of WCF 4.5. You can also follow me on Twitter (@IdoFlatow) to get updates as soon as new posts are published.&lt;/p&gt;
&lt;div style="PADDING-BOTTOM:0px;MARGIN:0px;PADDING-LEFT:0px;PADDING-RIGHT:0px;PADDING-TOP:0px;" class="wlWriterHeaderFooter"&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http://blogs.microsoft.co.il/blogs/idof/archive/2012/01/17/what-s-new-in-wcf-4-5-improved-streaming-in-iis-hosting.aspx"&gt;&lt;img border="0" alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://blogs.microsoft.co.il/blogs/idof/archive/2012/01/17/what-s-new-in-wcf-4-5-improved-streaming-in-iis-hosting.aspx&amp;amp;bgcolor=6600FF" /&gt;&lt;/a&gt; &lt;a href="http://dotnetshoutout.com/Submit?url=http://blogs.microsoft.co.il/blogs/idof/archive/2012/01/17/what-s-new-in-wcf-4-5-improved-streaming-in-iis-hosting.aspx"&gt;&lt;img style="BORDER-BOTTOM:0px;BORDER-LEFT:0px;BORDER-TOP:0px;BORDER-RIGHT:0px;" alt="Shout it" src="http://dotnetshoutout.com/image.axd?url=http://blogs.microsoft.co.il/blogs/idof/archive/2012/01/17/what-s-new-in-wcf-4-5-improved-streaming-in-iis-hosting.aspx" /&gt;&lt;/a&gt; &lt;a style="DISPLAY:none;" href="http://www.codeproject.com/script/Articles/BlogFeedList.aspx?amid=2199681" rel="tag"&gt;CodeProject&lt;/a&gt; &lt;/div&gt;&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=990797" width="1" height="1"&gt;</description><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/WCF/default.aspx">WCF</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/DEV/default.aspx">DEV</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/IIS/default.aspx">IIS</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/What_2700_s+new/default.aspx">What's new</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/WCF+4.5/default.aspx">WCF 4.5</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/Streamed/default.aspx">Streamed</category><feedburner:origLink>http://blogs.microsoft.co.il/blogs/idof/archive/2012/01/17/what-s-new-in-wcf-4-5-improved-streaming-in-iis-hosting.aspx</feedburner:origLink></item><item><title>Dear blog, it’s been a while since my last post</title><link>http://feedproxy.google.com/~r/IdoFlatowsBlog/~3/BYNIA427NBU/dear-blog-it-s-been-a-while-since-my-last-post.aspx</link><pubDate>Sun, 15 Jan 2012 23:16:46 GMT</pubDate><guid isPermaLink="false">b5c4f5bc-c09b-4439-a595-91a98c1847df:988921</guid><dc:creator>Ido Flatow</dc:creator><slash:comments>1</slash:comments><wfw:commentRss>http://blogs.microsoft.co.il/blogs/idof/rsscomments.aspx?PostID=988921</wfw:commentRss><comments>http://blogs.microsoft.co.il/blogs/idof/archive/2012/01/16/dear-blog-it-s-been-a-while-since-my-last-post.aspx#comments</comments><description>&lt;p&gt;If you’ve been wondering where I disappeared to in the last couple of weeks, and if you are still waiting anxiously for my next post about WCF 4.5, fear not, I’m here, I’m alive, and I’m still kicking.&lt;/p&gt;  &lt;p&gt;It’s been quite a rough month, as I have been occupied knee deep in home renovations. If you’ve ever dealt with contractors, technicians, and handyman, you know the type of frustration I’m talking about.&lt;/p&gt;  &lt;p&gt;Between re-tiling my floors, replacing my kitchen cabinets, and re-painting my entire home, I also managed to find the time to deliver some courses on &lt;a href="http://www.sela.co.il/syl/Syllabus.aspx?CourseCode=AzureWS&amp;amp;CategoryID=165"&gt;Windows Azure&lt;/a&gt;, &lt;a href="http://www.sela.co.il/syl/Syllabus.aspx?CourseCode=6427A&amp;amp;CategoryID=165"&gt;IIS&lt;/a&gt;, &lt;a href="http://www.sela.co.il/syl/Syllabus.aspx?CourseCode=AdvWCF&amp;amp;CategoryID=165"&gt;Advanced WCF&lt;/a&gt;, &lt;a href="http://www.sela.co.il/syl/Syllabus.aspx?CourseCode=50291B&amp;amp;CategoryID=165"&gt;Windows HPC Server&lt;/a&gt;, AppFabric Cache, and PowerShell.&lt;/p&gt;  &lt;p&gt;2012 is going to be very productive year – this year is going to be a lot about the new releases of .NET 4.5, VS11, and Windows Server 8. I’m guessing you’ll see many more posts about the new features of &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/2011/09/16/what-s-new-in-wcf-4-5-let-s-start-with-wcf-configuration.aspx"&gt;WCF 4.5&lt;/a&gt; (soon to come – a new post about the new streaming features of WCF 4.5 over IIS), .NET 4.5, and VS11.&lt;/p&gt;  &lt;p&gt;I’m also continuing my voyage with BigData solutions which I’ve started last year with my work on the &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/tags/Windows+HPC+Server+2008+R2/default.aspx"&gt;Windows HPC Server 2008 R2&lt;/a&gt;, and the new HPC labs we’ve created in Sela for the &lt;a href="http://msdn.microsoft.com/en-us/wazplatformtrainingcourse_hpcscheduler_unit"&gt;Windows Azure Platform Training Kit&lt;/a&gt;. This year is mostly going to be about Hadoop on Azure, so expect new labs and demos soon on the WAP TK (Windows Azure Platform Training Kit).&lt;/p&gt;  &lt;p&gt;This year I will continue to manage the Israeli Web Developer Community (WDCIL) along with &lt;a href="http://il.linkedin.com/pub/gal-kogman/9/853/220"&gt;Gal Kogman&lt;/a&gt;, and in a couple of days I will also start to moderate the WebDev IL MSDN forum with &lt;a href="http://blogs.microsoft.co.il/blogs/shlomo/"&gt;Sholomo Goldberg&lt;/a&gt;, AKA the DotNet Rabbi.&lt;/p&gt;  &lt;p&gt;I’m also continuing my speaking engagements this year, which ended last year with my sessions at &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/2011/10/20/my-mvc-jquery-razor-nuget-iis-express-session-at-vs-live-2011-redmond.aspx"&gt;VSLive Redmond&lt;/a&gt; and MCT Summit in October and &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/2011/12/07/slide-decks-and-demo-code-from-my-visual-studio-live-2011-orlando-sessions.aspx"&gt;VSLive Orlando&lt;/a&gt; in December. Other than my usual appearances at Sela’s SDP conferences in Israel, I will also be speaking this April in the &lt;a href="http://www.developermarch.com/developersummit/speakers.html#IdoFlatow"&gt;Great Indian Developer Summit&lt;/a&gt; (GIDS) in Bangalore (India of course), and hopefully in additional conferences in Europe and the US (more information to come in the next couple of weeks).&lt;/p&gt;  &lt;p&gt;So check out for my &lt;a href="http://blogs.microsoft.co.il/blogs/idof/"&gt;posts&lt;/a&gt;, my &lt;a href="http://twitter.com/idoflatow"&gt;tweets&lt;/a&gt;, my courses, and my &lt;a href="http://speakermix.com/ido-flatow"&gt;speaking&lt;/a&gt; engagements, and don’t forget – if you need me, just turn on the bat signal, and I’ll come to your rescue, just kidding – you can always contact me through my blog, my tweeter account, or send me an email, and I’ll do my best to answer you promptly.&lt;/p&gt;  &lt;p&gt;Happy new year to y’all, enjoy the new leap year, and hopefully we’ll &lt;a href="http://en.wikipedia.org/wiki/2012_phenomenon"&gt;still be here&lt;/a&gt; to see 2013.&lt;/p&gt;&lt;div class="wlWriterHeaderFooter" style="margin:0px;padding:0px 0px 0px 0px;"&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http://blogs.microsoft.co.il/blogs/idof/archive/2012/01/16/dear-blog-it-s-been-a-while-since-my-last-post.aspx"&gt;&lt;img border="0" alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://blogs.microsoft.co.il/blogs/idof/archive/2012/01/16/dear-blog-it-s-been-a-while-since-my-last-post.aspx&amp;amp;bgcolor=6600FF" /&gt;&lt;/a&gt; &lt;a href="http://dotnetshoutout.com/Submit?url=http://blogs.microsoft.co.il/blogs/idof/archive/2012/01/16/dear-blog-it-s-been-a-while-since-my-last-post.aspx"&gt;&lt;img alt="Shout it" src="http://dotnetshoutout.com/image.axd?url=http://blogs.microsoft.co.il/blogs/idof/archive/2012/01/16/dear-blog-it-s-been-a-while-since-my-last-post.aspx" style="border:0px;" /&gt;&lt;/a&gt; &lt;/div&gt;&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=988921" width="1" height="1"&gt;</description><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/WCF/default.aspx">WCF</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/DEV/default.aspx">DEV</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/IIS/default.aspx">IIS</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/Courses/default.aspx">Courses</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/Azure/default.aspx">Azure</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/HPC/default.aspx">HPC</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/Visual+Studio+Live_2100_+2011/default.aspx">Visual Studio Live! 2011</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/Windows+HPC+Server+2008+R2/default.aspx">Windows HPC Server 2008 R2</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/speakers/default.aspx">speakers</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/WCF+4.5/default.aspx">WCF 4.5</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/Visual+Studio+11/default.aspx">Visual Studio 11</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/MCT+Summit/default.aspx">MCT Summit</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/WDCIL/default.aspx">WDCIL</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/engagements/default.aspx">engagements</category><feedburner:origLink>http://blogs.microsoft.co.il/blogs/idof/archive/2012/01/16/dear-blog-it-s-been-a-while-since-my-last-post.aspx</feedburner:origLink></item><item><title>Slide decks and demo code from my Visual Studio Live 2011 (Orlando) sessions</title><link>http://feedproxy.google.com/~r/IdoFlatowsBlog/~3/ihbRAE8urB0/slide-decks-and-demo-code-from-my-visual-studio-live-2011-orlando-sessions.aspx</link><pubDate>Wed, 07 Dec 2011 21:22:28 GMT</pubDate><guid isPermaLink="false">b5c4f5bc-c09b-4439-a595-91a98c1847df:950730</guid><dc:creator>Ido Flatow</dc:creator><slash:comments>5</slash:comments><wfw:commentRss>http://blogs.microsoft.co.il/blogs/idof/rsscomments.aspx?PostID=950730</wfw:commentRss><comments>http://blogs.microsoft.co.il/blogs/idof/archive/2011/12/07/slide-decks-and-demo-code-from-my-visual-studio-live-2011-orlando-sessions.aspx#comments</comments><description>&lt;p&gt;Yesterday I had two session in VS Live, one about the new features of WCF 4, and the other about the new way to develop web applications using ASP.NET MVC, the Razor view engine, jQuery, and IIS 7.5 Express.&lt;/p&gt;  &lt;p&gt;The slide decks and demo code for both sessions can be downloaded from here: &lt;a href="http://bit.ly/vslive-2011-orlando"&gt;http://bit.ly/vslive-2011-orlando&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;I really enjoyed delivering both sessions, and congratulations to all the people that won &lt;a href="http://www.youtube.com/watch?v=UbdRmLaHMeY"&gt;Angry Bird balls&lt;/a&gt; for answering my questions, and for asking tough questions.&lt;/p&gt;  &lt;p&gt;Hopefully we will meet in next year’s VSLive (if my sessions are picked up again).&lt;/p&gt;&lt;div class="wlWriterHeaderFooter" style="margin:0px;padding:0px 0px 0px 0px;"&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http://blogs.microsoft.co.il/blogs/idof/archive/2011/12/07/slide-decks-and-demo-code-from-my-visual-studio-live-2011-orlando-sessions.aspx"&gt;&lt;img border="0" alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://blogs.microsoft.co.il/blogs/idof/archive/2011/12/07/slide-decks-and-demo-code-from-my-visual-studio-live-2011-orlando-sessions.aspx&amp;amp;bgcolor=6600FF" /&gt;&lt;/a&gt; &lt;a href="http://dotnetshoutout.com/Submit?url=http://blogs.microsoft.co.il/blogs/idof/archive/2011/12/07/slide-decks-and-demo-code-from-my-visual-studio-live-2011-orlando-sessions.aspx"&gt;&lt;img alt="Shout it" src="http://dotnetshoutout.com/image.axd?url=http://blogs.microsoft.co.il/blogs/idof/archive/2011/12/07/slide-decks-and-demo-code-from-my-visual-studio-live-2011-orlando-sessions.aspx" style="border:0px;" /&gt;&lt;/a&gt; &lt;/div&gt;&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=950730" width="1" height="1"&gt;</description><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/WCF/default.aspx">WCF</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/Presentation/default.aspx">Presentation</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/DEV/default.aspx">DEV</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/ASP.NET+MVC+3/default.aspx">ASP.NET MVC 3</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/Visual+Studio+Live_2100_+2011/default.aspx">Visual Studio Live! 2011</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/VS+Live/default.aspx">VS Live</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/razor/default.aspx">razor</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/jquery/default.aspx">jquery</category><feedburner:origLink>http://blogs.microsoft.co.il/blogs/idof/archive/2011/12/07/slide-decks-and-demo-code-from-my-visual-studio-live-2011-orlando-sessions.aspx</feedburner:origLink></item><item><title>Creating your own (customized) standard endpoints in WCF 4</title><link>http://feedproxy.google.com/~r/IdoFlatowsBlog/~3/RlLelkShy9I/creating-your-own-customized-standard-endpoints-in-wcf-4.aspx</link><pubDate>Wed, 07 Dec 2011 21:10:00 GMT</pubDate><guid isPermaLink="false">b5c4f5bc-c09b-4439-a595-91a98c1847df:950722</guid><dc:creator>Ido Flatow</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://blogs.microsoft.co.il/blogs/idof/rsscomments.aspx?PostID=950722</wfw:commentRss><comments>http://blogs.microsoft.co.il/blogs/idof/archive/2011/12/07/creating-your-own-customized-standard-endpoints-in-wcf-4.aspx#comments</comments><description>&lt;p&gt;Lately I’ve been writing and speaking a lot about WCF 4.5, but while delivering my “What’s new in WCF 4” session in &lt;a href="http://vslive.com/events/orlando-2011/home.aspx"&gt;Visual Studio Live&lt;/a&gt; yesterday I realized that there is one feature of WCF 4 that most people are not aware of, and do not really understand how useful it is – Standard Endpoints.&lt;/p&gt;
&lt;p&gt;In WCF we always have to specify a set of address+binding+contract (ABC) for our endpoints. If our endpoints also need to be configured, for example – change the binding configuration, or the endpoint behavior, then we need to add some more configuration. We can use default configuration (another feature of WCF 4), but if we have two common settings, we cannot set two defaults and we’re back to square one.&lt;/p&gt;
&lt;p&gt;Standard endpoints change the way we define endpoints – with standard endpoints we specify a special “kind” name in our endpoint, which automatically sets our endpoint’s address, binding, contract, binding configuration, and endpoint behavior.&lt;/p&gt;
&lt;p&gt;For example – if we define the following endpoint:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;endpoint&lt;/span&gt; &lt;span class="attr"&gt;address&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;mex&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;kind&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;mexEndpoint&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;The above endpoint will automatically be set with the &lt;strong&gt;mexHttpBinding&lt;/strong&gt; and the &lt;strong&gt;IMetadataExchange&lt;/strong&gt; contract.&lt;/p&gt;
&lt;p&gt;If we define the following endpoints:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;endpoint&lt;/span&gt; &lt;span class="attr"&gt;address&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;web&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;kind&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;webHttpEndpoint&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;contract&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;MyNS.IMyContract&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;We will get an endpoint which uses &lt;strong&gt;webHttpBinding&lt;/strong&gt;, and automatically gets the &lt;strong&gt;webHttp&lt;/strong&gt; endpoint behavior.&lt;/p&gt;
&lt;p&gt;Although this is quite nice, this is the least we can do with standard endpoints. The real use of standard endpoints is when you create some of your own.&lt;/p&gt;
&lt;p&gt;Image the following – you are a part of an infrastructure team in your organization and you need to explain to the dev teams which endpoint configuration they should use in their projects – “Please use &lt;strong&gt;NetTcp &lt;/strong&gt;binding, with &lt;strong&gt;increased message size limits&lt;/strong&gt;, with either &lt;strong&gt;security none or transport&lt;/strong&gt;, and don’t forget to &lt;strong&gt;increase the send timeout”&lt;/strong&gt;. &lt;/p&gt;
&lt;p&gt;One way to do this is to send a memo to all the dev teams, hoping everyone follow your instructions to the letter. Another way you can do that is to create your own standard endpoint with all of the above configuration and just send it to the dev teams to use.&lt;/p&gt;
&lt;p&gt;First of all you need to create your custom endpoint:&lt;/p&gt;
&lt;div class="csharpcode"&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; CompanyNameStandardEndpoint : ServiceEndpoint&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;{&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;    &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; _isSecured;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; CompanyNameStandardEndpoint(ContractDescription contract)&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;        : &lt;span class="kwrd"&gt;base&lt;/span&gt;(contract)&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;    {&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;        &lt;span class="kwrd"&gt;this&lt;/span&gt;.Binding = &lt;span class="kwrd"&gt;new&lt;/span&gt; NetTcpBinding();&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;        ResetBindingConfiguration(&lt;span class="kwrd"&gt;this&lt;/span&gt;.Binding);&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;        &lt;span class="kwrd"&gt;this&lt;/span&gt;.IsSystemEndpoint = &lt;span class="kwrd"&gt;false&lt;/span&gt;;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  11:  &lt;/span&gt;    }&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  12:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  13:  &lt;/span&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; IsSecured&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  14:  &lt;/span&gt;    {&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  15:  &lt;/span&gt;        get&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  16:  &lt;/span&gt;        {&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  17:  &lt;/span&gt;            &lt;span class="kwrd"&gt;return&lt;/span&gt; _isSecured;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  18:  &lt;/span&gt;        }&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  19:  &lt;/span&gt;        set&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  20:  &lt;/span&gt;        {&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  21:  &lt;/span&gt;            _isSecured = &lt;span class="kwrd"&gt;value&lt;/span&gt;;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  22:  &lt;/span&gt;            &lt;span class="kwrd"&gt;if&lt;/span&gt; (_isSecured)&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  23:  &lt;/span&gt;            {&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  24:  &lt;/span&gt;                (&lt;span class="kwrd"&gt;this&lt;/span&gt;.Binding &lt;span class="kwrd"&gt;as&lt;/span&gt; NetTcpBinding).Security.Mode = SecurityMode.Transport;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  25:  &lt;/span&gt;            }&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  26:  &lt;/span&gt;            &lt;span class="kwrd"&gt;else&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  27:  &lt;/span&gt;            {&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  28:  &lt;/span&gt;                (&lt;span class="kwrd"&gt;this&lt;/span&gt;.Binding &lt;span class="kwrd"&gt;as&lt;/span&gt; NetTcpBinding).Security.Mode = SecurityMode.None;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  29:  &lt;/span&gt;            }&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  30:  &lt;/span&gt;        }&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  31:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  32:  &lt;/span&gt;    }&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  33:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  34:  &lt;/span&gt;    &lt;span class="rem"&gt;// Receive a dynamic object instead of creating separate methods&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  35:  &lt;/span&gt;    &lt;span class="rem"&gt;// for netTcp, basicHttp, WSHttpBinding...&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  36:  &lt;/span&gt;    &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; ResetBindingConfiguration(dynamic binding)&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  37:  &lt;/span&gt;    {&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  38:  &lt;/span&gt;        binding.SendTimeout = TimeSpan.FromMinutes(5);&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  39:  &lt;/span&gt;        binding.MaxReceivedMessageSize = Int32.MaxValue;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  40:  &lt;/span&gt;        binding.MaxBufferSize = Int32.MaxValue;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  41:  &lt;/span&gt;    }&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  42:  &lt;/span&gt;}&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Line 8 makes sure that your endpoint will use NetTcp binding.&lt;/p&gt;
&lt;p&gt;Line 9 will call a method that initializes the binding settings (lines 36-41).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Note &lt;/strong&gt;: the &lt;strong&gt;ResetBindingConfiguration &lt;/strong&gt;method receives a dynamic object because for some reason some of the binding properties such as the &lt;strong&gt;MaxReceivedMessageSize &lt;/strong&gt;and the &lt;strong&gt;MaxBufferSize &lt;/strong&gt;are defined in each of the bindings instead of being defined in a base Binding class. The dynamic will allow us to change our code later on to support both TCP and HTTP bindings without duplicating our method for overloads.&lt;/p&gt;
&lt;p&gt;Line 10 specifies that this is a user-defined endpoint and not a system endpoint.&lt;/p&gt;
&lt;p&gt;Lines 13-32 are responsible of handling the user’s selection to whether the endpoint is secured or not by changing the security mode to either &lt;strong&gt;Transport &lt;/strong&gt;or &lt;strong&gt;None&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;So now we have a new standard endpoint that initializes the binding to &lt;strong&gt;NetTcpBinding&lt;/strong&gt;, sets the timeout and message size, and knows to set the security according to the user’s selection. We can now add this endpoint in code to our service by calling the following code:&lt;/p&gt;
&lt;div class="csharpcode"&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;CompanyNameStandardEndpoint newEndpoint = &lt;span class="kwrd"&gt;new&lt;/span&gt; CompanyNameStandardEndpoint(&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;        ContractDescription.GetContract(&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(IService1)));&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;newEndpoint.IsSecured = &lt;span class="kwrd"&gt;false&lt;/span&gt;;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;newEndpoint.Address = &lt;span class="kwrd"&gt;new&lt;/span&gt; EndpointAddress(tcpBaseAddress + &lt;span class="str"&gt;&amp;quot;companyUnsecured&amp;quot;&lt;/span&gt;);&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;host.AddServiceEndpoint(newEndpoint);            &lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;To be able to add this endpoint configuration in the config file, you will need to add some boilerplate code:&lt;/p&gt;
&lt;div class="csharpcode"&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; CompanyNameStandardEndpointCollectionElement :&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;    StandardEndpointCollectionElement&amp;lt;CompanyNameStandardEndpoint, CompanyNameStandardEndpointElement&amp;gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;{&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;}&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; CompanyNameStandardEndpointElement : StandardEndpointElement&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;{&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;    &lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; ServiceEndpoint CreateServiceEndpoint(ContractDescription contractDescription)&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;    {&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;        &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; CompanyNameStandardEndpoint(contractDescription);&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  11:  &lt;/span&gt;    }&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  12:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  13:  &lt;/span&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; IsSecured&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  14:  &lt;/span&gt;    {&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  15:  &lt;/span&gt;        get { &lt;span class="kwrd"&gt;return&lt;/span&gt; (&lt;span class="kwrd"&gt;bool&lt;/span&gt;)&lt;span class="kwrd"&gt;base&lt;/span&gt;[&lt;span class="str"&gt;&amp;quot;isSecured&amp;quot;&lt;/span&gt;]; }&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  16:  &lt;/span&gt;        set { &lt;span class="kwrd"&gt;base&lt;/span&gt;[&lt;span class="str"&gt;&amp;quot;isSecured&amp;quot;&lt;/span&gt;] = &lt;span class="kwrd"&gt;value&lt;/span&gt;; }&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  17:  &lt;/span&gt;    }&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  18:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  19:  &lt;/span&gt;    &lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; ConfigurationPropertyCollection Properties&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  20:  &lt;/span&gt;    {&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  21:  &lt;/span&gt;        get&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  22:  &lt;/span&gt;        {&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  23:  &lt;/span&gt;            ConfigurationPropertyCollection properties = &lt;span class="kwrd"&gt;base&lt;/span&gt;.Properties;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  24:  &lt;/span&gt;            properties.Add(&lt;span class="kwrd"&gt;new&lt;/span&gt; ConfigurationProperty(&lt;span class="str"&gt;&amp;quot;isSecured&amp;quot;&lt;/span&gt;, &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(&lt;span class="kwrd"&gt;bool&lt;/span&gt;), &lt;span class="kwrd"&gt;false&lt;/span&gt;, ConfigurationPropertyOptions.None));&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  25:  &lt;/span&gt;            &lt;span class="kwrd"&gt;return&lt;/span&gt; properties;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  26:  &lt;/span&gt;        }&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  27:  &lt;/span&gt;    }&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  28:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  29:  &lt;/span&gt;    &lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; Type EndpointType&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  30:  &lt;/span&gt;    {&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  31:  &lt;/span&gt;        get { &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(CompanyNameStandardEndpoint); }&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  32:  &lt;/span&gt;    }&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  33:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  34:  &lt;/span&gt;    &lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; OnApplyConfiguration(ServiceEndpoint endpoint, ServiceEndpointElement serviceEndpointElement)&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  35:  &lt;/span&gt;    {&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  36:  &lt;/span&gt;        CompanyNameStandardEndpoint customEndpoint = (CompanyNameStandardEndpoint)endpoint;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  37:  &lt;/span&gt;        customEndpoint.IsSecured = &lt;span class="kwrd"&gt;this&lt;/span&gt;.IsSecured;            &lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  38:  &lt;/span&gt;    }&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  39:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  40:  &lt;/span&gt;    &lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; OnApplyConfiguration(ServiceEndpoint endpoint, ChannelEndpointElement channelEndpointElement)&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  41:  &lt;/span&gt;    {&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  42:  &lt;/span&gt;        CompanyNameStandardEndpoint customEndpoint = (CompanyNameStandardEndpoint)endpoint;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  43:  &lt;/span&gt;        customEndpoint.IsSecured = &lt;span class="kwrd"&gt;this&lt;/span&gt;.IsSecured;            &lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  44:  &lt;/span&gt;    }&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  45:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  46:  &lt;/span&gt;    &lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; OnInitializeAndValidate(ServiceEndpointElement serviceEndpointElement)&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  47:  &lt;/span&gt;    {&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  48:  &lt;/span&gt;            &lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  49:  &lt;/span&gt;    }&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  50:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  51:  &lt;/span&gt;    &lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; OnInitializeAndValidate(ChannelEndpointElement channelEndpointElement)&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  52:  &lt;/span&gt;    {&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  53:  &lt;/span&gt;           &lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  54:  &lt;/span&gt;    }&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  55:  &lt;/span&gt;}&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The above code is a basic configuration element code. The most important part is lines&amp;nbsp; 13-17 in which you need to repeat each of the properties you created in the custom standard element (for a mapping between XML and CLR) and line 24 where you add all the properties that can be set in the configuration file, so the configuration can be validated. &lt;/p&gt;
&lt;p&gt;Once you create the above code, you need just on more step to use the new endpoint kind in your configuration – you need to tell WCF that you have a new service endpoint. To do that you add the following XML in your &amp;lt;system.serviceModel&amp;gt; section:&lt;/p&gt;
&lt;div class="csharpcode"&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;extensions&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;endpointExtensions&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;add&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;      &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;companyNameEndpoint&amp;quot;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;      &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;TestWcfStandardEndpoints.CompanyNameStandardEndpointCollectionElement, TestWcfStandardEndpoints&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;endpointExtensions&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;extensions&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Note: On MSDN you can find a good explanation on &lt;a href="http://msdn.microsoft.com/en-us/library/ee358762.aspx"&gt;standard endpoints&lt;/a&gt;, but the extensions configuration part is incorrect, the above configuration is the correct one (the correct element in the &amp;lt;extensions&amp;gt; is &lt;strong&gt;&amp;lt;endpointExtensions&amp;gt;&lt;/strong&gt; and not &lt;strong&gt;&amp;lt;standardEndpointExtensions&amp;gt;&lt;/strong&gt; as it appears in the article).&lt;/p&gt;
&lt;p&gt;Now you are ready to declare your new endpoints and configure them:&lt;/p&gt;
&lt;div class="csharpcode"&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;services&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;service&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;TestWcfStandardEndpoints.Service1&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;endpoint&lt;/span&gt; &lt;span class="attr"&gt;binding&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;basicHttpBinding&amp;quot;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;            &lt;span class="attr"&gt;contract&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;TestWcfStandardEndpoints.IService1&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;endpoint&lt;/span&gt; &lt;span class="attr"&gt;address&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;mex&amp;quot;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;            &lt;span class="attr"&gt;kind&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;mexEndpoint&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;endpoint&lt;/span&gt; &lt;span class="attr"&gt;address&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;companySecured&amp;quot;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;            &lt;span class="attr"&gt;kind&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;companyNameEndpoint&amp;quot;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;            &lt;span class="attr"&gt;endpointConfiguration&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;securedEndpoint&amp;quot;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;            &lt;span class="attr"&gt;contract&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;TestWcfStandardEndpoints.IService1&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  11:  &lt;/span&gt;    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;service&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  12:  &lt;/span&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;services&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  13:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  14:  &lt;/span&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;standardEndpoints&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  15:  &lt;/span&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;companyNameEndpoint&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  16:  &lt;/span&gt;        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;standardEndpoint&lt;/span&gt; &lt;span class="attr"&gt;isSecured&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;securedEndpoint&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  17:  &lt;/span&gt;    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;companyNameEndpoint&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  18:  &lt;/span&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;standardEndpoints&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;In lines 7-10 we define the endpoint with the new “kind” (line 9) and specify where we configure the rest of the endpoint (line 10).&lt;/p&gt;
&lt;p&gt;Lines 14-18 contains the configuration of the standard endpoint which we created.&lt;/p&gt;
&lt;p&gt;So to conclude, standard endpoints are an easy way to create fully-configured endpoints with binding configuration, contract settings, and endpoint behaviors. It’s mostly useful when wanting to create the same endpoint over and over again in multiple projects (which happens in 99.99% of the time).&lt;/p&gt;
&lt;p&gt;Don’t bother copy pasting all the above code – you can just download the complete solution from &lt;a href="https://skydrive.live.com/redir.aspx?cid=5ef5be1ab30a6056&amp;amp;resid=5EF5BE1AB30A6056!458&amp;amp;parid=root"&gt;here&lt;/a&gt;&lt;/p&gt;
&lt;div style="PADDING-BOTTOM:0px;MARGIN:0px;PADDING-LEFT:0px;PADDING-RIGHT:0px;PADDING-TOP:0px;" class="wlWriterHeaderFooter"&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http://blogs.microsoft.co.il/blogs/idof/archive/2011/12/07/creating-your-own-customized-standard-endpoints-in-wcf-4.aspx"&gt;&lt;img border="0" alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://blogs.microsoft.co.il/blogs/idof/archive/2011/12/07/creating-your-own-customized-standard-endpoints-in-wcf-4.aspx&amp;amp;bgcolor=6600FF" /&gt;&lt;/a&gt; &lt;a href="http://dotnetshoutout.com/Submit?url=http://blogs.microsoft.co.il/blogs/idof/archive/2011/12/07/creating-your-own-customized-standard-endpoints-in-wcf-4.aspx"&gt;&lt;img style="BORDER-BOTTOM:0px;BORDER-LEFT:0px;BORDER-TOP:0px;BORDER-RIGHT:0px;" alt="Shout it" src="http://dotnetshoutout.com/image.axd?url=http://blogs.microsoft.co.il/blogs/idof/archive/2011/12/07/creating-your-own-customized-standard-endpoints-in-wcf-4.aspx" /&gt;&lt;/a&gt; &lt;a style="DISPLAY:none;" href="http://www.codeproject.com/script/Articles/BlogFeedList.aspx?amid=2199681" rel="tag"&gt;CodeProject&lt;/a&gt; &lt;/div&gt;&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=950722" width="1" height="1"&gt;</description><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/WCF/default.aspx">WCF</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/DEV/default.aspx">DEV</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/standard+endpoint/default.aspx">standard endpoint</category><feedburner:origLink>http://blogs.microsoft.co.il/blogs/idof/archive/2011/12/07/creating-your-own-customized-standard-endpoints-in-wcf-4.aspx</feedburner:origLink></item><item><title>Slide decks and sample code from my WCF 4.5 open-house in Microsoft</title><link>http://feedproxy.google.com/~r/IdoFlatowsBlog/~3/e2Qn7-Ffuog/slide-decks-and-sample-code-from-my-wcf-4-5-open-house-in-microsoft.aspx</link><pubDate>Sun, 27 Nov 2011 22:35:39 GMT</pubDate><guid isPermaLink="false">b5c4f5bc-c09b-4439-a595-91a98c1847df:942316</guid><dc:creator>Ido Flatow</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://blogs.microsoft.co.il/blogs/idof/rsscomments.aspx?PostID=942316</wfw:commentRss><comments>http://blogs.microsoft.co.il/blogs/idof/archive/2011/11/28/slide-decks-and-sample-code-from-my-wcf-4-5-open-house-in-microsoft.aspx#comments</comments><description>&lt;p&gt;Today I delivered a half-day talk about WCF on the following subjects:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;&lt;strong&gt;The new features of WCF 4.5       &lt;br /&gt;&lt;/strong&gt;We talked about configuration simplicity, WebSocket and UDP support, streaming fixes for IIS, binary compression, and more.&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Monitoring and troubleshooting WCF services (WCF 3.5/4/4.5)       &lt;br /&gt;&lt;/strong&gt;We talked about performance counters, ETW, WMI, AppFabric, sniffing tools, tracing and message logging, instancing, concurrency, load tests and more.&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;According to the events website at &lt;a href="http://events.microsoft.com"&gt;http://events.microsoft.com&lt;/a&gt;, it looks like this was the first Microsoft event worldwide about WCF 4.5. We like new technologies in Israel &lt;img style="border-bottom-style:none;border-left-style:none;border-top-style:none;border-right-style:none;" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://blogs.microsoft.co.il/blogs/idof/wlEmoticon-smile_697E2F33.png" /&gt;.&lt;/p&gt;  &lt;p&gt;We had a full-house (~100 people), got a lot of questions from people during and after the session, so it was lots of fun. I really enjoyed delivering the session, and I hope that in the coming year we will be able to see the RTM of Visual Studio 11 and .NET 4.5.&lt;/p&gt;  &lt;p&gt;If you missed today’s session, you have another chance to hear me talk about WCF 4.5 in the November meeting of the Web Developers Community (WDCIL) this Tuesday in Microsoft Raanana. You can get more information and register to the event at &lt;a title="http://wdcil2011nov.eventbrite.com" href="http://wdcil2011nov.eventbrite.com"&gt;http://wdcil2011nov.eventbrite.com&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;In the meanwhile, you can &lt;strong&gt;download &lt;/strong&gt;the presentation and the sample code I’ve shown from my SkyDrive at &lt;a href="http://bit.ly/wcf45msdn"&gt;http://bit.ly/wcf45msdn&lt;/a&gt; – this also includes the WCF 4.5 demos I showed, so don’t forget to install VS 11 and .NET 4.5 (&lt;a href="http://reddevnews.com/blogs/rdn-express/2011/11/back-to-app-migrations-with-ms-net-vnext.aspx"&gt;preferably&lt;/a&gt; on a VM).&lt;/p&gt;  &lt;p&gt;I want to repeat what I told people in the event today – the WCF team is eager to know what you think about WCF, what is missing in WCF to make your work easier, and if you encountered any bugs in the product. There are several ways by which you can contact them:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;For WCF 4.5&lt;/li&gt;    &lt;ul&gt;     &lt;li&gt;Visit the .NET 4.5 forum at: &lt;a title="http://forums.asp.net/1239.aspx/1?ASP+NET+4+5+ASP+NET+WCF+and+Visual+Studio+11+Developer+Previews" href="http://forums.asp.net/1239.aspx/1?ASP+NET+4+5+ASP+NET+WCF+and+Visual+Studio+11+Developer+Previews"&gt;http://forums.asp.net/1239.aspx/1?ASP+NET+4+5+ASP+NET+WCF+and+Visual+Studio+11+Developer+Previews&lt;/a&gt;&lt;/li&gt;      &lt;li&gt;Report an issue, feedback, or bugs on Microsoft Connect: &lt;a href="https://connect.microsoft.com/VisualStudio"&gt;https://connect.microsoft.com/VisualStudio&lt;/a&gt;&lt;/li&gt;   &lt;/ul&gt;    &lt;li&gt;For WCF 4&lt;/li&gt;    &lt;ul&gt;     &lt;li&gt;Visit the WCF forum at: &lt;a title="http://social.msdn.microsoft.com/Forums/en/wcf" href="http://social.msdn.microsoft.com/Forums/en/wcf"&gt;http://social.msdn.microsoft.com/Forums/en/wcf&lt;/a&gt;&lt;/li&gt;      &lt;li&gt; Report an issue, feedback, or bugs on Microsoft Connect: &lt;a title="https://connect.microsoft.com/wcf" href="https://connect.microsoft.com/wcf"&gt;https://connect.microsoft.com/wcf&lt;/a&gt;&lt;/li&gt;   &lt;/ul&gt; &lt;/ul&gt;  &lt;p&gt;If you want to read more about WCF 4.5, check out previous posts I published. I will publish new in-depth posts on the new features, so stay tuned. You can also follow me on Twitter @IdoFlatow&lt;/p&gt;  &lt;p&gt;1. &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/2011/09/16/what-s-new-in-wcf-4-5-let-s-start-with-wcf-configuration.aspx"&gt;What’s new in WCF 4.5? let’s start with WCF configuration&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;2. &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/2011/09/17/what-s-new-in-wcf-4-5-a-single-wsdl-file.aspx"&gt;What’s new in WCF 4.5? a single WSDL file&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;3. &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/2011/09/19/what-s-new-in-wcf-4-5-configuration-tooltips-and-intellisense-in-config-files.aspx"&gt;What’s new in WCF 4.5? Configuration tooltips and intellisense in config files&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;4. &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/2011/09/25/what-s-new-in-wcf-4-5-configuration-validations.aspx"&gt;What’s new in WCF 4.5? Configuration validations&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;5. &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/2011/09/25/what-s-new-in-wcf-4-5-multiple-authentication-support-on-a-single-endpoint-in-iis.aspx"&gt;What’s new in WCF 4.5? Multiple authentication support on a single endpoint in IIS&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;6. &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/2011/10/05/what-s-new-in-wcf-4-5-automatic-https-endpoint-for-iis.aspx"&gt;What’s new in WCF 4.5? Automatic HTTPS endpoint for IIS&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;7. &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/2011/10/10/what-s-new-in-wcf-4-5-basichttpsbinding.aspx"&gt;What’s new in WCF 4.5? BasicHttpsBinding&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;8. &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/2011/10/31/what-s-new-in-wcf-4-5-changed-default-for-asp-net-compatibility-mode.aspx"&gt;What’s new in WCF 4.5? Changed default for ASP.NET compatibility mode&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;If you want to learn more about WCF, check out the following WCF sessions we have at &lt;a href="http://www.sela.co.il/s/SDP/Dec2011/index.html"&gt;Sela’s DevDays&lt;/a&gt; next week:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;WCF Crash Course - &lt;a href="http://www.sela.co.il/s/SDP/Dec2011/tutorials2.html#d53"&gt;http://www.sela.co.il/s/SDP/Dec2011/tutorials2.html#d53&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;Advanced WCF - &lt;a href="http://www.sela.co.il/s/SDP/Dec2011/tutorials2.html#d63"&gt;http://www.sela.co.il/s/SDP/Dec2011/tutorials2.html#d63&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;&lt;div class="wlWriterHeaderFooter" style="margin:0px;padding:0px 0px 0px 0px;"&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http://blogs.microsoft.co.il/blogs/idof/archive/2011/11/28/slide-decks-and-sample-code-from-my-wcf-4-5-open-house-in-microsoft.aspx"&gt;&lt;img border="0" alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://blogs.microsoft.co.il/blogs/idof/archive/2011/11/28/slide-decks-and-sample-code-from-my-wcf-4-5-open-house-in-microsoft.aspx&amp;amp;bgcolor=6600FF" /&gt;&lt;/a&gt; &lt;a href="http://dotnetshoutout.com/Submit?url=http://blogs.microsoft.co.il/blogs/idof/archive/2011/11/28/slide-decks-and-sample-code-from-my-wcf-4-5-open-house-in-microsoft.aspx"&gt;&lt;img alt="Shout it" src="http://dotnetshoutout.com/image.axd?url=http://blogs.microsoft.co.il/blogs/idof/archive/2011/11/28/slide-decks-and-sample-code-from-my-wcf-4-5-open-house-in-microsoft.aspx" style="border:0px;" /&gt;&lt;/a&gt; &lt;/div&gt;&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=942316" width="1" height="1"&gt;</description><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/WCF/default.aspx">WCF</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/DEV/default.aspx">DEV</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/open+house/default.aspx">open house</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/What_2700_s+new/default.aspx">What's new</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/monitoring/default.aspx">monitoring</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/WCF+4.5/default.aspx">WCF 4.5</category><feedburner:origLink>http://blogs.microsoft.co.il/blogs/idof/archive/2011/11/28/slide-decks-and-sample-code-from-my-wcf-4-5-open-house-in-microsoft.aspx</feedburner:origLink></item><item><title>WDCIL Call for Speakers</title><link>http://feedproxy.google.com/~r/IdoFlatowsBlog/~3/25XfMaDQOkQ/wdcil-call-for-speakers.aspx</link><pubDate>Mon, 31 Oct 2011 21:17:34 GMT</pubDate><guid isPermaLink="false">b5c4f5bc-c09b-4439-a595-91a98c1847df:923623</guid><dc:creator>Ido Flatow</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://blogs.microsoft.co.il/blogs/idof/rsscomments.aspx?PostID=923623</wfw:commentRss><comments>http://blogs.microsoft.co.il/blogs/idof/archive/2011/10/31/wdcil-call-for-speakers.aspx#comments</comments><description>&lt;p&gt;If you are not familiar with our user group, the Israeli WDC user group is a meeting place for web developers, designers, and architects, where we discuss new and existing web technologies, best practices in web development, and any other interesting stuff that relates to the web world. The user group is managed by &lt;a href="http://www.linkedin.com/pub/gal-kogman/9/853/220"&gt;Gal Kogman&lt;/a&gt; and yours truly, with the support of Microsoft Israel.&lt;/p&gt;  &lt;p&gt;This is just a short list of things we talked about in previous meetings:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;ASP.NET MVC&lt;/li&gt;    &lt;li&gt;Win8, HTML5, and JS libraries&lt;/li&gt;    &lt;li&gt;jQuery mobile framework&lt;/li&gt;    &lt;li&gt;Beyond Visual Studio 2010 – Lightswitch, NuGet, IIS Express …&lt;/li&gt;    &lt;li&gt;Javascript and jQuery tricks&lt;/li&gt;    &lt;li&gt;Facebook for developers&lt;/li&gt;    &lt;li&gt;Rich application for the browser – EF, WCF, Ajax, and jQuery&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;You can read more about the user group on our Microsoft &lt;a href="http://www.microsoft.com/israel/communities/usergroups/wdc.mspx"&gt;page&lt;/a&gt; (a bit outdated), and for the latest news and information, I suggest you visit our Facebook &lt;a href="http://www.facebook.com/wdcil"&gt;page&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;So what’s the purpose of this post, you ask? I’m writing this post to let you know that we are always looking for potential speakers - the field of web development is very vast, and many of us deal with all sorts of web technologies and techniques, so if you think you have worked with a special technology you want to share with the community by presenting it in one of the meetings, please let me know by email or by writing in our Facebook wall. You don’t need to be an experienced speaker to present at the meetings, just make sure you don’t have stage freight beforehand &lt;img alt="Smile" src="http://blogs.microsoft.co.il/blogs/idof/wlEmoticon-smile_66FF140D.png" /&gt;.&lt;/p&gt;&lt;div class="wlWriterHeaderFooter" style="margin:0px;padding:0px 0px 0px 0px;"&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http://blogs.microsoft.co.il/blogs/idof/archive/2011/10/31/wdcil-call-for-speakers.aspx"&gt;&lt;img border="0" alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://blogs.microsoft.co.il/blogs/idof/archive/2011/10/31/wdcil-call-for-speakers.aspx&amp;amp;bgcolor=6600FF" /&gt;&lt;/a&gt; &lt;a href="http://dotnetshoutout.com/Submit?url=http://blogs.microsoft.co.il/blogs/idof/archive/2011/10/31/wdcil-call-for-speakers.aspx"&gt;&lt;img alt="Shout it" src="http://dotnetshoutout.com/image.axd?url=http://blogs.microsoft.co.il/blogs/idof/archive/2011/10/31/wdcil-call-for-speakers.aspx" style="border:0px;" /&gt;&lt;/a&gt; &lt;/div&gt;&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=923623" width="1" height="1"&gt;</description><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/DEV/default.aspx">DEV</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/WDC/default.aspx">WDC</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/WDCIL/default.aspx">WDCIL</category><feedburner:origLink>http://blogs.microsoft.co.il/blogs/idof/archive/2011/10/31/wdcil-call-for-speakers.aspx</feedburner:origLink></item><item><title>What’s new in WCF 4.5? Changed default for ASP.NET compatibility mode</title><link>http://feedproxy.google.com/~r/IdoFlatowsBlog/~3/EmnYizbkmr0/what-s-new-in-wcf-4-5-changed-default-for-asp-net-compatibility-mode.aspx</link><pubDate>Mon, 31 Oct 2011 09:46:00 GMT</pubDate><guid isPermaLink="false">b5c4f5bc-c09b-4439-a595-91a98c1847df:923278</guid><dc:creator>Ido Flatow</dc:creator><slash:comments>3</slash:comments><wfw:commentRss>http://blogs.microsoft.co.il/blogs/idof/rsscomments.aspx?PostID=923278</wfw:commentRss><comments>http://blogs.microsoft.co.il/blogs/idof/archive/2011/10/31/what-s-new-in-wcf-4-5-changed-default-for-asp-net-compatibility-mode.aspx#comments</comments><description>&lt;p&gt;This is the eighth post in the WCF 4.5 series. This post continues the previous posts on web-hosting features. This post is about the ASP.NET compatibility mode default change of WCF 4.5.&lt;/p&gt;
&lt;p&gt;Previous posts:&lt;/p&gt;
&lt;p&gt;1. &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/2011/09/16/what-s-new-in-wcf-4-5-let-s-start-with-wcf-configuration.aspx"&gt;What’s new in WCF 4.5? let’s start with WCF configuration&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;2. &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/2011/09/17/what-s-new-in-wcf-4-5-a-single-wsdl-file.aspx"&gt;What’s new in WCF 4.5? a single WSDL file&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;3. &lt;a title="What’s new in WCF 4.5- Configuration tooltips and intellisense in config files" href="http://blogs.microsoft.co.il/blogs/idof/archive/2011/09/19/what-s-new-in-wcf-4-5-configuration-tooltips-and-intellisense-in-config-files.aspx"&gt;What’s new in WCF 4.5? Configuration tooltips and intellisense in config files&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;4. &lt;font style="BACKGROUND-COLOR:#ffffff;"&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/2011/09/25/what-s-new-in-wcf-4-5-configuration-validations.aspx"&gt;What’s new in WCF 4.5? Configuration validations&lt;/a&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;5. &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/2011/09/25/what-s-new-in-wcf-4-5-multiple-authentication-support-on-a-single-endpoint-in-iis.aspx"&gt;What’s new in WCF 4.5? Multiple authentication support on a single endpoint in IIS&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;6. &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/2011/10/05/what-s-new-in-wcf-4-5-automatic-https-endpoint-for-iis.aspx"&gt;What’s new in WCF 4.5? Automatic HTTPS endpoint for IIS&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;7. &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/2011/10/10/what-s-new-in-wcf-4-5-basichttpsbinding.aspx"&gt;What’s new in WCF 4.5? BasicHttpsBinding&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Normally, a WCF service hosted under IIS works side-by-side with ASP.NET – they share some of the pipeline, they have the same application domain, but work quite independently of each other when it comes to the HTTP context (authorization, context, session, etc…). &lt;strong&gt;This is the default behavior of WCF.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;However, you can change the default behavior of WCF and set it to ASP.NET compatibility mode – this allows WCF and ASP.NET to share most of the pipeline, and have the same HTTP context. This has some advantages and some disadvantages (such as the &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/2010/09/27/asp-net-compatible-wcf-services-concurrency-problem.aspx"&gt;problem&lt;/a&gt; of ASP.NET sessions and blocking WCF calls). &lt;/p&gt;
&lt;p&gt;To make WCF use the ASP.NET compatibility mode you need to do the following two changes:&lt;/p&gt;
&lt;p&gt;1. Enable ASP.NET compatibility mode for the hosting environment in your web.config:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;system.serviceModel&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;serviceHostingEnvironment&lt;/span&gt; &lt;span class="attr"&gt;aspNetCompatibilityEnabled&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;    
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;system.serviceModel&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;2. Set each of your services to support the compatibility mode, by adding the &lt;strong&gt;AspNetCompatibilityRequirements&lt;/strong&gt; attribute.&lt;/p&gt;&lt;pre class="csharpcode"&gt;[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] &lt;/pre&gt;
&lt;p&gt;You can read more about WCF and ASP.NET on &lt;a href="http://msdn.microsoft.com/en-us/library/aa702682(v=vs.110).aspx"&gt;MSDN&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;u&gt;So what has changed in WCF 4.5? &lt;/u&gt;&lt;/p&gt;
&lt;p&gt;In WCF 4.5 the default behavior of WCF is to support the ASP.NET compatibility mode automatically. This is achieved by the following changes: &lt;/p&gt;
&lt;p&gt;1. In the WCF Service Application project template, the &lt;strong&gt;aspNetCompatibilityEnabled&lt;/strong&gt; attribute was added to the &lt;strong&gt;serviceHostingEnvironment&lt;/strong&gt; element, and it is set to true by default.&lt;/p&gt;
&lt;p&gt;2. The default value of the &lt;strong&gt;AspNetCompatibilityRequirements&lt;/strong&gt; attribute has changed from &lt;strong&gt;NotAllowed&lt;/strong&gt; to &lt;strong&gt;Allowed&lt;/strong&gt;. Without this changed default, you would have needed to manually add the attribute to every new service. This is noticeable in the attribute’s documentation:&lt;/p&gt;
&lt;p&gt;WCF 4 - &lt;a title="http://msdn.microsoft.com/en-us/library/system.servicemodel.activation.aspnetcompatibilityrequirementsattribute.requirementsmode(v=VS.100).aspx" href="http://msdn.microsoft.com/en-us/library/system.servicemodel.activation.aspnetcompatibilityrequirementsattribute.requirementsmode(v=VS.100).aspx"&gt;http://msdn.microsoft.com/en-us/library/system.servicemodel.activation.aspnetcompatibilityrequirementsattribute.requirementsmode(v=VS.100).aspx&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;WCF 4.5 - &lt;a title="http://msdn.microsoft.com/en-us/library/system.servicemodel.activation.aspnetcompatibilityrequirementsattribute.requirementsmode(v=VS.110).aspx" href="http://msdn.microsoft.com/en-us/library/system.servicemodel.activation.aspnetcompatibilityrequirementsattribute.requirementsmode(v=VS.110).aspx"&gt;http://msdn.microsoft.com/en-us/library/system.servicemodel.activation.aspnetcompatibilityrequirementsattribute.requirementsmode(v=VS.110).aspx&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;ASP.NET compatibility mode is very useful if you need to use share information between your ASP.NET application and WCF service in regards to the HTTP context, session, or user authorization, but be careful of the &lt;a href="http://blogs.microsoft.co.il/blogs/idof/archive/2010/09/27/asp-net-compatible-wcf-services-concurrency-problem.aspx"&gt;concurrency problem&lt;/a&gt; that occurs when sharing session state between WCF and ASP.NET.&lt;/p&gt;
&lt;p&gt;Expect more on ASP.NET and WCF in next posts, so stay tuned. You can also follow me on Twitter (@IdoFlatow) to get updates as soon as new posts are published.&lt;/p&gt;
&lt;p&gt;The RTM of .NET 4.5 is still to come, and I assume many of you are still adjusting to WCF 4. If you want to learn more about the new features of WCF 4, come to my &lt;a href="http://vslive.com/Events/Orlando-2011/Sessions/Tuesday/T07-Whats-New-in-WCF-4.aspx"&gt;session&lt;/a&gt; at Visual Studio Live! 2011 in Orlando (December 5-9).&lt;/p&gt;
&lt;div style="PADDING-BOTTOM:0px;MARGIN:0px;PADDING-LEFT:0px;PADDING-RIGHT:0px;PADDING-TOP:0px;" class="wlWriterHeaderFooter"&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http://blogs.microsoft.co.il/blogs/idof/archive/2011/10/31/what-s-new-in-wcf-4-5-changed-default-for-asp-net-compatibility-mode.aspx"&gt;&lt;img border="0" alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://blogs.microsoft.co.il/blogs/idof/archive/2011/10/31/what-s-new-in-wcf-4-5-changed-default-for-asp-net-compatibility-mode.aspx&amp;amp;bgcolor=6600FF" /&gt;&lt;/a&gt; &lt;a href="http://dotnetshoutout.com/Submit?url=http://blogs.microsoft.co.il/blogs/idof/archive/2011/10/31/what-s-new-in-wcf-4-5-changed-default-for-asp-net-compatibility-mode.aspx"&gt;&lt;img style="BORDER-BOTTOM:0px;BORDER-LEFT:0px;BORDER-TOP:0px;BORDER-RIGHT:0px;" alt="Shout it" src="http://dotnetshoutout.com/image.axd?url=http://blogs.microsoft.co.il/blogs/idof/archive/2011/10/31/what-s-new-in-wcf-4-5-changed-default-for-asp-net-compatibility-mode.aspx" /&gt;&lt;/a&gt; &lt;a style="DISPLAY:none;" href="http://www.codeproject.com/script/Articles/BlogFeedList.aspx?amid=2199681" rel="tag"&gt;CodeProject&lt;/a&gt; &lt;/div&gt;&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=923278" width="1" height="1"&gt;</description><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/DEV/default.aspx">DEV</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/aspnetcompatibilitymode/default.aspx">aspnetcompatibilitymode</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/What_2700_s+new/default.aspx">What's new</category><category domain="http://blogs.microsoft.co.il/blogs/idof/archive/tags/WCF+4.5/default.aspx">WCF 4.5</category><feedburner:origLink>http://blogs.microsoft.co.il/blogs/idof/archive/2011/10/31/what-s-new-in-wcf-4-5-changed-default-for-asp-net-compatibility-mode.aspx</feedburner:origLink></item></channel></rss>

