<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Zulfiqar&#039;s weblog</title>
	<atom:link href="http://zamd.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://zamd.net</link>
	<description>Middleware, security &#38; random .Net</description>
	<lastBuildDate>Mon, 30 Apr 2012 21:05:30 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='zamd.net' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Zulfiqar&#039;s weblog</title>
		<link>http://zamd.net</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://zamd.net/osd.xml" title="Zulfiqar&#039;s weblog" />
	<atom:link rel='hub' href='http://zamd.net/?pushpress=hub'/>
		<item>
		<title>Deploying Umbraco to Windows Azure</title>
		<link>http://zamd.net/2012/01/27/deploying-umbraco-to-windows-azure/</link>
		<comments>http://zamd.net/2012/01/27/deploying-umbraco-to-windows-azure/#comments</comments>
		<pubDate>Fri, 27 Jan 2012 21:41:03 +0000</pubDate>
		<dc:creator>zamd</dc:creator>
				<category><![CDATA[Windows Azure]]></category>

		<guid isPermaLink="false">https://zuahmed.wordpress.com/?p=372</guid>
		<description><![CDATA[Umbraco is a fairly mature CMS system and recently I was engaged in an assignment to deploy Umbraco CMS to Windows Azure. In this post, I’ll share some of my learning’s. Umbraco accelerator (I call it bootstrapper) works well for small to medium web sites but you definitely have to increase the default blob sync [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zamd.net&amp;blog=13272925&amp;post=372&amp;subd=zuahmed&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://umbraco.com/">Umbraco</a> is a fairly mature CMS system and recently I was engaged in an assignment to deploy Umbraco CMS to Windows Azure. In this post, I’ll share some of my learning’s.</p>
<ul>
<li>Umbraco accelerator (I call it bootstrapper) works well for small to medium web sites but you definitely have to increase the default blob sync interval which by default is set to 1 second.</li>
<li>In the context of Windows Azure, accelerator/bootstrapper become your main application which gets deployed to Azure Web Roles using Azure service model.</li>
<li>Umbraco installation (I used standard Umbraco download) is stored in blob storage while accelerator is configured to pick this and install it on the web roles where accelerator itself is running. Accelerator does both push &amp; pull so file system changes done by Umbraco would be pushed to blob storage and automatically be synced to other web roles by the accelerator.</li>
<li>The standard Azure staging/production deployment doesn’t really fit with accelerator style deployment used by Umbraco. So instead of using staging &amp; production, we used azure production environment only(with well known DNS) and decided to use two hosted services representing UAT &amp; Live environments. Our plan is to use end to end separation i.e. separate blob storage &amp; separate SQL Azure databases. This setup would give us required change management &amp; content management control.</li>
<li>Using accelerator I was quickly able to deploy Umbraco web app to two Azure web roles.</li>
<li>Soon after the deployment I was welcomed by ASP.net yellow screen of death.</li>
<li>I RDP into the server and debugged the W3P.exe to realize ASP.net was failing to validate ViewState.  Make sense! <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Azure is load-balanced &amp; requests were sent to two web role instances in a round robin scheme. ASP.net machine key scheme was set to default <strong>Autogenerate </strong>which resulted in both web roles using different keys to secure/validate ViewState. Once we knew the issue the fix was simple:</li>
<li><strong>Use pre-generated fixed key values for &lt;machineKey&gt;</strong></li>
</ul>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">machineKey</span> <span class="attr">validationKey</span><span class="kwrd">="21F090935F6E49C2C797F69BBAAD8402ABD2EE0B667A8B44EA7DD4374267A75D7"</span>
            <span class="attr">decryptionKey</span><span class="kwrd">="ABAA84D7EC4BB56D75D217CECFFB9628809BDB8BF91CFCD64568A145BE59719F"</span>
            <span class="attr">validation</span><span class="kwrd">="SHA1"</span>
            <span class="attr">decryption</span><span class="kwrd">="AES"</span><span class="kwrd">/&gt;</span></pre>
<ul>
<li>Next step was to create the Umbraco database for which we decided to use SQL Azure as the DB platform.</li>
<li>My first thoughts were to use the basic approach of manually creating a blank DB in Sql Azure and then run Umbraco configuration wizard to populate the schema &amp; data. Even though this approach won’t give us necessary control for the DB assets it was simple to use.</li>
<li>Turns out this approach doesn’t work &amp; Umbraco simply hangs. I debugged &amp; found Umbraco configuration wizard was unable to create couple of columns (of bit data type) &amp; data access was failing because of the missing columns. I discarded this approach without going any further.</li>
<li>I then installed a local Umbraco instance and configured a local Sql Server database which worked smoothly.</li>
<li>I used <a href="http://msdn.microsoft.com/en-us/library/ff381683(SQL.100).aspx">data tier application framework</a> to export local SQL Server database as a package. As SQL Azure natively supports import of dacpac packages, the import was fairly simple process using the Sql Azure management portal.</li>
<li>The dacpac approach also solved the lack of control issues with the simple in-place DB creation option as it gave us a golden copy of the database for future use. We are also planning to use dacpac feature as the basis for backup &amp; restore requirements.</li>
<li>Once DB is ready in SQL Azure,  Umbraco was configured to use this DB and we have a somewhat working Umbraco installation.</li>
<li>During testing, I quickly realized that by default Umbraco stores session state in memory and this would not work in Window Azure load balanced environment.</li>
<li>I could use SQL Azure for session state storage but it’s <a href="http://blogs.msdn.com/b/sqlazure/archive/2010/08/04/10046103.aspx">NOT supported</a> in SQL Azure and also adds quite a bit of overhead in terms of session state clean up as there is no SQL Agent in Azure.</li>
<li>I decided to use Windows Azure Cache (a.k.a AppFabric cache) as the session state storage mechanism. It’s fast &amp; also doesn’t require additional data purge solutions. I created a 128MB cache and configured Umbaco web app to use AppFabric cache (instead of local machine’s memory) as the session state storage.</li>
<li>And finally Umbraco is up &amp; running in Azure <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </li>
</ul>
<p>Enjoy…</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/zuahmed.wordpress.com/372/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/zuahmed.wordpress.com/372/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/zuahmed.wordpress.com/372/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/zuahmed.wordpress.com/372/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/zuahmed.wordpress.com/372/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/zuahmed.wordpress.com/372/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/zuahmed.wordpress.com/372/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/zuahmed.wordpress.com/372/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/zuahmed.wordpress.com/372/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/zuahmed.wordpress.com/372/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/zuahmed.wordpress.com/372/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/zuahmed.wordpress.com/372/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/zuahmed.wordpress.com/372/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/zuahmed.wordpress.com/372/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zamd.net&amp;blog=13272925&amp;post=372&amp;subd=zuahmed&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://zamd.net/2012/01/27/deploying-umbraco-to-windows-azure/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7d41c3b038d67898247bff3e462c42a5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">zamd</media:title>
		</media:content>
	</item>
		<item>
		<title>WebSockets with WCF</title>
		<link>http://zamd.net/2011/11/23/websockets-with-wcf/</link>
		<comments>http://zamd.net/2011/11/23/websockets-with-wcf/#comments</comments>
		<pubDate>Wed, 23 Nov 2011 14:23:04 +0000</pubDate>
		<dc:creator>zamd</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">https://zuahmed.wordpress.com/?p=369</guid>
		<description><![CDATA[Notification &#38; “Duplex communication” are important scenario over the internet but firewalls and browser limitations makes them very hard to implement. In the browser world, tricks like long polling is commonly used to implement server-push requirements. For non-browser scenarios relay technologies like Azure Service Bus overcome the lack of inbound connectivity by creating a relay [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zamd.net&amp;blog=13272925&amp;post=369&amp;subd=zuahmed&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Notification &amp; “Duplex communication” are important scenario over the internet but firewalls and browser limitations makes them very hard to implement. In the browser world, tricks like <a href="http://en.wikipedia.org/wiki/Push_technology#Long_polling">long polling</a> is commonly used to implement server-push requirements. For non-browser scenarios relay technologies like <a href="http://msdn.microsoft.com/en-us/library/windowsazure/ee732537.aspx">Azure Service Bus</a> overcome the lack of inbound connectivity by creating a relay in the cloud where both client &amp; server connects by making an outbound connection. Both long polling &amp; relay works but are not optimum solutions due to latency and the complexity involved. </p>
<p>WebSockets is designed to address some of these limitation. With WebSockets, a client &amp; server can <em>upgrade </em>an existing HTTP connection to a full-duplex TCP/IP connection or setup a new WebSockets connection using an HTTP based handshake. WebSockets uses standard HTTP ports (80, 443) so it’s just works with Firewall &amp; the existing security infrastructure. WebSockets technology bucket has following two parts:</p>
<ol>
<li>WebSockets Protocol&#160; (Currently being standardized by IETF) </li>
<li>WebSockets JavaScript API (Currently being standardized by W3C) </li>
</ol>
<p>Windows “8” has native support for WebSockets protocol &amp; there are quite a few API (native &amp; managed) available for programing WebSockets servers &amp; clients on windows. In addition, IE 10 supports both Web Sockets protocol &amp; the JavaScript API.</p>
<p><strong>Client:</strong></p>
<ul>
<li>IE 10 </li>
<li>WinRT </li>
</ul>
<p><strong>Server:</strong></p>
<ul>
<li>Native windows implementation ( &gt;= Windows “8”)
<ul>
<li>IIS 8.0 </li>
</ul>
</li>
<li>System.Net.WebSockets (Managed Wrapper)
<ul>
<li>HttpListener </li>
</ul>
</li>
<li>System.Web (ASP.net)
<ul>
<li>HttpContext </li>
</ul>
</li>
<li>System.ServiceModel (WCF)
<ul>
<li>NetHttpBinding </li>
</ul>
</li>
</ul>
<p>WCF supported duplex services since V1 but these required either a duplex transport binding (netTcpBinding, netNamedPipeBinding) or <strong>wsDualHttpBinding</strong> which forces a client to have a public URI accessible to service (and to the world <img style="border-style:none;" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://zuahmed.files.wordpress.com/2011/11/wlemoticon-smile.png" />)&#160;&#160; running on the public internet. </p>
<p>wsDualHttpBinding is not really suitable for internet scenarios due to inbound connectivity issues. NetTcpBinding could also be problematic in tightly-locked down environments allowing only outbound connections to port 80/443. </p>
<p>With the WebSockets support in Windows, WCF introduced a new Binding <a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.nethttpbinding(v=vs.110).aspx">NetHttpBinding</a> which does binary SOAP messaging over WebSockets protocol and overcome the limitations of existing bindings. Below I created a basic duplex WCF service </p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:3a6e51c7-d203-45c0-9fe2-1720122ecfeb" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#000080;color:#fff;font-family:Verdana, Tahoma, Arial, sans-serif;font-weight:bold;padding:2px 5px;">Basic Service</div>
<div style="background-color:#ffffff;max-height:300px;overflow:auto;white-space:nowrap;padding:2px 5px;"><span style="background:#ffffff;color:#000000;">[</span><span style="background:#ffffff;color:#2b91af;">ServiceContract</span><span style="background:#ffffff;color:#000000;">(CallbackContract=</span><span style="background:#ffffff;color:#0000ff;">typeof</span><span style="background:#ffffff;color:#000000;">(</span><span style="background:#ffffff;color:#2b91af;">IPing</span><span style="background:#ffffff;color:#000000;">))]</span><br /> <span style="background:#ffffff;color:#000000;"></span><span style="background:#ffffff;color:#0000ff;">public</span><span style="background:#ffffff;color:#000000;"> </span><span style="background:#ffffff;color:#0000ff;">interface</span><span style="background:#ffffff;color:#000000;"> </span><span style="background:#ffffff;color:#2b91af;">IPing</span><br /> <span style="background:#ffffff;color:#000000;">{</span><br />     <span style="background:#ffffff;color:#000000;">[</span><span style="background:#ffffff;color:#2b91af;">OperationContract</span><span style="background:#ffffff;color:#000000;">(IsOneWay=</span><span style="background:#ffffff;color:#0000ff;">true</span><span style="background:#ffffff;color:#000000;">)]</span><br />     <span style="background:#ffffff;color:#000000;"></span><span style="background:#ffffff;color:#0000ff;">void</span><span style="background:#ffffff;color:#000000;"> Ping(</span><span style="background:#ffffff;color:#0000ff;">string</span><span style="background:#ffffff;color:#000000;"> msg);</span><br /> <span style="background:#ffffff;color:#000000;">}</span></p>
<p> <span style="background:#ffffff;color:#000000;"></span><span style="background:#ffffff;color:#0000ff;">class</span><span style="background:#ffffff;color:#000000;"> </span><span style="background:#ffffff;color:#2b91af;">PingService</span><span style="background:#ffffff;color:#000000;"> : </span><span style="background:#ffffff;color:#2b91af;">IPing</span><br /> <span style="background:#ffffff;color:#000000;">{</span><br />     <span style="background:#ffffff;color:#000000;"></span><span style="background:#ffffff;color:#0000ff;">public</span><span style="background:#ffffff;color:#000000;"> </span><span style="background:#ffffff;color:#0000ff;">void</span><span style="background:#ffffff;color:#000000;"> Ping(</span><span style="background:#ffffff;color:#0000ff;">string</span><span style="background:#ffffff;color:#000000;"> msg)</span><br />     <span style="background:#ffffff;color:#000000;">{</span><br />         <span style="background:#ffffff;color:#000000;"></span><span style="background:#ffffff;color:#2b91af;">Console</span><span style="background:#ffffff;color:#000000;">.WriteLine(</span><span style="background:#ffffff;color:#a31515;">&quot;Service: {0}&quot;</span><span style="background:#ffffff;color:#000000;">,msg);</span><br />         <span style="background:#ffffff;color:#000000;"></span><span style="background:#ffffff;color:#0000ff;">var</span><span style="background:#ffffff;color:#000000;"> chnl = </span><span style="background:#ffffff;color:#2b91af;">OperationContext</span><span style="background:#ffffff;color:#000000;">.Current.GetCallbackChannel&lt;</span><span style="background:#ffffff;color:#2b91af;">IPing</span><span style="background:#ffffff;color:#000000;">&gt;();</span></p>
<p>         <span style="background:#ffffff;color:#000000;">chnl.Ping(</span><span style="background:#ffffff;color:#0000ff;">string</span><span style="background:#ffffff;color:#000000;">.Format(</span><span style="background:#ffffff;color:#a31515;">&quot;You said &#092;&quot;{0}&#092;&quot;?&quot;</span><span style="background:#ffffff;color:#000000;">, msg));</span><br />     <span style="background:#ffffff;color:#000000;">}</span><br /> <span style="background:#ffffff;color:#000000;">}</span></div>
</p></div>
</p></div>
<p>Standard WCF hosting code with one endpoint using the new binding (line 5 &amp; 14) </p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:8d879469-5ba7-4602-8cb1-bcffa34824f1" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#000080;color:#fff;font-family:Verdana, Tahoma, Arial, sans-serif;font-weight:bold;padding:2px 5px;">Hosting</div>
<div style="background:#ddd;max-height:400px;overflow:auto;">
<ol style="background:#ffffff;white-space:nowrap;margin:0 0 0 2.5em;padding:0 0 0 5px;">
<li><span style="background:#ffffff;color:#000000;"></span><span style="background:#ffffff;color:#0000ff;">static</span><span style="background:#ffffff;color:#000000;"> </span><span style="background:#ffffff;color:#0000ff;">void</span><span style="background:#ffffff;color:#000000;"> Main(</span><span style="background:#ffffff;color:#0000ff;">string</span><span style="background:#ffffff;color:#000000;">[] args)</span></li>
<li><span style="background:#ffffff;color:#000000;">{</span></li>
<li>    <span style="background:#ffffff;color:#000000;"></span><span style="background:#ffffff;color:#0000ff;">var</span><span style="background:#ffffff;color:#000000;"> sh = </span><span style="background:#ffffff;color:#0000ff;">new</span><span style="background:#ffffff;color:#000000;"> </span><span style="background:#ffffff;color:#2b91af;">ServiceHost</span><span style="background:#ffffff;color:#000000;">(</span><span style="background:#ffffff;color:#0000ff;">typeof</span><span style="background:#ffffff;color:#000000;">(</span><span style="background:#ffffff;color:#2b91af;">PingService</span><span style="background:#ffffff;color:#000000;">), </span></li>
<li>        <span style="background:#ffffff;color:#000000;"></span><span style="background:#ffffff;color:#0000ff;">new</span><span style="background:#ffffff;color:#000000;"> </span><span style="background:#ffffff;color:#2b91af;">Uri</span><span style="background:#ffffff;color:#000000;">(</span><span style="background:#ffffff;color:#a31515;">&quot;http://localhost:9090/&quot;</span><span style="background:#ffffff;color:#000000;">));</span></li>
<li>    <span style="background:#ffffff;color:#000000;"></span><span style="background:#ffffff;color:#0000ff;">var</span><span style="background:#ffffff;color:#000000;"> binding = </span><span style="background:#ffffff;color:#0000ff;">new</span><span style="background:#ffffff;color:#000000;"> </span><span style="background:#ffffff;color:#2b91af;">NetHttpBinding</span><span style="background:#ffffff;color:#000000;">();</span></li>
<li>    <span style="background:#ffffff;color:#000000;">sh.AddServiceEndpoint(</span><span style="background:#ffffff;color:#0000ff;">typeof</span><span style="background:#ffffff;color:#000000;">(</span><span style="background:#ffffff;color:#2b91af;">IPing</span><span style="background:#ffffff;color:#000000;">), binding, </span><span style="background:#ffffff;color:#a31515;">&quot;Ping&quot;</span><span style="background:#ffffff;color:#000000;">);</span></li>
<li>&nbsp;</li>
<li>    <span style="background:#ffffff;color:#000000;">sh.Open();</span></li>
<li>&nbsp;</li>
<li>    <span style="background:#ffffff;color:#000000;"></span><span style="background:#ffffff;color:#2b91af;">Console</span><span style="background:#ffffff;color:#000000;">.WriteLine(</span><span style="background:#ffffff;color:#a31515;">&quot;Service ready&#8230;&quot;</span><span style="background:#ffffff;color:#000000;">);</span></li>
<li>&nbsp;</li>
<li>    <span style="background:#ffffff;color:#000000;"></span><span style="background:#ffffff;color:#0000ff;">var</span><span style="background:#ffffff;color:#000000;"> cf = </span><span style="background:#ffffff;color:#0000ff;">new</span><span style="background:#ffffff;color:#000000;"> </span><span style="background:#ffffff;color:#2b91af;">DuplexChannelFactory</span><span style="background:#ffffff;color:#000000;">&lt;</span><span style="background:#ffffff;color:#2b91af;">IPing</span><span style="background:#ffffff;color:#000000;">&gt;(</span></li>
<li>        <span style="background:#ffffff;color:#000000;"></span><span style="background:#ffffff;color:#0000ff;">new</span><span style="background:#ffffff;color:#000000;"> </span><span style="background:#ffffff;color:#2b91af;">InstanceContext</span><span style="background:#ffffff;color:#000000;">(</span><span style="background:#ffffff;color:#0000ff;">new</span><span style="background:#ffffff;color:#000000;"> </span><span style="background:#ffffff;color:#2b91af;">PingBack</span><span style="background:#ffffff;color:#000000;">()), </span></li>
<li>        <span style="background:#ffffff;color:#000000;">binding,</span></li>
<li>        <span style="background:#ffffff;color:#000000;"></span><span style="background:#ffffff;color:#0000ff;">new</span><span style="background:#ffffff;color:#000000;"> </span><span style="background:#ffffff;color:#2b91af;">EndpointAddress</span><span style="background:#ffffff;color:#000000;">(</span><span style="background:#ffffff;color:#a31515;">&quot;http://localhost:8080/Ping&quot;</span><span style="background:#ffffff;color:#000000;">));</span></li>
<li>&nbsp;</li>
<li>    <span style="background:#ffffff;color:#000000;"></span><span style="background:#ffffff;color:#0000ff;">var</span><span style="background:#ffffff;color:#000000;"> chnl = cf.CreateChannel();</span></li>
<li>    <span style="background:#ffffff;color:#000000;">chnl.Ping(</span><span style="background:#ffffff;color:#a31515;">&quot;Hello!&quot;</span><span style="background:#ffffff;color:#000000;">);</span></li>
<li>&nbsp;</li>
<li>    <span style="background:#ffffff;color:#000000;"></span><span style="background:#ffffff;color:#2b91af;">Console</span><span style="background:#ffffff;color:#000000;">.WriteLine(</span><span style="background:#ffffff;color:#a31515;">&quot;Finishing&#8230;&quot;</span><span style="background:#ffffff;color:#000000;">);</span></li>
<li>    <span style="background:#ffffff;color:#000000;"></span><span style="background:#ffffff;color:#2b91af;">Console</span><span style="background:#ffffff;color:#000000;">.ReadLine();</span></li>
<li><span style="background:#ffffff;color:#000000;">}</span></li>
</ol></div>
</p></div>
</p></div>
<p>and finally my callback handler class.</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:d45bbf48-7f7d-4a56-97ef-d32cf2d94ad6" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#000080;color:#fff;font-family:Verdana, Tahoma, Arial, sans-serif;font-weight:bold;padding:2px 5px;">Callback handler</div>
<div style="background-color:#ffffff;max-height:300px;overflow:auto;white-space:nowrap;padding:2px 5px;"><span style="background:#ffffff;color:#000000;"></span><span style="background:#ffffff;color:#0000ff;">public</span><span style="background:#ffffff;color:#000000;"> </span><span style="background:#ffffff;color:#0000ff;">class</span><span style="background:#ffffff;color:#000000;"> </span><span style="background:#ffffff;color:#2b91af;">PingBack</span><span style="background:#ffffff;color:#000000;"> : </span><span style="background:#ffffff;color:#2b91af;">IPing</span><br /> <span style="background:#ffffff;color:#000000;">{</span><br />     <span style="background:#ffffff;color:#000000;"></span><span style="background:#ffffff;color:#0000ff;">public</span><span style="background:#ffffff;color:#000000;"> </span><span style="background:#ffffff;color:#0000ff;">void</span><span style="background:#ffffff;color:#000000;"> Ping(</span><span style="background:#ffffff;color:#0000ff;">string</span><span style="background:#ffffff;color:#000000;"> msg)</span><br />     <span style="background:#ffffff;color:#000000;">{</span><br />         <span style="background:#ffffff;color:#000000;"></span><span style="background:#ffffff;color:#2b91af;">Console</span><span style="background:#ffffff;color:#000000;">.WriteLine(</span><span style="background:#ffffff;color:#a31515;">&quot;Client: {0}&quot;</span><span style="background:#ffffff;color:#000000;">,msg);</span><br />     <span style="background:#ffffff;color:#000000;">}</span><br /> <span style="background:#ffffff;color:#000000;">}</span></div>
</p></div>
</p></div>
<p>Running the project I get the expected output. </p>
<p>By default, WebSockets protocol is allowed on NetHttpBinding i.e. if your contract is a Duplex contract NetHttpBinding automatically upgrades to WebSockets protocol. Out of box, this binding does SOAP messaging and encodes SOAP using the WCF binary encoding. You can reuse the WebSockets transport binding element in a custom binding to support other encodings &amp; protocols and I’ll talk about this in a future post. </p>
<p><a href="http://zuahmed.files.wordpress.com/2011/11/image.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;margin:0;" title="image" border="0" alt="image" src="http://zuahmed.files.wordpress.com/2011/11/image_thumb.png?w=244&#038;h=76" width="244" height="76" /></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/zuahmed.wordpress.com/369/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/zuahmed.wordpress.com/369/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/zuahmed.wordpress.com/369/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/zuahmed.wordpress.com/369/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/zuahmed.wordpress.com/369/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/zuahmed.wordpress.com/369/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/zuahmed.wordpress.com/369/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/zuahmed.wordpress.com/369/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/zuahmed.wordpress.com/369/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/zuahmed.wordpress.com/369/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/zuahmed.wordpress.com/369/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/zuahmed.wordpress.com/369/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/zuahmed.wordpress.com/369/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/zuahmed.wordpress.com/369/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zamd.net&amp;blog=13272925&amp;post=369&amp;subd=zuahmed&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://zamd.net/2011/11/23/websockets-with-wcf/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7d41c3b038d67898247bff3e462c42a5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">zamd</media:title>
		</media:content>

		<media:content url="http://zuahmed.files.wordpress.com/2011/11/wlemoticon-smile.png" medium="image">
			<media:title type="html">Smile</media:title>
		</media:content>

		<media:content url="http://zuahmed.files.wordpress.com/2011/11/image_thumb.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>Pub/Sub with WCF (Part 2)</title>
		<link>http://zamd.net/2011/05/25/pubsub-with-wcf-part-2/</link>
		<comments>http://zamd.net/2011/05/25/pubsub-with-wcf-part-2/#comments</comments>
		<pubDate>Wed, 25 May 2011 22:18:13 +0000</pubDate>
		<dc:creator>zamd</dc:creator>
				<category><![CDATA[ServiceBusV2]]></category>

		<guid isPermaLink="false">https://zuahmed.wordpress.com/2011/05/25/pubsub-with-wcf-part-2/</guid>
		<description><![CDATA[Source Code Download Service Bus May CTP has a small glitch when it comes to pub/sub messaging using the WCF programing model. The May CTP API out-of-box doesn’t pick up filter/promoted properties from the WCF data contracts and requires you to explicitly specify these properties on the BrokeredMessage object outside of core WCF programing model [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zamd.net&amp;blog=13272925&amp;post=346&amp;subd=zuahmed&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong><a href="http://cid-724b6fcd63a8c1ac.office.live.com/self.aspx/zamd.net/ServiceBusPromotedPropertiesExtensions.zip">Source Code Download</a></strong></p>
<p>Service Bus May CTP has a small glitch when it comes to pub/sub messaging using the WCF programing model. The May CTP API out-of-box doesn’t pick up filter/promoted properties from the WCF data contracts and requires you to explicitly specify these properties on the BrokeredMessage object outside of core WCF programing model as shown in <a href="http://zamd.net/2011/05/19/pubsub-with-wcf-part-1/">part 1</a>.</p>
<p>I didn’t like this repetition and decided to prototype a solution using the WCF extensibility model and after few hours of coding created a solution which looks quite cool <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>In my solution a DataMember can be marked with [PromotedProperty] attribute and a custom operation behavior picks these annotations and promote them as filter properties by automatically attaching them with the outgoing message.</p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Consolas;"><span style="color:#000000;">    </span><span style="color:#0000ff;">public</span><span style="color:#000000;"> </span><span style="color:#0000ff;">class</span><span style="color:#000000;"> </span><span style="color:#2b91af;">Order</span><br />
</span><span style="font-family:Consolas;"><span style="color:#000000;">    {<br />
</span><span style="color:#0000ff;">public</span><span style="color:#000000;"> </span><span style="color:#0000ff;">double</span><span style="color:#000000;"> Amount { </span><span style="color:#0000ff;">get</span><span style="color:#000000;">; </span><span style="color:#0000ff;">set</span></span><span style="font-family:Consolas;"><span style="color:#000000;">; }<br />
</span><span style="background:none transparent scroll repeat 0 0;"><span style="color:#000000;">[</span><span style="color:#2b91af;">PromotedProperty</span><span style="color:#000000;">]</span></span><br />
<span style="color:#000000;">        </span><span style="color:#0000ff;">public</span><span style="color:#000000;"> </span><span style="color:#0000ff;">string</span><span style="color:#000000;"> ShipCity { </span><span style="color:#0000ff;">get</span><span style="color:#000000;">; </span><span style="color:#0000ff;">set</span></span><span style="font-family:Consolas;"><span style="color:#000000;">; }<br />
}</p>
<p>[</span><span style="color:#2b91af;">ServiceContract</span></span><span style="font-family:Consolas;"><span style="color:#000000;">]<br />
</span><span style="color:#0000ff;">public</span><span style="color:#000000;"> </span><span style="color:#0000ff;">interface</span><span style="color:#000000;"> </span><span style="color:#2b91af;">IOrderService</span><br />
</span><span style="font-family:Consolas;"><span style="color:#000000;">    {<br />
[</span><span style="color:#2b91af;">OperationContract</span><span style="color:#000000;">(Name = </span><span style="color:#a31515;">"SubmitFlat"</span><span style="color:#000000;">, IsOneWay = </span><span style="color:#0000ff;">true</span></span><span style="font-family:Consolas;"><span style="color:#000000;">)]<br />
</span><span style="background:none transparent scroll repeat 0 0;"><span style="color:#000000;">[</span><span style="color:#2b91af;">PropertyPromotionBehavior</span><span style="color:#000000;">]</span></span><br />
<span style="color:#000000;">        </span><span style="color:#0000ff;">void</span><span style="color:#000000;"> Submit(</span><span style="color:#0000ff;">double</span><span style="color:#000000;"> amount, [</span><span style="color:#2b91af;">PromotedProperty</span><span style="color:#000000;">] </span><span style="color:#0000ff;">string</span></span><span style="font-family:Consolas;"><span style="color:#000000;"> shipCity);</p>
<p>[</span><span style="color:#2b91af;">OperationContract</span><span style="color:#000000;">(IsOneWay = </span><span style="color:#0000ff;">true</span></span><span style="font-family:Consolas;"><span style="color:#000000;">)]<br />
[</span><span style="color:#2b91af;">PropertyPromotionBehavior</span></span><span style="font-family:Consolas;"><span style="color:#000000;">]<br />
</span><span style="color:#0000ff;">void</span><span style="color:#000000;"> Submit(</span><span style="color:#2b91af;">Order</span><span style="color:#000000;"> order);<br />
}</span></span></p>
<p>I have decided to use a custom formatter to implement property lifting and injection functionality primarily because at the formatter level I still have a fairly typed view of the method call. At message inspector level most of typed-ness has gone and it would have required more work.</p>
<p>The [PropertyPromotionBehavior] creates a ‘promotion model’ (list of properties needs to be promoted) by reflecting on the data contract. The ‘promotion model’ is then populated by the custom formatter with actual parameter values extracted from the call context. [PropertyPromotionBehavior] also replaces the default formatter with a custom <strong>PromotionFormatter </strong>which wraps the default formatter and does the additional work of property promotion. I have highlighted the relevant bits below.</p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Consolas;"><span style="color:#000000;">    [</span><span style="color:#2b91af;">AttributeUsage</span><span style="color:#000000;">(</span><span style="color:#2b91af;">AttributeTargets</span><span style="color:#000000;">.Method)]</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Consolas;"><span style="color:#000000;">    </span><span style="color:#0000ff;">public</span><span style="color:#0000ff;">class</span><span style="color:#2b91af;">PropertyPromotionBehaviorAttribute</span><span style="color:#000000;"> : </span><span style="color:#2b91af;">Attribute</span><span style="color:#000000;">, </span><span style="color:#2b91af;">IOperationBehavior</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Consolas;"><span style="color:#000000;">    {</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Consolas;"><span style="color:#000000;">        </span><span style="color:#0000ff;">public</span><span style="color:#0000ff;">void</span><span style="color:#000000;"> Validate(</span><span style="color:#2b91af;">OperationDescription</span><span style="color:#000000;"> operationDescription) { }</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Consolas;"><span style="color:#000000;"> </span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Consolas;"><span style="color:#000000;">        </span><span style="color:#0000ff;">public</span><span style="color:#0000ff;">void</span><span style="color:#000000;"> ApplyDispatchBehavior(</span><span style="color:#2b91af;">OperationDescription</span><span style="color:#000000;"> operationDescription, </span><span style="color:#2b91af;">DispatchOperation</span><span style="color:#000000;"> dispatchOperation) { }</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Consolas;"><span style="color:#000000;"> </span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Consolas;"><span style="color:#000000;">        </span><span style="color:#0000ff;">public</span><span style="color:#0000ff;">void</span><span style="color:#000000;"> ApplyClientBehavior(</span><span style="color:#2b91af;">OperationDescription</span><span style="color:#000000;"> operationDescription, </span><span style="color:#2b91af;">ClientOperation</span><span style="color:#000000;"> clientOperation)</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Consolas;"><span style="color:#000000;">        {</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Consolas;"><span style="color:#000000;">            </span><span style="color:#0000ff;">var</span><span style="color:#000000;"> promotedProperties = </span><span style="background:none transparent scroll repeat 0 0;"><span style="color:#000000;">LoadPromotedProperties(operationDescription);</span></span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Consolas;"><span style="color:#000000;">            </span><span style="color:#0000ff;">if</span><span style="color:#000000;"> (promotedProperties.Count &lt;= 0) </span><span style="color:#0000ff;">return</span><span style="color:#000000;">;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Consolas;"><span style="color:#000000;"> </span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Consolas;"><span style="color:#000000;">            </span><span style="color:#0000ff;">var</span><span style="color:#000000;"> dummy = </span><span style="color:#0000ff;">new</span><span style="color:#2b91af;">ClientOperation</span><span style="color:#000000;">(clientOperation.Parent, </span><span style="color:#a31515;">&#8220;dummy&#8221;</span><span style="color:#000000;">, </span><span style="color:#a31515;">&#8220;urn:dummy&#8221;</span><span style="color:#000000;">);</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Consolas;"><span style="color:#000000;">            </span><span style="color:#0000ff;">var</span><span style="color:#000000;"> behavior =</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Consolas;"><span style="color:#000000;">                operationDescription.Behaviors.Find&lt;</span><span style="color:#2b91af;">DataContractSerializerOperationBehavior</span><span style="color:#000000;">&gt;() </span><span style="color:#0000ff;">as</span><span style="color:#2b91af;">IOperationBehavior</span><span style="color:#000000;">;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Consolas;"><span style="color:#000000;">            behavior.ApplyClientBehavior(operationDescription, dummy);</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Consolas;"><span style="color:#000000;"> </span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Consolas;"><span style="color:#000000;">            </span><span style="background:none transparent scroll repeat 0 0;"><span style="color:#000000;">clientOperation.Formatter = </span><span style="color:#0000ff;">new</span><span style="color:#2b91af;">PromotionFormatter</span><span style="color:#000000;">(dummy.Formatter, promotedProperties);</span></span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="background:none transparent scroll repeat 0 0;"><span style="font-family:Consolas;"><span style="color:#000000;">            clientOperation.SerializeRequest = dummy.SerializeRequest;</span></span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Consolas;"><span style="color:#000000;">        }</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Consolas;"><span style="color:#000000;"> </span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Consolas;"><span style="color:#000000;">        </span><span style="color:#0000ff;">public</span><span style="color:#0000ff;">void</span><span style="color:#000000;"> AddBindingParameters(</span><span style="color:#2b91af;">OperationDescription</span><span style="color:#000000;"> operationDescription, </span><span style="color:#2b91af;">BindingParameterCollection</span><span style="color:#000000;"> bindingParameters) { }</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Consolas;"><span style="color:#000000;"> </span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Consolas;"><span style="color:#000000;">       &#8230;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Consolas;"><span style="color:#000000;">    }</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Consolas;"><span style="color:#000000;">    </span><span style="color:#0000ff;">class</span><span style="color:#2b91af;">PromotionFormatter</span><span style="color:#000000;"> : </span><span style="color:#2b91af;">IClientMessageFormatter</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Consolas;"><span style="color:#000000;">    {</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Consolas;"><span style="color:#000000;">        </span><span style="color:#0000ff;">private</span><span style="color:#0000ff;">readonly</span><span style="color:#2b91af;">IClientMessageFormatter</span><span style="color:#000000;"> _orignalFormatter;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Consolas;"><span style="color:#000000;">        </span><span style="color:#0000ff;">private</span><span style="color:#0000ff;">readonly</span><span style="color:#2b91af;">IList</span><span style="color:#000000;">&lt;</span><span style="color:#2b91af;">PromotedPropertyDescription</span><span style="color:#000000;">&gt; _promotions;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Consolas;"><span style="color:#000000;"> </span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Consolas;"><span style="color:#000000;">        </span><span style="color:#0000ff;">public</span><span style="color:#000000;"> PromotionFormatter(</span><span style="color:#2b91af;">IClientMessageFormatter</span><span style="color:#000000;"> orignalFormatter, </span><span style="color:#2b91af;">IList</span><span style="color:#000000;">&lt;</span><span style="color:#2b91af;">PromotedPropertyDescription</span><span style="color:#000000;">&gt; promotions)</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Consolas;"><span style="color:#000000;">        {</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Consolas;"><span style="color:#000000;">            _orignalFormatter = orignalFormatter;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Consolas;"><span style="color:#000000;">            _promotions = promotions;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Consolas;"><span style="color:#000000;">        }</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Consolas;"><span style="color:#000000;"> </span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Consolas;"><span style="color:#000000;">        </span><span style="color:#0000ff;">public</span><span style="color:#0000ff;">object</span><span style="color:#000000;"> DeserializeReply(</span><span style="color:#2b91af;">Message</span><span style="color:#000000;"> message, </span><span style="color:#0000ff;">object</span><span style="color:#000000;">[] parameters)</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Consolas;"><span style="color:#000000;">        {</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Consolas;"><span style="color:#000000;">            </span><span style="color:#0000ff;">return</span><span style="color:#000000;"> _orignalFormatter.DeserializeReply(message, parameters);</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Consolas;"><span style="color:#000000;">        }</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Consolas;"><span style="color:#000000;"> </span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Consolas;"><span style="color:#000000;">        </span><span style="color:#0000ff;">public</span><span style="color:#2b91af;">Message</span><span style="color:#000000;"> SerializeRequest(</span><span style="color:#2b91af;">MessageVersion</span><span style="color:#000000;"> messageVersion, </span><span style="color:#0000ff;">object</span><span style="color:#000000;">[] parameters)</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Consolas;"><span style="color:#000000;">        {</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Consolas;"><span style="color:#000000;">            </span><span style="color:#0000ff;">var</span><span style="color:#000000;"> message = _orignalFormatter.SerializeRequest(messageVersion, parameters);</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Consolas;"><span style="color:#000000;"> </span></span></p>
<p class="MsoNormal" style="line-height:normal;text-indent:36pt;margin:0 0 0 36pt;"><span style="font-family:Consolas;"><span style="color:#000000;">&#8230;</span></span></p>
<p class="MsoNormal" style="line-height:normal;text-indent:36pt;margin:0 0 0 36pt;"><span style="font-family:Consolas;"><span style="color:#000000;">&#8230;</span></span></p>
<p class="MsoNormal" style="line-height:normal;text-indent:36pt;margin:0 0 0 36pt;"><span style="font-family:Consolas;"><span style="color:#000000;"> </span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Consolas;"><span style="color:#000000;">            </span><span style="background:none transparent scroll repeat 0 0;"><span style="color:#0000ff;">if</span></span><span style="background:none transparent scroll repeat 0 0;"><span style="color:#000000;"> (_promotions.Count &gt; 0)</span></span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="background:none transparent scroll repeat 0 0;"><span style="font-family:Consolas;"><span style="color:#000000;">            {</span></span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="background:none transparent scroll repeat 0 0;"><span style="font-family:Consolas;"><span style="color:#000000;">                </span><span style="color:#0000ff;">var</span><span style="color:#000000;"> bmp = </span><span style="color:#0000ff;">new</span><span style="color:#2b91af;">BrokeredMessageProperty</span><span style="color:#000000;">();</span></span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="background:none transparent scroll repeat 0 0;"><span style="font-family:Consolas;"><span style="color:#000000;">                </span><span style="color:#0000ff;">foreach</span><span style="color:#000000;"> (</span><span style="color:#0000ff;">var</span><span style="color:#000000;"> promotion </span><span style="color:#0000ff;">in</span><span style="color:#000000;"> _promotions)</span></span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="background:none transparent scroll repeat 0 0;"><span style="font-family:Consolas;"><span style="color:#000000;">                {</span></span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="background:none transparent scroll repeat 0 0;"><span style="font-family:Consolas;"><span style="color:#000000;">                    bmp.Properties[promotion.Name] = promotion.Value;</span></span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="background:none transparent scroll repeat 0 0;"><span style="font-family:Consolas;"><span style="color:#000000;">                }</span></span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="background:none transparent scroll repeat 0 0;"><span style="font-family:Consolas;"><span style="color:#000000;">                message.Properties[</span><span style="color:#2b91af;">BrokeredMessageProperty</span><span style="color:#000000;">.Name] = bmp;</span></span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="background:none transparent scroll repeat 0 0;"><span style="font-family:Consolas;"><span style="color:#000000;">            }</span></span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Consolas;"><span style="color:#000000;">                                                               </span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Consolas;"><span style="color:#000000;">            </span><span style="color:#0000ff;">return</span><span style="color:#000000;"> message;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Consolas;"><span style="color:#000000;">        }</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Consolas;"><span style="color:#000000;">    }</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;">
<p class="MsoNormal" style="line-height:normal;margin:0;">With these extensions in place, the code looks just like the normal WCF code and property promotion happens in the background as you would expect.</p>
<p class="MsoNormal" style="line-height:normal;margin:0;">
<pre style="margin:0;"><span style="color:#0000ff;font-family:Consolas;">var</span><span style="font-family:Consolas;"><span style="color:#000000;"> cf = </span><span style="color:#0000ff;">new</span><span style="color:#000000;"> </span><span style="color:#2b91af;">ChannelFactory</span><span style="color:#000000;">&lt;</span><span style="color:#2b91af;">IOrderService</span></span><span style="font-family:Consolas;"><span style="color:#000000;">&gt;(serviceBusBinding, topicAddress); </span></span></pre>
<pre style="margin:0;"><span style="font-family:Consolas;"><span style="color:#0000ff;">var</span><span style="color:#000000;"> proxy = cf.CreateChannel();</span></span></pre>
<pre style="margin:0;"></pre>
<p><span style="font-family:Consolas;"><span style="color:#000000;">proxy.Submit(</span><span style="color:#0000ff;">new</span><span style="color:#000000;"> </span><span style="color:#2b91af;">Order</span><span style="color:#000000;"> { Amount = 200, ShipCity = </span><span style="color:#a31515;">&#8220;london&#8221;</span></span><span style="font-family:Consolas;"><span style="color:#000000;"> });</p>
<p>proxy.Submit(</span><span style="color:#0000ff;">new</span><span style="color:#000000;"> </span><span style="color:#2b91af;">Order</span><span style="color:#000000;"> { Amount = 322, ShipCity = </span><span style="color:#a31515;">&#8220;reading&#8221;</span></span><span style="font-family:Consolas;"><span style="color:#000000;"> });</p>
<p>proxy.Submit(101, </span><span style="color:#a31515;">&#8220;reading&#8221;</span></span><span style="font-family:Consolas;"><span style="color:#000000;">);</p>
<p></span><span style="color:#2b91af;">Console</span><span style="color:#000000;">.WriteLine(</span><span style="color:#a31515;">&#8220;Submitted.&#8221;</span><span style="color:#000000;">);</span></span></p>
<p>Hopefully Service Bus programing model will support this kind of behavior soon but for the time being these extensions would probably fill the gap.</p>
<p>I have attached complete source code with this post so please feel free to download and use.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/zuahmed.wordpress.com/346/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/zuahmed.wordpress.com/346/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/zuahmed.wordpress.com/346/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/zuahmed.wordpress.com/346/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/zuahmed.wordpress.com/346/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/zuahmed.wordpress.com/346/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/zuahmed.wordpress.com/346/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/zuahmed.wordpress.com/346/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/zuahmed.wordpress.com/346/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/zuahmed.wordpress.com/346/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/zuahmed.wordpress.com/346/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/zuahmed.wordpress.com/346/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/zuahmed.wordpress.com/346/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/zuahmed.wordpress.com/346/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zamd.net&amp;blog=13272925&amp;post=346&amp;subd=zuahmed&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://zamd.net/2011/05/25/pubsub-with-wcf-part-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7d41c3b038d67898247bff3e462c42a5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">zamd</media:title>
		</media:content>
	</item>
		<item>
		<title>Pub/Sub with WCF (Part 1)</title>
		<link>http://zamd.net/2011/05/19/pubsub-with-wcf-part-1/</link>
		<comments>http://zamd.net/2011/05/19/pubsub-with-wcf-part-1/#comments</comments>
		<pubDate>Thu, 19 May 2011 19:47:30 +0000</pubDate>
		<dc:creator>zamd</dc:creator>
				<category><![CDATA[ServiceBusV2]]></category>

		<guid isPermaLink="false">https://zuahmed.wordpress.com/2011/05/19/pubsub-with-wcf-part-1/</guid>
		<description><![CDATA[Code download In yesterday’s post I have explored how to use Service Bus queues as a transport to communicate between a WCF client and a service. In today’s post I will show you WCF pub/sub messaging using the topics and subscriptions. A subscription behaves exactly like a queue for reads while a topic behaves exactly [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zamd.net&amp;blog=13272925&amp;post=345&amp;subd=zuahmed&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://cid-724b6fcd63a8c1ac.office.live.com/self.aspx/zamd.net/ServiceBusTopicsWithWCF.zip">Code download</a></p>
<p>In <a href="http://zamd.net/2011/05/18/wcf-with-service-bus-v2-queues/">yesterday’s post</a> I have explored how to use Service Bus queues as a transport to communicate between a WCF client and a service. In today’s post I will show you WCF pub/sub messaging using the topics and subscriptions. A subscription behaves exactly like a queue for reads while a topic behaves exactly like a queue for writes. This metaphor maps nicely to WCF where our services would listen on different subscriptions while the clients would send messages to a single topic. Service Bus would automatically forward matching messages to correct services. </p>
<p>For this example, I have created a simple order service as shown below. The Write extension simply writes to the console using a certain color assigned to a particular host. I have used this to distinguish the service host receiving the messages. </p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:96cd91ee-1481-457a-a754-0e76700fd6b4" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background-color:#ffffff;max-height:400px;overflow:auto;white-space:nowrap;padding:2px 5px;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> <span style="color:#2b91af;">Order</span><br /> {<br />     <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">double</span> Amount { <span style="color:#0000ff;">get</span>; <span style="color:#0000ff;">set</span>; }<br />     <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">string</span> ShipCity { <span style="color:#0000ff;">get</span>; <span style="color:#0000ff;">set</span>; }<br /> }</p>
<p> [<span style="color:#2b91af;">ServiceContract</span>]<br /> <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">interface</span> <span style="color:#2b91af;">IOrderService</span><br /> {<br />     [<span style="color:#2b91af;">OperationContract</span>(IsOneWay = <span style="color:#0000ff;">true</span>)]<br />     <span style="color:#0000ff;">void</span> Submit(<span style="color:#2b91af;">Order</span> order);<br /> }</p>
<p> <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> <span style="color:#2b91af;">OrderService</span> : <span style="color:#2b91af;">IOrderService</span><br /> {<br />     <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> Submit(<span style="color:#2b91af;">Order</span> order)<br />     {<br />         <span style="color:#0000ff;">var</span> writer = <span style="color:#2b91af;">OperationContext</span>.Current.Host.Extensions.Find&lt;<span style="color:#2b91af;">Writer</span>&gt;();</p>
<p>         writer.WriteLine(<span style="color:#a31515;">&quot;Received order value = {0}, ShipCity = {1}&quot;</span>, order.Amount, order.ShipCity);<br />     }<br /> }</div>
</p></div>
</p></div>
<p>Next I use the Management API to create topics &amp; related subscriptions.</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:6c599ccb-83d0-4698-9d30-26c528d528df" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background-color:#ffffff;max-height:300px;overflow:auto;padding:2px 5px;"><span style="color:#0000ff;">var</span> baseAddress = <span style="color:#a31515;">&quot;sb://soundbyte.servicebus.appfabriclabs.com&quot;</span>;<br /> <span style="color:#0000ff;">var</span> credential = <span style="color:#2b91af;">TransportClientCredentialBase</span>.CreateSharedSecretCredential(<span style="color:#a31515;">&quot;owner&quot;</span>, <span style="color:#a31515;">&quot;zYDbQ2wM4343dbBukWJTF6Y=&quot;</span>);<br /> <span style="color:#0000ff;">var</span> namespaceClient = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">ServiceBusNamespaceClient</span>(baseAddress, credential);</p>
<p> <span style="color:#0000ff;">try</span><br /> {<br />     namespaceClient.DeleteTopic(<span style="color:#a31515;">&quot;orders&quot;</span>);<br /> }<br /> <span style="color:#0000ff;">catch</span> { }</p>
<p> <span style="color:#0000ff;">var</span> topic= namespaceClient.CreateTopic(<span style="color:#a31515;">&quot;orders&quot;</span>);<br /> topic.AddSubscription(<span style="color:#a31515;">&quot;london&quot;</span>, <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">SqlFilterExpression</span>(<span style="color:#a31515;">&quot;ShipCity = &#039;london&#039;&quot;</span>));<br /> topic.AddSubscription(<span style="color:#a31515;">&quot;reading&quot;</span>, <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">SqlFilterExpression</span>(<span style="color:#a31515;">&quot;ShipCity = &#039;reading&#039;&quot;</span>));</div>
</p></div>
</p></div>
<p>Both subscriptions has a filter applied to them and only the messages matching this filter would be delivered to the subscription. I then create two separate service hosts simulating separate services running in different cities. I assigned ‘Cyan’ color to the London host (simulated service hosted in London) and ‘Yellow’ to the Reading Host (Service hosted in Reading).</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:0ba24c27-03bf-42dd-a298-3bc73c0a2874" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background-color:#ffffff;max-height:300px;overflow:auto;padding:2px 5px;"><span style="color:#0000ff;">var</span> serviceBusBinding = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">ServiceBusMessagingBinding</span>();<br /> serviceBusBinding.MessagingFactorySettings.Credential = credential;</p>
<p> <span style="color:#0000ff;">string</span> topicAddress = baseAddress + <span style="color:#a31515;">&quot;/orders&quot;</span>;<br /> <span style="color:#0000ff;">string</span> londonSubscription = baseAddress + <span style="color:#a31515;">&quot;/orders/subscriptions/london&quot;</span>;<br /> <span style="color:#0000ff;">string</span> readingSubscription = baseAddress + <span style="color:#a31515;">&quot;/orders/subscriptions/reading&quot;</span>;</p>
<p> <span style="color:#0000ff;">var</span> hostLondon = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">ServiceHost</span>(<span style="color:#0000ff;">typeof</span>(<span style="color:#2b91af;">OrderService</span>));<br /> hostLondon.Extensions.Add(<span style="color:#0000ff;">new</span> <span style="color:#2b91af;">Writer</span>(<span style="color:#2b91af;">ConsoleColor</span>.Cyan));<br /> hostLondon.AddServiceEndpoint(<span style="color:#0000ff;">typeof</span>(<span style="color:#2b91af;">IOrderService</span>), serviceBusBinding, <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">Uri</span>(topicAddress), <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">Uri</span>(londonSubscription));<br /> hostLondon.Open();</p>
<p> <span style="color:#0000ff;">var</span> hostReading = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">ServiceHost</span>(<span style="color:#0000ff;">typeof</span>(<span style="color:#2b91af;">OrderService</span>));<br /> hostReading.Extensions.Add(<span style="color:#0000ff;">new</span> <span style="color:#2b91af;">Writer</span>(<span style="color:#2b91af;">ConsoleColor</span>.Yellow));<br /> hostReading.AddServiceEndpoint(<span style="color:#0000ff;">typeof</span>(<span style="color:#2b91af;">IOrderService</span>), serviceBusBinding, <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">Uri</span>(topicAddress), <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">Uri</span>(readingSubscription));<br /> hostReading.Open();</div>
</p></div>
</p></div>
<p>Next I have created a simple WCF client using the ChannelFactory API and used it to send messages to the topic. In the current CTP, you have to set the filter properties separately on the BrokeredMessage object, which is a native ServiceBus message object and is different from the WCF Message object. </p>
<p>ServiceBusMessagingBinding automatically converts the WCF message object (generated by the proxy object) to a BrokeredMessage object which is then sent to ServiceBus. On the receive side a similar conversion happens from BrokeredMessage to a WCF Message which is then on to WCF Service. To set BrokeredMessage specific properties, we need to create a BrokeredMessageProperty object, set the properties on it and add it to generated WCF messages. ServiceBusMessagingBinding looks for this property and copy all the properties to the BrokeredMessage object it creates. I’m doing exactly the same using the OperationContextScope below.</p>
<p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:de725806-9913-4801-9063-27572619df11" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background-color:#ffffff;max-height:300px;overflow:auto;padding:2px 5px;"><span style="color:#0000ff;">var</span> cf = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">ChannelFactory</span>&lt;<span style="color:#2b91af;">IOrderService</span>&gt;(serviceBusBinding, topicAddress);<br /> <span style="color:#0000ff;">var</span> proxy = cf.CreateChannel();</p>
<p> <span style="color:#0000ff;">using</span> (<span style="color:#0000ff;">new</span> <span style="color:#2b91af;">OperationContextScope</span>( (<span style="color:#2b91af;">IContextChannel</span>)  proxy))<br /> {<br />     <span style="color:#0000ff;">var</span> bmp = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">BrokeredMessageProperty</span>();<br />     bmp.Properties[<span style="color:#a31515;">&quot;ShipCity&quot;</span>] = <span style="color:#a31515;">&quot;london&quot;</span>;<br />     <span style="color:#2b91af;">OperationContext</span>.Current.OutgoingMessageProperties.Add(<span style="color:#2b91af;">BrokeredMessageProperty</span>.Name, bmp);<br />     proxy.Submit(<span style="color:#0000ff;">new</span> <span style="color:#2b91af;">Order</span> {Amount = 200, ShipCity = <span style="color:#a31515;">&quot;london&quot;}</span>);</p>
<p>     bmp.Properties[<span style="color:#a31515;">&quot;ShipCity&quot;</span>] = <span style="color:#a31515;">&quot;reading&quot;</span>;<br />     proxy.Submit(<span style="color:#0000ff;">new</span> <span style="color:#2b91af;">Order</span> { Amount = 322, ShipCity = <span style="color:#a31515;">&quot;london&quot;</span> });</p>
<p> }</p></div>
</p></div>
</p></div>
</p>
<p>As you can see from the following output that the ‘london’ message was received by London host (‘yellow’) while the ‘reading’ message was received by Reading (‘cyan’) service host.</p>
<p><a href="http://zuahmed.files.wordpress.com/2011/05/image1.png"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;" title="image" border="0" alt="image" src="http://zuahmed.files.wordpress.com/2011/05/image_thumb1.png?w=644&#038;h=244" width="644" height="244" /></a></p>
<p>Finally yes it looks bit ugly that I have to specify these promoted/filter properties separately <img style="border-style:none;" class="wlEmoticon wlEmoticon-sadsmile" alt="Sad smile" src="http://zuahmed.files.wordpress.com/2011/05/wlemoticon-sadsmile.png" />from their WCF contract values. Ideally ServiceBus APIs should have picked up the ShipCity property from my Order object.&#160; Unfortunately in the current CTP you have to do this separately as I have shown you in the above snippet.&#160; In the next post I’ll show how you can extend WCF so that it automatically picks these ‘filter properties’&#160; from operations parameters or WCF DataContract(s). </p>
<p>Stay tuned…</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/zuahmed.wordpress.com/345/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/zuahmed.wordpress.com/345/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/zuahmed.wordpress.com/345/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/zuahmed.wordpress.com/345/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/zuahmed.wordpress.com/345/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/zuahmed.wordpress.com/345/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/zuahmed.wordpress.com/345/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/zuahmed.wordpress.com/345/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/zuahmed.wordpress.com/345/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/zuahmed.wordpress.com/345/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/zuahmed.wordpress.com/345/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/zuahmed.wordpress.com/345/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/zuahmed.wordpress.com/345/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/zuahmed.wordpress.com/345/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zamd.net&amp;blog=13272925&amp;post=345&amp;subd=zuahmed&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://zamd.net/2011/05/19/pubsub-with-wcf-part-1/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7d41c3b038d67898247bff3e462c42a5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">zamd</media:title>
		</media:content>

		<media:content url="http://zuahmed.files.wordpress.com/2011/05/image_thumb1.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://zuahmed.files.wordpress.com/2011/05/wlemoticon-sadsmile.png" medium="image">
			<media:title type="html">Sad smile</media:title>
		</media:content>
	</item>
		<item>
		<title>WCF with Service Bus V2: Queues</title>
		<link>http://zamd.net/2011/05/18/wcf-with-service-bus-v2-queues/</link>
		<comments>http://zamd.net/2011/05/18/wcf-with-service-bus-v2-queues/#comments</comments>
		<pubDate>Wed, 18 May 2011 19:17:30 +0000</pubDate>
		<dc:creator>zamd</dc:creator>
				<category><![CDATA[ServiceBusV2]]></category>

		<guid isPermaLink="false">https://zuahmed.wordpress.com/2011/05/18/wcf-with-service-bus-v2-queues/</guid>
		<description><![CDATA[May CTP of Service Bus introduced tons of new messaging capabilities including Queuing and Topic based pub/sub messaging. Check out Clemens post for an overview. The usage of Service Bus messaging entities (Queues, Topics) is divided across two namespaces – a ‘Management Namespace’ and a ‘Runtime Namespace’. Management namespace is used to create/define messaging entities [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zamd.net&amp;blog=13272925&amp;post=341&amp;subd=zuahmed&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>May CTP of Service Bus introduced tons of new messaging capabilities including Queuing and Topic based pub/sub messaging. <a href="http://blogs.msdn.com/b/clemensv/archive/2011/05/16/introducing-the-windows-azure-appfabric-service-bus-may-2011-ctp.aspx">Check out</a> Clemens post for an overview.</p>
<p>The usage of Service Bus messaging entities (Queues, Topics) is divided across two namespaces – a ‘Management Namespace’ and a ‘Runtime Namespace’. Management namespace is used to create/define messaging entities while the Runtime Namespace is used to do the actual messaging operations using the already defined ‘messaging entities’. The management namespace is exposed using as a REST service and Service Bus SDK also provides with a client library which hides the HTTP based interface behind a nice object oriented API.</p>
<p>So once a messaging entity (for example a Queue) is created and is ready you can use the Runtime API to send/receive messages. May CTP comes with two flavours of runtime APIs.</p>
<ul>
<li>A low level MessagingFactory based API: Which is the native, high fidelity Service Bus API exposing all the Service Bus messaging features.</li>
<li>A higher level WCF binding: Which internally uses the MessagingFactory API and integrates the Service Bus messaging with WCF programing model. </li>
</ul>
<p>There are already few <a href="http://rickgaribay.net/archive/2011/05/17/appfabric-service-bus-v2-ctp.aspx">blogs posts</a> which talks about the MessagingFactory API so I’m not going to repeat that here. Let’s see how can I use Service Bus queues a communication mechanism between my WCF client &amp; service. I’ll start with creating a usual one-way service as you would do for MSMQ or any other queuing technology.</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:e864518a-3257-42d4-99ed-432d65515829" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background-color:#ffffff;max-height:300px;overflow:auto;white-space:nowrap;padding:2px 5px;">    [<span style="color:#2b91af;">ServiceContract</span>]<br />     <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">interface</span> <span style="color:#2b91af;">IHelloService</span><br />     {<br />         [<span style="color:#2b91af;">OperationContract</span>(IsOneWay = <span style="color:#0000ff;">true</span>)]<br />         <span style="color:#0000ff;">void</span> SayHello(<span style="color:#0000ff;">string</span> input);<br />     }</p>
<p>     <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> <span style="color:#2b91af;">HelloService</span> : <span style="color:#2b91af;">IHelloService</span><br />     {<br />         <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> SayHello(<span style="color:#0000ff;">string</span> input)<br />         {<br />             <span style="color:#2b91af;">Console</span>.WriteLine(<span style="color:#a31515;">&quot;Says: &quot;</span> + input);<br />         }<br />     }</div>
</p></div>
</p></div>
<p>&#160;</p>
<p>Following snippet create a queue (line 6) using the management API. I’m using the wrapper class provided with the SDK for the REST based management service.</p>
<p>I then create a binding instance and specify ACS credentials on it. All the operations on Service Bus requires a valid token from ACS and these credentials would be used to acquire an ACS token for SB operations.</p>
<p>Finally I added an endpoint specifying the queue location as the endpoint address. </p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:181e0178-4c97-47ea-b8aa-54f5b96a8515" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#ddd;max-height:500px;overflow:auto;">
<ol style="background:#ffffff;margin:0 0 0 2.5em;padding:0 0 0 5px;">
<li><span style="color:#0000ff;">static</span> <span style="color:#0000ff;">void</span> Main(<span style="color:#0000ff;">string</span>[] args)</li>
<li style="background:#f3f3f3;">{</li>
<li>    <span style="color:#0000ff;">const</span> <span style="color:#0000ff;">string</span> baseAddress = <span style="color:#a31515;">&quot;sb://soundbyte.servicebus.appfabriclabs.com&quot;</span>;</li>
<li style="background:#f3f3f3;">    <span style="color:#0000ff;">var</span> credential = <span style="color:#2b91af;">TransportClientCredentialBase</span>.CreateSharedSecretCredential(<span style="color:#a31515;">&quot;owner&quot;</span>,</li>
<li>                                                                                <span style="color:#a31515;">&quot;zYDbQ2wM1k7J32323232323VdbBukWJTF6Y=&quot;</span>);</li>
<li style="background:#f3f3f3;">    CreateQueue(baseAddress, credential,<span style="color:#a31515;">&quot;q1&quot;</span>);</li>
<li>&nbsp;</li>
<li style="background:#f3f3f3;">    <span style="color:#0000ff;">var</span> serviceBusBinding = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">ServiceBusMessagingBinding</span>();</li>
<li>    serviceBusBinding.MessagingFactorySettings.Credential = credential;</li>
<li style="background:#f3f3f3;">&nbsp;</li>
<li>    <span style="color:#0000ff;">var</span> sh = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">ServiceHost</span>(<span style="color:#0000ff;">typeof</span> (<span style="color:#2b91af;">HelloService</span>));</li>
<li style="background:#f3f3f3;">    sh.AddServiceEndpoint(<span style="color:#0000ff;">typeof</span> (<span style="color:#2b91af;">IHelloService</span>), serviceBusBinding, baseAddress + <span style="color:#a31515;">&quot;/q1&quot;</span>);</li>
<li>    sh.Open();</li>
<li style="background:#f3f3f3;">&nbsp;</li>
<li>&nbsp;</li>
<li style="background:#f3f3f3;">&nbsp;</li>
<li>    <span style="color:#2b91af;">Console</span>.WriteLine(<span style="color:#a31515;">&quot;Host ready&#8230;&quot;</span>);</li>
<li style="background:#f3f3f3;">&nbsp;</li>
<li>    <span style="color:#0000ff;">var</span> cf = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">ChannelFactory</span>&lt;<span style="color:#2b91af;">IHelloService</span>&gt;(serviceBusBinding, baseAddress + <span style="color:#a31515;">&quot;/q1&quot;</span>);</li>
<li style="background:#f3f3f3;">    <span style="color:#0000ff;">var</span> proxy = cf.CreateChannel();</li>
<li>    <span style="color:#0000ff;">for</span> (<span style="color:#0000ff;">int</span> i = 0; i &lt; 10; i++)</li>
<li style="background:#f3f3f3;">    {</li>
<li>        proxy.SayHello(<span style="color:#a31515;">&quot;Hi &quot;</span> + i);</li>
<li style="background:#f3f3f3;">    }</li>
<li>&nbsp;</li>
<li style="background:#f3f3f3;">    <span style="color:#2b91af;">Console</span>.ReadLine();</li>
<li>}</li>
</ol></div>
</p></div>
</p></div>
<p>&#160;</p>
<p>My client is a standard WCF proxy (line 19-23) which is sending messages to the same endpoint address (queue location) using the same ServiceBus binding. </p>
<p>The above produces following expected output. Easy isn’t it?</p>
<p><a href="http://zuahmed.files.wordpress.com/2011/05/image.png"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;" title="image" border="0" alt="image" src="http://zuahmed.files.wordpress.com/2011/05/image_thumb.png?w=181&#038;h=244" width="181" height="244" /></a></p>
<p>By integrating Service Bus messaging with WCF programing model, we can reuse all of the WCF goodness with Service bus messaging. For example I can secure messages while they are traveling through queues/topics by just changing the binding.</p>
<p>Next time I’ll show how to do pub/sub using the WCF programing model. </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/zuahmed.wordpress.com/341/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/zuahmed.wordpress.com/341/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/zuahmed.wordpress.com/341/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/zuahmed.wordpress.com/341/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/zuahmed.wordpress.com/341/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/zuahmed.wordpress.com/341/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/zuahmed.wordpress.com/341/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/zuahmed.wordpress.com/341/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/zuahmed.wordpress.com/341/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/zuahmed.wordpress.com/341/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/zuahmed.wordpress.com/341/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/zuahmed.wordpress.com/341/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/zuahmed.wordpress.com/341/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/zuahmed.wordpress.com/341/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zamd.net&amp;blog=13272925&amp;post=341&amp;subd=zuahmed&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://zamd.net/2011/05/18/wcf-with-service-bus-v2-queues/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7d41c3b038d67898247bff3e462c42a5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">zamd</media:title>
		</media:content>

		<media:content url="http://zuahmed.files.wordpress.com/2011/05/image_thumb.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>NuGet Package to enable SWT in WIF</title>
		<link>http://zamd.net/2011/04/27/nuget-package-to-enable-swt-in-wif/</link>
		<comments>http://zamd.net/2011/04/27/nuget-package-to-enable-swt-in-wif/#comments</comments>
		<pubDate>Wed, 27 Apr 2011 12:25:26 +0000</pubDate>
		<dc:creator>zamd</dc:creator>
				<category><![CDATA[WIF]]></category>

		<guid isPermaLink="false">https://zuahmed.wordpress.com/2011/04/27/nuget-package-to-enable-swt-in-wif/</guid>
		<description><![CDATA[Just found Daniel Cazzulino@Clarius has packaged some of my work in a reusable NuGet package. Pretty cool&#8230; http://nuget.org/List/Packages/netfx-Microsoft.IdentityModel.Swt<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zamd.net&amp;blog=13272925&amp;post=336&amp;subd=zuahmed&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><span style="line-height:115%;font-family:&quot;font-size:12pt;" lang="EN"></span>
<p>Just found <a href="http://blogs.clariusconsulting.net/">Daniel Cazzulino@Clarius</a> has packaged some of <a href="http://zamd.net/2011/02/08/using-simple-web-token-swt-with-wif/">my work</a> in a reusable NuGet package. Pretty cool&#8230;</p>
</p>
<p><a href="http://zuahmed.files.wordpress.com/2011/04/image.png"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;" title="image" border="0" alt="image" src="http://zuahmed.files.wordpress.com/2011/04/image_thumb.png?w=904&#038;h=604" width="904" height="604" /></a></p>
<p><a title="http://nuget.org/List/Packages/netfx-Microsoft.IdentityModel.Swt" href="http://nuget.org/List/Packages/netfx-Microsoft.IdentityModel.Swt">http://nuget.org/List/Packages/netfx-Microsoft.IdentityModel.Swt</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/zuahmed.wordpress.com/336/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/zuahmed.wordpress.com/336/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/zuahmed.wordpress.com/336/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/zuahmed.wordpress.com/336/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/zuahmed.wordpress.com/336/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/zuahmed.wordpress.com/336/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/zuahmed.wordpress.com/336/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/zuahmed.wordpress.com/336/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/zuahmed.wordpress.com/336/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/zuahmed.wordpress.com/336/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/zuahmed.wordpress.com/336/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/zuahmed.wordpress.com/336/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/zuahmed.wordpress.com/336/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/zuahmed.wordpress.com/336/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zamd.net&amp;blog=13272925&amp;post=336&amp;subd=zuahmed&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://zamd.net/2011/04/27/nuget-package-to-enable-swt-in-wif/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7d41c3b038d67898247bff3e462c42a5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">zamd</media:title>
		</media:content>

		<media:content url="http://zuahmed.files.wordpress.com/2011/04/image_thumb.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>Silverlight Claim-Based-Security Part-2</title>
		<link>http://zamd.net/2011/03/23/silverlight-claim-based-security-part-2/</link>
		<comments>http://zamd.net/2011/03/23/silverlight-claim-based-security-part-2/#comments</comments>
		<pubDate>Wed, 23 Mar 2011 22:40:16 +0000</pubDate>
		<dc:creator>zamd</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">https://zuahmed.wordpress.com/2011/03/23/silverlight-claim-based-security-part-2/</guid>
		<description><![CDATA[In part 1 I talked about a simple approach to combine WCF Routing service and claims-based security and I got some questions about the sample code and routing service configuration. In this post, I’ll explain some additional scenarios and would provide link to the source code. In my original post I used following very simple [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zamd.net&amp;blog=13272925&amp;post=331&amp;subd=zuahmed&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://zamd.net/2011/02/08/silverlight-claim-based-security/">part 1</a> I talked about a simple approach to combine WCF Routing service and claims-based security and I got some questions about the sample code and routing service configuration. In this post, I’ll explain some additional scenarios and would provide link to the source code. In my original post I used following very simple routing configuration where the RST (Request Security Token) message goes to the STS and everything else goes to the UserService (a business service)</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:fc35c06f-e70e-4be2-9bf6-fc5d69f83440" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#000080;color:#fff;font-family:Verdana, Tahoma, Arial, sans-serif;font-weight:bold;padding:2px 5px;">Simple Routing Configuration</div>
<div style="background:#ddd;max-height:300px;overflow:auto;">
<ol style="background:#ffffff;margin:0 0 0 2.5em;padding:0 0 0 5px;">
<li><span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">routing</span><span style="color:#0000ff;">&gt;</span></li>
<li style="background:#f3f3f3;">  <span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">filterTables</span><span style="color:#0000ff;">&gt;</span></li>
<li>    <span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">filterTable</span><span style="color:#0000ff;"> </span><span style="color:#ff0000;">name</span><span style="color:#0000ff;">=</span>&quot;<span style="color:#0000ff;">SLRouting</span>&quot;<span style="color:#0000ff;">&gt;</span></li>
<li style="background:#f3f3f3;">      <span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">add</span><span style="color:#0000ff;"> </span><span style="color:#ff0000;">endpointName</span><span style="color:#0000ff;">=</span>&quot;<span style="color:#0000ff;">stsEndpoint</span>&quot;<span style="color:#0000ff;"> </span><span style="color:#ff0000;">filterName</span><span style="color:#0000ff;">=</span>&quot;<span style="color:#0000ff;">matchRST</span>&quot;<span style="color:#0000ff;"> </span><span style="color:#ff0000;">priority</span><span style="color:#0000ff;">=</span>&quot;<span style="color:#0000ff;">5</span>&quot;<span style="color:#0000ff;">/&gt;</span></li>
<li>      <span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">add</span><span style="color:#0000ff;"> </span><span style="color:#ff0000;">endpointName</span><span style="color:#0000ff;">=</span>&quot;<span style="color:#0000ff;">serviceEndpoint</span>&quot;<span style="color:#0000ff;"> </span><span style="color:#ff0000;">filterName</span><span style="color:#0000ff;">=</span>&quot;<span style="color:#0000ff;">allMessages</span>&quot;<span style="color:#0000ff;"> </span><span style="color:#ff0000;">priority</span><span style="color:#0000ff;">=</span>&quot;<span style="color:#0000ff;">1</span>&quot;<span style="color:#0000ff;">/&gt;</span></li>
<li style="background:#f3f3f3;">    <span style="color:#0000ff;">&lt;/</span><span style="color:#a31515;">filterTable</span><span style="color:#0000ff;">&gt;</span></li>
<li>  <span style="color:#0000ff;">&lt;/</span><span style="color:#a31515;">filterTables</span><span style="color:#0000ff;">&gt;</span></li>
<li style="background:#f3f3f3;">  <span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">filters</span><span style="color:#0000ff;">&gt;</span></li>
<li>    <span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">filter</span><span style="color:#0000ff;"> </span><span style="color:#ff0000;">filterType</span><span style="color:#0000ff;">=</span>&quot;<span style="color:#0000ff;">Action</span>&quot;<span style="color:#0000ff;"> </span><span style="color:#ff0000;">filterData</span><span style="color:#0000ff;">=</span>&quot;<span style="color:#0000ff;">http://docs.oasis-open.org/ws-sx/ws-trust/200512/RST/Issue</span>&quot;<span style="color:#0000ff;"> </span><span style="color:#ff0000;">name</span><span style="color:#0000ff;">=</span>&quot;<span style="color:#0000ff;">matchRST</span>&quot;<span style="color:#0000ff;">/&gt;</span></li>
<li style="background:#f3f3f3;">    <span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">filter</span><span style="color:#0000ff;"> </span><span style="color:#ff0000;">filterType</span><span style="color:#0000ff;">=</span>&quot;<span style="color:#0000ff;">MatchAll</span>&quot;<span style="color:#0000ff;"> </span><span style="color:#ff0000;">name</span><span style="color:#0000ff;">=</span>&quot;<span style="color:#0000ff;">allMessages</span>&quot;<span style="color:#0000ff;">/&gt;</span></li>
<li>  <span style="color:#0000ff;">&lt;/</span><span style="color:#a31515;">filters</span><span style="color:#0000ff;">&gt;</span></li>
<li style="background:#f3f3f3;"><span style="color:#0000ff;">&lt;/</span><span style="color:#a31515;">routing</span><span style="color:#0000ff;">&gt;</span></li>
</ol></div>
</p></div>
</p></div>
<p>&#160;</p>
<p>The STS endpoint uses an action filter (line 4) which looks for a WS-Trust RST message and forwards it to the STS. If RST filter doesn’t match, then the routing engine goes and tries the second filter (line 5) which is a match all. So in my simple configuration all non-RST messages are simply sent to the second endpoint. Real world scenarios obviously would require more granular routing but it can easily be enabled using the same pattern. WCF routing configuration is quite powerful and supports composite (AND, OR etc) and custom filters using which you can model any routing logic as you per your needs. </p>
<p>Another interesting scenarios is to support multiple authentication schemes on the STS – windows authentication for the intranet while userName password for the internet.&#160; </p>
<p>To enables this I have exposed the STS functionality using two different endpoints supporting both username/password based authentication as well as windows authentication.&#160; </p>
<pre><font color="#0000ff">/ActiveSTS/issue.svc/IWSTrust13<br />/ActiveSTS/windowsintegrated/issue.svc/IWSTrust13</font><br /></pre>
<p>Because windows authentication is point-point so I relied on impersonation to flow the end-user identity to the STS via the Router. The windows authentication flow looks like this:</p>
<p><a href="http://zuahmed.files.wordpress.com/2011/03/image.png"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;" title="image" border="0" alt="image" src="http://zuahmed.files.wordpress.com/2011/03/image_thumb.png?w=865&#038;h=162" width="865" height="162" /></a></p>
<p>For the windows-integrated endpoint,&#160; router is configured to impersonate the client and the outgoing messages is sent under this impersonated context which enables the STS to authenticate the original user using windows authentication. </p>
<pre><font face="Consolas"><span><font color="#0000ff"><font>&#160;&#160;&#160;&#160;&#160; &lt;</font></font></span><font><span><font color="#a31515">serviceBehaviors</font></span></font></font><font><font face="Consolas"><font color="#0000ff"><span>&gt;</span><br /><span>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;</span></font><span><font color="#a31515">behavior</font></span></font><font face="Consolas"><font color="#0000ff"><span>&gt;</span><br /><span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;</span></font><span><font color="#a31515">serviceAuthorization</font></span><span><font color="#0000ff">&#160;</font></span><span><font color="#ff0000">impersonateCallerForAllOperations</font></span><span><font color="#0000ff">=</font></span><font color="#000000">&quot;</font><span><font color="#0000ff">true</font></span><font color="#000000">&quot;</font></font><font face="Consolas"><font color="#0000ff"><span>/&gt;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><br /><span>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;/</span></font><span><font color="#a31515">behavior</font></span></font></font><font face="Consolas"><font><font color="#0000ff"><span>&gt;</span><br /><span>&#160;&#160;&#160;&#160;&#160; &lt;/</span></font><span><font color="#a31515">serviceBehaviors</font></span></font><span><font color="#0000ff">&gt;</font></span></font></pre>
<p>When deploying in IIS, both the router endpoint and the STS endpoint needs to be configured for windows-authentication and I have accomplished it by creating a sub-folder (windowsintegrated) under both virtual directories and configuring this for windows-authentication. The main/parent virtual directories still has anonymous access enabled for the userName authentication to work. Note with userName authentication,&#160; the credentials goes inside the SOAP message. My VS setup look like this:</p>
<p><a href="http://zuahmed.files.wordpress.com/2011/03/image1.png"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;margin:5px;" title="image" border="0" alt="image" src="http://zuahmed.files.wordpress.com/2011/03/image_thumb1.png?w=378&#038;h=633" width="378" height="633" /></a></p>
<p>The web.config(s) under the ‘windowsintegrated’ folder overrides the settings to enable windows-authentication. For example, in the STS project the root web.config defines both service endpoints along with a default binding which is configured for UserName authentication over HTTP.</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:07757c91-2e13-4f96-a3fd-17e5e2666f94" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#000080;color:#fff;font-family:Verdana, Tahoma, Arial, sans-serif;font-weight:bold;padding:2px 5px;">Root web.config: STS</div>
<div style="background:#ddd;max-height:300px;overflow:auto;">
<ol style="background:#ffffff;margin:0 0 0 2.5em;padding:0 0 0 5px;">
<li><span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">system.serviceModel</span><span style="color:#0000ff;">&gt;</span></li>
<li style="background:#f3f3f3;">  <span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">serviceHostingEnvironment</span><span style="color:#0000ff;">&gt;</span></li>
<li>    <span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">serviceActivations</span><span style="color:#0000ff;">&gt;</span></li>
<li style="background:#f3f3f3;">      <span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">add</span><span style="color:#0000ff;"> </span><span style="color:#ff0000;">relativeAddress</span><span style="color:#0000ff;">=</span>&quot;<span style="color:#0000ff;">~/issue.svc</span>&quot;<span style="color:#0000ff;"> </span><span style="color:#ff0000;">service</span><span style="color:#0000ff;">=</span>&quot;<span style="color:#0000ff;">CustomSecurityTokenServiceConfiguration</span>&quot;<span style="color:#0000ff;"> </span></li>
<li>           <span style="color:#0000ff;"></span><span style="color:#ff0000;">factory</span><span style="color:#0000ff;">=</span>&quot;<span style="color:#0000ff;">Microsoft.IdentityModel.Protocols.WSTrust.WSTrustServiceHostFactory</span>&quot;<span style="color:#0000ff;">/&gt;</span></li>
<li style="background:#f3f3f3;">      <span style="color:#0000ff;"></span></li>
<li>      <span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">add</span><span style="color:#0000ff;"> </span><span style="color:#ff0000;">relativeAddress</span><span style="color:#0000ff;">=</span>&quot;<span style="color:#0000ff;">~/windowsintegrated/issue.svc</span>&quot;<span style="color:#0000ff;"> </span><span style="color:#ff0000;">service</span><span style="color:#0000ff;">=</span>&quot;<span style="color:#0000ff;">CustomSecurityTokenServiceConfiguration</span>&quot;<span style="color:#0000ff;"> </span></li>
<li style="background:#f3f3f3;">           <span style="color:#0000ff;"></span><span style="color:#ff0000;">factory</span><span style="color:#0000ff;">=</span>&quot;<span style="color:#0000ff;">Microsoft.IdentityModel.Protocols.WSTrust.WSTrustServiceHostFactory</span>&quot;<span style="color:#0000ff;">/&gt;</span></li>
<li>    <span style="color:#0000ff;">&lt;/</span><span style="color:#a31515;">serviceActivations</span><span style="color:#0000ff;">&gt;</span></li>
<li style="background:#f3f3f3;">  <span style="color:#0000ff;">&lt;/</span><span style="color:#a31515;">serviceHostingEnvironment</span><span style="color:#0000ff;">&gt;</span></li>
<li>&nbsp;</li>
<li style="background:#f3f3f3;">  <span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">services</span><span style="color:#0000ff;">&gt;</span></li>
<li>    <span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">service</span><span style="color:#0000ff;"> </span><span style="color:#ff0000;">name</span><span style="color:#0000ff;">=</span>&quot;<span style="color:#0000ff;">Microsoft.IdentityModel.Protocols.WSTrust.WSTrustServiceContract</span>&quot;<span style="color:#0000ff;">&gt;</span></li>
<li style="background:#f3f3f3;">      <span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">endpoint</span><span style="color:#0000ff;"> </span><span style="color:#ff0000;">address</span><span style="color:#0000ff;">=</span>&quot;<span style="color:#0000ff;">IWSTrust13</span>&quot;</li>
<li>                <span style="color:#0000ff;"></span><span style="color:#ff0000;">binding</span><span style="color:#0000ff;">=</span>&quot;<span style="color:#0000ff;">customBinding</span>&quot;</li>
<li style="background:#f3f3f3;">                <span style="color:#0000ff;"></span><span style="color:#ff0000;">contract</span><span style="color:#0000ff;">=</span>&quot;<span style="color:#0000ff;">Microsoft.IdentityModel.Protocols.WSTrust.IWSTrust13SyncContract</span>&quot;<span style="color:#0000ff;">/&gt;</span></li>
<li>    <span style="color:#0000ff;">&lt;/</span><span style="color:#a31515;">service</span><span style="color:#0000ff;">&gt;</span></li>
<li style="background:#f3f3f3;">  <span style="color:#0000ff;">&lt;/</span><span style="color:#a31515;">services</span><span style="color:#0000ff;">&gt;</span></li>
<li>&nbsp;</li>
<li style="background:#f3f3f3;">  <span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">bindings</span><span style="color:#0000ff;">&gt;</span></li>
<li>    <span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">customBinding</span><span style="color:#0000ff;">&gt;</span></li>
<li style="background:#f3f3f3;">      <span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">binding</span><span style="color:#0000ff;">&gt;</span></li>
<li>        <span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">security</span><span style="color:#0000ff;"> </span><span style="color:#ff0000;">authenticationMode</span><span style="color:#0000ff;">=</span>&quot;<span style="color:#0000ff;">UserNameOverTransport</span>&quot;<span style="color:#0000ff;"> </span><span style="color:#ff0000;">allowInsecureTransport</span><span style="color:#0000ff;">=</span>&quot;<span style="color:#0000ff;">true</span>&quot;<span style="color:#0000ff;">/&gt;</span></li>
<li style="background:#f3f3f3;">        <span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">httpTransport</span><span style="color:#0000ff;">/&gt;</span></li>
<li>      <span style="color:#0000ff;">&lt;/</span><span style="color:#a31515;">binding</span><span style="color:#0000ff;">&gt;</span></li>
<li style="background:#f3f3f3;">    <span style="color:#0000ff;">&lt;/</span><span style="color:#a31515;">customBinding</span><span style="color:#0000ff;">&gt;</span></li>
<li>  <span style="color:#0000ff;">&lt;/</span><span style="color:#a31515;">bindings</span><span style="color:#0000ff;">&gt;</span></li>
<li style="background:#f3f3f3;"><span style="color:#0000ff;">&lt;/</span><span style="color:#a31515;">system.serviceModel</span><span style="color:#0000ff;">&gt;</span></li>
</ol>
</div>
</div>
</div>
<p>&#160;</p>
<p>The web.config in the ‘windowsintegrated’ changes the default binding to enable windows authentication. I’m using the ‘Simplified WCF Configuration’ here so the final config is very clean as a result. </p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:d3b377ff-fa71-4e8a-9a64-38be0d6476b7" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#000080;color:#fff;font-family:Verdana, Tahoma, Arial, sans-serif;font-weight:bold;padding:2px 5px;">Overriden default CustomBindin</div>
<div style="background:#ddd;max-height:300px;overflow:auto;">
<ol style="background:#ffffff;margin:0 0 0 2.5em;padding:0 0 0 5px;">
<li><span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">system.serviceModel</span><span style="color:#0000ff;">&gt;</span></li>
<li style="background:#f3f3f3;">  <span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">services</span><span style="color:#0000ff;">/&gt;</span></li>
<li>  <span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">bindings</span><span style="color:#0000ff;">&gt;</span></li>
<li style="background:#f3f3f3;">    <span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">customBinding</span><span style="color:#0000ff;">&gt;</span></li>
<li>      <span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">binding</span><span style="color:#0000ff;">&gt;</span></li>
<li style="background:#f3f3f3;">        <span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">httpTransport</span><span style="color:#0000ff;"> </span><span style="color:#ff0000;">authenticationScheme</span><span style="color:#0000ff;">=</span>&quot;<span style="color:#0000ff;">Negotiate</span>&quot;<span style="color:#0000ff;">/&gt;</span></li>
<li>      <span style="color:#0000ff;">&lt;/</span><span style="color:#a31515;">binding</span><span style="color:#0000ff;">&gt;</span></li>
<li style="background:#f3f3f3;">    <span style="color:#0000ff;">&lt;/</span><span style="color:#a31515;">customBinding</span><span style="color:#0000ff;">&gt;</span></li>
<li>  <span style="color:#0000ff;">&lt;/</span><span style="color:#a31515;">bindings</span><span style="color:#0000ff;">&gt;</span></li>
<li style="background:#f3f3f3;"><span style="color:#0000ff;">&lt;/</span><span style="color:#a31515;">system.serviceModel</span><span style="color:#0000ff;">&gt;</span></li>
</ol>
</div>
</div>
</div>
<p>Similar technique is used on the WebSite/Router where I pick different STS endpoint/binding depending on the chosen router endpoint. The root web.config goes to the anonymous STS endpoint (line 2 &amp; 3) and authentication is done using the message credentials (userName). </p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:ec28efc2-5f07-4833-8009-1f9fd4f59522" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#000080;color:#fff;font-family:Verdana, Tahoma, Arial, sans-serif;font-weight:bold;padding:2px 5px;">Root web.config WebSite</div>
<div style="background:#ddd;max-height:300px;overflow:auto;">
<ol style="background:#ffffff;margin:0 0 0 2.5em;padding:0 0 0 5px;">
<li><span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">client</span><span style="color:#0000ff;">&gt;</span></li>
<li style="background:#f3f3f3;">  <span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">endpoint</span><span style="color:#0000ff;"> </span><span style="color:#ff0000;">name</span><span style="color:#0000ff;">=</span>&quot;<span style="color:#0000ff;">stsEndpoint</span>&quot;<span style="color:#0000ff;"> </span><span style="color:#ff0000;">address</span><span style="color:#0000ff;">=</span>&quot;<span style="color:#0000ff;">http://localhost/ActiveSTS/issue.svc/IWSTrust13</span>&quot;</li>
<li>            <span style="color:#0000ff;"></span><span style="color:#ff0000;">binding</span><span style="color:#0000ff;">=</span>&quot;<span style="color:#0000ff;">customBinding</span>&quot;<span style="color:#0000ff;"> </span><span style="color:#ff0000;">bindingConfiguration</span><span style="color:#0000ff;">=</span>&quot;<span style="color:#0000ff;">outBinding</span>&quot;<span style="color:#0000ff;"> </span><span style="color:#ff0000;">contract</span><span style="color:#0000ff;">=</span>&quot;<span style="color:#0000ff;">*</span>&quot;<span style="color:#0000ff;">&gt;</span></li>
<li style="background:#f3f3f3;">  <span style="color:#0000ff;">&lt;/</span><span style="color:#a31515;">endpoint</span><span style="color:#0000ff;">&gt;</span></li>
<li>&nbsp;</li>
<li style="background:#f3f3f3;">  <span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">endpoint</span><span style="color:#0000ff;"> </span><span style="color:#ff0000;">name</span><span style="color:#0000ff;">=</span>&quot;<span style="color:#0000ff;">serviceEndpoint</span>&quot;<span style="color:#0000ff;"> </span><span style="color:#ff0000;">address</span><span style="color:#0000ff;">=</span>&quot;<span style="color:#0000ff;">http://localhost/UserService/Service1.svc</span>&quot;</li>
<li>      <span style="color:#0000ff;"></span><span style="color:#ff0000;">binding</span><span style="color:#0000ff;">=</span>&quot;<span style="color:#0000ff;">customBinding</span>&quot;<span style="color:#0000ff;"> </span><span style="color:#ff0000;">bindingConfiguration</span><span style="color:#0000ff;">=</span>&quot;<span style="color:#0000ff;">outBinding</span>&quot;<span style="color:#0000ff;"> </span><span style="color:#ff0000;">contract</span><span style="color:#0000ff;">=</span>&quot;<span style="color:#0000ff;">*</span>&quot;<span style="color:#0000ff;">&gt;</span></li>
<li style="background:#f3f3f3;">&nbsp;</li>
<li>  <span style="color:#0000ff;">&lt;/</span><span style="color:#a31515;">endpoint</span><span style="color:#0000ff;">&gt;</span></li>
<li style="background:#f3f3f3;">&nbsp;</li>
<li><span style="color:#0000ff;">&lt;/</span><span style="color:#a31515;">client</span><span style="color:#0000ff;">&gt;</span></li>
</ol>
</div>
</div>
</div>
<p>&#160;</p>
<p>Web.config in the ‘windowsintegrated’ changes the default STS endpoint/binding to match the windows authentication requirements and also enables impersonation to flow windows identity to the STS. </p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:f3db0aa1-e617-45fd-9c5f-f64dfad8e817" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#000080;color:#fff;font-family:Verdana, Tahoma, Arial, sans-serif;font-weight:bold;padding:2px 5px;">Router config for windows auth</div>
<div style="background:#ddd;max-height:300px;overflow:auto;">
<ol style="background:#ffffff;margin:0 0 0 2.5em;padding:0 0 0 5px;">
<li><span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">system.serviceModel</span><span style="color:#0000ff;">&gt;</span></li>
<li style="background:#f3f3f3;">  <span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">services</span><span style="color:#0000ff;">/&gt;</span></li>
<li>  <span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">client</span><span style="color:#0000ff;">&gt;</span></li>
<li style="background:#f3f3f3;">    <span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">remove</span><span style="color:#0000ff;"> </span><span style="color:#ff0000;">name</span><span style="color:#0000ff;">=</span>&quot;<span style="color:#0000ff;">stsEndpoint</span>&quot;<span style="color:#0000ff;">/&gt;</span></li>
<li>    <span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">endpoint</span><span style="color:#0000ff;"> </span><span style="color:#ff0000;">name</span><span style="color:#0000ff;">=</span>&quot;<span style="color:#0000ff;">stsEndpoint</span>&quot;<span style="color:#0000ff;"> </span><span style="color:#ff0000;">address</span><span style="color:#0000ff;">=</span>&quot;<span style="color:#0000ff;">http://localhost/ActiveSTS/windowsintegrated/issue.svc/IWSTrust13</span>&quot;</li>
<li style="background:#f3f3f3;">              <span style="color:#0000ff;"></span><span style="color:#ff0000;">binding</span><span style="color:#0000ff;">=</span>&quot;<span style="color:#0000ff;">customBinding</span>&quot;<span style="color:#0000ff;"> </span><span style="color:#ff0000;">bindingConfiguration</span><span style="color:#0000ff;">=</span>&quot;<span style="color:#0000ff;">outBinding</span>&quot;<span style="color:#0000ff;"> </span><span style="color:#ff0000;">contract</span><span style="color:#0000ff;">=</span>&quot;<span style="color:#0000ff;">*</span>&quot;<span style="color:#0000ff;">/&gt;</span></li>
<li>  <span style="color:#0000ff;">&lt;/</span><span style="color:#a31515;">client</span><span style="color:#0000ff;">&gt;</span></li>
<li style="background:#f3f3f3;">  <span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">bindings</span><span style="color:#0000ff;">&gt;</span></li>
<li>    <span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">customBinding</span><span style="color:#0000ff;">&gt;</span></li>
<li style="background:#f3f3f3;">      <span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">binding</span><span style="color:#0000ff;"> </span><span style="color:#ff0000;">name</span><span style="color:#0000ff;">=</span>&quot;<span style="color:#0000ff;">inBinding</span>&quot;<span style="color:#0000ff;">&gt;</span></li>
<li>        <span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">httpsTransport</span><span style="color:#0000ff;"> </span><span style="color:#ff0000;">authenticationScheme</span><span style="color:#0000ff;">=</span>&quot;<span style="color:#0000ff;">Negotiate</span>&quot;<span style="color:#0000ff;">/&gt;</span></li>
<li style="background:#f3f3f3;">      <span style="color:#0000ff;">&lt;/</span><span style="color:#a31515;">binding</span><span style="color:#0000ff;">&gt;</span></li>
<li>&nbsp;</li>
<li style="background:#f3f3f3;">      <span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">binding</span><span style="color:#0000ff;"> </span><span style="color:#ff0000;">name</span><span style="color:#0000ff;">=</span>&quot;<span style="color:#0000ff;">outBinding</span>&quot;<span style="color:#0000ff;">&gt;</span></li>
<li>        <span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">httpTransport</span><span style="color:#0000ff;"> </span><span style="color:#ff0000;">authenticationScheme</span><span style="color:#0000ff;">=</span>&quot;<span style="color:#0000ff;">Negotiate</span>&quot;<span style="color:#0000ff;">/&gt;</span></li>
<li style="background:#f3f3f3;">      <span style="color:#0000ff;">&lt;/</span><span style="color:#a31515;">binding</span><span style="color:#0000ff;">&gt;</span></li>
<li>&nbsp;</li>
<li style="background:#f3f3f3;">    <span style="color:#0000ff;">&lt;/</span><span style="color:#a31515;">customBinding</span><span style="color:#0000ff;">&gt;</span></li>
<li>  <span style="color:#0000ff;">&lt;/</span><span style="color:#a31515;">bindings</span><span style="color:#0000ff;">&gt;</span></li>
<li style="background:#f3f3f3;">  <span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">behaviors</span><span style="color:#0000ff;">&gt;</span></li>
<li>    <span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">serviceBehaviors</span><span style="color:#0000ff;">&gt;</span></li>
<li style="background:#f3f3f3;">      <span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">behavior</span><span style="color:#0000ff;">&gt;</span></li>
<li>        <span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">serviceAuthorization</span><span style="color:#0000ff;"> </span><span style="color:#ff0000;">impersonateCallerForAllOperations</span><span style="color:#0000ff;">=</span>&quot;<span style="color:#0000ff;">true</span>&quot;<span style="color:#0000ff;">/&gt;          </span></li>
<li style="background:#f3f3f3;">      <span style="color:#0000ff;">&lt;/</span><span style="color:#a31515;">behavior</span><span style="color:#0000ff;">&gt;</span></li>
<li>    <span style="color:#0000ff;">&lt;/</span><span style="color:#a31515;">serviceBehaviors</span><span style="color:#0000ff;">&gt;</span></li>
<li style="background:#f3f3f3;">  <span style="color:#0000ff;">&lt;/</span><span style="color:#a31515;">behaviors</span><span style="color:#0000ff;">&gt;</span></li>
<li><span style="color:#0000ff;">&lt;/</span><span style="color:#a31515;">system.serviceModel</span><span style="color:#0000ff;">&gt;</span></li>
<li style="background:#f3f3f3;"><span style="color:#0000ff;"></span></li>
</ol>
</div>
</div>
</div>
<p>&#160;</p>
<p>Finally make sure to enable integrated windows authentication on the ‘windowsintegrated’ directory in IIS before you run the samples. </p>
<p><a href="http://zuahmed.files.wordpress.com/2011/03/image2.png"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;margin:5px;" title="image" border="0" alt="image" src="http://zuahmed.files.wordpress.com/2011/03/image_thumb2.png?w=807&#038;h=376" width="807" height="376" /></a></p>
<p>enjoy… </p>
<p>Download: <a href="http://cid-724b6fcd63a8c1ac.office.live.com/self.aspx/zamd.net/SLClaimsBasedSecurity.zip">Sample solution</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/zuahmed.wordpress.com/331/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/zuahmed.wordpress.com/331/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/zuahmed.wordpress.com/331/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/zuahmed.wordpress.com/331/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/zuahmed.wordpress.com/331/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/zuahmed.wordpress.com/331/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/zuahmed.wordpress.com/331/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/zuahmed.wordpress.com/331/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/zuahmed.wordpress.com/331/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/zuahmed.wordpress.com/331/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/zuahmed.wordpress.com/331/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/zuahmed.wordpress.com/331/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/zuahmed.wordpress.com/331/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/zuahmed.wordpress.com/331/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zamd.net&amp;blog=13272925&amp;post=331&amp;subd=zuahmed&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://zamd.net/2011/03/23/silverlight-claim-based-security-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7d41c3b038d67898247bff3e462c42a5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">zamd</media:title>
		</media:content>

		<media:content url="http://zuahmed.files.wordpress.com/2011/03/image_thumb.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://zuahmed.files.wordpress.com/2011/03/image_thumb1.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://zuahmed.files.wordpress.com/2011/03/image_thumb2.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>Using Simple Web Token (SWT) with WIF</title>
		<link>http://zamd.net/2011/02/08/using-simple-web-token-swt-with-wif/</link>
		<comments>http://zamd.net/2011/02/08/using-simple-web-token-swt-with-wif/#comments</comments>
		<pubDate>Tue, 08 Feb 2011 19:46:00 +0000</pubDate>
		<dc:creator>zamd</dc:creator>
				<category><![CDATA[WIF]]></category>
		<category><![CDATA[Windows Azure AppFabric]]></category>

		<guid isPermaLink="false">https://zuahmed.wordpress.com/2011/02/08/using-simple-web-token-swt-with-wif/</guid>
		<description><![CDATA[SAML 1.1/SAML 2.0 is the default token format when using ACS as the authentication service for your website. In this model, your website talks to ACS using WS-Federation protocol and what it normally gets back is a Saml token. This scenarios is fairly straight-forward as WIF natively supports WS-Federation protocol &#38; SAML1.1/SAML 2.0 token formats. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zamd.net&amp;blog=13272925&amp;post=324&amp;subd=zuahmed&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>SAML 1.1/SAML 2.0 is the default token format when using ACS as the authentication service for your website. In this model, your website talks to ACS using WS-Federation protocol and what it normally gets back is a Saml token. This scenarios is fairly straight-forward as WIF natively supports WS-Federation protocol &amp; SAML1.1/SAML 2.0 token formats. </p>
<p>There are cases where you might want to return a Simple Web Tokens (SWT) after a successful authentication. For example, you might want to use this same SWT (available as a bootstrap token) to call other downstream REST/OData services as depicted in the following diagram. </p>
<p><a href="http://zuahmed.files.wordpress.com/2011/02/image9.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;margin:5px;" title="image" border="0" alt="image" src="http://zuahmed.files.wordpress.com/2011/02/image_thumb9.png?w=1024&#038;h=606" width="1024" height="606" /></a></p>
<p>ACS fully supports returning an SWT token after a successfully WS-Fed authentication but WIF currently doesn’t support SWT tokens. You would have to write a custom Security Token Handler for WIF to process SWT tokens coming back to your website. I have created some extensions which enables this and other OAuth WRAP related scenarios. Feel free to <a href="http://cid-724b6fcd63a8c1ac.office.live.com/self.aspx/zamd.net/WIFBasedOAuthWrapIssuer.zip">download the code</a> from my SkyDrive.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/zuahmed.wordpress.com/324/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/zuahmed.wordpress.com/324/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/zuahmed.wordpress.com/324/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/zuahmed.wordpress.com/324/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/zuahmed.wordpress.com/324/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/zuahmed.wordpress.com/324/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/zuahmed.wordpress.com/324/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/zuahmed.wordpress.com/324/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/zuahmed.wordpress.com/324/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/zuahmed.wordpress.com/324/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/zuahmed.wordpress.com/324/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/zuahmed.wordpress.com/324/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/zuahmed.wordpress.com/324/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/zuahmed.wordpress.com/324/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zamd.net&amp;blog=13272925&amp;post=324&amp;subd=zuahmed&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://zamd.net/2011/02/08/using-simple-web-token-swt-with-wif/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7d41c3b038d67898247bff3e462c42a5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">zamd</media:title>
		</media:content>

		<media:content url="http://zuahmed.files.wordpress.com/2011/02/image_thumb9.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>Silverlight Claim-Based-Security</title>
		<link>http://zamd.net/2011/02/08/silverlight-claim-based-security/</link>
		<comments>http://zamd.net/2011/02/08/silverlight-claim-based-security/#comments</comments>
		<pubDate>Tue, 08 Feb 2011 00:18:50 +0000</pubDate>
		<dc:creator>zamd</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[WCF]]></category>
		<category><![CDATA[WIF]]></category>

		<guid isPermaLink="false">https://zuahmed.wordpress.com/2011/02/08/silverlight-claim-based-security/</guid>
		<description><![CDATA[This would hopefully be a multi-part series showing some tricks to enable claims-based-security in Silverlight 4.0. Silverlight 5.0 would have a much better story around claim-based-security as mentioned here. In this first post, I’ll give you a high level overview of the solution. The main idea is to use the ‘WCF Routing Service’ in the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zamd.net&amp;blog=13272925&amp;post=321&amp;subd=zuahmed&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This would hopefully be a multi-part series showing some tricks to enable claims-based-security in Silverlight 4.0. Silverlight 5.0 would have a much better story around claim-based-security as mentioned <a href="http://www.microsoft.com/silverlight/future/">here</a>. </p>
<p>In this first post, I’ll give you a high level overview of the solution. The main idea is to use the ‘<a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.routing.routingservice.aspx">WCF Routing Service’</a> in the DMZ to route both token issuance requests &amp; business requests to the actual backend services.</p>
<p><strong>1. </strong>Routing Service looks for a token issuing request and forwards it to the STS where the actual authentication is performed. After the successful authentication, STS issues a SAML token which goes back to Silverlight client via the routing service. Routing Service also terminates the SSL and backend is called using straight HTTP. This model offers strong security on the internet while keeping the internal deployment simpler &amp; efficient. This model also resembles with the standard SSL offloading setup where a hardware load-balancer is used to terminate the SSL. </p>
<h2><u>1: Token Issuance Path</u></h2>
<p><a href="http://zuahmed.files.wordpress.com/2011/02/image7.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;margin:5px;" title="image" border="0" alt="image" src="http://zuahmed.files.wordpress.com/2011/02/image_thumb7.png?w=1028&#038;h=242" width="1028" height="242" /></a></p>
<h5><u></u></h5>
<p><strong>2.</strong> Once the Silverlight client got a SAML token, it can attach it to all subsequent message sent to business service(s). Routing Services forwards al the business messages (messages which doesn’t match the token issuance filter) to the actual backend services again doing the protocol transitioning from HTTPS to HTTP. Please note, here you can use the rich filtering mechanism provided by the Routing services to decide which messages should to which services. I used a very simple MatchAll filter which forwards all the non-token-issuance messages to the business service.</p>
<h2><u>2: Web Service Call Containing a SAML Token</u></h2>
<p><a href="http://zuahmed.files.wordpress.com/2011/02/image8.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;margin:5px;" title="image" border="0" alt="image" src="http://zuahmed.files.wordpress.com/2011/02/image_thumb8.png?w=1028&#038;h=251" width="1028" height="251" /></a></p>
<p>To implement the 1st part of solution I have used the WSTrustClient class &amp; the associated bindings from the <a href="http://www.microsoft.com/downloads/en/details.aspx?FamilyID=c3e315fa-94e2-4028-99cb-904369f177c0">identity training kit</a>.</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:48d7aab9-b557-4be9-b746-f5085c517abf" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background-color:#ffffff;max-height:300px;overflow:auto;white-space:nowrap;padding:2px 5px;"><span style="color:#0000ff;">var</span> vm = <span style="color:#0000ff;">this</span>.DataContext <span style="color:#0000ff;">as</span> <span style="color:#2b91af;">MainPageViewModel</span>;</p>
<p> <span style="color:#0000ff;">var</span> stsBinding = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">WSTrustBindingUsernameMixed</span>();</p>
<p> <span style="color:#0000ff;">var</span> stsCreds = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">UsernameCredentials</span>(vm.UserId, vm.Password);<br /> <span style="color:#0000ff;">var</span> client = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">WSTrustClient</span>(<br />     stsBinding,<br />     <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">EndpointAddress</span>(vm.SelectedEndpoint),<br />     stsCreds);</p>
<p> <span style="color:#0000ff;">var</span> rst = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">RequestSecurityToken</span>(<span style="color:#2b91af;">WSTrust13Constants</span>.<span style="color:#2b91af;">KeyTypes</span>.Bearer);<br /> rst.AppliesTo = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">EndpointAddress</span>(vm.AppliesTo);</p>
<p> client.IssueCompleted += <span style="color:#0000ff;">new</span> System.<span style="color:#2b91af;">EventHandler</span>&lt;<span style="color:#2b91af;">IssueCompletedEventArgs</span>&gt;(client_IssueCompleted);<br /> client.IssueAsync(rst);</div>
</p>
</div>
</div>
<p>For the 2nd part I have implemented a message inspector along with an extension method which makes it super easy to attach the SAML with outgoing messages. </p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:6de907f2-3711-418c-99c0-41262b248b0a" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background-color:#ffffff;max-height:300px;overflow:auto;white-space:nowrap;padding:2px 5px;"><span style="color:#0000ff;">var</span> vm = <span style="color:#0000ff;">this</span>.DataContext <span style="color:#0000ff;">as</span> <span style="color:#2b91af;">MainPageViewModel</span>;<br /> <span style="color:#0000ff;">var</span> client = <span style="color:#0000ff;">new</span> ServiceReference1.<span style="color:#2b91af;">Service1Client</span>();</p>
<p> client.AttachToken(vm.SecurityToken.RawToken);</p>
<p> client.GetDataCompleted += <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">EventHandler</span>&lt;ServiceReference1.<span style="color:#2b91af;">GetDataCompletedEventArgs</span>&gt;(client_GetDataCompleted);<br /> client.GetDataAsync(32);</div>
</p>
</div>
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/zuahmed.wordpress.com/321/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/zuahmed.wordpress.com/321/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/zuahmed.wordpress.com/321/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/zuahmed.wordpress.com/321/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/zuahmed.wordpress.com/321/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/zuahmed.wordpress.com/321/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/zuahmed.wordpress.com/321/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/zuahmed.wordpress.com/321/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/zuahmed.wordpress.com/321/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/zuahmed.wordpress.com/321/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/zuahmed.wordpress.com/321/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/zuahmed.wordpress.com/321/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/zuahmed.wordpress.com/321/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/zuahmed.wordpress.com/321/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zamd.net&amp;blog=13272925&amp;post=321&amp;subd=zuahmed&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://zamd.net/2011/02/08/silverlight-claim-based-security/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7d41c3b038d67898247bff3e462c42a5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">zamd</media:title>
		</media:content>

		<media:content url="http://zuahmed.files.wordpress.com/2011/02/image_thumb7.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://zuahmed.files.wordpress.com/2011/02/image_thumb8.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>Securing WF 4 Workflow Services</title>
		<link>http://zamd.net/2011/02/03/securing-wf-4-workflow-services/</link>
		<comments>http://zamd.net/2011/02/03/securing-wf-4-workflow-services/#comments</comments>
		<pubDate>Thu, 03 Feb 2011 19:45:23 +0000</pubDate>
		<dc:creator>zamd</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">https://zuahmed.wordpress.com/2011/02/03/securing-wf-4-workflow-services/</guid>
		<description><![CDATA[If you interested in an in-depth understanding of workflow services along with various security options. Then check out my latest MSDN magazine article. http://msdn.microsoft.com/en-gb/magazine/gg598919.aspx Associated Source code<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zamd.net&amp;blog=13272925&amp;post=316&amp;subd=zuahmed&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>If you interested in an in-depth understanding of workflow services along with various security options. Then check out my latest <a href="http://msdn.microsoft.com/en-gb/magazine/gg598919.aspx">MSDN magazine</a> article.</p>
<p><a title="http://msdn.microsoft.com/en-gb/magazine/gg598919.aspx" href="http://msdn.microsoft.com/en-gb/magazine/gg598919.aspx">http://msdn.microsoft.com/en-gb/magazine/gg598919.aspx</a></p>
<p>Associated <a href="http://code.msdn.microsoft.com/mag201102Workflow/Release/ProjectReleases.aspx?ReleaseId=5386">Source code</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/zuahmed.wordpress.com/316/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/zuahmed.wordpress.com/316/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/zuahmed.wordpress.com/316/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/zuahmed.wordpress.com/316/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/zuahmed.wordpress.com/316/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/zuahmed.wordpress.com/316/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/zuahmed.wordpress.com/316/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/zuahmed.wordpress.com/316/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/zuahmed.wordpress.com/316/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/zuahmed.wordpress.com/316/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/zuahmed.wordpress.com/316/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/zuahmed.wordpress.com/316/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/zuahmed.wordpress.com/316/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/zuahmed.wordpress.com/316/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zamd.net&amp;blog=13272925&amp;post=316&amp;subd=zuahmed&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://zamd.net/2011/02/03/securing-wf-4-workflow-services/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7d41c3b038d67898247bff3e462c42a5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">zamd</media:title>
		</media:content>
	</item>
	</channel>
</rss>
