<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-4918396109946207501</id><updated>2012-01-13T22:44:53.375+03:00</updated><category term='Claims'/><category term='interop'/><category term='Microsoft'/><category term='.NET Service Bus'/><category term='WIF'/><category term='REST'/><category term='Windows Server AppFabric'/><category term='Web Services'/><category term='BizTalk'/><category term='WF 4.0'/><category term='MSMQ'/><category term='VS 2010'/><category term='MVP'/><category term='Oracle Client'/><category term='Workflow'/><category term='Parallel Programming'/><category term='SharePoint 2010'/><category term='PIA'/><category term='PDC 2009'/><category term='Large Messages'/><category term='Azure'/><category term='TechEd'/><category term='Concurrency'/><category term='Azure AppFabric'/><category term='SOAP'/><category term='C#'/><category term='GDC 09'/><category term='Microsoft Open Doors'/><category term='Devlifestyle'/><category term='VSTS'/><category term='Ajax 4.0'/><category term='One Click Deployment'/><category term='WCF'/><category term='.NET 4.0'/><category term='ROCS'/><category term='SQL Azure'/><category term='CLR4'/><category term='SQL Server 2008 R2'/><category term='SSL'/><category term='MicrosoftFeed'/><category term='ASPNET'/><category term='Windows 7 Sensor and Location Platform'/><category term='.NET'/><category term='C# 4.0'/><category term='Workflow Services'/><title type='text'>The Dot Net Hub</title><subtitle type='html'>A definition of Hub is: "a hub is the central part of a wheel where the spokes come together." well in this case, .NET is the hub and all related technologies are the spokes wheeling around!</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://thedotnethub.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://thedotnethub.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>mohamad halabi</name><uri>http://www.blogger.com/profile/10259946099831243955</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>59</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4918396109946207501.post-2537780920498584831</id><published>2012-01-13T22:44:00.000+03:00</published><updated>2012-01-13T22:44:53.402+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='REST'/><category scheme='http://www.blogger.com/atom/ns#' term='WCF'/><title type='text'>Creating a SOAP/REST – based WCF Service with Custom Binding/Behaviors</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;br /&gt;&lt;div class="MsoNoSpacing"&gt;&lt;b&gt;&lt;u&gt;Introduction&lt;o:p&gt;&lt;/o:p&gt;&lt;/u&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;Ok, basically the title says it all. This post shows a WCF service with a method exposed both as a SOAP-based and REST-based endpoint. For the SOAP-based endpoint I found that there is no binding that satisfy my needs (yep, I am picky!) so I will create a custom binding – explaining what are custom bindings and what is the Channel layer in general. &lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;Also In order to enable logging operations, I will create two custom behaviors – again explaining what are custom behaviors and what is the ServiceModel layer in general.&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;The code can be downloaded from here: &lt;a href="http://www.devlifestyle.net/media/p/1177/download.aspx"&gt;http://www.devlifestyle.net/media/p/1177/download.aspx&lt;/a&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;So let’s start with the basics. I have an IIS 7 (you can also go with IIS 6 – no Net-based bindings here) hosted WCF service which exposes a single operation. My simple target is to expose this operation on SOAP-based and REST-based endpoints at the same time.&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;Lets add a twist: for the SOAP-based endpoint I want to use the basicHttpBinding but I want to have the calls authenticated via a username/password however I do not want any on-the-wire security (i.e. encryption) since all calls are inside my intranet and I do not want the overhead of SSL – so in short I want the same basic behavior of good old ASMX services, just using WCF! Now here is the bump: there is no way to do so out of the box in WCF.&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;Enter Custom Bindings and the Channel layer.&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;b&gt;&lt;u&gt;WCF Architecture…the Channel Layer&lt;o:p&gt;&lt;/o:p&gt;&lt;/u&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;WCF is made up of two architectural layers: the Service Model and the Channel layers. Service Model is the higher-level abstraction that you deal with most of the time. Most of developers know it by the famous name of “proxy” at the client side (and less commonly by the name of “dispatcher” at the service side). In its most simple form, when acting as the proxy the Service Model converts our “objects” (data contracts) into the proper message format that the Channel layer understands and hands it down to the Channel layer (known commonly as “serialization”); while when acting as the dispatcher the Service Model gets the message from the low level Channel layer and puts it back into the “objectized” format that our code understands (known commonly as “deserialization”).&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;While we focus on extending the Service Model later when we create the inspectors, let’s focus now on the low-level Channel layer and creating the custom binding.&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;So, now we know that the Channel layer is the low-level devil that we all hate to get near to. But anytime you deal with WCF bindings, all what you are actually doing is controlling the creation of WCF channel stack! You are just doing it in the higher-level abstraction courtesy of predefined WCF bindings. But what happens when the out of the box bindings are not enough? Simple: you write down your own binding. In order to do so, you must understand some essentials about WCF bindings and the channel stack.&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;Bindings (simply) produce a set of ordered BindingElement objects at runtime depending on the type of binding you chose. These binding elements form the entire channel stack (thus the Channel layer). Memorizing all the available BindingElements is difficult unless writing custom bindings (and at times custom BindingElements) is your daily work. Luckily this is not my case! Unluckily though, everytime I have to deal with the channel stack I have to pay a visit for MSDN (&lt;a href="http://msdn.microsoft.com/en-us/library/aa347793.aspx"&gt;http://msdn.microsoft.com/en-us/library/aa347793.aspx&lt;/a&gt;) to refresh my memory about the BindingElements and what each does.&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;So once you get yourself familiar with the type of BindingElements, all what is left for you is to create a custom binding that utilizes these elements in a predefined order…and that’s all what you need to know about the (scary) channel stack.&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;So what is a BindingElement exactly? Simply it’s a processing step. So simply a binding stacks a set of BindingElements on top of each other where a WCF message passes through each step of this stack and “something” happens to the message. For example, a message security binding element provides message encryption (and other stuff), encoding binding element sets message encoding (text, binary, etc…), a transport encoding sets the protocol (TCP, HTTP, HTTPs, etc…)…you got the point.&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;b&gt;&lt;u&gt;Custom Binding&lt;o:p&gt;&lt;/o:p&gt;&lt;/u&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;So, back to our custom binding implementing. Recall what are my requirements? I just want to have username/password authentication over HTTP and without any SSL. Here is the part of the code that adds up the proper BindingElements:&lt;/div&gt;&lt;table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border: none; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 1184;"&gt;&lt;tbody&gt;&lt;tr&gt;   &lt;td style="border: solid black 1.0pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 6.65in;" valign="top" width="638"&gt;   &lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;public&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt; &lt;span style="color: blue;"&gt;override&lt;/span&gt;   &lt;span style="color: #2b91af;"&gt;BindingElementCollection&lt;/span&gt;   CreateBindingElements()&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;var&lt;/span&gt;   res = &lt;span style="color: blue;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;BindingElementCollection&lt;/span&gt;();&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #2b91af;"&gt;XmlDictionaryReaderQuotas&lt;/span&gt;   rqMax = &lt;span style="color: #2b91af;"&gt;XmlDictionaryReaderQuotas&lt;/span&gt;.Max;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #2b91af;"&gt;TextMessageEncodingBindingElement&lt;/span&gt;   textBE = &lt;span style="color: blue;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;TextMessageEncodingBindingElement&lt;/span&gt;()   { MessageVersion = &lt;span style="color: #2b91af;"&gt;MessageVersion&lt;/span&gt;.Soap12WSAddressing10,   MaxReadPoolSize = &lt;span style="color: blue;"&gt;int&lt;/span&gt;.MaxValue,   MaxWritePoolSize = &lt;span style="color: blue;"&gt;int&lt;/span&gt;.MaxValue };&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;   rqMax.CopyTo(textBE.ReaderQuotas);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; res.Add(textBE);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #2b91af;"&gt;TransportSecurityBindingElement&lt;/span&gt;   transportSec = &lt;span style="color: #2b91af;"&gt;SecurityBindingElement&lt;/span&gt;.CreateUserNameOverTransportBindingElement();&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;   transportSec.LocalServiceSettings.MaxClockSkew = &lt;span style="color: blue;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;TimeSpan&lt;/span&gt;(10,   0, 0); &lt;span style="color: green;"&gt;//allow clock difference between client and   service&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; transportSec.LocalClientSettings.MaxClockSkew   = &lt;span style="color: blue;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;TimeSpan&lt;/span&gt;(10,   0, 0);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; res.Add(transportSec);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; res.Add(&lt;span style="color: blue;"&gt;new&lt;/span&gt;   &lt;span style="color: #2b91af;"&gt;AutoSecuredHttpTransportElement&lt;/span&gt;() {   MaxReceivedMessageSize = &lt;span style="color: blue;"&gt;int&lt;/span&gt;.MaxValue,   MaxBufferPoolSize = &lt;span style="color: blue;"&gt;int&lt;/span&gt;.MaxValue,   MaxBufferSize = &lt;span style="color: blue;"&gt;int&lt;/span&gt;.MaxValue });&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;return&lt;/span&gt;   res;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div class="MsoNoSpacing"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;Once the custom binding is done, I want to expose my SOAP-based endpoint using this new binding instead of the basicHttpBinding. That’s the easy part. Let’s see the service configuration:&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;First we create a binding extenstion element and supply and custom binding dll:&lt;/div&gt;&lt;table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border: none; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 1184;"&gt;&lt;tbody&gt;&lt;tr&gt;   &lt;td style="border: solid black 1.0pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 6.65in;" valign="top" width="638"&gt;   &lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;"&gt;extensions&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;"&gt;bindingExtensions&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;"&gt;add&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt; &lt;/span&gt;&lt;span style="color: red; font-family: Consolas; font-size: 9.5pt;"&gt;name&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;=&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;"&lt;span style="color: blue;"&gt;customHttpBinding&lt;/span&gt;"&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: red;"&gt;type&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;MOHE.CustomHttpBinding.CustomHttpCollectionElement,   CustomHttpBinding&lt;/span&gt;"&lt;span style="color: blue;"&gt;/&amp;gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;!--&lt;/span--&gt;&lt;span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;"&gt;bindingExtensions&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;!--&lt;/span--&gt;&lt;span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;"&gt;extensions&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div class="MsoNoSpacing"&gt;Then we create the binding element itself:&lt;/div&gt;&lt;table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border: none; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 1184;"&gt;&lt;tbody&gt;&lt;tr&gt;   &lt;td style="border: solid black 1.0pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 6.65in;" valign="top" width="638"&gt;   &lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;"&gt;bindings&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;"&gt;customHttpBinding&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;"&gt;binding&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt; &lt;/span&gt;&lt;span style="color: red; font-family: Consolas; font-size: 9.5pt;"&gt;name&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;=&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;"&lt;span style="color: blue;"&gt;myCustomHttpBinding&lt;/span&gt;"&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;!--&lt;/span--&gt;&lt;span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;"&gt;binding&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;!--&lt;/span--&gt;&lt;span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;"&gt;customHttpBinding&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;!--&lt;/span--&gt;&lt;span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;"&gt;bindings&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div class="MsoNoSpacing"&gt;Finally, we define our SOAP endpoint using the new binding, as follows:&lt;/div&gt;&lt;table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border: none; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 1184;"&gt;&lt;tbody&gt;&lt;tr&gt;   &lt;td style="border: solid black 1.0pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 6.65in;" valign="top" width="638"&gt;   &lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;"&gt;services&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;"&gt;service&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt; &lt;/span&gt;&lt;span style="color: red; font-family: Consolas; font-size: 9.5pt;"&gt;name&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;=&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;"&lt;span style="color: blue;"&gt;Service&lt;/span&gt;"&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: red;"&gt;behaviorConfiguration&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;ServiceBehavior&lt;/span&gt;"&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;"&gt;endpoint&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt; &lt;/span&gt;&lt;span style="color: red; font-family: Consolas; font-size: 9.5pt;"&gt;address&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;=&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;"&lt;span style="color: blue;"&gt;soap&lt;/span&gt;"&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: red;"&gt;binding&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;customHttpBinding&lt;/span&gt;"&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: red;"&gt;bindingConfiguration&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;myCustomHttpBinding&lt;/span&gt;"&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: red;"&gt;contract&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;IService&lt;/span&gt;"&lt;span style="color: blue;"&gt; /&amp;gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;!--&lt;/span--&gt;&lt;span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;"&gt;service&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;!--&lt;/span--&gt;&lt;span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;"&gt;services&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div class="MsoNoSpacing"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;Needless to say that the binding must also be used at the client side…since now you know what the configuration elements mean you can check the client configuration yourself.&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;b&gt;&lt;u&gt;Custom Username/Password Validator&lt;o:p&gt;&lt;/o:p&gt;&lt;/u&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;Before wrapping up, while we are in the “customization” mode, lets do one final thing: now that we have a custom binding that supports username/password authentication, lets a create a custom username/password validator and plug that into our service to isolate that authentication logic from the service logic. The code is rather simple:&lt;/div&gt;&lt;table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border: none; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 1184;"&gt;&lt;tbody&gt;&lt;tr&gt;   &lt;td style="border: solid black 1.0pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 6.65in;" valign="top" width="638"&gt;   &lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;Public&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt; &lt;span style="color: blue;"&gt;Class&lt;/span&gt;   &lt;span style="color: #2b91af;"&gt;UsernameValidator&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;Inherits&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;UserNamePasswordValidator&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;Public&lt;/span&gt; &lt;span style="color: blue;"&gt;Overrides&lt;/span&gt; &lt;span style="color: blue;"&gt;Sub&lt;/span&gt;   Validate(&lt;span style="color: blue;"&gt;ByVal&lt;/span&gt; userName &lt;span style="color: blue;"&gt;As&lt;/span&gt; &lt;span style="color: blue;"&gt;String&lt;/span&gt;, &lt;span style="color: blue;"&gt;ByVal&lt;/span&gt; password &lt;span style="color: blue;"&gt;As&lt;/span&gt; &lt;span style="color: blue;"&gt;String&lt;/span&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;Try&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;If&lt;/span&gt;   userName &amp;lt;&amp;gt; &lt;span style="color: #a31515;"&gt;"mohamad"&lt;/span&gt; &lt;span style="color: blue;"&gt;Or&lt;/span&gt; password &amp;lt;&amp;gt; &lt;span style="color: #a31515;"&gt;"halabi"&lt;/span&gt;   &lt;span style="color: blue;"&gt;Then&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;Throw&lt;/span&gt;   &lt;span style="color: blue;"&gt;New&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;Exception&lt;/span&gt;(&lt;span style="color: #a31515;"&gt;"Unknown Username or Password"&lt;/span&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;End&lt;/span&gt;   &lt;span style="color: blue;"&gt;If&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;Catch&lt;/span&gt;   ex &lt;span style="color: blue;"&gt;As&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;IndexOutOfRangeException&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;Throw&lt;/span&gt;   &lt;span style="color: blue;"&gt;New&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;FaultException&lt;/span&gt;(&lt;span style="color: #a31515;"&gt;"Unknown Username or Password"&lt;/span&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;End&lt;/span&gt; &lt;span style="color: blue;"&gt;Try&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;End&lt;/span&gt; &lt;span style="color: blue;"&gt;Sub&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;End&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt; &lt;span style="color: blue;"&gt;Class&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div class="MsoNoSpacing"&gt;Needless to say, I hardcoded my username/password…you will authenticate against your favorite user store; be it SQL, AD, etc…&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;Again, lets see how to add the custom username/password validator to the WCF config file:&lt;/div&gt;&lt;table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border: none; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 1184;"&gt;&lt;tbody&gt;&lt;tr&gt;   &lt;td style="border: solid black 1.0pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 6.65in;" valign="top" width="638"&gt;   &lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;"&gt;serviceBehaviors&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;"&gt;behavior&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt; &lt;/span&gt;&lt;span style="color: red; font-family: Consolas; font-size: 9.5pt;"&gt;name&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;=&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;"&lt;span style="color: blue;"&gt;ServiceBehavior&lt;/span&gt;"&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;"&gt;dataContractSerializer&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt; &lt;/span&gt;&lt;span style="color: red; font-family: Consolas; font-size: 9.5pt;"&gt;maxItemsInObjectGraph&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;=&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;"&lt;span style="color: blue;"&gt;10000000&lt;/span&gt;"&lt;span style="color: blue;"&gt;/&amp;gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;"&gt;serviceMetadata&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt; &lt;/span&gt;&lt;span style="color: red; font-family: Consolas; font-size: 9.5pt;"&gt;httpGetEnabled&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;=&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;"&lt;span style="color: blue;"&gt;true&lt;/span&gt;"&lt;span style="color: blue;"&gt; /&amp;gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;"&gt;serviceDebug&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt; &lt;/span&gt;&lt;span style="color: red; font-family: Consolas; font-size: 9.5pt;"&gt;includeExceptionDetailInFaults&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;=&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;"&lt;span style="color: blue;"&gt;true&lt;/span&gt;"&lt;span style="color: blue;"&gt; /&amp;gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;"&gt;serviceCredentials&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;"&gt;userNameAuthentication&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt; &lt;/span&gt;&lt;span style="color: red; font-family: Consolas; font-size: 9.5pt;"&gt;userNamePasswordValidationMode&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;=&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;"&lt;span style="color: blue;"&gt;Custom&lt;/span&gt;"&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: red;"&gt;customUserNamePasswordValidatorType&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;CustomUsernameValidator.UsernameValidator,&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&lt;span style="color: blue;"&gt;CustomUsernameValidator&lt;/span&gt;"&lt;span style="color: blue;"&gt;/&amp;gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;!--&lt;/span--&gt;&lt;span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;"&gt;serviceCredentials&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;!--&lt;/span--&gt;&lt;span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;"&gt;behavior&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;!--&lt;/span--&gt;&lt;span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;"&gt;serviceBehaviors&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div class="MsoNoSpacing"&gt;The “userNameAuthentication” tag is supplied with the dll holding my custom validation logic.&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;Just in case you’re wondering about the other configurations, here’s a quick look:&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="text-indent: -0.25in;"&gt;--dataContractSerializer: if you want to parse large messages in WCF (&lt;/span&gt;&lt;a href="http://thedotnethub.blogspot.com/2009/10/passing-large-messages-in-wcf.html" style="text-indent: -0.25in;"&gt;http://thedotnethub.blogspot.com/2009/10/passing-large-messages-in-wcf.html&lt;/a&gt;&lt;span style="text-indent: -0.25in;"&gt;) there are some attributes you want to set. One of those is maxItemsInObjectGraph which sets how many objects can be serialized and passed around.&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="text-indent: -0.25in;"&gt;--serviceMetadata: enables metadata publishing which grants access to the wsdl&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="text-indent: -0.25in;"&gt;--serviceDebug: enables exception details to be propagated to callers; handy in development&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="text-indent: -0.25in;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;b&gt;&lt;u&gt;REST-enabling the service&lt;o:p&gt;&lt;/o:p&gt;&lt;/u&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;So, let’s think about this: we have a WCF-SOAP service that is using an HTTP based binding. What SOAP-features are we exactly using here? Besides SOAP envelopes…nothing! We aren’t using message security, we aren’t using addressing, we aren’t using routing, we aren’t using transactions…in short we aren’t using any of the WSE standards. Frankly, SOAP is an overhead here! Why? try passing an array of – say 500 – objects from a SOAP service to a client. Now pass the same exact objects in REST style. You will find that the size of the REST request is at least 50% less than the size of the SOAP request. Now that’s some saving.&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;Moral of the story: unless you need SOAP (i.e. any of the WSE standards), REST is the way to go. Its reliance on HTTP verbs makes it perfect for interoperability (SOAP also supports interoperability), it supports caching, and makes it a perfect fit for client-side invoking via JavaScript, jQuery, or Ajax. Even if you need encryption, you can still enable SSL over REST-based services (but you cannot implement the fine-grained message level security that SOAP supports).&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;So, in our example I will enable the same operation to be invoked REST-style returning the result in JSON format. Why JSON? It’s the easiest to be parsed with client-side calls…although not shown here. Why JSON #2? Although it makes you sound cool to say “POX”, I just like Javascript more.&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;So, lets see our operation:&lt;/div&gt;&lt;table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border: none; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 1184;"&gt;&lt;tbody&gt;&lt;tr&gt;   &lt;td style="border: solid black 1.0pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 6.65in;" valign="top" width="638"&gt;   &lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;[&lt;span style="color: #2b91af;"&gt;OperationContract&lt;/span&gt;]&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; [&lt;span style="color: #2b91af;"&gt;WebInvoke&lt;/span&gt;(Method   = &lt;span style="color: #a31515;"&gt;"POST"&lt;/span&gt;, UriTemplate = &lt;span style="color: #a31515;"&gt;"/PostPerson"&lt;/span&gt;, ResponseFormat = &lt;span style="color: #2b91af;"&gt;WebMessageFormat&lt;/span&gt;.Json)]&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #2b91af;"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af;"&gt;Person&lt;/span&gt;&amp;gt; PostPerson(&lt;span style="color: #2b91af;"&gt;Person&lt;/span&gt;   person);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div class="MsoNoSpacing"&gt;The OperationContract is for exposing the operation SOAP-style…what we seen before. The WebInvoke attribute is what enables REST magic. I will be using the “POST” verb; although I can also use the “PUT” verb but I will follow the analogy that POSTs are for inserts while PUTs are for updates. You also have DELETE and GET.&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;Simply, in the web.config we publish the same contract via a second binding, called webHttpBinding:&lt;/div&gt;&lt;table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border: none; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 1184;"&gt;&lt;tbody&gt;&lt;tr&gt;   &lt;td style="border: solid black 1.0pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 6.65in;" valign="top" width="638"&gt;   &lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;"&gt;endpoint&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt; &lt;/span&gt;&lt;span style="color: red; font-family: Consolas; font-size: 9.5pt;"&gt;address&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;=&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;"&lt;span style="color: blue;"&gt;rest&lt;/span&gt;"&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: red;"&gt;binding&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;webHttpBinding&lt;/span&gt;"&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: red;"&gt;contract&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;IService&lt;/span&gt;"&lt;span style="color: blue;"&gt; /&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div class="MsoNoSpacing"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;Now there’s one important point to highlight here: in this example, I am using the webHttpBinding with the REST starter kit dlls (&lt;a href="http://msdn.microsoft.com/en-us/netframework/cc950529"&gt;http://msdn.microsoft.com/en-us/netframework/cc950529&lt;/a&gt;) to REST-enable WCF. The updated way to do this is using WCF Web API dlls (http://wcf.codeplex.com/wikipage?title=WCF%20HTTP). While I am lazy to update the code, the idea – the concept – behind REST and the method of REST-enabling WCF remains largely the same. &lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;So how do we actually call the REST-enabled operation from the client code? Recall there’s no proxy here, just plain simple HTTP requests. So here is a simple helper method that works with generics to be called from multiple places with different in/out objects.&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;br /&gt;&lt;/div&gt;&lt;table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border: none; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 1184;"&gt;&lt;tbody&gt;&lt;tr&gt;   &lt;td style="border: solid black 1.0pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 6.65in;" valign="top" width="638"&gt;   &lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;public&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt; &lt;span style="color: blue;"&gt;static&lt;/span&gt;   Response Post&lt;content, faultcontract="" response,=""&gt;(&lt;span style="color: blue;"&gt;string&lt;/span&gt; username, &lt;span style="color: blue;"&gt;string&lt;/span&gt;   password, &lt;span style="color: #2b91af;"&gt;RESTService&lt;/span&gt; service, &lt;span style="color: blue;"&gt;string&lt;/span&gt; uri, Content content, System.Xml.&lt;span style="color: #2b91af;"&gt;UniqueId&lt;/span&gt; messageId)&lt;o:p&gt;&lt;/o:p&gt;&lt;/content,&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;Response response;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&lt;span style="color: blue;"&gt;using&lt;/span&gt;   (&lt;span style="color: #2b91af;"&gt;HttpClient&lt;/span&gt; client = &lt;span style="color: blue;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;HttpClient&lt;/span&gt;(GetRESTURL(service)))&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt; text-align: left;"&gt;if&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt; text-align: left;"&gt;   (&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt; text-align: left;"&gt;string&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt; text-align: left;"&gt;.IsNullOrEmpty(username)) &lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt; text-align: left;"&gt;throw&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt; text-align: left;"&gt; &lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt; text-align: left;"&gt;new&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt; text-align: left;"&gt; &lt;/span&gt;&lt;span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt; text-align: left;"&gt;Exception&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt; text-align: left;"&gt;(&lt;/span&gt;&lt;span style="color: #a31515; font-family: Consolas; font-size: 9.5pt; text-align: left;"&gt;"You   must pass username"&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt; text-align: left;"&gt;);&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&lt;span style="color: blue;"&gt;if&lt;/span&gt;   (&lt;span style="color: blue;"&gt;string&lt;/span&gt;.IsNullOrEmpty(password)) &lt;span style="color: blue;"&gt;throw&lt;/span&gt; &lt;span style="color: blue;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;Exception&lt;/span&gt;(&lt;span style="color: #a31515;"&gt;"You   must pass password"&lt;/span&gt;);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&lt;span style="color: blue;"&gt;if&lt;/span&gt;   (messageId == &lt;span style="color: blue;"&gt;null&lt;/span&gt;) &lt;span style="color: blue;"&gt;throw&lt;/span&gt;   &lt;span style="color: blue;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;Exception&lt;/span&gt;(&lt;span style="color: #a31515;"&gt;"You must pass messageid"&lt;/span&gt;);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;client.TransportSettings.ConnectionTimeout = &lt;span style="color: blue;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;TimeSpan&lt;/span&gt;(0,   3, 0);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;client.DefaultHeaders.Add(&lt;span style="color: #a31515;"&gt;"username"&lt;/span&gt;, username);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;client.DefaultHeaders.Add(&lt;span style="color: #a31515;"&gt;"password"&lt;/span&gt;, password);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;client.DefaultHeaders.Add(&lt;span style="color: #a31515;"&gt;"clientmachinename"&lt;/span&gt;, &lt;span style="color: #2b91af;"&gt;Environment&lt;/span&gt;.MachineName);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;client.DefaultHeaders.Add(&lt;span style="color: #a31515;"&gt;"messageid"&lt;/span&gt;, messageId.ToString());&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&lt;span style="color: #2b91af;"&gt;HttpContent&lt;/span&gt;   httpContent = &lt;span style="color: #2b91af;"&gt;HttpContentExtensions&lt;/span&gt;.CreateJsonDataContract(content);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&lt;span style="color: blue;"&gt;using&lt;/span&gt;   (&lt;span style="color: #2b91af;"&gt;HttpResponseMessage&lt;/span&gt; httpResponse =   client.Post(uri, httpContent))&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&lt;span style="color: blue;"&gt;if&lt;/span&gt;   (httpResponse.StatusCode == &lt;span style="color: #2b91af;"&gt;HttpStatusCode&lt;/span&gt;.BadRequest)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&lt;span style="color: #2b91af;"&gt;DataContractJsonSerializer&lt;/span&gt;   ser = &lt;span style="color: blue;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;DataContractJsonSerializer&lt;/span&gt;(&lt;span style="color: blue;"&gt;typeof&lt;/span&gt;(FaultContract));&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;FaultContract fault =   (FaultContract)ser.ReadObject(httpResponse.Content.ReadAsStream());&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&lt;span style="color: blue;"&gt;throw&lt;/span&gt;   &lt;span style="color: blue;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;WebFaultException&lt;/span&gt;&lt;faultcontract&gt;(fault,   &lt;span style="color: #2b91af;"&gt;HttpStatusCode&lt;/span&gt;.BadRequest);&lt;o:p&gt;&lt;/o:p&gt;&lt;/faultcontract&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&lt;span style="color: blue;"&gt;else&lt;/span&gt;   &lt;span style="color: blue;"&gt;if&lt;/span&gt; (httpResponse.StatusCode == &lt;span style="color: #2b91af;"&gt;HttpStatusCode&lt;/span&gt;.ServiceUnavailable)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&lt;span style="color: blue;"&gt;throw&lt;/span&gt;   &lt;span style="color: blue;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;Exception&lt;/span&gt;(&lt;span style="color: #a31515;"&gt;"ServiceUnavailable"&lt;/span&gt;);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&lt;span style="color: blue;"&gt;else&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&lt;span style="color: #2b91af;"&gt;DataContractJsonSerializer&lt;/span&gt;   ser = &lt;span style="color: blue;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;DataContractJsonSerializer&lt;/span&gt;(&lt;span style="color: blue;"&gt;typeof&lt;/span&gt;(Response));&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;response =   (Response)ser.ReadObject(httpResponse.Content.ReadAsStream());&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&lt;span style="color: blue;"&gt;return&lt;/span&gt;   response;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div class="MsoNoSpacing"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;b&gt;&lt;u&gt;WCF Architecture…the Service Layer&lt;o:p&gt;&lt;/o:p&gt;&lt;/u&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;Enough easy stuff! Back to the architecture. So recall, that one of the targets of the example is to have logging feature to log every message in and out of the service. Sure we can do this inside the service itself. But this will be neither a good architecture nor cool enough for a post.&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;So, how do we create a module that catchs every single message into and out from our service, yet we want to do it as a reusable extension without touching our service?&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;Enter Custom Behaviors and the Service Layer.&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;Recall that the Service Layer is called “proxy” at the client side and “dispatcher” at the service side. Its job is simply to serialize and deserialize messages to and from the Channel Later respectively. Both the proxy and the dispatcher give you locations – called extensibility locations – that allow you to inject your own logic to inspect messages at various stages and possibly alter the default execution behavior. You can create this logic to inspect messages, operations, parameters, and you can even change serialization &amp;amp; deserialization behavior.&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;In our example, I am interested in a “message inspector” at the dispatcher side which simply intercepts messages coming in and returning back (requests &amp;amp; responses), and log them into a database. There is one catch here: I want to use the same inspector to log both SOAP and REST messages. SOAP messages are XML-based while REST messages are JSON based so there are some considerations to be taken.&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;At the proxy side, I also want to create a “client message inspector” to add some metadata to my SOAP message before it is handed on to the channel stack. (note: for variety of configurations, I will enable the client inspector to the SOAP endpoint only).&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;b&gt;&lt;u&gt;Message Inspector&lt;o:p&gt;&lt;/o:p&gt;&lt;/u&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;Once a message is received, we need to differentiate if it is a SOAP message or a JSON message. Why? because the way to transform the stream into a string format for logging differs:&lt;/div&gt;&lt;table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border: none; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 1184;"&gt;&lt;tbody&gt;&lt;tr&gt;   &lt;td style="border: solid black 1.0pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 6.65in;" valign="top" width="638"&gt;   &lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;object&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt; &lt;span style="color: #2b91af;"&gt;IDispatchMessageInspector&lt;/span&gt;.AfterReceiveRequest(&lt;span style="color: blue;"&gt;ref&lt;/span&gt; System.ServiceModel.Channels.&lt;span style="color: #2b91af;"&gt;Message&lt;/span&gt; request,&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;System.ServiceModel.&lt;span style="color: #2b91af;"&gt;IClientChannel&lt;/span&gt; channel,&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;System.ServiceModel.&lt;span style="color: #2b91af;"&gt;InstanceContext&lt;/span&gt; instanceContext)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&lt;span style="color: #2b91af;"&gt;HttpRequestMessageProperty&lt;/span&gt;   httpReq =&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 13px; text-align: left;"&gt;(&lt;/span&gt;&lt;span style="color: #2b91af; font-family: Consolas; font-size: 13px; text-align: left;"&gt;HttpRequestMessageProperty&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 13px; text-align: left;"&gt;)&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt; text-align: left;"&gt;request.Properties[&lt;/span&gt;&lt;span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt; text-align: left;"&gt;HttpRequestMessageProperty&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt; text-align: left;"&gt;.Name];&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&lt;span style="color: blue;"&gt;if&lt;/span&gt;   (!httpReq.Headers[&lt;span style="color: #a31515;"&gt;"Content-Type"&lt;/span&gt;].Contains(&lt;span style="color: #a31515;"&gt;"soap"&lt;/span&gt;))&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&lt;span style="color: blue;"&gt;return&lt;/span&gt;   RESTAfterReceiveRequest(&lt;span style="color: blue;"&gt;ref&lt;/span&gt; request, channel,   instanceContext);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&lt;span style="color: blue;"&gt;else&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&lt;span style="color: blue;"&gt;return&lt;/span&gt;   SOAPAfterReceiveRequest(&lt;span style="color: blue;"&gt;ref&lt;/span&gt; request, channel,   instanceContext);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div class="MsoNoSpacing"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;Similarly, before sending the response back we again want to log it:&lt;/div&gt;&lt;table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border: none; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 1184;"&gt;&lt;tbody&gt;&lt;tr&gt;   &lt;td style="border: solid black 1.0pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 6.65in;" valign="top" width="638"&gt;   &lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;void&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt; &lt;span style="color: #2b91af;"&gt;IDispatchMessageInspector&lt;/span&gt;.BeforeSendReply(&lt;span style="color: blue;"&gt;ref&lt;/span&gt; System.ServiceModel.Channels.&lt;span style="color: #2b91af;"&gt;Message&lt;/span&gt; reply, &lt;span style="color: blue;"&gt;object&lt;/span&gt;   correlationState)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;if&lt;/span&gt;   (reply.Headers.Action == &lt;span style="color: blue;"&gt;null&lt;/span&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RESTBeforeSendReply(&lt;span style="color: blue;"&gt;ref&lt;/span&gt; reply, correlationState);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;else&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SOAPBeforeSendReply(&lt;span style="color: blue;"&gt;ref&lt;/span&gt; reply, correlationState);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div class="MsoNoSpacing"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;There are a lot of details in this inspector, such as reading HTTP headers, implementing authentication for REST calls based on these headers, using Task Parallel Libray (TPL) to log data without delaying moving the message down to the channel stack and up to the dispatch operations, and compressing the message before logging it…these are all enhancements however and should lay themselves clear when you download the code.&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;Now lets see the configuration to add the message inspector:&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;br /&gt;&lt;/div&gt;&lt;table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border: none; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 1184;"&gt;&lt;tbody&gt;&lt;tr&gt;   &lt;td style="border: solid black 1.0pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 6.65in;" valign="top" width="638"&gt;   &lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;"&gt;extensions&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;"&gt;behaviorExtensions&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;"&gt;add&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt; &lt;/span&gt;&lt;span style="color: red; font-family: Consolas; font-size: 9.5pt;"&gt;name&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;=&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;"&lt;span style="color: blue;"&gt;messageInspector&lt;/span&gt;"&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: red;"&gt;type&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;MessageInspector.MessageBehaviorExtensionElement,   MessageInspector, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null&lt;/span&gt;"&lt;span style="color: blue;"&gt;/&amp;gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;!--&lt;/span--&gt;&lt;span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;"&gt;behaviorExtensions&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;!--&lt;/span--&gt;&lt;span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;"&gt;extensions&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;"&gt;endpointBehaviors&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;"&gt;behavior&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt; &lt;/span&gt;&lt;span style="color: red; font-family: Consolas; font-size: 9.5pt;"&gt;name&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;=&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;"&lt;span style="color: blue;"&gt;RestBehavior&lt;/span&gt;"&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;"&gt;messageInspector&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;/&amp;gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;"&gt;webHttp&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt; &lt;/span&gt;&lt;span style="color: red; font-family: Consolas; font-size: 9.5pt;"&gt;helpEnabled&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;=&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;"&lt;span style="color: blue;"&gt;true&lt;/span&gt;"&lt;span style="color: blue;"&gt; /&amp;gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;!--&lt;/span--&gt;&lt;span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;"&gt;behavior&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;"&gt;behavior&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt; &lt;/span&gt;&lt;span style="color: red; font-family: Consolas; font-size: 9.5pt;"&gt;name&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;=&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;"&lt;span style="color: blue;"&gt;SoapBehavior&lt;/span&gt;"&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;"&gt;messageInspector&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;/&amp;gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;!--&lt;/span--&gt;&lt;span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;"&gt;behavior&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;!--&lt;/span--&gt;&lt;span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;"&gt;endpointBehaviors&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;!--&lt;/span--&gt;&lt;span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;"&gt;behaviors&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;"&gt;services&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;"&gt;service&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt; &lt;/span&gt;&lt;span style="color: red; font-family: Consolas; font-size: 9.5pt;"&gt;name&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;=&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;"&lt;span style="color: blue;"&gt;Service&lt;/span&gt;"&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: red;"&gt;behaviorConfiguration&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;ServiceBehavior&lt;/span&gt;"&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;"&gt;endpoint&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt; &lt;/span&gt;&lt;span style="color: red; font-family: Consolas; font-size: 9.5pt;"&gt;address&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;=&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;"&lt;span style="color: blue;"&gt;rest&lt;/span&gt;"&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: red;"&gt;binding&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;webHttpBinding&lt;/span&gt;"&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: red;"&gt;contract&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;IService&lt;/span&gt;"&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: red;"&gt;behaviorConfiguration&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;RestBehavior&lt;/span&gt;"&lt;span style="color: blue;"&gt; /&amp;gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;"&gt;endpoint&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt; &lt;/span&gt;&lt;span style="color: red; font-family: Consolas; font-size: 9.5pt;"&gt;address&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;=&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;"&lt;span style="color: blue;"&gt;soap&lt;/span&gt;"&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: red;"&gt;binding&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;customHttpBinding&lt;/span&gt;"&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: red;"&gt;bindingConfiguration&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;myCustomHttpBinding&lt;/span&gt;"&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: red;"&gt;contract&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;IService&lt;/span&gt;"&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: red;"&gt;behaviorConfiguration&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;SoapBehavior&lt;/span&gt;"&lt;span style="color: blue;"&gt;/&amp;gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;!--&lt;/span--&gt;&lt;span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;"&gt;service&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;!--&lt;/span--&gt;&lt;span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;"&gt;services&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div class="MsoNoSpacing"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;The inspector is added as a behavior extension…recall this means plugging it in the Service Layer. We then define two endpoint behaviors to add the message inspector to both SOAP and REST endpoints. And finally we update the endpoint definitions so that both endpoints now use the message inspector.&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;b&gt;&lt;u&gt;Client Message Inspector&lt;o:p&gt;&lt;/o:p&gt;&lt;/u&gt;&lt;/b&gt;&lt;/div&gt;&lt;br /&gt;&lt;div class="MsoNoSpacing"&gt;Finally, I also said that I want to add a client inspector at the proxy side to add some metadata to the message. Basically, what I want is simply to log (I know, I have a thing for logging) the name of the machine from where the request is initiated:&lt;/div&gt;&lt;table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border: none; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 1184;"&gt;&lt;tbody&gt;&lt;tr&gt;   &lt;td style="border: solid black 1.0pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 6.65in;" valign="top" width="638"&gt;   &lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;object&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt; &lt;span style="color: #2b91af;"&gt;IClientMessageInspector&lt;/span&gt;.BeforeSendRequest(&lt;span style="color: blue;"&gt;ref&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;Message&lt;/span&gt;   request, &lt;span style="color: #2b91af;"&gt;IClientChannel&lt;/span&gt; channel)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: green;"&gt;//   Prepare the request message copy to be modified&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #2b91af;"&gt;MessageBuffer&lt;/span&gt;   buffer = request.CreateBufferedCopy(&lt;span style="color: blue;"&gt;int&lt;/span&gt;.MaxValue);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; request = buffer.CreateMessage();&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; request.Headers.Add(&lt;span style="color: #2b91af;"&gt;MessageHeader&lt;/span&gt;.CreateHeader(&lt;span style="color: #a31515;"&gt;"MachineName"&lt;/span&gt;, &lt;span style="color: #a31515;"&gt;"http://machinename/CustomHeaders"&lt;/span&gt;, System.&lt;span style="color: #2b91af;"&gt;Environment&lt;/span&gt;.MachineName));&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;return&lt;/span&gt;   &lt;span style="color: blue;"&gt;null&lt;/span&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div class="MsoNoSpacing"&gt;And we then configure our client application to use this inspector for every SOAP message going out:&lt;/div&gt;&lt;table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border: none; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 1184;"&gt;&lt;tbody&gt;&lt;tr&gt;   &lt;td style="border: solid black 1.0pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 6.65in;" valign="top" width="638"&gt;   &lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;"&gt;extensions&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;"&gt;behaviorExtensions&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;"&gt;add&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt; &lt;/span&gt;&lt;span style="color: red; font-family: Consolas; font-size: 9.5pt;"&gt;name&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;=&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;"&lt;span style="color: blue;"&gt;clientMessageInspector&lt;/span&gt;"&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: red;"&gt;type&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;ClientMessageInspector.ClientMessageBehaviorExtensionElement,   ClientMessageInspector, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null&lt;/span&gt;"&lt;span style="color: blue;"&gt;/&amp;gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;!--&lt;/span--&gt;&lt;span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;"&gt;behaviorExtensions&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&lt;!--&lt;/span--&gt;&lt;span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;"&gt;extensions&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;"&gt;behaviors&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;"&gt;endpointBehaviors&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;"&gt;behavior&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt; &lt;/span&gt;&lt;span style="color: red; font-family: Consolas; font-size: 9.5pt;"&gt;name&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;=&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;"&lt;span style="color: blue;"&gt;EndpointBehavior&lt;/span&gt;"&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;"&gt;clientMessageInspector&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;/&amp;gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;"&gt;dataContractSerializer&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt; &lt;/span&gt;&lt;span style="color: red; font-family: Consolas; font-size: 9.5pt;"&gt;maxItemsInObjectGraph&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;=&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;"&lt;span style="color: blue;"&gt;10000000&lt;/span&gt;"&lt;span style="color: blue;"&gt;/&amp;gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;!--&lt;/span--&gt;&lt;span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;"&gt;behavior&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;!--&lt;/span--&gt;&lt;span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;"&gt;endpointBehaviors&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;!--&lt;/span--&gt;&lt;span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;"&gt;behaviors&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;"&gt;client&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;"&gt;endpoint&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt; &lt;/span&gt;&lt;span style="color: red; font-family: Consolas; font-size: 9.5pt;"&gt;address&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;=&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;"&lt;span style="color: blue;"&gt;http://localhost/WCFService/Service.svc/soap&lt;/span&gt;"&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color: red; font-family: Consolas; font-size: 9.5pt;"&gt;behaviorConfiguration&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;=&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;"&lt;span style="color: blue;"&gt;EndpointBehavior&lt;/span&gt;"&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: red;"&gt;binding&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;customHttpBinding&lt;/span&gt;"&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color: red; font-family: Consolas; font-size: 9.5pt;"&gt;bindingConfiguration&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;=&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;"&lt;span style="color: blue;"&gt;myCustomHttpBinding&lt;/span&gt;"&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: red;"&gt;contract&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;SOAPRef.IService&lt;/span&gt;"&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color: red; font-family: Consolas; font-size: 9.5pt;"&gt;name&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;=&lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;"&lt;span style="color: blue;"&gt;CustomHttpBinding_IService&lt;/span&gt;"&lt;span style="color: blue;"&gt; /&amp;gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-family: Consolas; font-size: 9.5pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;!--&lt;/span--&gt;&lt;span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;"&gt;client&lt;/span&gt;&lt;span style="color: blue; font-family: Consolas; font-size: 9.5pt;"&gt;&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div class="MsoNoSpacing"&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4918396109946207501-2537780920498584831?l=thedotnethub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thedotnethub.blogspot.com/feeds/2537780920498584831/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thedotnethub.blogspot.com/2012/01/creating-soaprest-based-wcf-service.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/2537780920498584831'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/2537780920498584831'/><link rel='alternate' type='text/html' href='http://thedotnethub.blogspot.com/2012/01/creating-soaprest-based-wcf-service.html' title='Creating a SOAP/REST – based WCF Service with Custom Binding/Behaviors'/><author><name>mohamad halabi</name><uri>http://www.blogger.com/profile/10259946099831243955</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4918396109946207501.post-7439879291250074755</id><published>2011-07-05T15:57:00.000+03:00</published><updated>2011-07-05T15:57:13.630+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Azure AppFabric'/><category scheme='http://www.blogger.com/atom/ns#' term='WIF'/><category scheme='http://www.blogger.com/atom/ns#' term='Claims'/><title type='text'>Azure AppFabric, Claims-based access, WIF Recording</title><content type='html'>Here is my recordings talking about Windows Azure AppFabric, Claims-based access, and Windows Identity Foundation(WIF)...this recording is a part of Devlifestyle June 2011 session held in PSU.&lt;br /&gt;Note that this recording is in Arabic only.&lt;br /&gt;&lt;br /&gt;&lt;iframe width="560" height="349" src="http://www.youtube.com/embed/gQRDuX3GIFc" frameborder="0" allowfullscreen&gt;&lt;/iframe&gt;&lt;br /&gt;&lt;br /&gt;&lt;iframe width="560" height="349" src="http://www.youtube.com/embed/i9XFEMQwmaQ" frameborder="0" allowfullscreen&gt;&lt;/iframe&gt;&lt;br /&gt;&lt;br /&gt;&lt;iframe width="560" height="349" src="http://www.youtube.com/embed/w16hjxw6_G0" frameborder="0" allowfullscreen&gt;&lt;/iframe&gt;&lt;br /&gt;&lt;br /&gt;&lt;iframe width="560" height="349" src="http://www.youtube.com/embed/ayHY37xwgBE" frameborder="0" allowfullscreen&gt;&lt;/iframe&gt;&lt;br /&gt;&lt;br /&gt;&lt;iframe width="560" height="349" src="http://www.youtube.com/embed/yatWWPyuR9s" frameborder="0" allowfullscreen&gt;&lt;/iframe&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4918396109946207501-7439879291250074755?l=thedotnethub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thedotnethub.blogspot.com/feeds/7439879291250074755/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thedotnethub.blogspot.com/2011/07/azure-appfabric-claims-based-access-wif.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/7439879291250074755'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/7439879291250074755'/><link rel='alternate' type='text/html' href='http://thedotnethub.blogspot.com/2011/07/azure-appfabric-claims-based-access-wif.html' title='Azure AppFabric, Claims-based access, WIF Recording'/><author><name>mohamad halabi</name><uri>http://www.blogger.com/profile/10259946099831243955</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://img.youtube.com/vi/gQRDuX3GIFc/default.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4918396109946207501.post-1537490349571178613</id><published>2011-06-20T23:35:00.000+03:00</published><updated>2011-06-20T23:35:21.237+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Azure AppFabric'/><category scheme='http://www.blogger.com/atom/ns#' term='Azure'/><title type='text'>Windows Azure Demo-Based Online Recording</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Here is an online recording for my Devlifestyle Online June session about Windows Azure...I present the architecture behind Windows Azure and then dive into demos showing the various services from the Azure Platform&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;object style="height: 390px; width: 640px"&gt;&lt;param name="movie" value="http://www.youtube.com/v/H8e1wJlJlC8?version=3"&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;param name="allowScriptAccess" value="always"&gt;&lt;embed src="http://www.youtube.com/v/H8e1wJlJlC8?version=3" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="640" height="390"&gt;&lt;/object&gt;&lt;br/&gt;&lt;br /&gt;&lt;object style="height: 390px; width: 640px"&gt;&lt;param name="movie" value="http://www.youtube.com/v/-iQFYrV5--E?version=3"&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;param name="allowScriptAccess" value="always"&gt;&lt;embed src="http://www.youtube.com/v/-iQFYrV5--E?version=3" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="640" height="390"&gt;&lt;/object&gt;&lt;br/&gt;&lt;br /&gt;&lt;object style="height: 390px; width: 640px"&gt;&lt;param name="movie" value="http://www.youtube.com/v/0tfLtYA9TWI?version=3"&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;param name="allowScriptAccess" value="always"&gt;&lt;embed src="http://www.youtube.com/v/0tfLtYA9TWI?version=3" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="640" height="390"&gt;&lt;/object&gt;&lt;br/&gt;&lt;br /&gt;&lt;object style="height: 390px; width: 640px"&gt;&lt;param name="movie" value="http://www.youtube.com/v/onvcEQ09m6s?version=3"&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;param name="allowScriptAccess" value="always"&gt;&lt;embed src="http://www.youtube.com/v/onvcEQ09m6s?version=3" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="640" height="390"&gt;&lt;/object&gt;&lt;br/&gt;&lt;br /&gt;&lt;object style="height: 390px; width: 640px"&gt;&lt;param name="movie" value="http://www.youtube.com/v/9ErFOhecXlQ?version=3"&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;param name="allowScriptAccess" value="always"&gt;&lt;embed src="http://www.youtube.com/v/9ErFOhecXlQ?version=3" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="640" height="390"&gt;&lt;/object&gt;&lt;br/&gt;&lt;br /&gt;&lt;object style="height: 390px; width: 640px"&gt;&lt;param name="movie" value="http://www.youtube.com/v/7KmMygMcSAM?version=3"&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;param name="allowScriptAccess" value="always"&gt;&lt;embed src="http://www.youtube.com/v/7KmMygMcSAM?version=3" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="640" height="390"&gt;&lt;/object&gt;&lt;br/&gt;&lt;br /&gt;&lt;object style="height: 390px; width: 640px"&gt;&lt;param name="movie" value="http://www.youtube.com/v/Jn4qQLgbhEk?version=3"&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;param name="allowScriptAccess" value="always"&gt;&lt;embed src="http://www.youtube.com/v/Jn4qQLgbhEk?version=3" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="640" height="390"&gt;&lt;/object&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4918396109946207501-1537490349571178613?l=thedotnethub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thedotnethub.blogspot.com/feeds/1537490349571178613/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thedotnethub.blogspot.com/2011/06/windows-azure-demo-based-online.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/1537490349571178613'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/1537490349571178613'/><link rel='alternate' type='text/html' href='http://thedotnethub.blogspot.com/2011/06/windows-azure-demo-based-online.html' title='Windows Azure Demo-Based Online Recording'/><author><name>mohamad halabi</name><uri>http://www.blogger.com/profile/10259946099831243955</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4918396109946207501.post-8690628786972112285</id><published>2011-06-13T15:44:00.000+03:00</published><updated>2011-06-13T15:44:24.766+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='.NET 4.0'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='Parallel Programming'/><title type='text'>Parallel Task with ASP.NET HttpContext</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;When using .NET 4.0 Parallel Programming (&lt;a href="http://www.codeproject.com/KB/Parallel_Programming/NET4ParallelIntro.aspx"&gt;Check my article&lt;/a&gt;) with ASP.NET, you will lose HttpContext once you jump in to another task.&lt;br /&gt;In my case I wanted to get hold of the context from which I wanted to get the current page handler. So I came up with the below code. &lt;br /&gt;&lt;br /&gt;HOWEVER, and as you can see this is BIG HOWEVER, although I tried the code and it did work I am not 100% sure about it because the idea of manually setting the context (as you will see in a moment) and messing up with the way threading works gives me the creeps! But anyway I thought I would share it:&lt;br /&gt;&lt;br /&gt;Action&amp;lt;object&amp;gt; action = new Action&amp;lt;object&amp;gt;(dostuff);&lt;br /&gt;Task.Factory.StartNew(action, obj);&lt;br /&gt;&lt;br /&gt;where:&lt;br /&gt;&lt;br /&gt;private void dostuff(object obj)&lt;br /&gt;{&lt;br /&gt;IHttpHandler han = ((HttpContext)obj).CurrentHandler;&lt;br /&gt;//do stuff&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;or you can use delegates:&lt;br /&gt;&lt;br /&gt;Task.Factory.StartNew(new Action&amp;lt;object&amp;gt;(&lt;br /&gt;delegate(object objContext)&lt;br /&gt;{&lt;br /&gt;IHttpHandler han = ((HttpContext)objContext).CurrentHandler;&lt;br /&gt;//do stuff&lt;br /&gt;}&lt;br /&gt;)&lt;br /&gt;, obj);&lt;br /&gt;&lt;br /&gt;or event better: &lt;a href="http://thedotnethub.blogspot.com/2009/05/cool-c-code.html"&gt;lambda&lt;/a&gt;:&lt;br /&gt;&lt;br /&gt;Task.Factory.StartNew(new Action&amp;lt;object&amp;gt;(&lt;br /&gt;objContext =&amp;gt;&lt;br /&gt;{&lt;br /&gt;IHttpHandler han = ((HttpContext)objContext).CurrentHandler;&lt;br /&gt;//do stuff&lt;br /&gt;}&lt;br /&gt;)&lt;br /&gt;, obj);&lt;br /&gt;&lt;br /&gt;Ok so it was a short post, and I thought I would spice it up with some code variations :)&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4918396109946207501-8690628786972112285?l=thedotnethub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thedotnethub.blogspot.com/feeds/8690628786972112285/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thedotnethub.blogspot.com/2011/06/parallel-task-with-aspnet-httpcontext.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/8690628786972112285'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/8690628786972112285'/><link rel='alternate' type='text/html' href='http://thedotnethub.blogspot.com/2011/06/parallel-task-with-aspnet-httpcontext.html' title='Parallel Task with ASP.NET HttpContext'/><author><name>mohamad halabi</name><uri>http://www.blogger.com/profile/10259946099831243955</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4918396109946207501.post-7726348429869188524</id><published>2011-06-03T18:20:00.000+03:00</published><updated>2011-06-03T18:20:57.076+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Azure'/><title type='text'>Azure Storage Emulator: Process cannot access the file because it is being used by another process</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;If you are trying to run the services of the azure storage emulator (Blob, Queue, Table) and you ever get this error:&lt;br /&gt;The process cannot access the file because it is being used by another process&lt;br /&gt;&lt;br /&gt;Then continue reading...&lt;br /&gt;As you might imagine it happened to me, and I found that the blob service is the one complaining:&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-N7tMZ1IlxbI/Tej5M0gkH5I/AAAAAAAAAIY/bwuh7mBFuh8/s1600/emulator1.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="101" src="http://4.bp.blogspot.com/-N7tMZ1IlxbI/Tej5M0gkH5I/AAAAAAAAAIY/bwuh7mBFuh8/s320/emulator1.jpg" t8="true" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;I knew something was wrong with the endpoint, from the error message i could tell that most probably the problem was that the endpoint address being used by some other process.&lt;br /&gt;So from the command prompt i ran Network Statistics tool (Netstat) and got the following:&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-kWoov0EGoCI/Tej6WReX67I/AAAAAAAAAIc/FcuhC9vxwoU/s1600/emulator2.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="161" src="http://2.bp.blogspot.com/-kWoov0EGoCI/Tej6WReX67I/AAAAAAAAAIc/FcuhC9vxwoU/s320/emulator2.jpg" t8="true" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;As you can see, i had ports 10001 and 10002 saying "cannot obtain ownership information" but anyway I had no problems with these ports as they are associated with the Queue and Table services respectively and both are started. However, it is clear that port 10000 is occupied by BitTorrent on my machine (yes you caught me!) so that is why the Blob service could not be started.&lt;br /&gt;Once I stopped BitTorrent I could start the Blob service.&lt;br /&gt;&lt;br /&gt;Note: you would have another option which would be changing the ports the emulator use for the storage services. You could do that by navigating to:&lt;br /&gt;C:\Program Files\Windows Azure SDK\v1.4\bin\devstore&lt;br /&gt;(replace 1.4 with your SDK version) and openning DSService.exe.config. From there you could change the configuration and make your services listen to another ports.&lt;br /&gt;﻿&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4918396109946207501-7726348429869188524?l=thedotnethub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thedotnethub.blogspot.com/feeds/7726348429869188524/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thedotnethub.blogspot.com/2011/06/azure-storage-emulator-process-cannot.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/7726348429869188524'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/7726348429869188524'/><link rel='alternate' type='text/html' href='http://thedotnethub.blogspot.com/2011/06/azure-storage-emulator-process-cannot.html' title='Azure Storage Emulator: Process cannot access the file because it is being used by another process'/><author><name>mohamad halabi</name><uri>http://www.blogger.com/profile/10259946099831243955</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/-N7tMZ1IlxbI/Tej5M0gkH5I/AAAAAAAAAIY/bwuh7mBFuh8/s72-c/emulator1.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4918396109946207501.post-1590177398412189344</id><published>2011-05-05T08:23:00.000+03:00</published><updated>2011-05-05T08:23:23.227+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Devlifestyle'/><category scheme='http://www.blogger.com/atom/ns#' term='WCF'/><title type='text'>Utilizing WCF Power for Integrations - Devlifestyle May 2011 Session Demo</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;So, after a (very?) long time without a post (absolutely hectic period), I am back with a WCF post for WCF lovers out there...here are the session materials for a session I did for &lt;a href="http://www.devlifestyle.net/default.aspx"&gt;Devlifestyle&lt;/a&gt; (actually the session is due in 5 hours as of this writing)&lt;br /&gt;&lt;a href="http://www.devlifestyle.net/media/p/1173/download.aspx"&gt;http://www.devlifestyle.net/media/p/1173/download.aspx&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;The demo shows various WCF configurations using basic, net, and MSMQ bindings. The demo also tackles WCF custom bindings and shows a custom http-based binding created as well as custom extensions (behaviors)....ENJOY!&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4918396109946207501-1590177398412189344?l=thedotnethub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thedotnethub.blogspot.com/feeds/1590177398412189344/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thedotnethub.blogspot.com/2011/05/utilizing-wcf-power-for-integrations.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/1590177398412189344'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/1590177398412189344'/><link rel='alternate' type='text/html' href='http://thedotnethub.blogspot.com/2011/05/utilizing-wcf-power-for-integrations.html' title='Utilizing WCF Power for Integrations - Devlifestyle May 2011 Session Demo'/><author><name>mohamad halabi</name><uri>http://www.blogger.com/profile/10259946099831243955</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4918396109946207501.post-5998984195799488528</id><published>2010-12-21T15:48:00.000+03:00</published><updated>2010-12-21T15:48:18.798+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='SOAP'/><category scheme='http://www.blogger.com/atom/ns#' term='REST'/><category scheme='http://www.blogger.com/atom/ns#' term='Devlifestyle'/><title type='text'>Second Riyadh Community Summit</title><content type='html'>I will speaking at the second Riyadh Community Summit, Thursday 23 December. Session will be about RESTful services tackling the popular SOAP vs. REST debate.&lt;br /&gt;Hopefuly I will be able to post the video recordings of the event.&lt;br /&gt;Full agenda here:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.devlifestyle.net/rcs2/"&gt;http://www.devlifestyle.net/rcs2/&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4918396109946207501-5998984195799488528?l=thedotnethub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thedotnethub.blogspot.com/feeds/5998984195799488528/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thedotnethub.blogspot.com/2010/12/second-riyadh-community-summit.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/5998984195799488528'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/5998984195799488528'/><link rel='alternate' type='text/html' href='http://thedotnethub.blogspot.com/2010/12/second-riyadh-community-summit.html' title='Second Riyadh Community Summit'/><author><name>mohamad halabi</name><uri>http://www.blogger.com/profile/10259946099831243955</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4918396109946207501.post-826267100694283416</id><published>2010-12-16T12:36:00.008+03:00</published><updated>2010-12-18T09:18:27.608+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='SharePoint 2010'/><category scheme='http://www.blogger.com/atom/ns#' term='Workflow'/><title type='text'>SharePoint 2010: Passing data from Workflow to Task Form</title><content type='html'>Implementing a state machine workflow project on a SharePoint 2010 Document Library (i will do a full post soon), I faced a situation where I wanted to pass data from the workflow instance to the ASP.NET task edit form.&lt;br /&gt;&lt;br /&gt;Before I have many times done the reverse: passing data from the Task Edit forms to the workflow instance by defining custom content types and referencing their fields inside my workflow using the ExtendedProperties Hashtable.&lt;br /&gt;&lt;br /&gt;So now I thought I could do the same to pass data into my task form: from inside the wf instance I used the ExtendedProperties hashtable to set a value to my field when creating the task as follows:&lt;br /&gt;&lt;em&gt;&lt;span style="font-family: times new roman;"&gt;task.ExtendedProperties["myItemGUID"] = ".....";&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;Now in the task form i tried to access the same property using:&lt;br /&gt;&lt;em&gt;&lt;span style="font-family: times new roman;"&gt;mytaskListItem.Properties["myItemGUID"]&lt;/span&gt;&lt;/em&gt; but it is always null.&lt;br /&gt;&lt;br /&gt;I then "watched" over the Xml property of mytaskListItem and found that "myItemGUID" was actually populated inside as follows:&lt;br /&gt;&lt;em&gt;&lt;span style="font-family: times new roman;"&gt;ows_ExtendedProperties = 'ows_myItemGUID=......'&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;Further if I use &lt;em&gt;&lt;span style="font-family: times new roman;"&gt;mytaskListItem.GetFormattedValue("ows_ExtendedProperties")&lt;/span&gt;&lt;/em&gt; i can get the same value &lt;em&gt;&lt;span style="font-family: times new roman;"&gt;"ows_myItemGUID=..."&lt;/span&gt;&lt;/em&gt; where parsing will be easier than having to parse the full Xml value.&lt;br /&gt;&lt;br /&gt;Now of course this will make me move on for now, but this is hardly an optimum solution. Till now I do not know why I could not "strongly-type get" the value of the field the same way I can do when getting data from the wf instance...Needless to say, SharePoint is not exactly my thing (so far!)...workflows are :) so I could be missing some SharePoint related stuff...anyway will get back to this once I finish the business process...&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4918396109946207501-826267100694283416?l=thedotnethub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thedotnethub.blogspot.com/feeds/826267100694283416/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thedotnethub.blogspot.com/2010/12/sharepoint-2010-passing-data-from.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/826267100694283416'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/826267100694283416'/><link rel='alternate' type='text/html' href='http://thedotnethub.blogspot.com/2010/12/sharepoint-2010-passing-data-from.html' title='SharePoint 2010: Passing data from Workflow to Task Form'/><author><name>mohamad halabi</name><uri>http://www.blogger.com/profile/10259946099831243955</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4918396109946207501.post-6684755904480343055</id><published>2010-11-14T15:06:00.010+03:00</published><updated>2010-11-14T15:49:52.114+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='MSMQ'/><category scheme='http://www.blogger.com/atom/ns#' term='WCF'/><title type='text'>WCF MSMQ Transactions Explained – Part1</title><content type='html'>&lt;h2&gt;Introduction&lt;/h2&gt;Before starting, I advise you to read &lt;a href="http://thedotnethub.blogspot.com/2009/04/truly-understanding-net-transactions.html"&gt;my detailed article&lt;/a&gt; about .NET transactions and WCF implementation for more in depth knowledge about how transactions work. However, you can still go through this post directly to get the required knowledge about WCF MSMQ transactions.&lt;br /&gt;When working with MSMQ and WCF, you have two options for bindings: NetMsmqBinding and MsmqIntegrationBinding.&lt;br /&gt;&lt;ul&gt;&lt;li&gt;The NetMsmqBinding is intended to be used when both the client and service are WCF and communicate over the assigned endpoints.&lt;/li&gt;&lt;li&gt;MsmqIntegrationBinding on the other hand can be used with already-written native MSMQ applications that use MSMQ COM or the System.Messaging APIs.&lt;/li&gt;&lt;/ul&gt;I will be using the NetMsmqBinding.&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;Getting to the point…&lt;/h2&gt;&lt;p&gt;I am going to show you the code directly explaining the concepts as we go.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;The service contract of my service application is defined below:&lt;br /&gt;&lt;br /&gt;&lt;em&gt;[OperationBehavior(TransactionScopeRequired = true, TransactionAutoComplete = true)]&lt;br /&gt;public void GetData(int value)&lt;br /&gt;{&lt;br /&gt;System.Diagnostics.EventLog.WriteEntry("WCF", value.ToString());&lt;br /&gt;Transaction.Current.Rollback();&lt;br /&gt;}&lt;/em&gt;&lt;br /&gt;TransactionScopeRequired indicates that my operation must be enlisted within a transaction and TransactionAutoComplete indicates that the transaction will be committed automatically once the operation finishes.&lt;br /&gt;&lt;br /&gt;In the operation body I simply print something to the event viewer and interestingly manually roll back the transaction. Why did I do that? This will become clear later.&lt;br /&gt;&lt;br /&gt;The relevant service configuration is where the magic happens. It is shown below:&lt;br /&gt;&lt;br /&gt;&lt;em&gt;&amp;lt;services&amp;gt;&lt;br /&gt;&amp;lt;service name="Service" behaviorConfiguration="ServiceBehavior"&amp;gt;&lt;br /&gt;&amp;lt;endpoint address="net.msmq://localhost/private/MSMQService/Service.svc" binding="netMsmqBinding" contract="IService" bindingConfiguration="MSMQ"&amp;gt;&amp;lt;/endpoint&amp;gt;&lt;br /&gt;&amp;lt;/service&amp;gt;&lt;br /&gt;&amp;lt;/services&amp;gt;&lt;br /&gt;&amp;lt;behaviors&amp;gt;&lt;br /&gt;&amp;lt;serviceBehaviors&amp;gt;&lt;br /&gt;&amp;lt;behavior name="ServiceBehavior"&amp;gt;&lt;br /&gt;&amp;lt;serviceMetadata httpGetEnabled="true" /&amp;gt;&lt;br /&gt;&amp;lt;/behavior&amp;gt;&lt;br /&gt;&amp;lt;/serviceBehaviors&amp;gt;&lt;br /&gt;&amp;lt;/behaviors&amp;gt;&lt;br /&gt;&amp;lt;bindings&amp;gt;&lt;br /&gt;&amp;lt;netMsmqBinding&amp;gt;&lt;br /&gt;&amp;lt;binding name="MSMQ" maxRetryCycles="1" receiveRetryCount="1" retryCycleDelay="00:00:20" deadLetterQueue="System" receiveErrorHandling="Move" exactlyOnce="true" durable="true" timeToLive="1.00:00:00"&amp;gt;&lt;br /&gt;&amp;lt;security mode="None"&amp;gt;&amp;lt;/security&amp;gt;&lt;br /&gt;&amp;lt;/binding&amp;gt;&lt;br /&gt;&amp;lt;/netMsmqBinding&amp;gt;&lt;br /&gt;&amp;lt;/bindings&amp;gt;&lt;/em&gt;&lt;br /&gt;First things first; I am using the netMsmqBinding and have set the address to a local TRANSACTIONAL private queue with the same name as my service application (check &lt;a href="http://thedotnethub.blogspot.com/2010/07/wcf-netmsmqbinding-on-iis-7.html"&gt;this post on how to set up WCF-MSMQ application on IIS 7&lt;/a&gt;). In this example, both the client and the service are hosted on the same machine so only the private queue will be used.&lt;br /&gt;&lt;br /&gt;Now on to the binding configuration:&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;exactlyOnce: when set to true means that transaction is enabled and the queue must be marked as “Transactional” on creation. This means that each message is guaranteed to be delivered one and only one time and a batch of messages are delivered in order.&lt;/li&gt;&lt;li&gt;durable: indicates that messages are never lost. Messages are persisted to the disk so if the MSMQ service is restarted messages are preserved.&lt;/li&gt;&lt;li&gt;receiveRetryCount: this setting indicates how many times the service will try to receive and process the message&lt;/li&gt;&lt;li&gt;retryCycleDelay: specifies the time between retry counts. For example if receiveRetryCount is set to 2 and retryCycleDelay is set to 20 seconds, then the service will try to receive and process the message total of 2 times within an interval of 20 seconds between each try.&lt;/li&gt;&lt;li&gt;maxRetryCycles: the number of cycles the retryCycleDelay and receiveRetryCount are run. For example if maxRetryCycles is set to 2, receiveRetryCount is set to 2, and retryCycleDelay is set to 20 seconds then the service will try to receive and process the message 2 times within and interval of 20 seconds and the whole cycle will be repeated 2 times.&lt;/li&gt;&lt;li&gt;timeToLive: Indicates the maximum amount of time a message can live in the queue waiting to be delivered to the service. This value supersedes all retry logic; if the TTL is less that the total time the cycle is configured to process then the cycle terminates once the TTL is reached . The default value is 1 day.&lt;/li&gt;&lt;/ul&gt;So what happens if the cycle fails? One of two things depending on the reason of failure:&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;If the failure is caused by the fact that the message cannot be delivered to the service, then the message will be placed in a transactional dead-letter queue. Setting deadLetterQueue specifies that the system dead letter queue will be used. A better idea would be to use a custom dead letter queue in order not to mix messages from different services in the same system dead letter queue. This is done by selecting “Custom” value for the deadLetterQueue setting and then specifying the name of this custom queue using setting customDeadLetterQueue.&lt;/li&gt;&lt;li&gt;If the message is delivered to the service but the transaction fails while processing, then the message will be considered “poisoned” and setting receiveErrorHandling specifies what to do with the message. “Move” means putting the message in a special automatically created queue called “poison”. Other values for the receiveErrorHandling are:&lt;/li&gt;&lt;ul&gt;&lt;li&gt;Fault: sends a fault to the listener that caused the ServiceHost to fault. The message must be removed from the application queue by some external mechanism before the application can continue to process messages from the queue&lt;/li&gt;&lt;li&gt;Drop: drops the poison message and the message is never delivered to the application&lt;/li&gt;&lt;li&gt;Reject: MSMQ will send a negative acknowledgement back to the sending queue that the application cannot receive the message. The message is placed in the sending queue dead-letter queue.&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt;So all in all I have configured my service to try to receive and process the message 1 time, wait 20 seconds and try to receive again. This ends the 1 cycle I have configured. If after this the message still cannot be received or processed then I want to either store my message in the system dead letter queue or store it in a poison queue depending on the reason of failure (error in delivery or error in processing – respectively).&lt;br /&gt;&lt;br /&gt;In my operation code now you will understand why I did manually roll back my transaction. I am simulating the required conditions to fail message processing and placing the message in the poison queue.&lt;br /&gt;&lt;br /&gt;Now create a console client application and add a service reference to the service. Then use the below code to invoke the service:&lt;br /&gt;&lt;br /&gt;&lt;em&gt;using (TransactionScope sc = new TransactionScope(TransactionScopeOption.Required))&lt;br /&gt;{&lt;br /&gt;proxy.GetData(1);&lt;br /&gt;sc.Complete();&lt;br /&gt;}&lt;/em&gt;&lt;br /&gt;I am enlisting the client in a transaction and I send the message to the private queue. It is important to note that the transactions enlisted at the client and the service are not related. The client transaction ends once the message is delivered to the queue; then the service transaction is in play trying to deliver the message from the queue to the service.&lt;br /&gt;&lt;br /&gt;Run the example and examine the complete process:&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;First&lt;/strong&gt;: The client sends a message to the private queue. DTC is used internally to accomplish this. You can see the stats of the DTC by examining the Local DTC Transaction Statistics from the Component Services on Windows 7. See below:&lt;br /&gt;&lt;a href="http://4.bp.blogspot.com/_oG_VVyp2tR4/TN_RIO6WqPI/AAAAAAAAAG4/DxhWAN-_b8E/s1600/MSMQ1.jpg"&gt;&lt;img style="WIDTH: 400px; HEIGHT: 281px; CURSOR: hand" id="BLOGGER_PHOTO_ID_5539376006061009138" border="0" alt="" src="http://4.bp.blogspot.com/_oG_VVyp2tR4/TN_RIO6WqPI/AAAAAAAAAG4/DxhWAN-_b8E/s400/MSMQ1.jpg" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;The client transaction ends here. If the transaction fails sending the message to the queue, the client will be notified and the transaction will roll back. This will be most helpful when the client is sending a group of messages to the queue and it’s important for all the messages to be either delivered as a batch or none is delivered.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Second&lt;/strong&gt;, the service picks the message from the main queue. The below image shows when the message first arrives at the queue:&lt;br /&gt;&lt;a href="http://1.bp.blogspot.com/_oG_VVyp2tR4/TN_RQpqZtiI/AAAAAAAAAHA/1YfhEfaPxlM/s1600/MSMQ2.jpg"&gt;&lt;img style="WIDTH: 400px; HEIGHT: 179px; CURSOR: hand" id="BLOGGER_PHOTO_ID_5539376150680811042" border="0" alt="" src="http://1.bp.blogspot.com/_oG_VVyp2tR4/TN_RQpqZtiI/AAAAAAAAAHA/1YfhEfaPxlM/s400/MSMQ2.jpg" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;The WCF service operation starts executing and then the transaction is rolled back. The message is placed back in the retry queue as shown below:&lt;br /&gt;&lt;a href="http://4.bp.blogspot.com/_oG_VVyp2tR4/TN_SALYG1_I/AAAAAAAAAHo/s-SoOBy6nj8/s1600/MSMQ3.jpg"&gt;&lt;img style="WIDTH: 400px; HEIGHT: 180px; CURSOR: hand" id="BLOGGER_PHOTO_ID_5539376967184734194" border="0" alt="" src="http://4.bp.blogspot.com/_oG_VVyp2tR4/TN_SALYG1_I/AAAAAAAAAHo/s-SoOBy6nj8/s400/MSMQ3.jpg" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;After 20 seconds the message is delivered again to the WCF service; yet the transaction is rolled back again. This time the message is placed in the poison queue for good as shown below:&lt;br /&gt;&lt;a href="http://3.bp.blogspot.com/_oG_VVyp2tR4/TN_SHKZ1VfI/AAAAAAAAAHw/zDt-ksN-af0/s1600/MSMQ4.jpg"&gt;&lt;img style="WIDTH: 400px; HEIGHT: 179px; CURSOR: hand" id="BLOGGER_PHOTO_ID_5539377087182624242" border="0" alt="" src="http://3.bp.blogspot.com/_oG_VVyp2tR4/TN_SHKZ1VfI/AAAAAAAAAHw/zDt-ksN-af0/s400/MSMQ4.jpg" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;What happens for messages placed in the dead-letter queue or the poison queue? Custom application logic must be written to compensate these messages and do “something” about them.&lt;br /&gt;Note that messages would have ended in the Transactional Dead-letter system queue had the message been failed to be delivered as opposed to fail during processing. The system queue is shown below:&lt;br /&gt;&lt;a href="http://1.bp.blogspot.com/_oG_VVyp2tR4/TN_SOtgZqSI/AAAAAAAAAH4/Eia2-l5552A/s1600/MSMQ5.jpg"&gt;&lt;img style="WIDTH: 256px; HEIGHT: 235px; CURSOR: hand" id="BLOGGER_PHOTO_ID_5539377216864495906" border="0" alt="" src="http://1.bp.blogspot.com/_oG_VVyp2tR4/TN_SOtgZqSI/AAAAAAAAAH4/Eia2-l5552A/s400/MSMQ5.jpg" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;What will happen in case of Public/Private queues?&lt;/h2&gt;Part 2 of this series will show the structure where the client and service are on separate machines (also MSMQ will be on a Windows Server Cluster…). But in a nutshell, in this case the following will happen:&lt;br /&gt;&lt;a href="http://1.bp.blogspot.com/_oG_VVyp2tR4/TN_SUen652I/AAAAAAAAAIA/71C4DUlrQV8/s1600/MSMQ6.jpg"&gt;&lt;img style="WIDTH: 400px; HEIGHT: 146px; CURSOR: hand" id="BLOGGER_PHOTO_ID_5539377315948717922" border="0" alt="" src="http://1.bp.blogspot.com/_oG_VVyp2tR4/TN_SUen652I/AAAAAAAAAIA/71C4DUlrQV8/s400/MSMQ6.jpg" /&gt;&lt;/a&gt;&lt;br /&gt;The client WCF endpoint will be configured to send the message to the destination queue on the service machine (actually in case of MSMQ cluster it will send to a virtual IP, but this is a separate issue to be discussed in part 2), however, since the service is on another machine then the client application will silently deliver the message to an automatically created private outgoing queue. This queue will then try to deliver the message to the real destination queue.&lt;br /&gt;&lt;br /&gt;The client will engage in one DTC transaction to deliver the message to the temp outgoing queue. The service will then be engaged in a separate DTC transaction to retrieve the message from the destination queue.&lt;br /&gt;&lt;br /&gt;The same retry rules and poison/dead-letter message discussions mentioned above still apply.&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;But isn’t DTC heavy on Performance? Do I really need it?&lt;/h2&gt;Sure! And it depends.&lt;br /&gt;&lt;br /&gt;Again if you follow the link (at the start) of my transactions article, you know that DTC implements a two-phase commit protocol and that definitely has a performance hit. However, whether you can live with or without transactions is governed by the scenario.&lt;br /&gt;&lt;br /&gt;Let’s start with the obvious: in the scenario I presented above DTC is not required! The client needed the transactions “only” to commit sending messages to the queue. The service also needed the transaction “only” to commit receiving messages from the queue. So why did the DTC kick in? Simply because – as of this writing – it seems that the netMsmqBinding is configured to use DTC and there seems to be no way of changing that. But I do need transactions you might say, only not DTC; so what is the alternative? The answer would be MSMQ Internal Transactions. This is a light weight transaction implemented internally for MSMQ that does not need DTC. However, this seems to be not supported when using WCF netMsmqbinding; the only way you can use it is to use the System.Messaging APIs to send and receive from MSMQ.&lt;br /&gt;&lt;br /&gt;To use the Internal Transaction you would use classes MessageQueue and MessageQueueTransaction from the System.Messaging API to send and receive messages within a transaction.&lt;br /&gt;&lt;br /&gt;So why would I bother going for DTC (and netMsmqBinding) when I can go with internal transactions? Well because netMsmqBinding rocks…just kidding! Consider this scenario: when you receive the message at the service you want to use it to perform an update on a SQL server DB. If the update fails however, you want to place the message back in the queue so that you can fix the problem and retry again. Meaning that you want to enlist the receiving of the message and the DB update in a single atomic transaction: either all succeeds or the transaction rolls back and the message is back safe in the queue. In this case DTC is a must because the transaction is spanning two resource managers (again for more details see link at the start).&lt;br /&gt;&lt;br /&gt;Note: I could not find any official say from MS that the netMsmqBinding does not support MSMQ internal transactions. I rather tested it myself and it did work.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4918396109946207501-6684755904480343055?l=thedotnethub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thedotnethub.blogspot.com/feeds/6684755904480343055/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thedotnethub.blogspot.com/2010/11/wcf-msmq-transactions-explained-part1.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/6684755904480343055'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/6684755904480343055'/><link rel='alternate' type='text/html' href='http://thedotnethub.blogspot.com/2010/11/wcf-msmq-transactions-explained-part1.html' title='WCF MSMQ Transactions Explained – Part1'/><author><name>mohamad halabi</name><uri>http://www.blogger.com/profile/10259946099831243955</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_oG_VVyp2tR4/TN_RIO6WqPI/AAAAAAAAAG4/DxhWAN-_b8E/s72-c/MSMQ1.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4918396109946207501.post-1744082151785325126</id><published>2010-11-08T21:54:00.004+03:00</published><updated>2010-11-08T21:58:08.949+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Microsoft Open Doors'/><category scheme='http://www.blogger.com/atom/ns#' term='Devlifestyle'/><category scheme='http://www.blogger.com/atom/ns#' term='Azure'/><title type='text'>Download Microsoft Open Door Azure Session materials</title><content type='html'>I had a great time presenting about Windows Azure in Microsoft Open Door conference held in Riyadh and Jeddah.&lt;br /&gt;Slides and Demos can be downloaded from Devlifestyle website:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.devlifestyle.net/blogs/articles/archive/2010/11/08/ms-open-door-azure-session-materials.aspx"&gt;http://www.devlifestyle.net/blogs/articles/archive/2010/11/08/ms-open-door-azure-session-materials.aspx&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4918396109946207501-1744082151785325126?l=thedotnethub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thedotnethub.blogspot.com/feeds/1744082151785325126/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thedotnethub.blogspot.com/2010/11/download-microsoft-open-door-azure.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/1744082151785325126'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/1744082151785325126'/><link rel='alternate' type='text/html' href='http://thedotnethub.blogspot.com/2010/11/download-microsoft-open-door-azure.html' title='Download Microsoft Open Door Azure Session materials'/><author><name>mohamad halabi</name><uri>http://www.blogger.com/profile/10259946099831243955</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4918396109946207501.post-3300864001673115749</id><published>2010-10-26T12:23:00.005+03:00</published><updated>2010-10-26T13:16:48.903+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Oracle Client'/><title type='text'>Installing Oracle Client on Windows Server 2008 R2 x64</title><content type='html'>i had previously installed Oracle client 10g on win 2003 machine to connect to my Oracle db from my .NET app.&lt;br /&gt;&lt;br /&gt;this time i wanted to do the same from my Win Server 2008 R2 x64 machine...&lt;br /&gt;for 64 bit machines Oracle has released a 11g 64 bit client which you can get from here:&lt;br /&gt;http://www.oracle.com/technetwork/database/enterprise-edition/downloads/112010-win64soft-094461.html&lt;br /&gt;(win64_11gR2_client.zip).&lt;br /&gt;&lt;br /&gt;Run the installation and select the first item (Oracle instance client):&lt;br /&gt;&lt;a href="http://3.bp.blogspot.com/_oG_VVyp2tR4/TMalRiWoMCI/AAAAAAAAAGw/bZdyCdbPnvQ/s1600/ora1.JPG"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 400px; height: 186px;" src="http://3.bp.blogspot.com/_oG_VVyp2tR4/TMalRiWoMCI/AAAAAAAAAGw/bZdyCdbPnvQ/s400/ora1.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5532290912969306146" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Continue the installation...it will finish in no time.&lt;br /&gt;&lt;br /&gt;However, after installation there was no tnsnames.ora and sqlnet.ora files...and there was no Network and Admin folders. In all previous installations these were the folders/files i deal with to set my settings and service names.&lt;br /&gt;&lt;br /&gt;What i did next was wierd but worked! i manually created folder Network and inside it created folder Admin...the full path was:&lt;br /&gt;C:\app\username\product\11.2.0\client_1\Network\Admin&lt;br /&gt;And i created the tnsnames.ora and sqlnet.ora inside the above path.&lt;br /&gt;That did the trick.&lt;br /&gt;&lt;br /&gt;Before that...&lt;br /&gt;&lt;br /&gt;If you are going to invoke Oracle client from a .NET application like me, you will get an error that says:&lt;br /&gt;"Attempt to load Oracle client libraries threw BadImageFormatException.  This problem will occur when running in 64 bit mode with the 32 bit Oracle client components installed."&lt;br /&gt;if your application process is targetting 32-bit. &lt;br /&gt;&lt;br /&gt;if you are using a console application, go to project properties --&gt; advanced compilation options and change the target cpu to x64.&lt;br /&gt;From IIS 7 make sure that the setting for the application pool accessing Oracle has "Enable 32 bit applications" set to false.&lt;br /&gt;&lt;br /&gt;PS: i read that its an IIS 7 best practice to keep 32-bit processes (pools) working on x64 machines. so the above step might incur performance overhead. my next attempt will be to install Oracle client 32-bit on my x64 machine and see if that works...&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4918396109946207501-3300864001673115749?l=thedotnethub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thedotnethub.blogspot.com/feeds/3300864001673115749/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thedotnethub.blogspot.com/2010/10/installing-oracle-client-on-windows.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/3300864001673115749'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/3300864001673115749'/><link rel='alternate' type='text/html' href='http://thedotnethub.blogspot.com/2010/10/installing-oracle-client-on-windows.html' title='Installing Oracle Client on Windows Server 2008 R2 x64'/><author><name>mohamad halabi</name><uri>http://www.blogger.com/profile/10259946099831243955</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_oG_VVyp2tR4/TMalRiWoMCI/AAAAAAAAAGw/bZdyCdbPnvQ/s72-c/ora1.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4918396109946207501.post-7646698039232189104</id><published>2010-10-22T10:11:00.000+03:00</published><updated>2010-10-22T10:12:47.663+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Microsoft'/><title type='text'>Share your Opinions/Feedbacks with Microsoft!</title><content type='html'>"&lt;em&gt;Microsoft regularly conducts surveys for customers and partners to ask for your open and honest feedback (what we did right or wrong last 6 months). And we’re very much thankful for those who sharing the feedback...&lt;/em&gt;"&lt;br /&gt;&lt;br /&gt;&lt;a href="http://blogs.technet.com/b/renatmin/archive/2010/10/19/3362771.aspx"&gt;Click here!&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4918396109946207501-7646698039232189104?l=thedotnethub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thedotnethub.blogspot.com/feeds/7646698039232189104/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thedotnethub.blogspot.com/2010/10/share-your-opinionsfeedbacks-with.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/7646698039232189104'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/7646698039232189104'/><link rel='alternate' type='text/html' href='http://thedotnethub.blogspot.com/2010/10/share-your-opinionsfeedbacks-with.html' title='Share your Opinions/Feedbacks with Microsoft!'/><author><name>mohamad halabi</name><uri>http://www.blogger.com/profile/10259946099831243955</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4918396109946207501.post-6056346658010838705</id><published>2010-10-06T23:50:00.002+03:00</published><updated>2010-10-06T23:52:13.695+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ROCS'/><title type='text'>Riyadh Online Community Summit Invitation</title><content type='html'>Riyadh Online Community Summit will be the first mega online event featuring MVPs and community leads from many regions. For more details and registration please check the below link:&lt;br /&gt;&lt;br /&gt;http://rocs1.eventbrite.com&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4918396109946207501-6056346658010838705?l=thedotnethub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thedotnethub.blogspot.com/feeds/6056346658010838705/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thedotnethub.blogspot.com/2010/10/riyadh-online-community-summit.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/6056346658010838705'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/6056346658010838705'/><link rel='alternate' type='text/html' href='http://thedotnethub.blogspot.com/2010/10/riyadh-online-community-summit.html' title='Riyadh Online Community Summit Invitation'/><author><name>mohamad halabi</name><uri>http://www.blogger.com/profile/10259946099831243955</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4918396109946207501.post-6457621856424329518</id><published>2010-10-06T02:07:00.002+03:00</published><updated>2010-10-06T02:08:48.123+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Microsoft Open Doors'/><title type='text'>Microsoft Open Doors</title><content type='html'>Microsoft Open Doors (KSA) is around the corner. The event will take place in Riyadh and Jeddah and I will be talking about Windows Azure in both events. Fun stuf!&lt;br /&gt;&lt;br /&gt;http://www.microsoft.com/saudi/about/opendoor/&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4918396109946207501-6457621856424329518?l=thedotnethub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thedotnethub.blogspot.com/feeds/6457621856424329518/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thedotnethub.blogspot.com/2010/10/microsoft-open-doors.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/6457621856424329518'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/6457621856424329518'/><link rel='alternate' type='text/html' href='http://thedotnethub.blogspot.com/2010/10/microsoft-open-doors.html' title='Microsoft Open Doors'/><author><name>mohamad halabi</name><uri>http://www.blogger.com/profile/10259946099831243955</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4918396109946207501.post-3500127253671935364</id><published>2010-09-30T00:48:00.002+03:00</published><updated>2010-09-30T00:54:49.077+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ROCS'/><title type='text'>What is ROCS?</title><content type='html'>We are preparing for a mega ONLINE event in Riyadh...hence ROCS (Riyadh Online Community Summit). The summit will feature MVPs and Community Leads from many regions in the world and the discussions will cover a wide array of topics ranging from client to mobile programming, database development and administration, all the way to collaboration and systems integration.&lt;br /&gt;&lt;br /&gt;The event will be on October 21 and 22 and you can watch it live from anywhere. The event details and participation link will be published soon.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4918396109946207501-3500127253671935364?l=thedotnethub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thedotnethub.blogspot.com/feeds/3500127253671935364/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thedotnethub.blogspot.com/2010/09/what-is-rocs.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/3500127253671935364'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/3500127253671935364'/><link rel='alternate' type='text/html' href='http://thedotnethub.blogspot.com/2010/09/what-is-rocs.html' title='What is ROCS?'/><author><name>mohamad halabi</name><uri>http://www.blogger.com/profile/10259946099831243955</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4918396109946207501.post-584414672113748903</id><published>2010-09-06T22:32:00.002+03:00</published><updated>2010-09-06T22:37:12.783+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Windows Server AppFabric'/><category scheme='http://www.blogger.com/atom/ns#' term='Workflow Services'/><category scheme='http://www.blogger.com/atom/ns#' term='WF 4.0'/><category scheme='http://www.blogger.com/atom/ns#' term='WCF'/><title type='text'>Managing Workflow Services with Windows Server AppFabric</title><content type='html'>Recently I started a series of posts tackling WF 4 Services development. Those posts used self hosting for all the examples. This post tackles the super cool AppFabric extensions that makes hosting WF Services in IIS a delightful experience.&lt;br /&gt;&lt;br /&gt;Read full article &lt;a href ="http://www.codeproject.com/KB/WF/WinSrvAppFabric.aspx"&gt;HERE&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4918396109946207501-584414672113748903?l=thedotnethub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thedotnethub.blogspot.com/feeds/584414672113748903/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thedotnethub.blogspot.com/2010/09/managing-workflow-services-with-windows.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/584414672113748903'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/584414672113748903'/><link rel='alternate' type='text/html' href='http://thedotnethub.blogspot.com/2010/09/managing-workflow-services-with-windows.html' title='Managing Workflow Services with Windows Server AppFabric'/><author><name>mohamad halabi</name><uri>http://www.blogger.com/profile/10259946099831243955</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4918396109946207501.post-4833693227179107217</id><published>2010-08-21T23:54:00.002+03:00</published><updated>2010-08-21T23:57:39.212+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='WF 4.0'/><category scheme='http://www.blogger.com/atom/ns#' term='WCF'/><title type='text'>WF 4 Persistence, Tracking, and Bookmarks: Practical Approach</title><content type='html'>Shows practical examples about WF 4 persistence, tracking, and bookmarks.&lt;br /&gt;See full article &lt;a href="http://www.codeproject.com/KB/WF/WF4Extensions.aspx"&gt;HERE&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4918396109946207501-4833693227179107217?l=thedotnethub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thedotnethub.blogspot.com/feeds/4833693227179107217/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thedotnethub.blogspot.com/2010/08/wf-4-persistence-tracking-and-bookmarks.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/4833693227179107217'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/4833693227179107217'/><link rel='alternate' type='text/html' href='http://thedotnethub.blogspot.com/2010/08/wf-4-persistence-tracking-and-bookmarks.html' title='WF 4 Persistence, Tracking, and Bookmarks: Practical Approach'/><author><name>mohamad halabi</name><uri>http://www.blogger.com/profile/10259946099831243955</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4918396109946207501.post-6095794053833336984</id><published>2010-07-06T15:09:00.008+03:00</published><updated>2010-07-06T15:30:46.599+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='WF 4.0'/><category scheme='http://www.blogger.com/atom/ns#' term='WCF'/><title type='text'>WF 4.0 WorkflowServiceHost Custom Tracking</title><content type='html'>In previous two-part post (&lt;a href="http://thedotnethub.blogspot.com/2010/07/wf-40-workflowservicehost-persistence.html"&gt;here &lt;/a&gt;and &lt;a href="http://thedotnethub.blogspot.com/2010/07/wf-40-workflowservicehost-persistence_03.html"&gt;here&lt;/a&gt;) I showed how to add persistence to a workflow hosted via the WorkflowServiceHost. In this post I will do some modifications on the same example to add tracking support. Now since I am a good guy and would like to make your lives easier, I will repost the full code here instead of pointing out only the differences. Let’s roll…&lt;br /&gt;&lt;br /&gt;Below is our simple workflow (Workflow1.xaml) (use Workflow Console Application template from VS 2010):&lt;br /&gt;&lt;br /&gt;&lt;a href="http://2.bp.blogspot.com/_oG_VVyp2tR4/TDMda3QByoI/AAAAAAAAAGY/f-MTqzxAmik/s1600/1.JPG"&gt;&lt;img style="WIDTH: 400px; HEIGHT: 301px; CURSOR: hand" id="BLOGGER_PHOTO_ID_5490764718039747202" border="0" alt="" src="http://2.bp.blogspot.com/_oG_VVyp2tR4/TDMda3QByoI/AAAAAAAAAGY/f-MTqzxAmik/s400/1.JPG" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;It receives a request from a client application, using a custom activity it retrieves the workflow instance id and returns it as a response to the client. Finally a delay shape delays execution for 30 seconds.&lt;br /&gt;&lt;br /&gt;Below is the code for the custom activity:&lt;br /&gt;&lt;br /&gt;&lt;div style="BORDER-BOTTOM: blue 1px solid; BORDER-LEFT: blue 1px solid; WIDTH: 100%; HEIGHT: 100%; BORDER-TOP: blue 1px solid; BORDER-RIGHT: blue 1px solid;font-size:8pt"&gt;&lt;br /&gt;public sealed class CodeActivity1 : CodeActivity&lt;br /&gt;{&lt;br /&gt;public OutArgument&lt;guid&gt; WFInstanceId { get; set; }&lt;br /&gt;&lt;br /&gt;protected override void Execute(CodeActivityContext context)&lt;br /&gt;{&lt;br /&gt;context.SetValue(WFInstanceId, context.WorkflowInstanceId);&lt;br /&gt;&lt;br /&gt;CustomTrackingRecord customRecord = new CustomTrackingRecord("CustomInfo")&lt;br /&gt;{&lt;br /&gt;Data =&lt;br /&gt;{&lt;br /&gt;{"Date", DateTime.Now.ToShortDateString()},&lt;br /&gt;}&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;context.Track(customRecord);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;The custom activity returns the workflow instance id and creates a new CustomTrackingRecord. CustomTrackingRecords are any custom information you want to be able to track. In this simple example I am tracking a custom variable which stores the current date…more on this in a moment.&lt;br /&gt;&lt;br /&gt;Below is the code from the Program.cs file needed to set up the host and tracking:&lt;br /&gt;&lt;br /&gt;&lt;div style="BORDER-BOTTOM: blue 1px solid; BORDER-LEFT: blue 1px solid; WIDTH: 100%; HEIGHT: 100%; BORDER-TOP: blue 1px solid; BORDER-RIGHT: blue 1px solid;font-size:8pt"&gt;&lt;br /&gt;class Program&lt;br /&gt;{&lt;br /&gt;static void Main(string[] args)&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;string baseAddress = "http://localhost:8089/TestWF";&lt;br /&gt;&lt;br /&gt;using (WorkflowServiceHost host =&lt;br /&gt;new WorkflowServiceHost(new Workflow1(), new Uri(baseAddress)))&lt;br /&gt;{&lt;br /&gt;host.Description.Behaviors.Add(new&lt;br /&gt;ServiceMetadataBehavior() { HttpGetEnabled = true });&lt;br /&gt;&lt;br /&gt;host.AddServiceEndpoint("IService",new BasicHttpBinding(), baseAddress);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;TrackingProfile fileTrackingProfile = new TrackingProfile();&lt;br /&gt;fileTrackingProfile.Queries.Add(new WorkflowInstanceQuery&lt;br /&gt;{&lt;br /&gt;States = { "*" }&lt;br /&gt;});&lt;br /&gt;fileTrackingProfile.Queries.Add(new ActivityStateQuery()&lt;br /&gt;{&lt;br /&gt;ActivityName = "*",&lt;br /&gt;States = { "*" },&lt;br /&gt;// You can use the following to specify specific stages:&lt;br /&gt;// States = {&lt;br /&gt;// ActivityStates.Executing,&lt;br /&gt;// ActivityStates.Closed&lt;br /&gt;//},&lt;br /&gt;Variables =&lt;br /&gt;{&lt;br /&gt;{ "*" }&lt;br /&gt;} // or you can enter specific variable names instead of “*”&lt;br /&gt;&lt;br /&gt;});&lt;br /&gt;fileTrackingProfile.Queries.Add(new CustomTrackingQuery()&lt;br /&gt;{&lt;br /&gt;ActivityName = "*",&lt;br /&gt;Name = "*"&lt;br /&gt;});&lt;br /&gt;&lt;br /&gt;FileTrackingParticipant fileTrackingParticipant =&lt;br /&gt;new FileTrackingParticipant();&lt;br /&gt;fileTrackingParticipant.TrackingProfile = fileTrackingProfile;&lt;br /&gt;host.WorkflowExtensions.Add(fileTrackingParticipant);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;host.Description.Behaviors.Add(new WorkflowIdleBehavior()&lt;br /&gt;{&lt;br /&gt;TimeToPersist = TimeSpan.FromSeconds(5),&lt;br /&gt;TimeToUnload = TimeSpan.FromSeconds(20)&lt;br /&gt;});&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;host.Open();&lt;br /&gt;Console.WriteLine("Car rental service listening at: " +&lt;br /&gt;baseAddress);&lt;br /&gt;Console.WriteLine("Press ENTER to exit");&lt;br /&gt;Console.ReadLine();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;public class FileTrackingParticipant : TrackingParticipant&lt;br /&gt;{&lt;br /&gt;string fileName;&lt;br /&gt;protected override void Track(TrackingRecord record,&lt;br /&gt;TimeSpan timeout)&lt;br /&gt;{&lt;br /&gt;fileName = @"c:\tracking\" + record.InstanceId + ".tracking";&lt;br /&gt;using (StreamWriter sw = File.AppendText(fileName))&lt;br /&gt;{&lt;br /&gt;WorkflowInstanceRecord workflowInstanceRecord = record as WorkflowInstanceRecord;&lt;br /&gt;if (workflowInstanceRecord != null)&lt;br /&gt;{&lt;br /&gt;sw.WriteLine("------WorkflowInstanceRecord------");&lt;br /&gt;sw.WriteLine("Workflow InstanceID: {0} Workflow instance state: {1}",&lt;br /&gt;record.InstanceId, workflowInstanceRecord.State);&lt;br /&gt;sw.WriteLine("\n");&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;ActivityStateRecord activityStateRecord = record as ActivityStateRecord;&lt;br /&gt;if (activityStateRecord != null)&lt;br /&gt;{&lt;br /&gt;IDictionary&lt;string,&gt; variables = activityStateRecord.Variables;&lt;br /&gt;StringBuilder vars = new StringBuilder();&lt;br /&gt;&lt;br /&gt;if (variables.Count &gt; 0)&lt;br /&gt;{&lt;br /&gt;vars.AppendLine("\n\tVariables:");&lt;br /&gt;foreach (KeyValuePair&lt;string,&gt; variable in variables)&lt;br /&gt;{&lt;br /&gt;vars.AppendLine(String.Format(&lt;br /&gt;"\t\tName: {0} Value: {1}", variable.Key, variable.Value));&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;sw.WriteLine("------ActivityStateRecord------");&lt;br /&gt;sw.WriteLine("Activity DisplayName: {0} :ActivityInstanceState: {1} {2}",&lt;br /&gt;activityStateRecord.Activity.Name, activityStateRecord.State,&lt;br /&gt;((variables.Count &gt; 0) ? vars.ToString() : String.Empty));&lt;br /&gt;sw.WriteLine("\n");&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;CustomTrackingRecord customTrackingRecord = record as CustomTrackingRecord;&lt;br /&gt;if ((customTrackingRecord != null) &amp;amp;&amp;amp; (customTrackingRecord.Data.Count &gt; 0))&lt;br /&gt;{&lt;br /&gt;sw.WriteLine("------CustomTrackingRecord------");&lt;br /&gt;sw.WriteLine("\n\tUser Data:");&lt;br /&gt;foreach (string data in customTrackingRecord.Data.Keys)&lt;br /&gt;{&lt;br /&gt;sw.WriteLine(" \t\t {0} : {1}", data, customTrackingRecord.Data[data]);&lt;br /&gt;}&lt;br /&gt;sw.WriteLine("\n");&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;So let me explain what’s going on: in a nutshell, when you deal with WF 4.0 tracking you have to understand three concepts:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Tracking records: these are the information records emitted by your workflow. There are four derived classes that correspond to the four types of tracking records:&lt;/li&gt;&lt;ul&gt;&lt;li&gt;WorkflowInstanceQuery: events about workflow instance state. For example started, suspended, unloaded, etc...&lt;/li&gt;&lt;li&gt;ActivityStateQuery: events about activities inside the WF&lt;/li&gt;&lt;li&gt;CustomTrackingQuery: any custom information you want to track&lt;/li&gt;&lt;li&gt;BookmarkResumptionQuery: bookmark name you want to track whenever this bookmark is resumed (I won’t cover bookmarks in this post to keep the concept clear, but I will have another dedicated post for this topic)&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;Tracking profiles: act like filters over tracking records in order to track only required information&lt;/li&gt;&lt;li&gt;Tracking participants: the medium where tracking information will be written to. WF 4.0 comes with one participant which writes to ETW (event tracking for windows). Custom participants can be easily developed to write tracking data into SQL Server for example, or like I did in this example into the File System&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;In my code, I create an instance of class TrackingProfile and added three types of records: WorkflowInstanceQuery, ActivityStateQuery, and CustomTrackingQuery.&lt;br /&gt;&lt;br /&gt;For the WorkflowInstanceQuery I asked the profile to track all workflow states using the “*” operator. I could also limit the number of states that I want to track (check commented code). Recall that in my workflow I have states of persist and unload (review behavior configuration and delay timespan) so you will see these states in he tracked data. For the ActivityStateQuery I asked the profile to track all states for all activities as well as any variables declared for these activities. Similarly for the CustomTrackingQuery I asked the profile to track any custom data I defined (recall that I did define custom data in my custom activity).&lt;br /&gt;&lt;br /&gt;Now that I have defined the tracking records as well as the tracking profile; final step is to define the tracking participant. I could have used the out of the box EtwTrackingParticipant class which writes to ETW, but to make things more interesting, I have created a custom tracking participant class (FileTrackingParticipant) which derives from TrackingParticipant. Check the code for that class which simply gets the information for each of the tracked records and writes it into a file.&lt;br /&gt;&lt;br /&gt;Back to the main program, I associate my tracking profile (fileTrackingProfile) with my tracking participant (fileTrackingParticipant) and finally add the participant to the set of the host WorkflowExtensions.&lt;br /&gt;&lt;br /&gt;To make sure you will have a running program, below is the trivial client program code:&lt;br /&gt;&lt;div style="BORDER-BOTTOM: blue 1px solid; BORDER-LEFT: blue 1px solid; WIDTH: 100%; HEIGHT: 100%; BORDER-TOP: blue 1px solid; BORDER-RIGHT: blue 1px solid;font-size:8pt"&gt;&lt;br /&gt;ServiceReference1.ServiceClient proxy = new ServiceReference1.ServiceClient();&lt;br /&gt;&lt;br /&gt;            Guid workflowId = (Guid)proxy.Operation1();&lt;br /&gt;&lt;br /&gt;            &lt;br /&gt;Console.WriteLine("client done");&lt;br /&gt;            Console.WriteLine("enter key");&lt;br /&gt;            Console.ReadLine();&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Run the service so that it is listening to requests on “http://localhost:8089/TestWF“, now run the client console and wait until the service console window prints “Workflow Ended”. Now examine the file where tracking is written and you will see workflow events, activity events, variables, and custom information all tracked…see the below image (reformatted for presentation):&lt;br /&gt;&lt;br /&gt;&lt;a href="http://4.bp.blogspot.com/_oG_VVyp2tR4/TDMgNHoOLKI/AAAAAAAAAGg/FMEP9DfYOa4/s1600/2.JPG"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 400px; height: 301px;" src="http://4.bp.blogspot.com/_oG_VVyp2tR4/TDMgNHoOLKI/AAAAAAAAAGg/FMEP9DfYOa4/s400/2.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5490767780452904098" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4918396109946207501-6095794053833336984?l=thedotnethub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thedotnethub.blogspot.com/feeds/6095794053833336984/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thedotnethub.blogspot.com/2010/07/wf-40-workflowservicehost-custom.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/6095794053833336984'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/6095794053833336984'/><link rel='alternate' type='text/html' href='http://thedotnethub.blogspot.com/2010/07/wf-40-workflowservicehost-custom.html' title='WF 4.0 WorkflowServiceHost Custom Tracking'/><author><name>mohamad halabi</name><uri>http://www.blogger.com/profile/10259946099831243955</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_oG_VVyp2tR4/TDMda3QByoI/AAAAAAAAAGY/f-MTqzxAmik/s72-c/1.JPG' height='72' width='72'/><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4918396109946207501.post-5155723238030535962</id><published>2010-07-03T14:14:00.009+03:00</published><updated>2010-07-03T15:14:37.646+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='WCF'/><title type='text'>WCF NetMSMQBinding on IIS 7</title><content type='html'>I had a previous post (&lt;a href="http://thedotnethub.blogspot.com/2009/03/wcf-queued-messaging.html"&gt;click here&lt;/a&gt;) about how to build a WCF queued messaging scenario. that example used self-hosted services. you can refer back to that post for all the details. in this post i will quickly show you how to get a WCF service with MSMQ binding hosted in IIS 7 up and running.&lt;br /&gt;&lt;br /&gt;Create a simple WCF web site, and add a simple operation as follows:&lt;br /&gt;&lt;br /&gt;&lt;div style="width:400px;height:200px;border-width:1px;border-color:blue;border-style:solid"&gt; &lt;br /&gt;[ServiceContract]&lt;br /&gt;public interface IService&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;    [OperationContract(IsOneWay=true)]&lt;br /&gt;    void GetData(int value);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;below is the service configuration:&lt;br /&gt;&lt;br /&gt;&lt;div style="width:800px;height:900px;border-width:1px;border-color:blue;border-style:solid"&gt; &lt;br /&gt;&amp;lt;system.serviceModel&amp;gt;&lt;br /&gt;&lt;br /&gt;    &amp;lt;services&amp;gt;&lt;br /&gt;      &amp;lt;service name=&amp;quot;Service&amp;quot; behaviorConfiguration=&amp;quot;ServiceBehavior&amp;quot;&amp;gt;&lt;br /&gt;        &amp;lt;host&amp;gt;&lt;br /&gt;          &amp;lt;baseAddresses&amp;gt;&lt;br /&gt;            &amp;lt;add baseAddress=&amp;quot;http://localhost/TestWCFMSMQ&amp;quot; /&amp;gt;&lt;br /&gt;          &amp;lt;/baseAddresses&amp;gt;&lt;br /&gt;        &amp;lt;/host&amp;gt;&lt;br /&gt;        &amp;lt;!-- Service Endpoints --&amp;gt;&lt;br /&gt;        &amp;lt;endpoint address=&lt;br /&gt;&amp;quot;net.msmq://localhost/private/TestWCFMSMQ/Service.svc&amp;quot; binding=&lt;br /&gt;&amp;quot;netMsmqBinding&amp;quot; &lt;br /&gt;contract=&amp;quot;IService&amp;quot; &lt;br /&gt;bindingConfiguration=&amp;quot;NoMsmqSecurity&amp;quot;/&amp;gt;&lt;br /&gt;        &amp;lt;endpoint address=&amp;quot;mex&amp;quot; &lt;br /&gt;binding=&amp;quot;mexHttpBinding&amp;quot; &lt;br /&gt;contract=&amp;quot;IMetadataExchange&amp;quot;/&amp;gt;&lt;br /&gt;      &amp;lt;/service&amp;gt;&lt;br /&gt;    &amp;lt;/services&amp;gt;&lt;br /&gt;&lt;br /&gt;    &amp;lt;bindings&amp;gt;&lt;br /&gt;      &amp;lt;netMsmqBinding&amp;gt;&lt;br /&gt;        &amp;lt;binding name=&amp;quot;NoMsmqSecurity&amp;quot;&amp;gt;&lt;br /&gt;          &amp;lt;security mode=&amp;quot;None&amp;quot; /&amp;gt;&lt;br /&gt;        &amp;lt;/binding&amp;gt;&lt;br /&gt;        &lt;br /&gt;      &amp;lt;/netMsmqBinding&amp;gt;&lt;br /&gt;    &amp;lt;/bindings&amp;gt;&lt;br /&gt;    &lt;br /&gt;    &amp;lt;behaviors&amp;gt;&lt;br /&gt;      &amp;lt;serviceBehaviors&amp;gt;&lt;br /&gt;        &amp;lt;behavior name=&amp;quot;ServiceBehavior&amp;quot;&amp;gt;&lt;br /&gt;          &lt;br /&gt;          &amp;lt;serviceMetadata httpGetEnabled=&amp;quot;true&amp;quot;/&amp;gt;&lt;br /&gt;          &amp;lt;serviceDebug includeExceptionDetailInFaults=&amp;quot;true&amp;quot;/&amp;gt;&lt;br /&gt;        &amp;lt;/behavior&amp;gt;&lt;br /&gt;      &amp;lt;/serviceBehaviors&amp;gt;&lt;br /&gt;    &amp;lt;/behaviors&amp;gt;&lt;br /&gt;    &amp;lt;serviceHostingEnvironment multipleSiteBindingsEnabled=&amp;quot;true&amp;quot; /&amp;gt;&lt;br /&gt;  &amp;lt;/system.serviceModel&amp;gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;This is a WCF services hosted on IIS, listening to a MSMQ endpoint through the net.msmq binding. also I have exposed the mex http endpoint to enable adding a service reference from the client application.&lt;br /&gt;&lt;br /&gt;next we need to enable the net.msmq binding on IIS 7 as its not enabled by default. on the web site hosting your service and on the service itself, go to configuration and add "net.msmq" to the list of bindings. by default it will only have "http".&lt;br /&gt;&lt;br /&gt;now lets turn our focus into MSMQ itself. turn on the MSMQ feature from the control panel. once you do you will be able to access it through right clicking on My Computer and clicking Manage. from there create a private queue called "TestWCFMSMQ/Service.svc" if you followed the same naming i used. else use "[yourvirtualdirectoryname]/[myservicefile].svc". i will explain later why this naming convention is important.&lt;br /&gt;next, give the application pool identity account sufficient priveleges on the queue created. this can simply be done by right click and properties on the queue itself.&lt;br /&gt;&lt;br /&gt;final step is to make sure the windows service "Net.Msmq Listener Adapter" is running. this is the service that checks for new messages in queues and notifies the WCF service about them. now for some reason that at the time of this post i do not yet know, this service failed to notice the messages in the queue unless the queue name is in the format i created above...will post an update once i know what's the catch here...&lt;br /&gt;&lt;br /&gt;oh,one more thing: when creating the private queue make sure to make it Transactional.&lt;br /&gt;&lt;br /&gt;now create a simple console application and add a service reference to the WCF service using the mex http endpoint. use the below code to invoke the service operation:&lt;br /&gt;&lt;br /&gt;&lt;div style="width:500px;height:300px;border-width:1px;border-color:blue;border-style:solid"&gt;&lt;br /&gt; ServiceReference1.ServiceClient proxy = new ServiceReference1.ServiceClient();&lt;br /&gt;            &lt;br /&gt;            using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))&lt;br /&gt;            {&lt;br /&gt;                proxy.GetData(12);&lt;br /&gt;                scope.Complete();&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;            Console.WriteLine("end");&lt;br /&gt;            Console.Read();&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;to see queuing in action. from IIS stop the WCF service. now run the client which drops a message in the private queue. open the queue and notice the message. now from IIS run the WCF application, wait for a couple of seconds and the message will be delivered to the service and disappear from the queue.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4918396109946207501-5155723238030535962?l=thedotnethub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thedotnethub.blogspot.com/feeds/5155723238030535962/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thedotnethub.blogspot.com/2010/07/wcf-netmsmqbinding-on-iis-7.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/5155723238030535962'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/5155723238030535962'/><link rel='alternate' type='text/html' href='http://thedotnethub.blogspot.com/2010/07/wcf-netmsmqbinding-on-iis-7.html' title='WCF NetMSMQBinding on IIS 7'/><author><name>mohamad halabi</name><uri>http://www.blogger.com/profile/10259946099831243955</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4918396109946207501.post-7324347343968144051</id><published>2010-07-03T10:20:00.004+03:00</published><updated>2010-07-03T10:28:09.254+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Workflow Services'/><category scheme='http://www.blogger.com/atom/ns#' term='WF 4.0'/><category scheme='http://www.blogger.com/atom/ns#' term='WCF'/><title type='text'>WF 4.0 WorkflowServiceHost Persistence – Part 2</title><content type='html'>In part 1 I configured the Persistence store for a WF 4.0 workflow services hosted by WorkflowServiceHost. I showed how the workflow is persisted just before sending a response to a client application and observed the persisted state in the database.&lt;br /&gt;&lt;br /&gt;In part 2 I will add a host behavior to persist the workflow based on an Idle time as opposed to before sending the response from the workflow itself, moreover I will also add a host behavior to unload the workflow after a specified time interval thus showing the difference between “just” persisting a workflow and unloading it from memory.&lt;br /&gt;&lt;br /&gt;Let’s start by unchecking (disabling) property PersistBeforeSend of the SendReplyToReceive shape. Next add the following code to the Program.cs file of the workflow application just before the “host.Open()” statement:&lt;br /&gt;&lt;br /&gt;&lt;div style="width:500px;height:150px;border-width:1px;border-color:blue;border-style:solid"&gt;&lt;br /&gt;host.Description.Behaviors.Add(new WorkflowIdleBehavior()&lt;br /&gt;                {&lt;br /&gt;                    TimeToPersist = TimeSpan.FromSeconds(5),&lt;br /&gt;                    TimeToUnload = TimeSpan.FromSeconds(20)&lt;br /&gt;                });&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;This code adds a behavior to persist the WF instance after 5 seconds of inactivity and to unload it completely after 20 seconds of inactivity. What’s the difference? Persistence – as explained in Part 1 – persists the workflow state in the DB but keeps the workflow instance running. Unloading however, does two things: it also persists the WF state but also unloads it from memory; typically for a long running process.&lt;br /&gt;&lt;br /&gt;Build the WF and run it. It’s ready to listen to requests on its endpoint.&lt;br /&gt;&lt;br /&gt;Now run the client. Once the service sends the response back to the client (recall – no persistence on send here), it enters a delay shape for 1 minute. Meanwhile we have configured to persist the WF after 5 seconds. So wait 5 seconds and open table “InstancesTable”; just like in Part 1 you will see the WF state persisted:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://2.bp.blogspot.com/_oG_VVyp2tR4/TC7lhxg6hMI/AAAAAAAAAGI/tIashV02i4A/s1600/4.JPG"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 400px; height: 50px;" src="http://2.bp.blogspot.com/_oG_VVyp2tR4/TC7lhxg6hMI/AAAAAAAAAGI/tIashV02i4A/s400/4.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5489577364201047234" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;However, now we have also configured the WF to unload after 20 seconds. So after an additional 15 seconds, this time open table “RunnableInstancesTable” and you will see one record corresponding to the same workflow. Why the “RunnableInstancesTable” table? Because this time the WF is not only persisted, but also is unloaded meaning that it is ready to be loaded again and continue execution:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://2.bp.blogspot.com/_oG_VVyp2tR4/TC7ltATpRtI/AAAAAAAAAGQ/UtAk3h0d6As/s1600/5.JPG"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 400px; height: 69px;" src="http://2.bp.blogspot.com/_oG_VVyp2tR4/TC7ltATpRtI/AAAAAAAAAGQ/UtAk3h0d6As/s400/5.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5489577557150484178" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;After the delay shape finishes, the WF instance will be loaded again into memory and finishes execution. Both records will disappear from the database.&lt;br /&gt;&lt;br /&gt;Finally, let’s add a control endpoint to our WF. Control endpoints allow sending commands to a WF instance from a client. Add the below code in the host application:&lt;br /&gt;&lt;br /&gt;&lt;div style="width:500px;height:150px;border-width:1px;border-color:blue;border-style:solid"&gt;&lt;br /&gt;WorkflowControlEndpoint controlEndpoint =&lt;br /&gt;                    new WorkflowControlEndpoint(&lt;br /&gt;                        new BasicHttpBinding(),&lt;br /&gt;                        new EndpointAddress(new Uri(baseAddress) + "/wce")&lt;br /&gt;                );&lt;br /&gt;                host.AddServiceEndpoint(controlEndpoint);&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;This code adds a special type of endpoint called the control endpoint with the following address: “http://localhost:8089/TestWF/wce”&lt;br /&gt;Run the service and update the service reference at the client application. Add the below code at the client application just after invoking the service operation:&lt;br /&gt;&lt;br /&gt;&lt;div style="width:600px;height:150px;border-width:1px;border-color:blue;border-style:solid"&gt;&lt;br /&gt;System.Threading.Thread.Sleep(new TimeSpan(0, 0, 30));&lt;br /&gt;            WorkflowControlEndpoint ep = new WorkflowControlEndpoint(new BasicHttpBinding(), new EndpointAddress("http://localhost:8089/TestWF/wce"));&lt;br /&gt;            WorkflowControlClient client = new WorkflowControlClient(ep);&lt;br /&gt;            client.Terminate(workflowId);&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;This code creates a workflow control client and uses the workflow instance id to send a command to terminate the WF instance. To test this I have caused the thread to sleep for 30 seconds. This way I am sure that at this point the WF instance has been unloaded (review the WF configuration). Now when I send the Terminate command, notice how the WF instance does not continue execution and is terminated. To be sure, see how the database persistence records are deleted after just 30 seconds as opposed to the 1 minute as explained previously.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4918396109946207501-7324347343968144051?l=thedotnethub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thedotnethub.blogspot.com/feeds/7324347343968144051/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thedotnethub.blogspot.com/2010/07/wf-40-workflowservicehost-persistence_03.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/7324347343968144051'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/7324347343968144051'/><link rel='alternate' type='text/html' href='http://thedotnethub.blogspot.com/2010/07/wf-40-workflowservicehost-persistence_03.html' title='WF 4.0 WorkflowServiceHost Persistence – Part 2'/><author><name>mohamad halabi</name><uri>http://www.blogger.com/profile/10259946099831243955</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_oG_VVyp2tR4/TC7lhxg6hMI/AAAAAAAAAGI/tIashV02i4A/s72-c/4.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4918396109946207501.post-7946730181741652149</id><published>2010-07-03T10:00:00.009+03:00</published><updated>2010-07-03T10:31:15.657+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Workflow Services'/><category scheme='http://www.blogger.com/atom/ns#' term='WF 4.0'/><category scheme='http://www.blogger.com/atom/ns#' term='WCF'/><title type='text'>WF 4.0 WorkflowServiceHost Persistence – Part 1</title><content type='html'>First step is setting up the new persistence databases. Go to “C:\Windows\Microsoft.NET\Framework\v4.0.30319\SQL\en” and there you will find two files:&lt;br /&gt;- SqlWorkflowInstanceStoreSchema.sql&lt;br /&gt;- SqlWorkflowInstanceStoreLogic.sql&lt;br /&gt;&lt;br /&gt;In SQL Server (Express or above), create a database with a convenient name (my database is called “SqlWorkflowInstanceStore”) and run the above scripts to create the required objects.&lt;br /&gt;&lt;br /&gt;The persistence model in WF 4 is different than that of WF 3.5. the new model is now called InstanceStore instead of PersistenceProvider. For WF 3.5, the PersistenceProvider databases are still available in the same location:&lt;br /&gt;- SqlPersistenceProviderLogic.sql&lt;br /&gt;- SqlPersistenceProviderSchema.sql&lt;br /&gt;&lt;br /&gt;In WF 3.5 there was service for managing WFs such as waking up workflow instances… the SQL files for this service is also still available in the same location:&lt;br /&gt;- SqlPersistenceService_Logic.sql&lt;br /&gt;- SqlPersistenceService_Schema.sql&lt;br /&gt;&lt;br /&gt;For tracking in 4.0 there is no tracking participant that writes to a SQL. The Tracking_Schema.sql applies to 3.5 WFs. Out of the box with WF 4.0 there is a tracking participant that writes to ETW (Event Tracing for Windows). Again, those files for WF 3.5 are:&lt;br /&gt;- Tracking_Schema.sql&lt;br /&gt;- Tracking_Logic.sql&lt;br /&gt;&lt;br /&gt;&lt;u&gt;&lt;em&gt;Building the WF&lt;/em&gt;&lt;br /&gt;&lt;/u&gt;&lt;br /&gt;Create a new Console Workflow Application, and use the default Workflow1.xaml to build the following simple workflow:&lt;br /&gt;&lt;a href="http://2.bp.blogspot.com/_oG_VVyp2tR4/TC7hOPjtNFI/AAAAAAAAAFw/RpPvq8gQ8IU/s1600/1.JPG"&gt;&lt;img style="WIDTH: 212px; HEIGHT: 400px; CURSOR: hand" id="BLOGGER_PHOTO_ID_5489572630621926482" border="0" alt="" src="http://2.bp.blogspot.com/_oG_VVyp2tR4/TC7hOPjtNFI/AAAAAAAAAFw/RpPvq8gQ8IU/s400/1.JPG" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;The Receive and SendReplyToReceive shape receives an empty request and returns the workflow instance id to the caller. The CodeAcitivty1 is a custom activity that retrieves the workflow instance id. Below is the code for this activity:&lt;br /&gt;&lt;br /&gt;&lt;div style="BORDER-BOTTOM: blue 1px solid; BORDER-LEFT: blue 1px solid; WIDTH: 500px; HEIGHT: 200px; BORDER-TOP: blue 1px solid; BORDER-RIGHT: blue 1px solid"&gt;&lt;br /&gt;public sealed class CodeActivity1 : CodeActivity&lt;guid&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;protected override Guid Execute(CodeActivityContext context)&lt;br /&gt;{&lt;br /&gt;return context.WorkflowInstanceId;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;The important catch is to set the property PersistBeforeSend on the SendReplyToReceive shape. This will cause the WF to persist just before sending the response to the caller. This means that now the WF will have a point to go back to in case the WF is suspended or unloaded…more on that later.&lt;br /&gt;&lt;br /&gt;The Delay activity is used to delay the WF for 1 minute…we will see why is that required after moments.&lt;br /&gt;&lt;br /&gt;Now go to the Program.cs file and let’s write the code required to host the WF and set up persistence.&lt;br /&gt;&lt;br /&gt;Use the following code and then I will explain it:&lt;br /&gt;&lt;br /&gt;&lt;div style="BORDER-BOTTOM: blue 1px solid; BORDER-LEFT: blue 1px solid; WIDTH: 600px; HEIGHT: 800px; BORDER-TOP: blue 1px solid; BORDER-RIGHT: blue 1px solid"&gt;&lt;br /&gt;class Program&lt;br /&gt;{&lt;br /&gt;static void Main(string[] args)&lt;br /&gt;{&lt;br /&gt;//WorkflowInvoker.Invoke(new Workflow1());&lt;br /&gt;&lt;br /&gt;string baseAddress = "http://localhost:8089/TestWF";&lt;br /&gt;&lt;br /&gt;using (WorkflowServiceHost host =&lt;br /&gt;new WorkflowServiceHost(new Workflow1(), new Uri(baseAddress)))&lt;br /&gt;{&lt;br /&gt;host.Description.Behaviors.Add(new&lt;br /&gt;ServiceMetadataBehavior() { HttpGetEnabled = true });&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;host.AddServiceEndpoint("IService",new BasicHttpBinding(), baseAddress);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;SqlWorkflowInstanceStore instanceStore = new SqlWorkflowInstanceStore(@"Data Source=.\SQLServer2008;Initial Catalog=SqlWorkflowInstanceStore;Integrated Security=True");&lt;br /&gt;host.DurableInstancingOptions.InstanceStore = instanceStore;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;host.Open();&lt;br /&gt;Console.WriteLine("Car rental service listening at: " +&lt;br /&gt;baseAddress);&lt;br /&gt;Console.WriteLine("Press ENTER to exit");&lt;br /&gt;Console.ReadLine();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;By default, the WorkflowInvoker is used to invoke the WF. I changed this into the WorkflowServiceHost, the reason is that the WorkflowInvoker cannot be configured with Persistence. WorkflowServiceHost is used to host WF Services. The other method of calling (hosting) workflows is the WorkflowApplication which – like WorkflowServiceHost – can be used to host long running asynch workflows with extensions (Persistence, Tracking) however only for workflows that are non services.&lt;br /&gt;&lt;br /&gt;After creating my WCF endpoint and adding it to the host, I use the SqlWorkflowInstaceStore class to configure my persistence store, which is the same store I prepared when I first started.&lt;br /&gt;&lt;br /&gt;&lt;em&gt;&lt;u&gt;Creating the Client&lt;/u&gt;&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;Run the WF so that the host is running and the WCF endpoint is listening for requests on “http://localhost:8089/TestWF”&lt;br /&gt;Now create a client (console) application and add a service reference to the above URL. Write the following code to invoke the service operation:&lt;br /&gt;&lt;br /&gt;&lt;div style="BORDER-BOTTOM: blue 1px solid; BORDER-LEFT: blue 1px solid; WIDTH: 600px; HEIGHT: 200px; BORDER-TOP: blue 1px solid; BORDER-RIGHT: blue 1px solid"&gt;&lt;br /&gt;ServiceReference1.ServiceClient proxy = new ServiceReference1.ServiceClient();&lt;br /&gt;&lt;br /&gt;            Guid workflowId = (Guid)proxy.Operation1();&lt;br /&gt;&lt;br /&gt;           &lt;br /&gt;            Console.WriteLine("client done");&lt;br /&gt;            Console.WriteLine("enter key");&lt;br /&gt;            Console.ReadLine();&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Run the client and observe the scenario: once the operation is invoked (and the workflow instance id is returned), open the table “InstancesTable” and you will see a record for a persisted WF. Why is that? Recall that we set a property on the SendReply shape to persist just before sending the reply. For this the WF has persisted state in the database but is still running as we did not suspend or unload the WF.  See images below:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://2.bp.blogspot.com/_oG_VVyp2tR4/TC7i8tPfxzI/AAAAAAAAAF4/nFRuHm8GOP8/s1600/2.JPG"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 400px; height: 50px;" src="http://2.bp.blogspot.com/_oG_VVyp2tR4/TC7i8tPfxzI/AAAAAAAAAF4/nFRuHm8GOP8/s400/2.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5489574528375834418" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://2.bp.blogspot.com/_oG_VVyp2tR4/TC7jDF-F2EI/AAAAAAAAAGA/OUiNnaRTdEg/s1600/3.JPG"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 400px; height: 66px;" src="http://2.bp.blogspot.com/_oG_VVyp2tR4/TC7jDF-F2EI/AAAAAAAAAGA/OUiNnaRTdEg/s400/3.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5489574638092933186" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;For how much time will this record appear in the database? For 1 minute because we have a delay shape in the WF to delay completion for 1 minute after which the WF execution will complete and the record will disappear from the database.&lt;br /&gt;&lt;br /&gt;In part 2 I will add support (behavior) to persist and unload the WF as well as add control endpoint to execute remote operations on the WF.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4918396109946207501-7946730181741652149?l=thedotnethub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thedotnethub.blogspot.com/feeds/7946730181741652149/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thedotnethub.blogspot.com/2010/07/wf-40-workflowservicehost-persistence.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/7946730181741652149'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/7946730181741652149'/><link rel='alternate' type='text/html' href='http://thedotnethub.blogspot.com/2010/07/wf-40-workflowservicehost-persistence.html' title='WF 4.0 WorkflowServiceHost Persistence – Part 1'/><author><name>mohamad halabi</name><uri>http://www.blogger.com/profile/10259946099831243955</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_oG_VVyp2tR4/TC7hOPjtNFI/AAAAAAAAAFw/RpPvq8gQ8IU/s72-c/1.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4918396109946207501.post-9194282744400511495</id><published>2010-06-14T12:06:00.003+03:00</published><updated>2010-06-14T12:28:14.661+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='SSL'/><category scheme='http://www.blogger.com/atom/ns#' term='Web Services'/><title type='text'>Web Service First Call Delay - SSL Handshake</title><content type='html'>i faced this issue recently and hope it helps someone...so here we go:&lt;br /&gt;&lt;br /&gt;a service provider gave me a XML Webservice to consume. this service was SSL secured and they gave us the certificate to install. However, they did not give us the CA...lets move on.&lt;br /&gt;&lt;br /&gt;i created a .net console app to test the web service and of course i had to write the code to ignore the certificate warning since again i did not have the CA. now do not judge me just yet :) instantly i mailed the web service owner asking for the CA; but it took some time...&lt;br /&gt;&lt;br /&gt;so meanwhile, my console app worked just fine. now i went to my main ASP.NET application and used the same code to invoke the web service...and there was a big problem: the first call took forever (more like 30 seconds really), then the subsequent calls were fast until my application is restarted!&lt;br /&gt;now since the console application worked just fine (first call was fast) but the problem was only in the ASP.NET application i moved my attention immediately to the serialzation issue. &lt;br /&gt;&lt;br /&gt;i read alot about how the serializer dll might take time to load the first time and thus the first call was slow. Now although this does not really explain why the problem occured only when calling the web service from my IIS hosted web site; however, i still used the SGen tool to pre-generate the serializer assembly in the form of [myproxyassemblyname].XmlSerializers.dll and put it inside my bin folder but without any result...still the first call was too slow.&lt;br /&gt;&lt;br /&gt;Note: instead of using the SGen tool you can use the compile options from VS and turn on the generate serialzer assembly option which will create the serialzer dll for you...&lt;br /&gt;&lt;br /&gt;now out of no where, the service provider sent my the CA. i installed it in the trusted root certificate authorities folder, removed the warning-ignoring code and boom the first call was fast and the problem was solved!&lt;br /&gt;thinking about it, the SSL handshake on the first call was taking a lot of time to find a problem in the CA and generating a warning.&lt;br /&gt;&lt;br /&gt;i have to admit though, it was a by chance. because till this moment i do not know why the console app did not complain about the SSL handshake (or to be more accurate, the SSL handshake did not take much time) while when from IIS the SSL handshake took about 30 seconds...the first logical explanation - although do not quote me on this - is that the IIS worker process was much slower than the .NET managed assembly (console app) in dealing with the SSL handshake issues...&lt;br /&gt;&lt;br /&gt;anyway, i can live with this for now :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4918396109946207501-9194282744400511495?l=thedotnethub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thedotnethub.blogspot.com/feeds/9194282744400511495/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thedotnethub.blogspot.com/2010/06/web-service-first-call-delay-ssl.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/9194282744400511495'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/9194282744400511495'/><link rel='alternate' type='text/html' href='http://thedotnethub.blogspot.com/2010/06/web-service-first-call-delay-ssl.html' title='Web Service First Call Delay - SSL Handshake'/><author><name>mohamad halabi</name><uri>http://www.blogger.com/profile/10259946099831243955</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4918396109946207501.post-630798446653947149</id><published>2010-06-05T12:17:00.004+03:00</published><updated>2010-06-05T12:21:52.204+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='GDC 09'/><category scheme='http://www.blogger.com/atom/ns#' term='SQL Azure'/><category scheme='http://www.blogger.com/atom/ns#' term='Azure'/><title type='text'>Windows Azure Videos</title><content type='html'>...so since i am in the mood of posting videos :) here are the videos for a chalk-talk session i gave with my buddy Mohamed Mosallem in Microsoft GDC 09 about Windows Azure...its a late post but better late than never :)&lt;br /&gt;Part1:&lt;br /&gt;&lt;object width="640" height="385"&gt;&lt;param name="movie" value="http://www.youtube.com/v/PjCR42v9xgs&amp;color1=0xb1b1b1&amp;color2=0xd0d0d0&amp;hl=en_US&amp;feature=player_embedded&amp;fs=1"&gt;&lt;/param&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;/param&gt;&lt;param name="allowScriptAccess" value="always"&gt;&lt;/param&gt;&lt;embed src="http://www.youtube.com/v/PjCR42v9xgs&amp;color1=0xb1b1b1&amp;color2=0xd0d0d0&amp;hl=en_US&amp;feature=player_embedded&amp;fs=1" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="640" height="385"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;br /&gt;Part2:&lt;br /&gt;&lt;object width="640" height="385"&gt;&lt;param name="movie" value="http://www.youtube.com/v/A9Y26g1bbeY&amp;color1=0xb1b1b1&amp;color2=0xd0d0d0&amp;hl=en_US&amp;feature=player_embedded&amp;fs=1"&gt;&lt;/param&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;/param&gt;&lt;param name="allowScriptAccess" value="always"&gt;&lt;/param&gt;&lt;embed src="http://www.youtube.com/v/A9Y26g1bbeY&amp;color1=0xb1b1b1&amp;color2=0xd0d0d0&amp;hl=en_US&amp;feature=player_embedded&amp;fs=1" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="640" height="385"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;br /&gt;Part3:&lt;br /&gt;&lt;object width="640" height="385"&gt;&lt;param name="movie" value="http://www.youtube.com/v/T-eVzhvrHpE&amp;color1=0xb1b1b1&amp;color2=0xd0d0d0&amp;hl=en_US&amp;feature=player_embedded&amp;fs=1"&gt;&lt;/param&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;/param&gt;&lt;param name="allowScriptAccess" value="always"&gt;&lt;/param&gt;&lt;embed src="http://www.youtube.com/v/T-eVzhvrHpE&amp;color1=0xb1b1b1&amp;color2=0xd0d0d0&amp;hl=en_US&amp;feature=player_embedded&amp;fs=1" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="640" height="385"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;br /&gt;Part4:&lt;br /&gt;&lt;object width="640" height="385"&gt;&lt;param name="movie" value="http://www.youtube.com/v/wc3t3_026EE&amp;color1=0xb1b1b1&amp;color2=0xd0d0d0&amp;hl=en_US&amp;feature=player_embedded&amp;fs=1"&gt;&lt;/param&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;/param&gt;&lt;param name="allowScriptAccess" value="always"&gt;&lt;/param&gt;&lt;embed src="http://www.youtube.com/v/wc3t3_026EE&amp;color1=0xb1b1b1&amp;color2=0xd0d0d0&amp;hl=en_US&amp;feature=player_embedded&amp;fs=1" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="640" height="385"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;br /&gt;Part5:&lt;br /&gt;&lt;object width="640" height="385"&gt;&lt;param name="movie" value="http://www.youtube.com/v/VdhcNgrEAgk&amp;color1=0xb1b1b1&amp;color2=0xd0d0d0&amp;hl=en_US&amp;feature=player_embedded&amp;fs=1"&gt;&lt;/param&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;/param&gt;&lt;param name="allowScriptAccess" value="always"&gt;&lt;/param&gt;&lt;embed src="http://www.youtube.com/v/VdhcNgrEAgk&amp;color1=0xb1b1b1&amp;color2=0xd0d0d0&amp;hl=en_US&amp;feature=player_embedded&amp;fs=1" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="640" height="385"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;br /&gt;Part6:&lt;br /&gt;&lt;object width="640" height="385"&gt;&lt;param name="movie" value="http://www.youtube.com/v/VKYSjUxh2Ww&amp;color1=0xb1b1b1&amp;color2=0xd0d0d0&amp;hl=en_US&amp;feature=player_embedded&amp;fs=1"&gt;&lt;/param&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;/param&gt;&lt;param name="allowScriptAccess" value="always"&gt;&lt;/param&gt;&lt;embed src="http://www.youtube.com/v/VKYSjUxh2Ww&amp;color1=0xb1b1b1&amp;color2=0xd0d0d0&amp;hl=en_US&amp;feature=player_embedded&amp;fs=1" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="640" height="385"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;br /&gt;Part7:&lt;br /&gt;&lt;object width="640" height="385"&gt;&lt;param name="movie" value="http://www.youtube.com/v/B0IoKQWJheQ&amp;color1=0xb1b1b1&amp;color2=0xd0d0d0&amp;hl=en_US&amp;feature=player_embedded&amp;fs=1"&gt;&lt;/param&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;/param&gt;&lt;param name="allowScriptAccess" value="always"&gt;&lt;/param&gt;&lt;embed src="http://www.youtube.com/v/B0IoKQWJheQ&amp;color1=0xb1b1b1&amp;color2=0xd0d0d0&amp;hl=en_US&amp;feature=player_embedded&amp;fs=1" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="640" height="385"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4918396109946207501-630798446653947149?l=thedotnethub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thedotnethub.blogspot.com/feeds/630798446653947149/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thedotnethub.blogspot.com/2010/06/windows-azure-videos.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/630798446653947149'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/630798446653947149'/><link rel='alternate' type='text/html' href='http://thedotnethub.blogspot.com/2010/06/windows-azure-videos.html' title='Windows Azure Videos'/><author><name>mohamad halabi</name><uri>http://www.blogger.com/profile/10259946099831243955</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4918396109946207501.post-3888162370925508585</id><published>2010-06-04T12:38:00.004+03:00</published><updated>2010-06-04T12:42:27.471+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Windows 7 Sensor and Location Platform'/><category scheme='http://www.blogger.com/atom/ns#' term='SQL Server 2008 R2'/><category scheme='http://www.blogger.com/atom/ns#' term='Devlifestyle'/><title type='text'>Devlifestyle May Event - Session Recordings</title><content type='html'>As part of &lt;a href="http://www.devlifestyle.net"&gt;Devlifestyle&lt;/a&gt; May 2010 Event, we talked about Windows 7 Sensor and Location Platform and SQL Server 2008 R2 Data Tier Applications. Below are the vidoes:&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;Windows 7 Sensor and Location Platform: &lt;a target="_blank" href="http://www.youtube.com/watch?v=Tcn7md8qcDc"&gt;Part1&lt;/a&gt;, &lt;a target="_blank" href="http://www.youtube.com/watch?v=zYI_UK065hg"&gt;Part2&lt;/a&gt;, &lt;a target="_blank" href="http://www.youtube.com/watch?v=Zu0lIyhsDj4"&gt;Part3&lt;/a&gt;, &lt;a target="_blank" href="http://www.youtube.com/watch?v=HLOqPIodNhM"&gt;Part4&lt;/a&gt; &lt;/li&gt;&lt;br /&gt;&lt;li&gt;Data tier applications, a new feature for SQL Server 2008 R2 and VS2010: &lt;a target="_blank" href="http://www.youtube.com/watch?v=jmFQrBp6D0g"&gt;Part1&lt;/a&gt;, &lt;a target="_blank" href="http://www.youtube.com/watch?v=K-AcmRFVcQs"&gt;Part2&lt;/a&gt;, &lt;a target="_blank" href="http://www.youtube.com/watch?v=tP7Z7C3Kc7A"&gt;Part3&lt;/a&gt;, &lt;a target="_blank" href="http://www.youtube.com/watch?v=M7QlYfITx1A"&gt;Part4&lt;/a&gt;, &lt;a target="_blank" href="http://www.youtube.com/watch?v=BoS9P2yGBjA"&gt;Part5&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4918396109946207501-3888162370925508585?l=thedotnethub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thedotnethub.blogspot.com/feeds/3888162370925508585/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thedotnethub.blogspot.com/2010/06/devlifesetyle-may-event-session.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/3888162370925508585'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/3888162370925508585'/><link rel='alternate' type='text/html' href='http://thedotnethub.blogspot.com/2010/06/devlifesetyle-may-event-session.html' title='Devlifestyle May Event - Session Recordings'/><author><name>mohamad halabi</name><uri>http://www.blogger.com/profile/10259946099831243955</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4918396109946207501.post-1258069778260284581</id><published>2010-06-03T12:15:00.005+03:00</published><updated>2010-06-05T12:11:06.322+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Windows Server AppFabric'/><category scheme='http://www.blogger.com/atom/ns#' term='WF 4.0'/><category scheme='http://www.blogger.com/atom/ns#' term='WCF'/><title type='text'>Building and Managing WCF and WF 4 Services with Windows Server AppFabric</title><content type='html'>Here are my session recordings talking about Building and Managing WCF and WF 4 Services with Windows Server AppFabric, as part of Devlifestyle Event...&lt;br /&gt;Part1:&lt;br /&gt;&lt;object width="640" height="385"&gt;&lt;param name="movie" value="http://www.youtube.com/v/jb0-U81JE7o&amp;hl=en_US&amp;fs=1&amp;rel=0"&gt;&lt;/param&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;/param&gt;&lt;param name="allowscriptaccess" value="always"&gt;&lt;/param&gt;&lt;embed src="http://www.youtube.com/v/jb0-U81JE7o&amp;hl=en_US&amp;fs=1&amp;rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="385"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;br /&gt;Part2:&lt;br /&gt;&lt;object width="640" height="385"&gt;&lt;param name="movie" value="http://www.youtube.com/v/vWW8FO20tk8&amp;hl=en_US&amp;fs=1&amp;rel=0"&gt;&lt;/param&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;/param&gt;&lt;param name="allowscriptaccess" value="always"&gt;&lt;/param&gt;&lt;embed src="http://www.youtube.com/v/vWW8FO20tk8&amp;hl=en_US&amp;fs=1&amp;rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="385"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;br /&gt;Part3:&lt;br /&gt;&lt;object width="640" height="385"&gt;&lt;param name="movie" value="http://www.youtube.com/v/ybXSxJtBqak&amp;hl=en_US&amp;fs=1&amp;rel=0"&gt;&lt;/param&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;/param&gt;&lt;param name="allowscriptaccess" value="always"&gt;&lt;/param&gt;&lt;embed src="http://www.youtube.com/v/ybXSxJtBqak&amp;hl=en_US&amp;fs=1&amp;rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="385"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;br /&gt;Part4:&lt;br /&gt;&lt;object width="640" height="385"&gt;&lt;param name="movie" value="http://www.youtube.com/v/F_xPguEGNVM&amp;hl=en_US&amp;fs=1&amp;rel=0"&gt;&lt;/param&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;/param&gt;&lt;param name="allowscriptaccess" value="always"&gt;&lt;/param&gt;&lt;embed src="http://www.youtube.com/v/F_xPguEGNVM&amp;hl=en_US&amp;fs=1&amp;rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="385"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;br /&gt;Part5:&lt;br /&gt;&lt;object width="640" height="385"&gt;&lt;param name="movie" value="http://www.youtube.com/v/hBOYU3D06D8&amp;hl=en_US&amp;fs=1&amp;rel=0"&gt;&lt;/param&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;/param&gt;&lt;param name="allowscriptaccess" value="always"&gt;&lt;/param&gt;&lt;embed src="http://www.youtube.com/v/hBOYU3D06D8&amp;hl=en_US&amp;fs=1&amp;rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="385"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;br /&gt;Part6:&lt;br /&gt;&lt;object width="640" height="385"&gt;&lt;param name="movie" value="http://www.youtube.com/v/7DOHc-5iWZ8&amp;hl=en_US&amp;fs=1&amp;rel=0"&gt;&lt;/param&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;/param&gt;&lt;param name="allowscriptaccess" value="always"&gt;&lt;/param&gt;&lt;embed src="http://www.youtube.com/v/7DOHc-5iWZ8&amp;hl=en_US&amp;fs=1&amp;rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="385"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;br /&gt;Part7:&lt;br /&gt;&lt;object width="640" height="385"&gt;&lt;param name="movie" value="http://www.youtube.com/v/NzUh3J6-7eY&amp;hl=en_US&amp;fs=1&amp;rel=0"&gt;&lt;/param&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;/param&gt;&lt;param name="allowscriptaccess" value="always"&gt;&lt;/param&gt;&lt;embed src="http://www.youtube.com/v/NzUh3J6-7eY&amp;hl=en_US&amp;fs=1&amp;rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="385"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;br /&gt;Part8:&lt;br /&gt;&lt;object width="640" height="385"&gt;&lt;param name="movie" value="http://www.youtube.com/v/LET0YpRAR-w&amp;hl=en_US&amp;fs=1&amp;rel=0"&gt;&lt;/param&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;/param&gt;&lt;param name="allowscriptaccess" value="always"&gt;&lt;/param&gt;&lt;embed src="http://www.youtube.com/v/LET0YpRAR-w&amp;hl=en_US&amp;fs=1&amp;rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="385"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4918396109946207501-1258069778260284581?l=thedotnethub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thedotnethub.blogspot.com/feeds/1258069778260284581/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thedotnethub.blogspot.com/2010/06/building-and-managing-wcf-and-wf-4.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/1258069778260284581'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/1258069778260284581'/><link rel='alternate' type='text/html' href='http://thedotnethub.blogspot.com/2010/06/building-and-managing-wcf-and-wf-4.html' title='Building and Managing WCF and WF 4 Services with Windows Server AppFabric'/><author><name>mohamad halabi</name><uri>http://www.blogger.com/profile/10259946099831243955</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4918396109946207501.post-6122255601014147235</id><published>2010-05-18T09:58:00.000+03:00</published><updated>2010-05-18T10:04:19.710+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Devlifestyle'/><title type='text'>Devlifestyle Event on May 27</title><content type='html'>Our next community event is just around the corner. we will be discussing a lot of hot topics: Win Server AppFabric, Win 7 Location and Sensor Platform, Windows Azure, SQL 2008 R2, Silverlight 4.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://devlifestylemayevent.eventbrite.com/"&gt;View here&lt;/a&gt;&lt;br /&gt;Cannot wait to start!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4918396109946207501-6122255601014147235?l=thedotnethub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thedotnethub.blogspot.com/feeds/6122255601014147235/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thedotnethub.blogspot.com/2010/05/devlifestyle-event-on-may-27.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/6122255601014147235'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/6122255601014147235'/><link rel='alternate' type='text/html' href='http://thedotnethub.blogspot.com/2010/05/devlifestyle-event-on-may-27.html' title='Devlifestyle Event on May 27'/><author><name>mohamad halabi</name><uri>http://www.blogger.com/profile/10259946099831243955</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4918396109946207501.post-3971578934131407181</id><published>2010-05-18T00:05:00.000+03:00</published><updated>2010-05-18T00:25:55.860+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Windows Server AppFabric'/><title type='text'>Clean AppFabric Databases</title><content type='html'>When you are developing and testing with AppFabric, you will quickly notice how much the tracked data size grows. as such you will need at times to empty the monitoring and persistence databases and start fresh.&lt;br /&gt;&lt;br /&gt;for this there is a great post by &lt;a href="http://blogs.msdn.com/rjacobs/archive/2010/04/14/how-to-clear-and-reinitialize-appfabric-persistence-and-monitoring-databases.aspx"&gt;Ron Jacobs &lt;/a&gt;about how to do just that.&lt;br /&gt;&lt;br /&gt;however, here are some minor issues that i faced to make this work. it might help you also.&lt;br /&gt;&lt;br /&gt;the powershell script to use is the following:&lt;br /&gt;-------------------------------------------------------&lt;br /&gt;import-module applicationserver&lt;br /&gt;$ConfirmPreference = "None"&lt;br /&gt;&lt;br /&gt;Remove-ASPersistenceSqlDatabase -Force -Server ".\SQL2008" -Database "AppFabricPersistence"&lt;br /&gt;&lt;br /&gt;Initialize-ASPersistenceSqlDatabase -Admins $env:computername\AS_Administrators -Readers $env:computername\AS_Observers -Users "BUILTIN\IIS_IUSRS" -Database "AppFabricPersistence" -Server ".\SQL2008"&lt;br /&gt;&lt;br /&gt;Clear-ASMonitoringSqlDatabase -Database "AppFabricMonitoring" -Server ".\SQL2008"&lt;br /&gt;---------------------------------------------------&lt;br /&gt;&lt;br /&gt;where AppFabricPersistence and AppFabricMonitoring are the database names i used when configuring AppFabric. while SQL2008 is my SQL named instance where AppFabric is configured.&lt;br /&gt;&lt;br /&gt;Save this text into a ".ps1" file and take care to remove line breaks. meaning that you will have a total of four lines. if you don't you will get script execution errors when later you run the script.&lt;br /&gt;&lt;br /&gt;now when you run powershell, make sure to do so in admin mode. in addition run the one called Windows Powershell and not Windows Powershell (x86). if you run the X86 verison you will get an error that module "applicationserver" cannot be loaded when you try to run the script. note that my setup was on Windows 7 64-bit.&lt;br /&gt;&lt;br /&gt;we are still not done, again now if you try to run the script in powershell by typing [filename].ps1 you will get an error "&lt;filename&gt;.ps1 is not recognized as the name of a cmdlet, function, script file, or operable program...".&lt;br /&gt;to solve this type ".\[filename].ps1"&lt;br /&gt;&lt;br /&gt;Finally, when you run the script you might get an error that "the execution of scripts is disabled on this system". you need to enable script execution for powershell. for this run command "set-executionpolicy unrestricted" for allowing all scripts. another key values might be "Restricted", "AllSigned", and "RemoteSigned".&lt;br /&gt;&lt;br /&gt;again i point that my environment was win 7 64-bit, so in another environment there could be some differences...but anyway...&lt;br /&gt;&lt;br /&gt;this should be enough then to run the script and watch your AppFabric dashboard clean again!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4918396109946207501-3971578934131407181?l=thedotnethub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thedotnethub.blogspot.com/feeds/3971578934131407181/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thedotnethub.blogspot.com/2010/05/clean-appfabric-databases.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/3971578934131407181'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/3971578934131407181'/><link rel='alternate' type='text/html' href='http://thedotnethub.blogspot.com/2010/05/clean-appfabric-databases.html' title='Clean AppFabric Databases'/><author><name>mohamad halabi</name><uri>http://www.blogger.com/profile/10259946099831243955</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4918396109946207501.post-2676484537298385154</id><published>2010-04-16T01:19:00.000+03:00</published><updated>2010-04-16T01:22:33.624+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='MVP'/><category scheme='http://www.blogger.com/atom/ns#' term='MicrosoftFeed'/><title type='text'>My MVP Interview</title><content type='html'>As being a new MVP, I was interviewed by &lt;a href="http://www.facebook.com/microsoft.feed"&gt;MicrosoftFeed&lt;/a&gt;. Here is the link:&lt;br /&gt;&lt;a href="http://microsoftfeed.com/2010/meet-mohamad-halabi-aspasp-net-mvp-from-saudi-arabia/"&gt;http://microsoftfeed.com/2010/meet-mohamad-halabi-aspasp-net-mvp-from-saudi-arabia/&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4918396109946207501-2676484537298385154?l=thedotnethub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thedotnethub.blogspot.com/feeds/2676484537298385154/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thedotnethub.blogspot.com/2010/04/my-mvp-interview.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/2676484537298385154'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/2676484537298385154'/><link rel='alternate' type='text/html' href='http://thedotnethub.blogspot.com/2010/04/my-mvp-interview.html' title='My MVP Interview'/><author><name>mohamad halabi</name><uri>http://www.blogger.com/profile/10259946099831243955</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4918396109946207501.post-3219829150022614589</id><published>2010-04-09T23:04:00.000+03:00</published><updated>2010-04-09T23:11:29.320+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='TechEd'/><category scheme='http://www.blogger.com/atom/ns#' term='BizTalk'/><category scheme='http://www.blogger.com/atom/ns#' term='Azure'/><title type='text'>My TechEd 2010 Sessions</title><content type='html'>I was a speaker at Tech Ed 2010 in Dubai.&lt;br /&gt;Below are links for my two breakout sessions (i had 3 other labs but are not recorded :( )&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.msteched.com/online/view.aspx?tid=a58281b6-32ea-4f2e-a906-1316d01ea673"&gt;BizTalk Dev&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.msteched.com/online/view.aspx?tid=495fdd4a-b983-4ad1-bdff-91fc21a2ca1e"&gt;Windows Azure Dev&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4918396109946207501-3219829150022614589?l=thedotnethub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thedotnethub.blogspot.com/feeds/3219829150022614589/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thedotnethub.blogspot.com/2010/04/my-teched-2010-sessions.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/3219829150022614589'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/3219829150022614589'/><link rel='alternate' type='text/html' href='http://thedotnethub.blogspot.com/2010/04/my-teched-2010-sessions.html' title='My TechEd 2010 Sessions'/><author><name>mohamad halabi</name><uri>http://www.blogger.com/profile/10259946099831243955</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4918396109946207501.post-4417499649119679941</id><published>2010-04-07T20:01:00.000+03:00</published><updated>2010-04-07T20:59:40.964+03:00</updated><title type='text'>Introducing .NET 4.0 Parallel Programming</title><content type='html'>&lt;ul class="Download"&gt;&lt;li&gt;&lt;a href="http://www.codeproject.com/KB/dotnet/NET4ParallelIntro/sln.zip"&gt;Download sln - 858.6 KB&lt;/a&gt; &lt;/li&gt;&lt;/ul&gt;&lt;p&gt;“With great power comes great responsibility”…As the hardware world is booming and its processing power increases, the responsibility lies with developers to utilize such power. Ok, so the comparison is lame but I am a fan of Spider Man movie and was always looking for a way to use its slogan…guess should keep looking :)&lt;/p&gt;&lt;p&gt;Seriously though, multi-core (and multi-processer) machines are dominant these days. Soon enough as reported by some lead vendors, you will not be able to find machines with less than 8 cores. As such, the traditional way of writing serial programs will not be able to make use of such power by default. These programs should be written in a way which utilizes the power of multi-cores.&lt;/p&gt;&lt;p&gt;Do we have to? Some might say. Wouldn’t running my program on a multi-core machine automatically improve performance; after all there are more threads? The answer is no! Running a serial program on a multi-core machine has nearly zero performance enhancements. With the exception of IO operations, your program will still use one thread of a single core at a time. Thread switching occurs – which incurs overhead by the way – but at all times only one thread will be active (again with the exception of IO operations which can happen on different threads).&lt;/p&gt;&lt;p&gt;Multi-threading programming is the way which allows developers to take advantage of multiple threads concurrently. And while it has been available for many years, multi-threading programming has often been avoided due to its complexity. Developers had to put most their effort in writing clean multi-threaded code rather than focusing on the business problem.&lt;/p&gt;&lt;p&gt;So what does Multithreading have to do with multi-cores? Cannot we write Multi-threaded code if we have a single core? Yes we can. But again as long as we have a single core, one thread at a time will work since all threads do belong for that same single core…logical enough. When your Multi-threaded program runs on a multi-core machine, threads belonging to different cores will be able to run together and hence your program will take advantage of the hardware power.&lt;/p&gt;&lt;p&gt;One final note before going on: Multithreading programming does not differ if you have multi-core machine or multi-processer machine. This is a hardware separation; underneath your code will be working with threads all the same.&lt;/p&gt;&lt;h2&gt;Parallel vs. Concurrent&lt;/h2&gt;&lt;p&gt;Well both concepts are related but not the same: In its simplest definition, Concurrency is about executing multiple un-related tasks in a concurrent mode. What these un-related tasks share are system resources, but they do not share a common problem to solve; meaning, they are logically independent. Now think of these tasks as threads. And since these threads share system resources, then you face the globally common problems of concurrent programming such as deadlocks and data races. This makes concurrent programming extremely difficult and debugging complicated.&lt;/p&gt;&lt;p&gt;So what is Parallelism? Parallelism is taking a certain task and dividing it into a set of related tasks to be executed concurrently. Sweet! So again thinking of these tasks as threads, Parallel Programming still has the same problems of concurrent programming (deadlocks, data races, etc...) and introduces new challenges most notably sharing and partitioning data across these related threads. This makes Parallel Programming even more difficult and debugging even more complicated :(&lt;/p&gt;&lt;p&gt;However, it is not all bad news. .NET 4.0 parallel programming is a great step onwards. The new API solves a lot of problems (but not all) of Parallel Programming and greatly eases up parallel debugging...&lt;/p&gt;&lt;h2&gt;Setting the Context of .NET Parallel Programming&lt;/h2&gt;&lt;p&gt;The previous sections introduced Multi-threading programming and its need. This section introduces the context of Parallel Programming in the .NET Framework in a gradual manner:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;So we have Multi-core machines and we need to think of a way to utilize their power…So is the need to think of Parallel Programming&lt;/li&gt;&lt;li&gt;So what is Parallel Programming all about? It’s about how to partition a single piece of work into multiple concurrent units&lt;/li&gt;&lt;li&gt;What partitioning options do we have? Option1 would be static partitioning. Static Partitioning is “hard-coding” the number of units and threads you want to use. For example saying that you want to divide a large chunk of work into “n” units each running on a single thread over a single core. The problem with this approach is that it is not scalable. While this solution would be fine on a machine with “n” cores, it quickly will become un-scalable for machines with “n+m” cores.&lt;/li&gt;&lt;li&gt;So the natural evolution of solving the partitioning problem would be Dynamic Partitioning. This means that you divide your work into a single unit per available core. While this would solve the scalability problem, it introduces another one: Load-imbalance. In real problems it is really unlikely that all work units will take the same amount of time to complete. This means that some cores will finish their work while other cores will be still busy without being able to utilize the now-free cores.&lt;/li&gt;&lt;li&gt;Moving up the chain of solutions we now have one more option: Over partition work into the smallest feasible units which will make use of the most feasible number of available threads. This will now solve the load-imbalance issue because as work is divided into the smallest possible units where each unit will run over an available thread. However, again now we have a problem: Thread overhead. Creating and killing threads is an expensive procedure.&lt;/li&gt;&lt;li&gt;So this brings us to the final partitioning option: The .NET Thread Pool. The .NET thread pool maintains a scheduler and a thread queue. Instead of killing a thread once it finishes its work, this thread is pushed into the queue and it is now available to be picked up by the next unit of work scheduled for execution. The thread pool is exposed through the System.Threading.ThreadPool namespace and it has been available since before .NET v 4.0.&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;p&gt;Wait a minute, so what is exactly new in the .NET 4.0 Parallel Programming model if the above discussion applies to pre-v 4.0? The answer will come by inspecting the shortcomings of the thread pool as discussed. The thread pool is a fire-and-forget programming model. Once you created a thread by code, you basically have no way to perform any operations on it. There is no support for continuing, composing, monitoring data flow, performing work cancellation and work waiting.&lt;/p&gt;&lt;p&gt;So what is the solution? It is the .NET 4.0 Task-based Programming. In v 4.0 of the framework you can program over Tasks as opposed to the lower-level threads. Now you can divide your work over Tasks instead of threads. This will give you much more power and control over your parallel work as we will see later. Of course you can still work with the thread pool directly if you want to work with the deeper-detail of threads.&lt;/p&gt;&lt;h2&gt;.NET 4.0 Parallel Programming&lt;/h2&gt;&lt;p&gt;The Parallel Programming model of the .NET 4.0 is composed of the following:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;The Task Parallel Library (TPL): this is the base of the Task-based programming discussed in the previous section. It consists of: &lt;/li&gt;&lt;ul&gt;&lt;li&gt;Task class: the unit of work you will code against instead of the previous thread model &lt;/li&gt;&lt;li&gt;Parallel class: a static class that exposes a task-based version of some parallel-nature problems. More specifically it contains the following methods:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;For &lt;/li&gt;&lt;li&gt;Foreach &lt;/li&gt;&lt;li&gt;Invoke &lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;Parallel LINQ (PLINQ): built on top of the TPL and exposes the familiar LINQ as Parallel extensions. &lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;h2&gt;About the Examples&lt;/h2&gt;&lt;p&gt;All examples discussed are downloadable. To illustrate main ideas, some code samples will be shown in the below sections.&lt;/p&gt;&lt;p&gt;All examples are built using VS 2010 RC1; nothing else is required. In order to feel the value of Parallel Programming you will need a multi-core (or multi-processer) machine; the results shown are that of running the examples on a dual-core machine.&lt;/p&gt;&lt;h2&gt;Example1: Tasks&lt;/h2&gt;&lt;p&gt;The first example shows the new Tasks programming model. As explained previously, Tasks – as opposed to the Thread Pool – grants more control over thread programming. In fact you now deal with Tasks and not threads.&lt;/p&gt;&lt;pre lang="CS"&gt;static void Main(string[] args)&lt;br /&gt;        {&lt;br /&gt;            Task t = Task.Factory.StartNew(() =&amp;gt;&lt;br /&gt;            {&lt;br /&gt;                Console.WriteLine("I am the first task");&lt;br /&gt;            });&lt;br /&gt;&lt;br /&gt;            var t2 = t.ContinueWith(delegate&lt;br /&gt;            {&lt;br /&gt;                //simulate compute intensive&lt;br /&gt;                Thread.Sleep(5000);&lt;br /&gt;                return "Tasks Example";&lt;br /&gt;            });&lt;br /&gt;&lt;br /&gt;            //block1&lt;br /&gt;            //string result = t2.Result;&lt;br /&gt;            //Console.WriteLine("result of second task is: " + result);&lt;br /&gt;            //end block1&lt;br /&gt;&lt;br /&gt;            //block2&lt;br /&gt;            //t2.ContinueWith(delegate&lt;br /&gt;            //    {&lt;br /&gt;            //        Console.WriteLine("Here i am");&lt;br /&gt;            //    });&lt;br /&gt;            //Console.WriteLine("Waiting my task");&lt;br /&gt;            //end block2&lt;br /&gt;&lt;br /&gt;            Console.ReadLine();&lt;br /&gt;&lt;br /&gt;        }&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;In the above code we first create a new Task using the Task class and we pass to the lambda expression the code to run inside that Task (in a separate thread). &lt;/p&gt;&lt;p&gt;Another feature is the ability to “continue” on a running Task. What this means is that once the Task is completed (in our example task “t”) start running another task “t2” with the code to run supplied in an anonymous method (through a delegate).&lt;/p&gt;&lt;p&gt;Now uncomment block1. Here we see another feature which is to get a result back from a task. Notice that we have assigned a value for task “t2” called “Tasks Example” through the “return” statement. Now in block1 we can retrieve that value. Now this kicks in a question: what will happen if the statement “t2.Result” is executed before “t2” finishes execution (recall that “t2” is running on a separate thread other than the thread of the main program)? Force this behavior (that is why I am using Thread.Sleep) and you will see that in this case the main thread will wait at “t2.Result” until “t2” finishes execution and its “return” statement is executed. Neat! A power which was not possible before.&lt;/p&gt;&lt;p&gt;Now uncomment block2. Set two break points at the first and second “Console.WriteLine” statements. Run the program and notice that line “Waiting my task” is printed before “Here i am”. This indicates that the main program (thread) was waiting task “t2” running on another thread to finish. Once “t2” finishes (delayed by using Thread.Sleep) its statement is printed.&lt;/p&gt;&lt;h2&gt;Example2: Parallel&lt;/h2&gt;&lt;p&gt;This example introduces the Parallel class. Specifically it shows how to use the new For method to perform what usually was done serially in a parallel manner.&lt;/p&gt;&lt;pre lang="CS"&gt;static void Main(string[] args)&lt;br /&gt;        {&lt;br /&gt;            Stopwatch watch;&lt;br /&gt;            watch = new Stopwatch();&lt;br /&gt;            watch.Start();&lt;br /&gt;&lt;br /&gt;            //serial implementation&lt;br /&gt;            for (int i = 0; i &amp;lt; 10; i++)&lt;br /&gt;            {&lt;br /&gt;                Thread.Sleep(1000);&lt;br /&gt;                //Do stuff&lt;br /&gt;            }&lt;br /&gt;            watch.Stop();&lt;br /&gt;            Console.WriteLine("Serial Time: " + watch.Elapsed.Seconds.ToString());&lt;br /&gt;&lt;br /&gt;            //parallel implementation&lt;br /&gt;            watch = new Stopwatch();&lt;br /&gt;            watch.Start();&lt;br /&gt;            System.Threading.Tasks.Parallel.For(0, 10, i =&amp;gt;&lt;br /&gt;            {&lt;br /&gt;                Thread.Sleep(1000);&lt;br /&gt;                //Do stuff with i&lt;br /&gt;            }&lt;br /&gt;            );&lt;br /&gt;            watch.Stop();&lt;br /&gt;            Console.WriteLine("Parallel Time: " + watch.Elapsed.Seconds.ToString());&lt;br /&gt;&lt;br /&gt;            Console.ReadLine();&lt;br /&gt;&lt;br /&gt;        }&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;The above code shows the difference in execution time of performing a unit of work (simulated by a Sleep operation) serially versus in parallel. In my dual-core machine the time is cut by half. Now this is huge improvement! Imagine all the work you usually do inside For loops (or Foreach loops) and think of the time enhancement you now can get by utilizing the new Parallel.For and Parallel.Foreach methods.&lt;/p&gt;&lt;p&gt;One important note: sometimes it’s just not that easy though. When parallelizing your work sometimes you have to take care of special problems like synchronization and dead-locks; you still have to handle these and I will discuss them in the next examples.&lt;/p&gt;&lt;p&gt;For the sake of variation, let’s see an overload of the Parallel.For method: In order to support breaking out of a parallel loop, there is an overload of the Parallel.For method which takes ParallelLoopState as a parameter in the Action delegate:&lt;/p&gt;&lt;pre lang="CS"&gt;Parallel.For(0,1000,(int i, ParallelLoopState loopState) =&amp;gt;&lt;br /&gt;{&lt;br /&gt;    If(i==500)&lt;br /&gt;       loopState.Break();&lt;br /&gt;       //or loopState.Stop();&lt;br /&gt;      return; // to ensure that this iteration also returns&lt;br /&gt;     //do stuff&lt;br /&gt;});&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The difference between the Break and Stop methods is that Break insures that all earlier iterations that started in the loop are executed before exiting the loop. &lt;/p&gt;&lt;p&gt;The Stop method makes no such guarantees; it basically says that this loop is done and should exit as soon as possible.&lt;/p&gt;&lt;p&gt;Both methods will stop future iterations from running.&lt;/p&gt;&lt;h2&gt;Example3: PLINQ&lt;/h2&gt;&lt;p&gt;PLINQ is a LINQ Provider, so you still use the familiar LINQ model. In the underlying model however, PLINQ uses multiple threads to evaluate queries. &lt;/p&gt;&lt;pre lang="CS"&gt;static void Main(string[] args)&lt;br /&gt;        {&lt;br /&gt;            Stopwatch watch;&lt;br /&gt;&lt;br /&gt;            //for loop&lt;br /&gt;            watch = new Stopwatch();&lt;br /&gt;            watch.Start();&lt;br /&gt;            bool[] results = new bool[arr.Length];&lt;br /&gt;            for (int i = 0; i &amp;lt; arr.Length; i++)&lt;br /&gt;            {&lt;br /&gt;                results[i] = IsPrime(arr[i]);&lt;br /&gt;            }&lt;br /&gt;            watch.Stop();&lt;br /&gt;            Console.WriteLine("For Loop took: " + watch.Elapsed.Seconds);&lt;br /&gt;&lt;br /&gt;            //LINQ to Objects&lt;br /&gt;            watch = new Stopwatch();&lt;br /&gt;            watch.Start();&lt;br /&gt;            bool[] results1 = arr.Select(x =&amp;gt; IsPrime(x))&lt;br /&gt;                .ToArray();&lt;br /&gt;            watch.Stop();&lt;br /&gt;            Console.WriteLine("LINQ took: " + watch.Elapsed.Seconds);&lt;br /&gt;&lt;br /&gt;            //PLINQ&lt;br /&gt;            watch = new Stopwatch();&lt;br /&gt;            watch.Start();&lt;br /&gt;            bool[] results2 = arr.AsParallel().Select(x =&amp;gt; IsPrime(x))&lt;br /&gt;                .ToArray();&lt;br /&gt;            watch.Stop();&lt;br /&gt;            Console.WriteLine("PLINQ took: " + watch.Elapsed.Seconds);&lt;br /&gt;&lt;br /&gt;            Console.ReadLine();&lt;br /&gt;&lt;br /&gt;        }&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;The above code shows how to perform a deliberately time-expensive IsPrime function using LINQ (and For) vs. PLINQ. The AsParallel extension allows your code to run using PLINQ instead of LINQ. The step of using AsParallel wraps the data source with a ParallelQuery wrapper and causes the remaining extension methods in the query to bind to PLINQ rather than to LINQ to Objects.&lt;/p&gt;&lt;p&gt;Run the example and will notice that while the time for execution using serial For loop and traditional LINQ is nearly the same (actually opposite to many beliefs, LINQ has a performance overhead over For loop…but that’s another story), the execution time using PLINQ is again nearly cut in half.&lt;/p&gt;&lt;h2&gt;Example4: PLINQ Extensions&lt;/h2&gt;&lt;p&gt;PLINQ has many extensions that affect how work partitioning is done. In this example we will discuss one of these extensions. Examine the below code:&lt;/p&gt;&lt;pre lang="CS"&gt;static void Main(string[] args)&lt;br /&gt;        {&lt;br /&gt;            Stopwatch watch = new Stopwatch();&lt;br /&gt;            watch.Start();&lt;br /&gt;            int[] src = Enumerable.Range(0, 200).ToArray();&lt;br /&gt;            var query = src.AsParallel()&lt;br /&gt;                         .Select(x =&amp;gt; ExpensiveFunc(x));&lt;br /&gt;&lt;br /&gt;            foreach (var x in query)&lt;br /&gt;            {&lt;br /&gt;                Console.WriteLine(x);&lt;br /&gt;            }&lt;br /&gt;            watch.Stop();&lt;br /&gt;            Console.WriteLine("Elapsed: " + watch.Elapsed.Seconds.ToString());&lt;br /&gt;                    &lt;br /&gt;            Console.ReadLine();&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        private static int ExpensiveFunc(int x)&lt;br /&gt;        {&lt;br /&gt;            Thread.Sleep(1);&lt;br /&gt;            return x;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;This code is similar to the previous example. It shows how to execute a function using PLINQ’s AsParallel extension. Now run the program. What you will see is something that you might not have expected. Notice that values 0 through 199 are printed however they are not printed in the correct order.&lt;/p&gt;&lt;p&gt;Think about it: we are using an enumerator from 0 to 200. However since we are using PLINQ and not LINQ; the partitioning itself is not serial. The work is divided into random parallel units; for example from 0 till 10 is assigned to thread A while from 11 till 30 is assigned to thread B and so on. Once a unit of work is done its output is immediately flushed back to the final result. That’s why the output is not arranged. The below image gives an indication about this:&lt;/p&gt;&lt;a href="http://1.bp.blogspot.com/_oG_VVyp2tR4/S7y_1YVFW6I/AAAAAAAAAFA/xcE4NMnSPdE/s1600/1.jpg"&gt;&lt;img style="WIDTH: 364px; HEIGHT: 341px; CURSOR: hand" id="BLOGGER_PHOTO_ID_5457447772251052962" border="0" alt="" src="http://1.bp.blogspot.com/_oG_VVyp2tR4/S7y_1YVFW6I/AAAAAAAAAFA/xcE4NMnSPdE/s400/1.jpg" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;p&gt;Now edit the code and use the AsOrdered extension as follows: &lt;/p&gt;&lt;pre lang="CS"&gt;var query = src.AsParallel().AsOrdered()&lt;br /&gt;                         .Select(x =&amp;gt; ExpensiveFunc(x));&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Run the example again and this time notice that the output is arranged from 0 till 199. This time the AsOrdered extension forces the use of a buffer where all work units outputs are gathered and arranged before being flushed back to the final output. The below image shows the process:&lt;/p&gt;&lt;a href="http://2.bp.blogspot.com/_oG_VVyp2tR4/S7zAWttFfCI/AAAAAAAAAFI/K7YFubClsWE/s1600/2.jpg"&gt;&lt;img style="WIDTH: 400px; HEIGHT: 227px; CURSOR: hand" id="BLOGGER_PHOTO_ID_5457448344924552226" border="0" alt="" src="http://2.bp.blogspot.com/_oG_VVyp2tR4/S7zAWttFfCI/AAAAAAAAAFI/K7YFubClsWE/s400/2.jpg" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;Example5: Data Races&lt;/h2&gt;&lt;p&gt;In Example2 I mentioned that Data Races can occur when doing multi-threading programming. This example shows a Data Race scenario and how to solve it.&lt;/p&gt;&lt;pre lang="CS"&gt;static void Main(string[] args)&lt;br /&gt;        {&lt;br /&gt;            Stopwatch watch = new Stopwatch();&lt;br /&gt;            watch.Start();&lt;br /&gt;            Parallel.For(0, 100000, i =&amp;gt;&lt;br /&gt;            {&lt;br /&gt;&lt;br /&gt;                Thread.Sleep(1);&lt;br /&gt;&lt;br /&gt;                counter++;&lt;br /&gt;            });&lt;br /&gt;            watch.Stop();&lt;br /&gt;            Console.WriteLine("Seconds Elapsed: " + watch.Elapsed.Seconds);&lt;br /&gt;            Console.WriteLine(counter.ToString());&lt;br /&gt;            Console.ReadKey();&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The above code again uses the Parallel.For method to execute a simple Sleep statement. A counter gets incremented each time the loop body gets executed.&lt;/p&gt;&lt;p&gt;What number do you expect to see if you run the program on a multi-core machine? 100000 is the logical result. Now run the program and you will notice that the number is less than that (if you do get 100000, you are just being lucky so try again:)). So what happened here? Why did we get this wrong when it seemed to be so obvious? The answer is data race occurred.&lt;/p&gt;&lt;p&gt;Let’s explain this. The trick here is in understanding how statement counter++ gets executed. When at Intermediate Language (IL) level, counter++ is not a single statement anymore. Actually it gets executed in 4 IL steps by the JIT (Just In-time Compiler):&lt;/p&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;Get the current value of counter &lt;/li&gt;&lt;li&gt;Get the value of 1 &lt;/li&gt;&lt;li&gt;Add the two numbers together &lt;/li&gt;&lt;li&gt;Save the result back to counter &lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;p&gt;So what does this have to do with Parallel Programming and using Parallel.For? When executed over multiple cores as we do now, the body of the loop gets executed in parallel over multiple threads. The following image explains what happens in this case:&lt;/p&gt;&lt;a href="http://1.bp.blogspot.com/_oG_VVyp2tR4/S7zAp9r3qbI/AAAAAAAAAFQ/GxOO_r5gm2A/s1600/3.jpg"&gt;&lt;img style="WIDTH: 400px; HEIGHT: 208px; CURSOR: hand" id="BLOGGER_PHOTO_ID_5457448675631933874" border="0" alt="" src="http://1.bp.blogspot.com/_oG_VVyp2tR4/S7zAp9r3qbI/AAAAAAAAAFQ/GxOO_r5gm2A/s400/3.jpg" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;p&gt;So as a result, one step increment was overlooked due to the fact that two threads were granted access to the variable counter at the same time. The above scenario occurs many times and you will get the final value wrong as we did when we ran the program. This is classical case of Data Race.&lt;/p&gt;&lt;p&gt;The solution of such case is to lock the variable so that once one thread is accessing that variable; some other thread has to wait until the lock is released before getting access to the variable. Granted this introduces time delay but it is a cost we have to pay for solving data races. &lt;/p&gt;&lt;p&gt;There are many ways we could use to lock a variable and a full discussion is outside the scope of this article, but I will use the best option in my case which is the Interlocked.Increment method as shown below (the “lock” statement is another method which is used in another example. The comments show how to use it instead):&lt;/p&gt;&lt;pre lang="CS"&gt;static void Main(string[] args)&lt;br /&gt;        {&lt;br /&gt;            //Object thisLock = new Object(); //if not using Interlocked&lt;br /&gt;&lt;br /&gt;            Stopwatch watch = new Stopwatch();&lt;br /&gt;            watch.Start();&lt;br /&gt;            Parallel.For(0, 100000, i =&amp;gt;&lt;br /&gt;            {&lt;br /&gt;&lt;br /&gt;                Thread.Sleep(1);&lt;br /&gt;&lt;br /&gt;                #region L&lt;br /&gt;                Interlocked.Increment(ref counter);&lt;br /&gt;                //lock (thisLock) //lock is another method and is done using two lines&lt;br /&gt;                //    counter++;&lt;br /&gt;                #endregion&lt;br /&gt;              &lt;br /&gt;                //counter++;&lt;br /&gt;            });&lt;br /&gt;            watch.Stop();&lt;br /&gt;            Console.WriteLine("Seconds Elapsed: " + watch.Elapsed.Seconds);&lt;br /&gt;            Console.WriteLine(counter.ToString());&lt;br /&gt;            Console.ReadKey();&lt;br /&gt;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;Example6: Debugging&lt;/h2&gt;&lt;p&gt;Note: this example is built by Microsoft.&lt;/p&gt;&lt;pre lang="CS"&gt;static void Main(string[] args)&lt;br /&gt;        {&lt;br /&gt;            var primes =&lt;br /&gt;                from n in Enumerable.Range(1, 10000000)&lt;br /&gt;                .AsParallel()&lt;br /&gt;                .AsOrdered()&lt;br /&gt;                .WithMergeOptions(ParallelMergeOptions.NotBuffered)&lt;br /&gt;                where IsPrime(n)&lt;br /&gt;                select n;&lt;br /&gt;            foreach (var prime in primes)&lt;br /&gt;                Console.Write(prime + ", ");&lt;br /&gt;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        public static bool IsPrime(int numberToTest)&lt;br /&gt;        {&lt;br /&gt;            if (numberToTest == 2) return true;&lt;br /&gt;            if (numberToTest &amp;lt; 2  (numberToTest &amp;amp; 1) == 0) return false;&lt;br /&gt;            int upperBound = (int)Math.Sqrt(numberToTest);&lt;br /&gt;            for (int i = 3; i &amp;lt; upperBound; i += 2)&lt;br /&gt;            {&lt;br /&gt;                if ((numberToTest % i) == 0) return false;&lt;br /&gt;            }&lt;br /&gt;            // It’s prime!&lt;br /&gt;            return true;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The above code uses PLINQ to print all prime numbers of a given range. There is nothing special about the parallel code itself, except that the IsPrime function has a logical error deliberately thrown inside it: on running the program you will notice that numbers 9, 15, and 25 are reported as prime numbers which is wrong. Now say you want to debug the IsPrime function and set a breakpoint inside it. Run the program and you will quickly notice the problem here: because multiple threads are executing, the debugging behavior is unclear as focus will switch from one thread to another as threads take turn hitting the break point.&lt;/p&gt;&lt;p&gt;To solve this issue Microsoft gave us the Parallel Tasks window (Debug Menu -&amp;gt; Windows -&amp;gt; Parallel Tasks):&lt;/p&gt;&lt;a href="http://3.bp.blogspot.com/_oG_VVyp2tR4/S7zA9U1viYI/AAAAAAAAAFY/EiNyyB5Y9yA/s1600/4.jpg"&gt;&lt;img style="WIDTH: 400px; HEIGHT: 194px; CURSOR: hand" id="BLOGGER_PHOTO_ID_5457449008264874370" border="0" alt="" src="http://3.bp.blogspot.com/_oG_VVyp2tR4/S7zA9U1viYI/AAAAAAAAAFY/EiNyyB5Y9yA/s400/4.jpg" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;p&gt;Through this window you can see all running threads in debug mode. You can select to freeze all threads except the one that you want to actually debug and once done you can run other threads.&lt;/p&gt;&lt;p&gt;Another useful window is the Parallel Stacks window (Debug Menu  Windows  Parallel Stacks):&lt;/p&gt;&lt;a href="http://4.bp.blogspot.com/_oG_VVyp2tR4/S7zBM06-0GI/AAAAAAAAAFg/4z-744t35Yc/s1600/5.jpg"&gt;&lt;img style="WIDTH: 400px; HEIGHT: 141px; CURSOR: hand" id="BLOGGER_PHOTO_ID_5457449274574819426" border="0" alt="" src="http://4.bp.blogspot.com/_oG_VVyp2tR4/S7zBM06-0GI/AAAAAAAAAFg/4z-744t35Yc/s400/5.jpg" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;p&gt;Through this window you can see a graphical representation of the running threads of your program and how they originated.&lt;/p&gt;&lt;h2&gt;Example7: Deadlocks&lt;/h2&gt;&lt;p&gt;Note: this example is built by Microsoft.&lt;/p&gt;&lt;p&gt;Example5 explained Data Races and how to deal with them through locks. However, you should take care that locking can bite you in the ugly form of Deadlocks. Simply put deadlock is a case where thread TA is locking resource R1 and thread TB is locking resource R2; now TA needs R2 to continue while TB needs R1 to continue. Both threads are stuck and cannot continue thus causing a deadlock.&lt;/p&gt;&lt;p&gt;Let’s see an example of such deadlock.&lt;/p&gt;&lt;pre lang="CS"&gt;static void Main(string[] args)&lt;br /&gt;        {&lt;br /&gt;            int transfersCompleted = 0;&lt;br /&gt;            WatchDeadlock.BreakIfRepeats(() =&amp;gt; transfersCompleted, 500);&lt;br /&gt;            BankAccount a = new BankAccount { Balance = 1000 };&lt;br /&gt;            BankAccount b = new BankAccount { Balance = 1000 };&lt;br /&gt;            while (true)&lt;br /&gt;            {&lt;br /&gt;                Parallel.Invoke(&lt;br /&gt;                () =&amp;gt; Transfer(a, b, 100),&lt;br /&gt;                () =&amp;gt; Transfer(b, a, 100));&lt;br /&gt;                transfersCompleted += 2;&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        class BankAccount { public int Balance; }&lt;br /&gt;        static void Transfer(BankAccount one, BankAccount two, int amount)&lt;br /&gt;        {&lt;br /&gt;            lock (one)&lt;br /&gt;            {&lt;br /&gt;                lock (two)&lt;br /&gt;                {&lt;br /&gt;                    one.Balance -= amount;&lt;br /&gt;                    two.Balance += amount;&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The above code uses Parallel.Invoke to concurrently perform money transfer between bank accounts “a” to “b” and vice versa. Inside the Transfer method, Locks are applied on both objects (using “lock” statement) with the intention of making it thread-safe for concurrent execution. This method of locking will cause a deadlock scenario.&lt;/p&gt;&lt;p&gt;The “WatchDeadlock” class is used to force break using Debugger.Break if it notices that no new transfers have been completed after a certain amount of time. &lt;/p&gt;&lt;p&gt;Run the program and see how now we have deadlock between our hands.&lt;/p&gt;&lt;p&gt;Let’s see how VS 2010 debugging support helps us identify such deadlocks. With the program running, fire the Parallel Tasks window. The window will clearly show you a case of deadlock. Not only that, it will specifically tell you what are the two threads causing the lock and how each thread is waiting a resource (in this case a Bank object) owned by the other thread:&lt;/p&gt;&lt;a href="http://2.bp.blogspot.com/_oG_VVyp2tR4/S7zBcv6BTXI/AAAAAAAAAFo/dtfBJEeicC8/s1600/6.jpg"&gt;&lt;img style="WIDTH: 400px; HEIGHT: 83px; CURSOR: hand" id="BLOGGER_PHOTO_ID_5457449548106517874" border="0" alt="" src="http://2.bp.blogspot.com/_oG_VVyp2tR4/S7zBcv6BTXI/AAAAAAAAAFo/dtfBJEeicC8/s400/6.jpg" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;p&gt;So how do you avoid deadlocks? The answer is: simply do not do them. When doing parallel programming and locks, always program in a way that deadlocks will not occur! &lt;/p&gt;&lt;h2&gt;Takeouts&lt;/h2&gt;&lt;p&gt;It’s obvious that the new Parallel Programming in .NET 4.0 solves a lot of the multi-threading complexities. It grants you more control over threads in the form of tasks, it gives you many method overloads for performing parallel operations like For, Foreach, and Invoke, it gives you the power of PLINQ, it does take care of partitioning for you, and it introduces new Thread-Safe collections in .NET 4.0 such as ConcurrentDictionary, ConcurrentQueue, and ConcurrentStack. In addition, improved debugging support makes it easier to handle parallel related problems. However, you still have to take care of multi-threading related concepts such as Data Races and Deadlocks.&lt;/p&gt;&lt;p&gt;The better news is that for Microsoft, Parallel Programming is still an ongoing project so we can expect more features and improved support in the next releases.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4918396109946207501-4417499649119679941?l=thedotnethub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thedotnethub.blogspot.com/feeds/4417499649119679941/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thedotnethub.blogspot.com/2010/04/introducing-net-40-parallel-programming.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/4417499649119679941'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/4417499649119679941'/><link rel='alternate' type='text/html' href='http://thedotnethub.blogspot.com/2010/04/introducing-net-40-parallel-programming.html' title='Introducing .NET 4.0 Parallel Programming'/><author><name>mohamad halabi</name><uri>http://www.blogger.com/profile/10259946099831243955</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_oG_VVyp2tR4/S7y_1YVFW6I/AAAAAAAAAFA/xcE4NMnSPdE/s72-c/1.jpg' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4918396109946207501.post-945783581721493687</id><published>2010-04-02T00:41:00.000+03:00</published><updated>2010-04-02T00:45:57.704+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='MVP'/><title type='text'>MVP is here!</title><content type='html'>It's been a while since I've blogged due to some mad things at work and personal life; but this is really worthy :)&lt;br /&gt;I have been awarded with the 2010 Microsoft® MVP Award...that's it for now until I activate the award and access the MVP site for the first time; this will be fun :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4918396109946207501-945783581721493687?l=thedotnethub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thedotnethub.blogspot.com/feeds/945783581721493687/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thedotnethub.blogspot.com/2010/04/mvp-is-here.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/945783581721493687'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/945783581721493687'/><link rel='alternate' type='text/html' href='http://thedotnethub.blogspot.com/2010/04/mvp-is-here.html' title='MVP is here!'/><author><name>mohamad halabi</name><uri>http://www.blogger.com/profile/10259946099831243955</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4918396109946207501.post-1455550582206126665</id><published>2009-12-23T10:13:00.001+03:00</published><updated>2009-12-23T10:27:46.463+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Concurrency'/><category scheme='http://www.blogger.com/atom/ns#' term='.NET 4.0'/><category scheme='http://www.blogger.com/atom/ns#' term='Parallel Programming'/><title type='text'>A Common Question: Concurrency vs Parallelism</title><content type='html'>While presenting a .NET 4.0 session in GDC, i came across Parallel Computing. I allocated about 15 minutes to this topic since the session was a lap around .NET 4.0 features...&lt;br /&gt;One of the questions I received and seemed to cause much of the confusion was the traditional one: What is the difference between Concurrency and Parallelism.&lt;br /&gt;&lt;br /&gt;Well both concepts are related but not the same: In its simplest definition, Concurrency is about executing multiple un-related tasks in a concurrent mode. What these un-related tasks share are system resources, but they do not share a common problem to solve; meaning, they are logically independent. Now think of these tasks as threads. And since these threads share system resources, then you face the globally common problems of concurrent programming such as deadlocks and data races. This makes concurrent programming extremely difficult and debugging even more tendous.&lt;br /&gt;&lt;br /&gt;So what is Parallelim? Parallelism is taking a certain task and dividing it into a set of realted tasks to be executed concurrently. Sweet! So again thinking of these tasks as threads, Parallel Programming still has the same problems of concurrent programming (deadlocks, data races, etc..) and introduces new challenges most notibly sharing and partitioning data across these related threads. This makes Parallel Programming even more difficult and debugging even more tendous :(&lt;br /&gt;&lt;br /&gt;However, it is not all bad news. .NET 4.0 parallel programming is a great step onwards. The new API solves a lot of problems (but not all) of Parallel Programming and greatly eases up Parallel Debugging...&lt;br /&gt;&lt;br /&gt;I will post more about this great feature, but for now I hope the idea is clarified.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4918396109946207501-1455550582206126665?l=thedotnethub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thedotnethub.blogspot.com/feeds/1455550582206126665/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thedotnethub.blogspot.com/2009/12/common-question-concurrency-vs.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/1455550582206126665'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/1455550582206126665'/><link rel='alternate' type='text/html' href='http://thedotnethub.blogspot.com/2009/12/common-question-concurrency-vs.html' title='A Common Question: Concurrency vs Parallelism'/><author><name>mohamad halabi</name><uri>http://www.blogger.com/profile/10259946099831243955</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4918396109946207501.post-8789598450265962994</id><published>2009-12-23T10:09:00.000+03:00</published><updated>2009-12-23T10:12:15.734+03:00</updated><title type='text'>GDC 09 Materials Available for download</title><content type='html'>As I mentioned before, &lt;a href="http://thedotnethub.blogspot.com/2009/12/gdc-09-is-over-now.html"&gt;GDC 09&lt;/a&gt; is over. Audiences requested the materials, and we love our audiences :)&lt;br /&gt;so go to &lt;a href="http://www.devlifestyle.net"&gt;www.devlifestyle.net&lt;/a&gt; to download the presentations and demos&lt;br /&gt;also there are a lot of vidoes uploaded there&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4918396109946207501-8789598450265962994?l=thedotnethub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thedotnethub.blogspot.com/feeds/8789598450265962994/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thedotnethub.blogspot.com/2009/12/gdc-09-materials-available-for-download.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/8789598450265962994'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/8789598450265962994'/><link rel='alternate' type='text/html' href='http://thedotnethub.blogspot.com/2009/12/gdc-09-materials-available-for-download.html' title='GDC 09 Materials Available for download'/><author><name>mohamad halabi</name><uri>http://www.blogger.com/profile/10259946099831243955</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4918396109946207501.post-7559590912515716933</id><published>2009-12-20T05:32:00.000+03:00</published><updated>2010-02-09T09:49:19.745+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='GDC 09'/><title type='text'>GDC 09 is over now!</title><content type='html'>The Gulf Developers Conference is over now, it was a great experience. I met some really nice people who also happen to be very experts, and this could not hurt :)&lt;br /&gt;&lt;br /&gt;I gave 5 sessions during the GDC:&lt;br /&gt;&lt;br /&gt;1. Cloud Computing Key Note; that was a last addition. I showed a simple demo about creating and deploying an ASP.NET web role on windows Azure&lt;br /&gt;&lt;br /&gt;2. Cloud Computing Chalk-talk. It was a detailed discussion about cloud computing in general and i showed detailed demos about Windows Azure, SQL Azure, .NET Services, and Live Services. This was an amazing session with people eager to discuss and share their ideas. Time passed by very quickly.&lt;br /&gt;&lt;br /&gt;3. A Lap Around .NET 4.0. This was a very packed session. A lot of features to be explained in 75 minutes. I showed 1-Click web deployment, Ajax 4.0, Parallel Computing (my personal favorite), Entity Framework, Data Services (REST is sooo cool!), CLR Type Equivelance, and Dynamic Data. My head was spinning towards the end!&lt;br /&gt;&lt;br /&gt;4. Building SOA Applications with WCF and WF 4.0. Focused mainly on WCF advantages and why to use it. Then I created an example of a SOA app based on WF 4.0 Services (that's also covering WCF) and Data Services.&lt;br /&gt;&lt;br /&gt;5. A comparison of Integration Technologies Chalk-talk. The main focus was BizTalk Server due to the audiences requests, but i also discussed WF-Services and the new Windows Server AppFabric. This was a cool session as somewhere during the middle of the session, 6 experts were suddenly added as guests to the session and I had to manage and give each one a role to perform...wondering why? MBC tv channel came to shoot and they wanted to create the ultimate Chalk-talk environment :)&lt;br /&gt;&lt;br /&gt;Anyway, most of the materials are posted on &lt;a href="http://www.devlifestyle.net"&gt;DevLifestyle&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;I will post about all these technologies in the near future...so stay tuned&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4918396109946207501-7559590912515716933?l=thedotnethub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thedotnethub.blogspot.com/feeds/7559590912515716933/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thedotnethub.blogspot.com/2009/12/gdc-09-is-over-now.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/7559590912515716933'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/7559590912515716933'/><link rel='alternate' type='text/html' href='http://thedotnethub.blogspot.com/2009/12/gdc-09-is-over-now.html' title='GDC 09 is over now!'/><author><name>mohamad halabi</name><uri>http://www.blogger.com/profile/10259946099831243955</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4918396109946207501.post-5759071724649550245</id><published>2009-12-08T15:41:00.000+03:00</published><updated>2009-12-08T15:50:37.817+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='.NET Service Bus'/><category scheme='http://www.blogger.com/atom/ns#' term='Azure AppFabric'/><category scheme='http://www.blogger.com/atom/ns#' term='Azure'/><title type='text'>Azure Service Bus Lab: ContractFilter Mismatch Error</title><content type='html'>If you are following the Windows Azure (November CTP) SDK, and you are implementing the .NET Service Bus (AppFabric) Hands on lab called "Introduction to the .NET Service Bus", then there is an error that you need to correct.&lt;br /&gt;&lt;br /&gt;In task 4 titled "Task 4 – Creating the WCF Client Project ", the lab says that you create an interface IEchoContract and apply to it the following attribute:&lt;br /&gt;&lt;br /&gt;[ServiceContract(Name = "EchoContract", Namespace = "http://samples.microsoft.com/ServiceModel/Relay/")]&lt;br /&gt;&lt;br /&gt;Well the Name is wrong. if you have followed the lab manual precisely, then the Name should be "IEchoContract" instead.&lt;br /&gt;&lt;br /&gt;If you run the sample without correcting the issue, you will be faced with the following exception:&lt;br /&gt;&lt;br /&gt;The message with Action 'http://samples.microsoft.com/ServiceModel/Relay/' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver.  Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None)."&lt;br /&gt;&lt;br /&gt;This problem can also appear if the namespace is different between the client and the service, so make sure to use the same namespace&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4918396109946207501-5759071724649550245?l=thedotnethub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thedotnethub.blogspot.com/feeds/5759071724649550245/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thedotnethub.blogspot.com/2009/12/azure-service-bus-lab-contractfilter.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/5759071724649550245'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/5759071724649550245'/><link rel='alternate' type='text/html' href='http://thedotnethub.blogspot.com/2009/12/azure-service-bus-lab-contractfilter.html' title='Azure Service Bus Lab: ContractFilter Mismatch Error'/><author><name>mohamad halabi</name><uri>http://www.blogger.com/profile/10259946099831243955</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4918396109946207501.post-2701661908225230749</id><published>2009-12-01T17:10:00.000+03:00</published><updated>2009-12-01T17:20:11.445+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='SQL Azure'/><category scheme='http://www.blogger.com/atom/ns#' term='Azure'/><title type='text'>SQL Azure Object Browser Support in SQL Server 2008</title><content type='html'>If you are playing with the Azure training kit (November update) and you come across the lab about setting up SQL Azure, then you need to notice one thing:&lt;br /&gt;&lt;br /&gt;the lab shows you how to connect to the cloud database using SQL Server 2008 R2 and thus you will get the Object Browser support.&lt;br /&gt;&lt;br /&gt;However, the object browser is not supported in SQL Server 2008 pre-R2. So if you follow the steps without having R2 you will end up with an error message saying:&lt;br /&gt;"Invalid Object name sys.configurations".&lt;br /&gt;The reason is that the Management Studio cannot load the Object Browser from SQL Azure simply because it is not supported yet (again for pre-2008 R2 releases).&lt;br /&gt;&lt;br /&gt;So the only way to connect to your SQL Azure database is through the "New Query" link in the Management Studio. This will give you full connectivity but without the Object Browser, so you will have to rely on your DDL skills to manage your db objects.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4918396109946207501-2701661908225230749?l=thedotnethub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thedotnethub.blogspot.com/feeds/2701661908225230749/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thedotnethub.blogspot.com/2009/12/sql-azure-object-browser-support-in-sql.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/2701661908225230749'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/2701661908225230749'/><link rel='alternate' type='text/html' href='http://thedotnethub.blogspot.com/2009/12/sql-azure-object-browser-support-in-sql.html' title='SQL Azure Object Browser Support in SQL Server 2008'/><author><name>mohamad halabi</name><uri>http://www.blogger.com/profile/10259946099831243955</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4918396109946207501.post-3294824159569089690</id><published>2009-12-01T12:19:00.001+03:00</published><updated>2009-12-01T12:28:16.866+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Azure'/><title type='text'>Activating Azure Storage Service for Non SQL Express</title><content type='html'>I recently installed the November release of the Azure SDK.&lt;br /&gt;&lt;br /&gt;I created a sample Web Role application and tried to run it, but I got the below error:&lt;br /&gt;&lt;br /&gt;"Windows Azure Tools: Failed to initialize the Development Storage service. Unable to start Development Storage. Failed to start Development Storage: the SQL Server instance ‘localhost\SQLExpress’ could not be found.   Please configure the SQL Server instance for Development Storage using the ‘DSInit’ utility in the Windows Azure SDK."&lt;br /&gt;&lt;br /&gt;Under default configurations, the SDK will point your storage service into SQL Server express instance.&lt;br /&gt;Well in my case I did not have Express, instead I had SQL Server 2008 Dev Edition. &lt;br /&gt;&lt;br /&gt;So to resolve this, go to the "Windows Azure SDK Command Prompt" and run the following command:&lt;br /&gt;DSInit /sqlInstance:. /forceCreate&lt;br /&gt;&lt;br /&gt;This will create your storage database under the default instance. Of course you will have to supply the named instance in case you have one. For example:&lt;br /&gt;&lt;br /&gt;DSInit /sqlInstance:MyNamedInstance&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4918396109946207501-3294824159569089690?l=thedotnethub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thedotnethub.blogspot.com/feeds/3294824159569089690/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thedotnethub.blogspot.com/2009/12/activating-azure-storage-service-for.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/3294824159569089690'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/3294824159569089690'/><link rel='alternate' type='text/html' href='http://thedotnethub.blogspot.com/2009/12/activating-azure-storage-service-for.html' title='Activating Azure Storage Service for Non SQL Express'/><author><name>mohamad halabi</name><uri>http://www.blogger.com/profile/10259946099831243955</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4918396109946207501.post-9169787928072508945</id><published>2009-11-21T13:48:00.000+03:00</published><updated>2009-11-21T13:53:11.769+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='PDC 2009'/><title type='text'>PDC 2009 Videos Released</title><content type='html'>The Professional Developers Conference (PDC) 2009 was recently held in LA between 17 and 19 November.&lt;br /&gt;PDC is the biggest Microsoft developer event where usually new technology releases are discussed.&lt;br /&gt;Now the videos for the sessions are released, and as usual some really great stuff to learn.&lt;br /&gt;You can download the videos here:&lt;br /&gt;&lt;br /&gt;http://microsoftpdc.com/Videos&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4918396109946207501-9169787928072508945?l=thedotnethub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thedotnethub.blogspot.com/feeds/9169787928072508945/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thedotnethub.blogspot.com/2009/11/pdc-2009-videos-released.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/9169787928072508945'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/9169787928072508945'/><link rel='alternate' type='text/html' href='http://thedotnethub.blogspot.com/2009/11/pdc-2009-videos-released.html' title='PDC 2009 Videos Released'/><author><name>mohamad halabi</name><uri>http://www.blogger.com/profile/10259946099831243955</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4918396109946207501.post-4786942499807354769</id><published>2009-11-14T11:45:00.000+03:00</published><updated>2009-11-15T09:40:20.603+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Ajax 4.0'/><category scheme='http://www.blogger.com/atom/ns#' term='.NET 4.0'/><category scheme='http://www.blogger.com/atom/ns#' term='ASPNET'/><title type='text'>ASP.NET Ajax 4.0 takes the page on a diet</title><content type='html'>I was playing around with the VS 2010 Beta 2 training kit and came across the new ASP.NET Ajax 4.0. A lot of interesting stuff there, but a killer feature is how Ajax now gives you the ability to minimize the request and response size.&lt;br /&gt;&lt;br /&gt;See prior to 4.0, Ajax most famous control was the UpdatePanel. Granted, that is a great control and used heavily; it still lacked the true heart and soul of pure client-side Ajax. UpdatePanel kept both data processing and HTML rendering at the server. This caused that each page post was actually a full post with a full page life cycle and the &lt;a href="http://thedotnethub.blogspot.com/2009/03/aspnet-viewstate-and-page-life-cycle.html"&gt;viewstate&lt;/a&gt; rendered was still fairly large.&lt;br /&gt;&lt;br /&gt;Now in 4.0, Ajax improves on the idea of client-side templates. That is moving the responsibility of HTML generation to the client and thus giving the server only the mission of data processing. This results in smaller request size and smaller viewstate in the response.&lt;br /&gt;  &lt;br /&gt;If you already have the 2010 beta 2 training kit installed, you will find the following solution:&lt;br /&gt;&lt;br /&gt;[installation path]\Demos\AspNetAjax10in1\Source\AjaxApplication.sln&lt;br /&gt;&lt;br /&gt;This is a really great source to start learning about Ajax 4.0, but I want to show you how the page size is reduced:&lt;br /&gt;&lt;br /&gt;The page “1_ServerSideAjax.aspx” is a traditional Ajax page. It uses the UpdatePanel to partially load a set of data based on an item selection of a dropdown list. Run this page and change the item selected as follows:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://3.bp.blogspot.com/_oG_VVyp2tR4/Sv5uXQ9xRTI/AAAAAAAAAEE/dTMDC9ce2mw/s1600-h/1.JPG"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 400px; height: 202px;" src="http://3.bp.blogspot.com/_oG_VVyp2tR4/Sv5uXQ9xRTI/AAAAAAAAAEE/dTMDC9ce2mw/s400/1.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5403877948861269298" /&gt;&lt;/a&gt;&lt;br /&gt; &lt;br /&gt;Great, now view the source of the page and take note of the view state:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://3.bp.blogspot.com/_oG_VVyp2tR4/Sv5ubiwYo7I/AAAAAAAAAEM/P49cSI-UCdA/s1600-h/2.JPG"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 400px; height: 120px;" src="http://3.bp.blogspot.com/_oG_VVyp2tR4/Sv5ubiwYo7I/AAAAAAAAAEM/P49cSI-UCdA/s400/2.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5403878022356444082" /&gt;&lt;/a&gt;&lt;br /&gt; &lt;br /&gt;That is a lot of viewstate!&lt;br /&gt;&lt;br /&gt;Now similarly run page “2_ClientSideAjax.aspx” and select the same item. View the source and take a note of the viewstate:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://3.bp.blogspot.com/_oG_VVyp2tR4/Sv5uen24TPI/AAAAAAAAAEU/VeRQo2g8xr0/s1600-h/3.JPG"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 400px; height: 36px;" src="http://3.bp.blogspot.com/_oG_VVyp2tR4/Sv5uen24TPI/AAAAAAAAAEU/VeRQo2g8xr0/s400/3.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5403878075265469682" /&gt;&lt;/a&gt;&lt;br /&gt; &lt;br /&gt;See how much the viewstate is reduced! This is amazing. The difference is that in Ajax 4.0 you can define client templates and use new client controls like the DataView control (not to be confused with the ADO.NET DataView). Now the request to the server is issued to a web service which returns result in the Javascript Object Notation (JSON) format. The result data is then de-serialized and bound to the client control. This idea of keeping the rendering responsibility on the client while getting only the data from the server, greatly reduces both request and response viewstate size.&lt;br /&gt;&lt;br /&gt;Let’s have a look at how this is implemented. Open the “2_ClientSideAjax.aspx” page and notice the following line:&lt;br /&gt;&lt;br /&gt;movieView = $create(Sys.UI.DataView, {}, {}, {}, $get("movieBody"));&lt;br /&gt;&lt;br /&gt;The $create function of the Ajax Sys library created a new client control; this control is of type Sys.UI.DataView. Also the $get function acts as a shortcut for the getElementById function to get the movieBody template which is defined in the page as follows:&lt;br /&gt;&lt;br /&gt;&amp;lt;tbody id="movieBody" class="sys-template"&amp;gt;&lt;br /&gt;    &amp;lt;tr&amp;gt;&lt;br /&gt;        &amp;lt;td&amp;gt;{{ Title }}&amp;lt;/td&amp;gt;&lt;br /&gt;        &amp;lt;td&amp;gt;{{ Director }}&amp;lt;/td&amp;gt;&lt;br /&gt;        &amp;lt;td&amp;gt;{{ DateReleased.localeFormat("D") }}&amp;lt;/td&amp;gt;        &lt;br /&gt;    &amp;lt;/tr&amp;gt;&lt;br /&gt;    &amp;lt;/tbody&amp;gt;&lt;br /&gt; &lt;br /&gt;“Title”, “Director”, and “DateReleased” are binding fields which will be returned by the JSON response of the web service. The below line calls the web service:&lt;br /&gt;&lt;br /&gt;AjaxApplication.Services.MovieService.GetMovies(categoryId, showMoviesComplete);&lt;br /&gt;&lt;br /&gt;If you are like me and would want to examine things behind the scenes, open your favorite network monitoring tool – such as Fiddler and examine the traffic. You will see for example that the request and response for the page using the UpdatePanel:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://3.bp.blogspot.com/_oG_VVyp2tR4/Sv5uieXpd4I/AAAAAAAAAEc/47-O6FquJlo/s1600-h/4.JPG"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 400px; height: 381px;" src="http://3.bp.blogspot.com/_oG_VVyp2tR4/Sv5uieXpd4I/AAAAAAAAAEc/47-O6FquJlo/s400/4.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5403878141438031746" /&gt;&lt;/a&gt;&lt;br /&gt; &lt;br /&gt;Now examine the request and response for the page using Ajax 4.0:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://4.bp.blogspot.com/_oG_VVyp2tR4/Sv5ulnfh_dI/AAAAAAAAAEk/zE7Z9bktXFs/s1600-h/5.JPG"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 400px; height: 305px;" src="http://4.bp.blogspot.com/_oG_VVyp2tR4/Sv5ulnfh_dI/AAAAAAAAAEk/zE7Z9bktXFs/s400/5.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5403878195426622930" /&gt;&lt;/a&gt;&lt;br /&gt; &lt;br /&gt;Notice any difference!!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4918396109946207501-4786942499807354769?l=thedotnethub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thedotnethub.blogspot.com/feeds/4786942499807354769/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thedotnethub.blogspot.com/2009/11/aspnet-ajax-40-takes-page-on-diet.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/4786942499807354769'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/4786942499807354769'/><link rel='alternate' type='text/html' href='http://thedotnethub.blogspot.com/2009/11/aspnet-ajax-40-takes-page-on-diet.html' title='ASP.NET Ajax 4.0 takes the page on a diet'/><author><name>mohamad halabi</name><uri>http://www.blogger.com/profile/10259946099831243955</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_oG_VVyp2tR4/Sv5uXQ9xRTI/AAAAAAAAAEE/dTMDC9ce2mw/s72-c/1.JPG' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4918396109946207501.post-8673304455804884499</id><published>2009-11-10T07:03:00.000+03:00</published><updated>2009-11-10T07:31:43.103+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='PIA'/><category scheme='http://www.blogger.com/atom/ns#' term='.NET 4.0'/><category scheme='http://www.blogger.com/atom/ns#' term='interop'/><category scheme='http://www.blogger.com/atom/ns#' term='CLR4'/><title type='text'>CLR4 No-PIA</title><content type='html'>One of the .NET 4.0 (actually CLR4) enhancements is a feature called “No-PIA” which greatly enhances COM interoperability. This fits in a larger picture in CLR4 which is Type Equivalence. &lt;br /&gt;First let’s review what PIA is…&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;Primary Interop Assemblies (PIAs)&lt;/h2&gt;&lt;br /&gt;MSDN best described PIA as follows:&lt;br /&gt;&lt;br /&gt;&lt;i&gt;“Like any other managed assembly, an interop assembly is a collection of types that are deployed, versioned, and configured as a single unit. However, unlike other managed assemblies, an interop assembly contains type definitions (not implementation) of types that have already been defined in COM. These type definitions allow managed applications to bind to the COM types at compile time and provide information to the common language runtime about how the types should be marshaled at run time.&lt;br /&gt;While any number of interop assemblies may exist that describe a given COM type, only one interop assembly is labeled the PIA. The PIA contains the official description of the types as defined by the publisher of those types. The PIA may contain certain customizations that make the types easier to use from managed code. The PIA is always signed by the publisher of the original COM type.&lt;br /&gt;The Tlbimp (Type Library Importer) tool provided in the Microsoft® .NET Framework SDK is capable of creating an interop assembly from an existing type library.”&lt;/i&gt;&lt;br /&gt;&lt;h2&gt;Importance of PIA&lt;/h2&gt;&lt;br /&gt;Again best explained via MSDN:&lt;br /&gt;&lt;br /&gt;&lt;i&gt;“Not using a PIA will lead to type incompatibilities for customers. For example, Company A uses the COM Widget object provided by the Acme Company within its managed application. Company A decides to produce another interop assembly with definitions of Acme's Widget library rather than use the PIA provided by the Acme Company. &lt;br /&gt;Company B obtains the PIA for the Widget Library directly from the Acme Company and uses it within its managed application. Both applications work fine on their own until a developer from one of Company A and Company B's common customers calls to find out why he keeps getting a type mismatch whenever he tries to pass a Widget from Company A to Company B. &lt;br /&gt;The reason for the type mismatch is because the Widget type used by Company A is completely different from the Widget type used by Company B. Even though they both have the same name, each interop assembly was signed by a different publisher, thereby making the types incompatible. The simple solution is for both companies to use the PIA provided by the Acme Company.”&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;Umm…so why the hell are you bragging about no-PIA?!&lt;/h2&gt;&lt;br /&gt;Actually no-PIA does not mean that PIAs are not there anymore. It simply means that you do not have to carry them with you anymore! Ok so let’s elaborate…&lt;br /&gt;&lt;br /&gt;Say you have a .NET 3.x application which “talks” to Microsoft Excel. When deploying your application on client machine A you have to include the PIA of Excel in your deployment. Why? Simply because Microsoft Office does not require the installation of .NET framework (it is a COM application right?), so it is very likely that by the time Office was installed on machine A, the Excel PIA was not installed with it due to the fact that .NET framework is missing. PIAs are managed assemblies that live in the GAC so they need .NET framework. &lt;br /&gt;&lt;br /&gt;So now when you want to deploy your application, you will want to include the PIA with it.&lt;br /&gt;&lt;br /&gt;What is so bad about deploying PIAs with your application you might say? It’s size. Office PIAs for example are multi MBs of size which you will have to deploy when your application is probably few KBs of size. This extra size is an overhead especially when you know you are using a very small number of interfaces available in that PIA and you do not need to deploy and load the whole thing.&lt;br /&gt;&lt;h2&gt;No-PIA to the rescue&lt;/h2&gt;&lt;br /&gt;Now in .NET 4.0 and CLR4 (or CLR3 if you keep counting from the previous version CLR2), you can instruct your assembly to include inside it only the needed types of the PIA and thus the PIA won’t have to be deployed along with your application.&lt;br /&gt;&lt;br /&gt;Let’s see an example.&lt;br /&gt;&lt;br /&gt;Below  is a simple VS 2010/C# 4.0 (currently beta2) console application code which simply creates an Excel document.&lt;br /&gt;&lt;br /&gt;&lt;div style="width:400px;height:600px;border-width:1px;border-color:black;border-style:solid"&gt;&lt;br /&gt;class Program&lt;br /&gt;    {&lt;br /&gt;        static void Main(string[] args)&lt;br /&gt;        {&lt;br /&gt;            var x1 = new Excel.Application();&lt;br /&gt;            &lt;br /&gt;            x1.Workbooks.Add();&lt;br /&gt;            x1.Visible = true;&lt;br /&gt;            x1.get_Range("A1").Value2 = "Name";&lt;br /&gt;            x1.get_Range("B1").Value2 = "Gender";&lt;br /&gt;            x1.get_Range("C1").Value2 = "Age";&lt;br /&gt;&lt;br /&gt;            x1.get_Range("A2").Value2 = "Mohd";&lt;br /&gt;            x1.get_Range("B2").Value2 = "Male";&lt;br /&gt;            x1.get_Range("C2").Value2 = "27";&lt;br /&gt;&lt;br /&gt;            x1.get_Range("A3").Value2 = "Sara";&lt;br /&gt;            x1.get_Range("B3").Value2 = "Female";&lt;br /&gt;            x1.get_Range("C3").Value2 = "25";&lt;br /&gt;            x1.get_Range("A3").Select();&lt;br /&gt;&lt;br /&gt;            ((Excel.Range)x1.Columns[1]).AutoFit();&lt;br /&gt;            ((Excel.Range)x1.Columns[2]).AutoFit();&lt;br /&gt;            ((Excel.Range)x1.Columns[3]).AutoFit();&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;The below screen shot shows this:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://2.bp.blogspot.com/_oG_VVyp2tR4/Svjns2OsBiI/AAAAAAAAADE/IC_4uebpHfU/s1600-h/1.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 400px; height: 128px;" src="http://2.bp.blogspot.com/_oG_VVyp2tR4/Svjns2OsBiI/AAAAAAAAADE/IC_4uebpHfU/s400/1.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5402322510688290338" /&gt;&lt;/a&gt;&lt;br /&gt; &lt;br /&gt;The Excel PIA is added as a reference for the project. It is through this PIA that the managed code interacts with Excel. The PIA contains all the managed equivalent of interfaces, structs, enums, delegates, etc…defined in the COM with the required marshalling data…see the below image:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://3.bp.blogspot.com/_oG_VVyp2tR4/SvjnyEUgnsI/AAAAAAAAADM/fpObNYMb3B4/s1600-h/2.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 293px; height: 332px;" src="http://3.bp.blogspot.com/_oG_VVyp2tR4/SvjnyEUgnsI/AAAAAAAAADM/fpObNYMb3B4/s400/2.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5402322600370151106" /&gt;&lt;/a&gt;&lt;br /&gt; &lt;br /&gt;Now if you use .NET reflector, you will find that our managed assembly (ExcelAddIn.exe) actually has the Excel PIA as a reference; which is predictable of course. So in this case when we deploy the application we have to deploy the PIA with it. See the below screen shot:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://3.bp.blogspot.com/_oG_VVyp2tR4/Svjn33OZuDI/AAAAAAAAADU/HX8se4mmA0Q/s1600-h/3.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 400px; height: 335px;" src="http://3.bp.blogspot.com/_oG_VVyp2tR4/Svjn33OZuDI/AAAAAAAAADU/HX8se4mmA0Q/s400/3.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5402322699934087218" /&gt;&lt;/a&gt;&lt;br /&gt; &lt;br /&gt;However, what you can do is open the VS2010 properties box of the referenced PIA and change the property “Embed Interop Types” to true. This will instruct the compiler to embed the portions (types) of the PIA that your application use inside the application’s assembly itself. This way the PIA is not needed anymore and your application is using the required types implicitly. Check the below image:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://4.bp.blogspot.com/_oG_VVyp2tR4/SvjoA5aS60I/AAAAAAAAADc/pzWatci_63c/s1600-h/4.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 222px; height: 400px;" src="http://4.bp.blogspot.com/_oG_VVyp2tR4/SvjoA5aS60I/AAAAAAAAADc/pzWatci_63c/s400/4.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5402322855139666754" /&gt;&lt;/a&gt;&lt;br /&gt; &lt;br /&gt;As we will see in more details shortly, CLR4 will make sure that the types embedded inside the application’s assembly are equivalent with the types defined in the PIA; this is known as CLR4 “Type Equivalence”.&lt;br /&gt;&lt;br /&gt;Ok, build your application. Refresh .NET reflector and now you can see that the PIA is no longer a reference. Instead the types used by the application are now embedded as namespaces inside the assembly itself. This way the application is not depending on the PIA anymore; hence no-PIA! See the below screen shot:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://1.bp.blogspot.com/_oG_VVyp2tR4/SvjoNtTsdfI/AAAAAAAAADk/n9m93jcwBs0/s1600-h/5.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 376px; height: 400px;" src="http://1.bp.blogspot.com/_oG_VVyp2tR4/SvjoNtTsdfI/AAAAAAAAADk/n9m93jcwBs0/s400/5.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5402323075229054450" /&gt;&lt;/a&gt;&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;CLR4 Type Equivalence&lt;/h2&gt;&lt;br /&gt;You have seen how VS 2010 enables you to change a property and the compiler will embed the needed types inside the assembly. However, let’s dive into a little more details.&lt;br /&gt;&lt;br /&gt;Locate the Excel PIA physical path on the machine and add it to the .NET reflector. Now you have the applications assembly (with no-PIA) and the PIA itself both loaded inside the reflector. Below is the view:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://2.bp.blogspot.com/_oG_VVyp2tR4/SvjoSE6XQQI/AAAAAAAAADs/Hb4GFdZah7Y/s1600-h/6.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 400px; height: 274px;" src="http://2.bp.blogspot.com/_oG_VVyp2tR4/SvjoSE6XQQI/AAAAAAAAADs/Hb4GFdZah7Y/s400/6.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5402323150284734722" /&gt;&lt;/a&gt;&lt;br /&gt; &lt;br /&gt;Now expand the Microsoft.Office.Interop.Excel namespace inside ExcelAddIn.exe and disassemble interface _Application as shown below:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://2.bp.blogspot.com/_oG_VVyp2tR4/Svjpvb6S8SI/AAAAAAAAAD0/y7JqPMUIkr4/s1600-h/7.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 400px; height: 193px;" src="http://2.bp.blogspot.com/_oG_VVyp2tR4/Svjpvb6S8SI/AAAAAAAAAD0/y7JqPMUIkr4/s400/7.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5402324754186301730" /&gt;&lt;/a&gt;&lt;br /&gt; &lt;br /&gt;Notice the new 4.0 keyword: TypeIdentifier. This tells the CLR that this type will participate in type equivalency. But how is this type equivalency actually happens? It is through the Guid. This Guid will be matched up by the CLR with the PIA type equivalent Guid such that when the application passes the interop type to the native code (Excel), this certifies that the application is using the same version of the type expected by Excel.&lt;br /&gt;&lt;br /&gt;To witness this, expand the dll Microsoft.Office.Interop.Excel and again disassemble interface _Application. You will notice that it has the same Guid of the type embedded inside the assembly. This is how the CLR did the type equivalence matching:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://4.bp.blogspot.com/_oG_VVyp2tR4/SvjpzkiH_AI/AAAAAAAAAD8/_5OBMFfpgBg/s1600-h/8.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 400px; height: 141px;" src="http://4.bp.blogspot.com/_oG_VVyp2tR4/SvjpzkiH_AI/AAAAAAAAAD8/_5OBMFfpgBg/s400/8.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5402324825220316162" /&gt;&lt;/a&gt;&lt;br /&gt; &lt;br /&gt;Of course it should be clear by now, but still worth mentioning: notice how the PIA has tons of types defined but only the ones needed by the application have been imported to the assembly.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4918396109946207501-8673304455804884499?l=thedotnethub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thedotnethub.blogspot.com/feeds/8673304455804884499/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thedotnethub.blogspot.com/2009/11/clr4-no-pia.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/8673304455804884499'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/8673304455804884499'/><link rel='alternate' type='text/html' href='http://thedotnethub.blogspot.com/2009/11/clr4-no-pia.html' title='CLR4 No-PIA'/><author><name>mohamad halabi</name><uri>http://www.blogger.com/profile/10259946099831243955</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_oG_VVyp2tR4/Svjns2OsBiI/AAAAAAAAADE/IC_4uebpHfU/s72-c/1.jpg' height='72' width='72'/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4918396109946207501.post-5189056579911296866</id><published>2009-11-06T17:51:00.000+03:00</published><updated>2009-11-06T18:26:28.353+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='VS 2010'/><category scheme='http://www.blogger.com/atom/ns#' term='One Click Deployment'/><title type='text'>VS 2010 1-Click Publishing</title><content type='html'>Web applications deployment has always been a tricky task for developers. Developers used to have many ways to perform deployment ranging from X-Copy to FTP to using installers. However, all deployment options have common problems; these are:&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;The solution has to be separately packaged. The database is just another package.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;After generating the packages, these should go “somehow” to the destination server and the deployment will happen on that server.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;On the destination server, IIS deployment for the web app and database deployment are two different tasks.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;On the destination server, configuration files have to be edited to reflect on the new environment such as database connection strings.&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;These problems have just surfaced the difficulties usually associated with deploying large APS.NET applications.&lt;br /&gt;&lt;br /&gt;Well in VS 2010 (currently in beta2), there is a huge feature: this is 1-Click Deployment (or publishing). It basically allows the developer to deploy the application along with the database and configuration changes directly from his development box to the destination server with one click!&lt;br /&gt;&lt;br /&gt;The technology behind 1-Click Deployment is MSDeploy. VS 2010 uses MSDeploy implicitly to implement the deployment. &lt;br /&gt;&lt;br /&gt;In the source server (development box), VS 2010 uses MSDeploy to create a zipped package of your project (containing web app, database with data, and deployment configurations). This package is then sent to the destination server which will have MSDeploy configured to listen to deployment requests and will perform the actual deployment of you web app and your database! Note that MSDeploy is installed with VS 2010 by default.&lt;br /&gt;&lt;br /&gt;Well in this article I will show you two walkthroughs on how this is implemented; during which I will try to highlight how stuff is happening…&lt;br /&gt;&lt;h2&gt;Deploying on a Hosting Company&lt;/h2&gt;&lt;br /&gt;When deploying web apps, you usually have two options; you either deploy on a web hosting company or on a server which you own. First let’s discuss option 1.&lt;br /&gt;ORCSWeb (https://www.orcsweb.com/signup/?planid=58) allows you to create free testing accounts to deploy VS 2010 Beta 2 web projects. I have created an account and during the registration process I have selected SQL Server 2008 as my database; because then they will allow you to deploy your app along with the database…&lt;br /&gt;&lt;br /&gt;After completing registration, I received an email containing the information I need to deploy. Lets us review the information:&lt;br /&gt;&lt;div style="width:900px;height:400px;border:1px solid black;"&gt;&lt;br /&gt;The information that you will need to enter into the Visual Studio "Publish Web" wizard is:&lt;br /&gt;Publish Method: MSDeploy Publish&lt;br /&gt;Service URL: https://SHARED18.orcsweb.com:8172/msdeploy.axd&lt;br /&gt;Site/Application: ITD1.orcsweb (you can optionally append a subfolder name)&lt;br /&gt;Allow Untrusted Certificate needs to be checked.&lt;br /&gt;User Name: itd1&lt;br /&gt;Password: xxxxxx&lt;br /&gt;&lt;br /&gt;You can view your site here: http://206.72.116.231/&lt;br /&gt;&lt;br /&gt;Additionally, you can deploy a database by going to &lt;br /&gt;the properties of the project and then the Deploy-SQL tab.&lt;br /&gt;&lt;br /&gt;Your database connection string is:&lt;br /&gt;Password=xxxxx;User ID=ITD1.orcsweb;Initial Catalog=ITD1.orcsweb;&lt;br /&gt;Data Source=sql08-2.orcsweb.com&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;The new thing to you might be the “Service URL”. This is the IIS handler which will perform the actual deployment of the application on the hosting server. See in the destination server assigned to me by ORCSWeb, MSDeploy is running and configured to listen to requests on the specified handler to perform the actual deployment. This detail is hidden from you in this case and is done by the destination server admin (ORCSWeb in this case). In the next walkthrough I will show you how to set up your own destination server to listen to requests from VS 2010…&lt;br /&gt;&lt;br /&gt;MSDeploy also comes with a SQL handler to perform database deployment. This will also be called implicitly on the destination server.&lt;br /&gt;Going back to the information, I have been supplied by a username/password combination to submit while deploying and with a SQL connection string for my database deployment.&lt;br /&gt;&lt;br /&gt;So now let’s see my web app I want to deploy. In VS 2010 I have created the simplest of applications: I used the default web app template and added a second page which reads a list of “Departments” from a SQL Server 2008 table.&lt;br /&gt;The below screen shots shows my simple app:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://3.bp.blogspot.com/_oG_VVyp2tR4/SvQ7T_UpGsI/AAAAAAAAACE/N_x8aFrelpQ/s1600-h/1.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 400px; height: 216px;" src="http://3.bp.blogspot.com/_oG_VVyp2tR4/SvQ7T_UpGsI/AAAAAAAAACE/N_x8aFrelpQ/s400/1.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5401007067725634242" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://2.bp.blogspot.com/_oG_VVyp2tR4/SvQ74nXVqDI/AAAAAAAAACM/AyeHsA1MpAM/s1600-h/2.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 400px; height: 269px;" src="http://2.bp.blogspot.com/_oG_VVyp2tR4/SvQ74nXVqDI/AAAAAAAAACM/AyeHsA1MpAM/s400/2.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5401007696949651506" /&gt;&lt;/a&gt;&lt;br /&gt; &lt;br /&gt;So now it is time to deploy! Let’s review the three problems that I want to solve for deployment:&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;I actually want to deploy the application without manual packaging and without leaving my dev box&lt;/li&gt;&lt;br /&gt;&lt;li&gt;I want to deploy the database along with my app in a single click!&lt;/li&gt;&lt;br /&gt;&lt;li&gt;I do not want to go to the destination server and change any configuration (like database connection string)&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;To solve the configuration issue, VS 2010 introduces XML Document Transforms (XDT) for automatic configuration changes. You can learn about the complete syntax of XDT from various online resources; however, for the sake of our discussion what you need to know is that VS 2010 allows you to create multiple versions of your web.config and associate each one with a configuration build (for example your application will have the normal web.config file, but it will also have web.config.debug and web.config.release for each of the debug and release configuration builds…you can have more builds as you like; for example web.config.staging…).&lt;br /&gt;&lt;br /&gt;Now let’s say that you are deploying your release version; XDT allows you to set a certain syntax in these config files such as while VS 2010 is performing the packaging of your project, the entries you specify in web.config.release replace the entries in web.config and a new final web.config file is created containing the updated configuration…so for example your web.config will hold the connection string for your local database. In the web.config.release you specify the connection string for the production database, and through XDT you instruct VS 2010 to dynamically replace the connection string in the web.config file with the connection string in the web.config.release when generating the production version of web.config which will be in the final package…&lt;br /&gt;&lt;br /&gt;Ok XDT wanted some explanation so now let’s start the actual packaging and deployment.&lt;br /&gt;&lt;br /&gt;If you expand the web.config node, you will find that by default there will be web.config.debug and web.config.release. As explained, these correspond to the default build configurations (Debug and Release) respectively. In our case we are going to be deploying the release version, so go ahead and edit the web.config.release file to read as follows:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://1.bp.blogspot.com/_oG_VVyp2tR4/SvQ8GSul2dI/AAAAAAAAACU/zktjDyzsZgQ/s1600-h/3.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 400px; height: 214px;" src="http://1.bp.blogspot.com/_oG_VVyp2tR4/SvQ8GSul2dI/AAAAAAAAACU/zktjDyzsZgQ/s400/3.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5401007931928205778" /&gt;&lt;/a&gt;&lt;br /&gt; &lt;br /&gt;Here we are using XDT (xdt:Transform=”Replace”) to instruct VS 2010 to replace the development-time connection string available in web.config with the release (or production) time connection string available in the web.config.release. This is the connection string supplied by the hosting company. The final web.config file in the final package will contain the updated connection string.&lt;br /&gt;&lt;br /&gt;Now let’s set up VS to deploy our SQL database also…this solves the concern of deploying the database along with the application in a single click. Open the properties window of the project. You will find a new tab called Deploy SQL. In this tab set up the connection string of the development database which you want to deploy (you can make VS 2010 import this from the web.config file by clicking “Import from Web.config”) and then provide the destination URL where the database will be deployed. This will be the connection string provided to you by the hosting company. Instruct VS 2010 to include data while deploying and make it get schema and data…the below screen shot shows the configuration I used to deploy my application:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://4.bp.blogspot.com/_oG_VVyp2tR4/SvQ8RamAHtI/AAAAAAAAACc/_Mc-q-YIcMo/s1600-h/4.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 400px; height: 310px;" src="http://4.bp.blogspot.com/_oG_VVyp2tR4/SvQ8RamAHtI/AAAAAAAAACc/_Mc-q-YIcMo/s400/4.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5401008123018223314" /&gt;&lt;/a&gt;&lt;br /&gt; &lt;br /&gt;Ok so now you are ready to do the actual deployment. First make sure that the “Release” build configuration for your project is selected as shown below.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://4.bp.blogspot.com/_oG_VVyp2tR4/SvQ8aa_Q8CI/AAAAAAAAACk/q4c-RybHh3w/s1600-h/5.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 400px; height: 114px;" src="http://4.bp.blogspot.com/_oG_VVyp2tR4/SvQ8aa_Q8CI/AAAAAAAAACk/q4c-RybHh3w/s400/5.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5401008277743005730" /&gt;&lt;/a&gt;&lt;br /&gt; &lt;br /&gt;Now right-click the project node and select the new “Publish…” option. A new window will open where you will enter the publish settings:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://4.bp.blogspot.com/_oG_VVyp2tR4/SvQ9cBKFCvI/AAAAAAAAACs/b78tgKvCUnk/s1600-h/6.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 289px; height: 400px;" src="http://4.bp.blogspot.com/_oG_VVyp2tR4/SvQ9cBKFCvI/AAAAAAAAACs/b78tgKvCUnk/s400/6.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5401009404680407794" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt; Publish Profile: you are allowed to create a profile for your settings so that you are not required to type them again and again for each deployment. For example I have created two profiles; one to deploy to the hosting company – which I am using now, and another one to deploy to another server which I will show you next.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Publish Method: Select MSDeploy Publish to perform the publishing based on MSDeploy&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Service URL: recall that this is the URL provided to us by the hosting company which contains the IIS handler&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Site/Application: the name of the IIS web site to deploy to – also provided by the hosting company. And the name of the application (virtual directory) under which to deploy.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Allow Untrusted Certificate: select this since we are deploying on a demo server and the certificate won’t probably be from a trusted CA (like VeriSign)&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Username/password: the account provided by the hosting company which will have permission to call MSDeploy and perform the deployment.&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;Ok, so now we are ready. Click publish and your web app and the database (with the data) will be deployed to the hosting company.&lt;br /&gt; &lt;br /&gt;Behind the scenes VS 2010 (and MSDeploy) created a packaged zip file of your application along with a manifest xml file and used these two files to publish your application to the destination server. The package file can be found by default on “obj\Release\Package\”; although you can change this in the “Package/Publish” tab of the properties window of your project.&lt;br /&gt;&lt;br /&gt;Actually, if by the time you are reading this article the testing account is still valid and the application is still deployed then you can check the application on the following URL:&lt;br /&gt;&lt;br /&gt;http://206.72.116.231/oneclickwebapp/Default.aspx&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;Deploying on another Server&lt;/h2&gt;&lt;br /&gt;&lt;br /&gt;Now let’s discuss the case when you own your production server and want to deploy on it. In this case the settings on the development box will be almost the same. However, now you have the responsibility of configuring MSDeploy on the production server to listen for deployment requests.&lt;br /&gt;&lt;br /&gt;In my case, I will deploy the same application I showed you on the same machine on IIS 7 on win server 2008. So the first and most important mission I have is to configure MSDeploy on my machine (acting as server) to listen for deployment requests.&lt;br /&gt;&lt;br /&gt;First make sure IIS 7 is installed on the server.&lt;br /&gt;&lt;br /&gt;Now you have to download the MSDeploy package. You can get it from here:&lt;br /&gt;&lt;br /&gt;http://www.microsoft.com/downloadS/details.aspx?familyid=32A781A2-4961-49FC-B34D-170BFA78414F&amp;displaylang=en&lt;br /&gt;&lt;br /&gt;Run this package on the server and install the following components:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://3.bp.blogspot.com/_oG_VVyp2tR4/SvQ9oDUM2kI/AAAAAAAAAC0/QQNq-Ij2g3I/s1600-h/7.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 400px; height: 310px;" src="http://3.bp.blogspot.com/_oG_VVyp2tR4/SvQ9oDUM2kI/AAAAAAAAAC0/QQNq-Ij2g3I/s400/7.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5401009611418163778" /&gt;&lt;/a&gt;&lt;br /&gt; &lt;br /&gt;The above components install MSDeploy along with its management UI and the IIS 7 handler for managing deployment requests. The management service will be the actual service listening for requests. The Remote Agent Service is another MSDeploy option used mainly for command-prompt deployment but is not required for VS 2010 1-Click Publishing.&lt;br /&gt;&lt;br /&gt;Now make sure that services “Web Deployment Agent Service” and “Web Management Service” are started and have a Startup type of “Automatic”.&lt;br /&gt;&lt;br /&gt;The final step is to enable remote connections for IIS (intermgr.exe --&gt; Management Service --&gt; Enable Remote Connections).&lt;br /&gt;&lt;br /&gt;Now you have the server ready to handle VS 2010 publish requests.&lt;br /&gt;Back to our project in VS 2010. Edit web.config.release to have the connection string of the server instead of the hosting company (in my case since it is the same server, I will have the same connection string as the one in the web.config file).&lt;br /&gt;Now on the Deploy SQL tab, also edit the connection string to point to the production server (again same server for me…) and select to move data and schema. Now you are ready to publish, select the “Publish…” tab and enter the below settings:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://1.bp.blogspot.com/_oG_VVyp2tR4/SvQ92g5YOkI/AAAAAAAAAC8/_PgZW9C8MHk/s1600-h/8.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 288px; height: 400px;" src="http://1.bp.blogspot.com/_oG_VVyp2tR4/SvQ92g5YOkI/AAAAAAAAAC8/_PgZW9C8MHk/s400/8.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5401009859876895298" /&gt;&lt;/a&gt;&lt;br /&gt; &lt;br /&gt;Notice that I have created a second profile for publishing. The settings are similar to the ones I used for hosting company’s profile; just note that in the Service URL I just supplied the name of the server to deploy to. This is the server I have configured MSDeploy service on; in this case my same dev machine…&lt;br /&gt;&lt;h2&gt;Summary&lt;/h2&gt;&lt;br /&gt;With all the great features coming in VS 2010 and .NET 4.0, 1-Click Publishing is one of the most important in my opinion. The ease of use and simplicity really stands out. The fact that you now can deploy your database and your configuration changes along with your application in one zipped file is great! Add to this that you can do this without even leaving your development machine is really cool…&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4918396109946207501-5189056579911296866?l=thedotnethub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thedotnethub.blogspot.com/feeds/5189056579911296866/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thedotnethub.blogspot.com/2009/11/vs-2010-1-click-publishing.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/5189056579911296866'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/5189056579911296866'/><link rel='alternate' type='text/html' href='http://thedotnethub.blogspot.com/2009/11/vs-2010-1-click-publishing.html' title='VS 2010 1-Click Publishing'/><author><name>mohamad halabi</name><uri>http://www.blogger.com/profile/10259946099831243955</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_oG_VVyp2tR4/SvQ7T_UpGsI/AAAAAAAAACE/N_x8aFrelpQ/s72-c/1.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4918396109946207501.post-171381706295515719</id><published>2009-10-26T18:23:00.000+03:00</published><updated>2009-10-26T18:34:35.910+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='VS 2010'/><category scheme='http://www.blogger.com/atom/ns#' term='VSTS'/><title type='text'>VS 2010 Beta 2  Released - No More VSTS</title><content type='html'>&lt;a href="http://msdn.microsoft.com/en-us/vstudio/dd582936.aspx"&gt;Beta 2 of VS 2010&lt;/a&gt; is released. This is supposed to be the final release before the official launching in March 2010.&lt;br /&gt;&lt;br /&gt;Visual Studio Team System (VSTS) does not exist anymore as a terminology in VS 2010. In the 2008 version, different Team Editions where available:&lt;br /&gt;- VSTS Team Suite&lt;br /&gt;- VSTS Developer Edition&lt;br /&gt;- VSTS Test Edition&lt;br /&gt;- VSTS Architecture Edition&lt;br /&gt;- VSTS Database Edition&lt;br /&gt;In addition to that you had the VS 2010 Professional Edition which contained all the basic VS features without any Team features.&lt;br /&gt;&lt;br /&gt;Well, that was a lot of naming and caused a lot of confusion when it came to licensing.&lt;br /&gt;MS has made a decision to ship 3 editions starting VS 2010 and no more is in use the term VSTS. These editions are:&lt;br /&gt;- VS Ultimate&lt;br /&gt;- VS Premium&lt;br /&gt;- VS Professional&lt;br /&gt;All previous VSTS 2008 team editions (plus more) features are still there but under the 3 above versions.&lt;br /&gt;A full feature comparison can be found &lt;a href="http://www.microsoft.com/visualstudio/en-us/products/2010/default.mspx"&gt;here&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4918396109946207501-171381706295515719?l=thedotnethub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thedotnethub.blogspot.com/feeds/171381706295515719/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thedotnethub.blogspot.com/2009/10/vs-2010-beta-2-released-no-more-vsts.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/171381706295515719'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/171381706295515719'/><link rel='alternate' type='text/html' href='http://thedotnethub.blogspot.com/2009/10/vs-2010-beta-2-released-no-more-vsts.html' title='VS 2010 Beta 2  Released - No More VSTS'/><author><name>mohamad halabi</name><uri>http://www.blogger.com/profile/10259946099831243955</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4918396109946207501.post-1452771534680097350</id><published>2009-10-24T09:12:00.000+03:00</published><updated>2009-10-24T12:21:58.957+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Large Messages'/><category scheme='http://www.blogger.com/atom/ns#' term='WCF'/><title type='text'>Passing Large Messages in WCF: maxItemsInObjectGraph, maxReceivedMessageSize, and maxBufferSize</title><content type='html'>in WCF it is known that you can pass messages up to multi GBs between a client and a service. however, there are certain configurations that you need to tweak.&lt;br /&gt;&lt;br /&gt;in one of my projects i had a SQL table with around 100,000 records. i had a service which simply reads all the records and pass them to a client.&lt;br /&gt;i decided to use the netTcpBinding for binary encoding which will enhance performance..of course i had .NET-based apps on both ends.&lt;br /&gt;&lt;br /&gt;i started out with the default configurations and i immediatley got an error that the max message quota limit was exceeded. so i set both&lt;br /&gt;- maxReceivedMessageSize = 2147483647&lt;br /&gt;- maxBufferSize = 2147483647&lt;br /&gt;&lt;br /&gt;however, it was interesting that with the above confiruation, although i have set up the allowed message and buffered size to more than 2 GB; i could not pass more than around 8000 records with message size of 3 MB! i was buffled for a second because i have granted the communication channel all the size limit it needs...&lt;br /&gt;&lt;br /&gt;i then turned on message logging and tracing, and every time i tried to pass more than 8000 records (again 3 MB) i got the following error:&lt;br /&gt;"the socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue"&lt;br /&gt;&lt;br /&gt;searching around i found on MSDN a property of DataContractSerializer called maxItemsInObjectGraph. after i set this property for a high value, then i could pass the full 100,000 records; that's around 50 MB.&lt;br /&gt;&lt;br /&gt;see, in my example i obviously was using the DataContractSerializer to serialize data on the wire, but more interesting i was filling out each of my SQL records into a seperate .NET object. so at then end i was trying to pass 100,000 objects from the service to the client. the maxItemsInObjectGraph, sets the max allowed objects to be passed around so setting this property to a high value solved the problem.&lt;br /&gt;&lt;br /&gt;the relevant part of the service configuration was:&lt;br /&gt;&lt;br /&gt;&amp;lt;servicebehaviors&amp;gt;&lt;br /&gt;&amp;lt;behavior name="ServiceBehavior"&amp;gt;&lt;br /&gt;&amp;lt;datacontractserializer maxitemsinobjectgraph="2000000"&amp;gt;&lt;br /&gt;&amp;lt;/behavior&amp;gt;&lt;br /&gt;&lt;br /&gt;the relevant part of the client configuration was:&lt;br /&gt;&lt;br /&gt;&amp;lt;behaviors&amp;gt;&lt;br /&gt;&amp;lt;endpointbehaviors&amp;gt;&lt;br /&gt;&amp;lt;behavior name="ClientBehavior"&amp;gt;&lt;br /&gt;&amp;lt;datacontractserializer maxitemsinobjectgraph="10000000"&amp;gt;&lt;br /&gt;&amp;lt;/behavior&amp;gt;&lt;br /&gt;&amp;lt;/endpointbehaviors&amp;gt;&lt;br /&gt;&amp;lt;/behaviors&amp;gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4918396109946207501-1452771534680097350?l=thedotnethub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thedotnethub.blogspot.com/feeds/1452771534680097350/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thedotnethub.blogspot.com/2009/10/passing-large-messages-in-wcf.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/1452771534680097350'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/1452771534680097350'/><link rel='alternate' type='text/html' href='http://thedotnethub.blogspot.com/2009/10/passing-large-messages-in-wcf.html' title='Passing Large Messages in WCF: maxItemsInObjectGraph, maxReceivedMessageSize, and maxBufferSize'/><author><name>mohamad halabi</name><uri>http://www.blogger.com/profile/10259946099831243955</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4918396109946207501.post-6542111633279013248</id><published>2009-07-04T07:50:00.000+03:00</published><updated>2009-07-04T07:52:25.724+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='.NET 4.0'/><category scheme='http://www.blogger.com/atom/ns#' term='WF 4.0'/><title type='text'>Introducing WF4.0: Building Distributed Apps with WF 4.0 and WF 4.0 Services</title><content type='html'>In 2006, Microsoft released .NET Framework 3.0, which basically consisted of extensions to .NET Framework 2.0. WCF was the biggest hit back then and gained the most attention. That even continued with the 3.5 release of the framework.&lt;br /&gt;&lt;br /&gt;With .NET Framework 4.0, Microsoft made WF the major focus, and with the many enhancements they have in place, it is evident the importance that WF 4.0 will have for building .NET-based applications.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.codeproject.com/KB/WF/WF4Services.aspx"&gt;Read Full Article Here&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4918396109946207501-6542111633279013248?l=thedotnethub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thedotnethub.blogspot.com/feeds/6542111633279013248/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thedotnethub.blogspot.com/2009/07/introducing-wf40-building-distributed.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/6542111633279013248'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/6542111633279013248'/><link rel='alternate' type='text/html' href='http://thedotnethub.blogspot.com/2009/07/introducing-wf40-building-distributed.html' title='Introducing WF4.0: Building Distributed Apps with WF 4.0 and WF 4.0 Services'/><author><name>mohamad halabi</name><uri>http://www.blogger.com/profile/10259946099831243955</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4918396109946207501.post-7151943862011710244</id><published>2009-06-06T14:58:00.000+03:00</published><updated>2009-06-06T15:18:13.124+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='.NET 4.0'/><title type='text'>.NET 4.0 Code Contracts</title><content type='html'>One of the great features of .NET 4.0 is Code Contracts. Code Contracts aid in the unit testing process of code and make catching bugs before deploying the code much easier.&lt;br /&gt;&lt;br /&gt;This post shows a sneak preview of Code Contracts in .NET Beta1 and VS 2010 Beta1. Note that by the time of the current writing, you need to install an Add-On to visual studio 2010 in order to work with code contracts.&lt;br /&gt;&lt;br /&gt;To do so, go to the following URL and download and install Code Contracts for .NET VSTS edition.&lt;br /&gt;http://msdn.microsoft.com/en-us/devlabs/dd491992.aspx#2&lt;br /&gt;&lt;br /&gt;once done, you will notice a new tab appearing in the Project Properties window. This tab is shown below:&lt;br /&gt;&lt;a href="http://2.bp.blogspot.com/_oG_VVyp2tR4/SipcmVUEduI/AAAAAAAAABc/K4unC5HdV5E/s1600-h/CodeContract1.JPG"&gt;&lt;img style="WIDTH: 400px; HEIGHT: 230px; CURSOR: hand" id="BLOGGER_PHOTO_ID_5344185721454622434" border="0" alt="" src="http://2.bp.blogspot.com/_oG_VVyp2tR4/SipcmVUEduI/AAAAAAAAABc/K4unC5HdV5E/s400/CodeContract1.JPG" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Now to test how Code Contracts work, consider the below code&lt;br /&gt;&lt;br /&gt; class Ctrct&lt;br /&gt;    {&lt;br /&gt;        public int Divide(int x, int y, ref int z)&lt;br /&gt;        {&lt;br /&gt;            Contract.Requires(y &gt; 0);&lt;br /&gt;            Contract.Ensures(z &gt; 1);&lt;br /&gt;            &lt;br /&gt;            z = x / y;&lt;br /&gt;&lt;br /&gt;            return z;&lt;br /&gt;           &lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;This class has a method that simply divides two numbers. First notice the line &lt;br /&gt;Contract.Requires(y &gt; 0);&lt;br /&gt;This line indicates that y should be greater than zero otherwise the code will fail. This check will happen before the execution of the method.&lt;br /&gt;&lt;br /&gt;The second line is&lt;br /&gt;Contract.Ensures(z &gt; 1);&lt;br /&gt;This line indicates that by the time the method ends, z should be greater than 1 else the code will fail.&lt;br /&gt;&lt;br /&gt;Now test with the above code passing first y=0 and you will find that the method fails at the entry level. Now even more interesting, pass y=1 and x=1; in this case the code will execute and z will be calculated to 1. in this case after the return statement is executed, the method will still fail. that is because the post condition of z being greater than one is not met. execution won't be delivered to the caller even though the return statement is executed!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4918396109946207501-7151943862011710244?l=thedotnethub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thedotnethub.blogspot.com/feeds/7151943862011710244/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thedotnethub.blogspot.com/2009/06/net-40-code-contracts.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/7151943862011710244'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/7151943862011710244'/><link rel='alternate' type='text/html' href='http://thedotnethub.blogspot.com/2009/06/net-40-code-contracts.html' title='.NET 4.0 Code Contracts'/><author><name>mohamad halabi</name><uri>http://www.blogger.com/profile/10259946099831243955</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_oG_VVyp2tR4/SipcmVUEduI/AAAAAAAAABc/K4unC5HdV5E/s72-c/CodeContract1.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4918396109946207501.post-4034030131468428332</id><published>2009-06-01T18:16:00.000+03:00</published><updated>2009-06-01T18:32:32.377+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C# 4.0'/><title type='text'>C# 4.0 Optional and Named Parameters</title><content type='html'>C# 4.0 now supports the optional and named prameters. this feature was already there in VB.NET so it is a C# language enhancement.&lt;br /&gt;consider the below class:&lt;br /&gt;&lt;br /&gt;class Optional&lt;br /&gt;{&lt;br /&gt;public void DoOperation(string name = "hello", int age = 4)&lt;br /&gt;{&lt;br /&gt;    Console.Write("Name {0}, Age {1}", name, age.ToString());&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;you can notice that now we can specify default values for parameters "name" and "age". so now when using the below code:&lt;br /&gt;&lt;br /&gt;Optional optional = new Optional();&lt;br /&gt;optional.DoOperation();&lt;br /&gt;&lt;br /&gt;the default parameter values are passed to the method. and when we call the method as follows:&lt;br /&gt;&lt;br /&gt;optional.DoOperation("mohamad");&lt;br /&gt;&lt;br /&gt;then "name" will have its new value set, while "age" parameter will have its default value.&lt;br /&gt;&lt;br /&gt;now the question is what if we want to call the method passing only the "age" parameter while giving the "name" parameter its default value? we cannot simpy do the following:&lt;br /&gt;&lt;br /&gt;optional.DoOperation(2);&lt;br /&gt;&lt;br /&gt;because this will give a compilation error since the compiler "understands" parameters by position and this means we are supplying an integer value to a string parameter. The solution is using Named Parameters. We can do the following:&lt;br /&gt;&lt;br /&gt;optional.DoOperation(age:2);&lt;br /&gt;&lt;br /&gt;by specifying the Parameter name we can ommit the first parameter and pass the second one only.&lt;br /&gt;&lt;br /&gt;as you might have noticed, this feature will for sure result in much less method overloading that we used to do just to change the number of parameters of each overload!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4918396109946207501-4034030131468428332?l=thedotnethub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thedotnethub.blogspot.com/feeds/4034030131468428332/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thedotnethub.blogspot.com/2009/06/c-40-optional-and-named-parameters.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/4034030131468428332'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/4034030131468428332'/><link rel='alternate' type='text/html' href='http://thedotnethub.blogspot.com/2009/06/c-40-optional-and-named-parameters.html' title='C# 4.0 Optional and Named Parameters'/><author><name>mohamad halabi</name><uri>http://www.blogger.com/profile/10259946099831243955</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4918396109946207501.post-1222409993143403238</id><published>2009-06-01T16:46:00.000+03:00</published><updated>2009-06-01T17:02:31.117+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C# 4.0'/><title type='text'>C# 4.0 Dynamic</title><content type='html'>one of the core functionalities of .NET 4.0 is its support for Dynamic languages. this is done primarly through the Dynamic Language Runtime (DLR) on top of the CLR. this post shows some of the usages of dynamic in C# 4.0.&lt;br /&gt;&lt;br /&gt;consider the following class:&lt;br /&gt;public class Sample&lt;br /&gt;    {&lt;br /&gt;        public static int Add(int x, int y)&lt;br /&gt;        {&lt;br /&gt;            return x + y;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        public static float Add(float x, float y)&lt;br /&gt;        {&lt;br /&gt;            return x + y;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        public static double Add(double x, double y)&lt;br /&gt;        {&lt;br /&gt;            return x + y;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;this shows a very familier pattern where we use overloading to support multiple versions of the Add method. Now normally in order to invoke the many overloads of the Add method, you would write something like the below code:&lt;br /&gt;&lt;br /&gt;int x = 3;&lt;br /&gt;int y = 4;&lt;br /&gt;int z = Sample.Add(x, y);&lt;br /&gt;&lt;br /&gt;float x1 = 3f;&lt;br /&gt;float y1 = 4f;&lt;br /&gt;float z1 = Sample.Add(x1, y1);&lt;br /&gt;&lt;br /&gt;long x2 = 3L;&lt;br /&gt;long y2 = 4L;&lt;br /&gt;long z2 = Sample.Add(x2, y2);&lt;br /&gt;&lt;br /&gt;the problem with this pattern is that we had to define parameters with appropriate types for each method overload. Now in C# 4.0 we can write much more elegant code as follows:&lt;br /&gt;&lt;br /&gt;dynamic x3 = 1.2;&lt;br /&gt;dynamic y3 = 1.55;&lt;br /&gt;dynamic z3 = Sample.Add(x3, y3);&lt;br /&gt;&lt;br /&gt;using the dynamic keyword, it is left to the runtime to determine the overload of method we would like to call; in this case the decimal-typed overload. for example changing the values of x3 and y3 to integers would call the integer-typed overloads as follows:&lt;br /&gt;&lt;br /&gt;dynamic x3 = 1;&lt;br /&gt;dynamic y3 = 1;&lt;br /&gt;dynamic z3 = Sample.Add(x3, y3);&lt;br /&gt;&lt;br /&gt;Now lets take another - even more impressive - example. Consider the below class&lt;br /&gt;&lt;br /&gt;public class Wrapper&lt;br /&gt;{&lt;br /&gt;  public void DoAction1()&lt;br /&gt;  {&lt;br /&gt;    //any stuff&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Normally, we do the following to invoke method DoAction1:&lt;br /&gt;&lt;br /&gt;Wrapper wrapper = new Wrapper();&lt;br /&gt;wrapper.DoAction1();&lt;br /&gt;&lt;br /&gt;ok so now what if you do not know about the method at design time? the direct answer would be reflection. true, but that's not pretty at all. Using dynamic you can use the following code:&lt;br /&gt;&lt;br /&gt;//instead of reflection&lt;br /&gt;dynamic dynWrapper = new Wrapper();&lt;br /&gt;dynamic val = dynWrapper.DoAction2();&lt;br /&gt;&lt;br /&gt;by initializing the class to a variable of type dynamic, we can now call methods that will be verified at runtime only. for instance the above code will compile even though DoAction2 does not exist! of course this code will fail at runtime but the idea is that at design time you might not know about the methods of class dynWrapper but you know that at runtime the method will be available...&lt;br /&gt; &lt;br /&gt;That's just a first look at C# 4.0 dynamic keyword.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4918396109946207501-1222409993143403238?l=thedotnethub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thedotnethub.blogspot.com/feeds/1222409993143403238/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thedotnethub.blogspot.com/2009/06/c-40-dynamic.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/1222409993143403238'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/1222409993143403238'/><link rel='alternate' type='text/html' href='http://thedotnethub.blogspot.com/2009/06/c-40-dynamic.html' title='C# 4.0 Dynamic'/><author><name>mohamad halabi</name><uri>http://www.blogger.com/profile/10259946099831243955</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4918396109946207501.post-3747272717724902999</id><published>2009-06-01T06:50:00.000+03:00</published><updated>2009-06-01T07:21:07.207+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>Cool C# Code</title><content type='html'>i was reviewing a piece of code of a colleague, and i came across a very familiar pattern of code. basically he had a list of employees where he wanted to "loop" over and exclude any employees with age over 30. so his first attempt was the most common one: he used a foreach loop to remove all employees with age &gt; 30. the code looked like the following&lt;br /&gt;&lt;br /&gt;foreach (Employee empl in lst)&lt;br /&gt;{&lt;br /&gt;   if (empl.age &gt; 30)&lt;br /&gt;    lst.Remove(empl);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;now clearly this will compile but blow up at runtime since it is trying to modify a collection while enumerating it! the second attempt was to create a new list and add all employees with age &gt; 30 to it...that would have worked but it is completely nonesense to do the days.&lt;br /&gt;&lt;br /&gt;the first thing that came into my mind is Predicates. so istead what we can do is to define a method as a predicate as follows:&lt;br /&gt;&lt;br /&gt;private static bool isAboveAge(Employee empl)&lt;br /&gt;{&lt;br /&gt;    return empl.age &gt; 30 ? true : false;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;then simple call the FindAll method of the list; as follows:&lt;br /&gt;&lt;br /&gt;List&lt;Employee&gt; newLst = lst.FindAll(isAboveAge);&lt;br /&gt;&lt;br /&gt;that's it; now it works in a much better way.&lt;br /&gt;&lt;br /&gt;However, why stop there? the only problem with the above code is that i had to create a method (isAboveAge) just for it to being called by FindAll. so to solve this we can use an anonymous method as follows:&lt;br /&gt;&lt;br /&gt;List&lt;Employee&gt; newLst = lst.FindAll(&lt;br /&gt;   delegate(Employee empl)&lt;br /&gt;   {&lt;br /&gt;     return empl.age &gt; 30 ? true : false;&lt;br /&gt;   }&lt;br /&gt;);&lt;br /&gt;&lt;br /&gt;very cool! but we can take this one more stop...lambda expressions. using lambda we can now - and finally - shrink our code to this:&lt;br /&gt;&lt;br /&gt;List&lt;Employee&gt; newLst = lst.FindAll(empl =&gt; empl.age &gt; 30 ? true : false);&lt;br /&gt;&lt;br /&gt;Nice!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4918396109946207501-3747272717724902999?l=thedotnethub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thedotnethub.blogspot.com/feeds/3747272717724902999/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thedotnethub.blogspot.com/2009/05/cool-c-code.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/3747272717724902999'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/3747272717724902999'/><link rel='alternate' type='text/html' href='http://thedotnethub.blogspot.com/2009/05/cool-c-code.html' title='Cool C# Code'/><author><name>mohamad halabi</name><uri>http://www.blogger.com/profile/10259946099831243955</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4918396109946207501.post-5552483417849165377</id><published>2009-04-08T11:18:00.000+03:00</published><updated>2009-04-08T11:27:32.341+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='BizTalk'/><title type='text'>BizTalk Business Features</title><content type='html'>BizTalk Server is an integration platform for developers. By nature Biztalk solutions are very technichal and its nearly impossible to show the value for business users.&lt;br /&gt;&lt;br /&gt;For that there are special BizTalk capabilities for business users to step in. These are:&lt;br /&gt;- Business Activity Monitoring (BAM)&lt;br /&gt;- Business Activity Services (BAS)&lt;br /&gt;- Business Rules Engine (BRE)&lt;br /&gt;&lt;br /&gt;BAM is defenitely the most important as it gives business users a detailed view on Key Performance Indicators (KPIs) of the solution. Standard reporting is possible but argubly the most interesting part is the out of the box integration with SSAS cubes.&lt;br /&gt;&lt;br /&gt;BAS is also interesting in that it allows business users to identify trading partners and agreements with these partners to "customize" business processes according to these agreements.&lt;br /&gt;&lt;br /&gt;BRE is somewhat sitting in the middle of developers and business users. BRE is a place for developers to identify dynamic rules instead of "hard coding" those. On the other hand, and through a special feature called Vocabulary, business users can access these rules at runtime and change the values of these rules. Processes will pick up the new values without any downtime...&lt;br /&gt;&lt;br /&gt;Keep tuned for articles and posts for every one of these features. After all its business users who own the money and their satisfaction is a priority for us poor developers :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4918396109946207501-5552483417849165377?l=thedotnethub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thedotnethub.blogspot.com/feeds/5552483417849165377/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thedotnethub.blogspot.com/2009/04/biztalk-business-features.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/5552483417849165377'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/5552483417849165377'/><link rel='alternate' type='text/html' href='http://thedotnethub.blogspot.com/2009/04/biztalk-business-features.html' title='BizTalk Business Features'/><author><name>mohamad halabi</name><uri>http://www.blogger.com/profile/10259946099831243955</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4918396109946207501.post-7112636561740388972</id><published>2009-04-08T11:15:00.000+03:00</published><updated>2009-04-08T11:17:51.877+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='.NET'/><category scheme='http://www.blogger.com/atom/ns#' term='WCF'/><title type='text'>Truly Understanding .NET Transactions and WCF Implementation</title><content type='html'>Strictly speaking, implementing transactions in WCF is easy: you use attributes to control the service and operations behaviors and you are done!&lt;br /&gt;&lt;br /&gt;just about like everything else in programming; you need to understand the architecture, the underground of whatever seems to be an easy task. Only then you can architect (design) solutions as opposed to only coding them…&lt;br /&gt;&lt;br /&gt;WCF transactions are built from ground up around .NET transactions. This is hardly surprising anyway since WCF is a .NET technology; however, this sums up as follows: you need to understand how .NET does transactions in order to utilize them in WCF.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.codeproject.com/KB/dotnet/NETTx.aspx"&gt;Read Full Article...&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4918396109946207501-7112636561740388972?l=thedotnethub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thedotnethub.blogspot.com/feeds/7112636561740388972/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thedotnethub.blogspot.com/2009/04/truly-understanding-net-transactions.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/7112636561740388972'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/7112636561740388972'/><link rel='alternate' type='text/html' href='http://thedotnethub.blogspot.com/2009/04/truly-understanding-net-transactions.html' title='Truly Understanding .NET Transactions and WCF Implementation'/><author><name>mohamad halabi</name><uri>http://www.blogger.com/profile/10259946099831243955</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4918396109946207501.post-2347923671260976424</id><published>2009-03-25T17:38:00.000+03:00</published><updated>2009-03-25T17:41:10.358+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='WCF'/><title type='text'>WCF Duplex Reentrant Services</title><content type='html'>This article illustrates working with Duplex mode in WCF with concurrency set to Reentrant. In general, Duplex is one of the three message exchange patterns (MEPs) which are:&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;One-way&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Request-Response (synchronous and asynchronous)&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Duplex&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;On the other hand, concurrency in WCF services deals with how many concurrent threads can access these services at one time...&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.codeproject.com/KB/WCF/WCFDuplexReentrant.aspx"&gt;Read full article here&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4918396109946207501-2347923671260976424?l=thedotnethub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thedotnethub.blogspot.com/feeds/2347923671260976424/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thedotnethub.blogspot.com/2009/03/wcf-duplex-reentrant-services.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/2347923671260976424'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/2347923671260976424'/><link rel='alternate' type='text/html' href='http://thedotnethub.blogspot.com/2009/03/wcf-duplex-reentrant-services.html' title='WCF Duplex Reentrant Services'/><author><name>mohamad halabi</name><uri>http://www.blogger.com/profile/10259946099831243955</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4918396109946207501.post-2207264870088117194</id><published>2009-03-24T09:05:00.000+03:00</published><updated>2009-03-24T09:14:44.117+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='BizTalk'/><title type='text'>ODBA Visio 2007 Hack</title><content type='html'>the orchestration designer for business analyst (ODBA) works with Visio 2003 SP1. if you try to install it when having Visio 2007 you will get an error. however, there is a cool hack (see link at the end) to apply to allow installing the ODBA with Visio 2003.&lt;br /&gt;&lt;br /&gt;If you want to use BizTalk ODBA with Visio 2007 instead of having to install Visio 2003, follow these steps:&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;Export this registry key:[HKLM\SOFTWARE\Microsoft\Office\12.0\Visio]&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Edit the resulting .reg file in notepad and replace all instances of 12.0\Visio with 11.0\Visio&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Reimport the file into the registry and the install for BizTalk ODBA should work.&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;Note: Do not change any other values in the file. Essentially, you will be copying the Visio key under the 12.0 key to the 11.0 key without making any value or data changes.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://bphillips76.spaces.live.com/blog/cns!F9B548E4C21D6166!345.entry"&gt;Click here for the original hack post&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4918396109946207501-2207264870088117194?l=thedotnethub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thedotnethub.blogspot.com/feeds/2207264870088117194/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thedotnethub.blogspot.com/2009/03/odba-visio-2007-hack.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/2207264870088117194'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/2207264870088117194'/><link rel='alternate' type='text/html' href='http://thedotnethub.blogspot.com/2009/03/odba-visio-2007-hack.html' title='ODBA Visio 2007 Hack'/><author><name>mohamad halabi</name><uri>http://www.blogger.com/profile/10259946099831243955</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4918396109946207501.post-2680949913620339280</id><published>2009-03-16T18:18:00.000+03:00</published><updated>2009-03-16T18:27:39.303+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='WCF'/><title type='text'>WCF Queued Messaging</title><content type='html'>One common requirement for all MEPs is message durability; that is the ability to preserve the message under all conditions and make sure that a message will arrive where it is supposed to.&lt;br /&gt;&lt;br /&gt;Microsoft Message Queuing service is a proven method to provide a queue for messages to reside inside until recipients are ready to pick them up. WCF offers implicit MSMQ integration through the NetMsmqBinding which is the topic of this article...&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.codeproject.com/KB/WCF/WCFMSMQ.aspx"&gt;Read my full article&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4918396109946207501-2680949913620339280?l=thedotnethub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thedotnethub.blogspot.com/feeds/2680949913620339280/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thedotnethub.blogspot.com/2009/03/wcf-queued-messaging.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/2680949913620339280'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/2680949913620339280'/><link rel='alternate' type='text/html' href='http://thedotnethub.blogspot.com/2009/03/wcf-queued-messaging.html' title='WCF Queued Messaging'/><author><name>mohamad halabi</name><uri>http://www.blogger.com/profile/10259946099831243955</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4918396109946207501.post-9141560493428039369</id><published>2009-03-13T15:49:00.000+03:00</published><updated>2009-03-13T15:50:44.090+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='BizTalk'/><category scheme='http://www.blogger.com/atom/ns#' term='.NET'/><title type='text'>Developing with Microsoft Business Rule Engine</title><content type='html'>Mainly this article is for two set of readers: first are those who are new to Microsoft Business Rule Engine and are looking for a direct hands-on approach rather than going though the theory and architecture behind BRE (links for that at the Additional Resources section).&lt;br /&gt;&lt;br /&gt;Second are those who are familiar (but not experts) with the topic in general and are looking to understand in practical manner how to program with BRE and leverage some of its powerful offerings...&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.codeproject.com/KB/biztalk/BRE.aspx"&gt;Read my article&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4918396109946207501-9141560493428039369?l=thedotnethub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thedotnethub.blogspot.com/feeds/9141560493428039369/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thedotnethub.blogspot.com/2009/03/developing-with-microsoft-business-rule.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/9141560493428039369'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/9141560493428039369'/><link rel='alternate' type='text/html' href='http://thedotnethub.blogspot.com/2009/03/developing-with-microsoft-business-rule.html' title='Developing with Microsoft Business Rule Engine'/><author><name>mohamad halabi</name><uri>http://www.blogger.com/profile/10259946099831243955</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4918396109946207501.post-520205978896324047</id><published>2009-03-13T15:44:00.000+03:00</published><updated>2009-03-13T15:46:53.958+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='.NET'/><category scheme='http://www.blogger.com/atom/ns#' term='ASPNET'/><title type='text'>.NET Delegates and Events</title><content type='html'>Many developers tend to use events and delegates "as is" without truly understanding the internal stuff - which, trust me, once understood, can help you do many cool stuff. When I first started .NET coding, I used to just double click the "Button" or "DataGrid" control, go to the code-behind, and write my code inside the event handler. Well, then a few years ago, I decided enough is enough, and I dug deep to really understand .NET events and delegates: This article is an attempt to share with you what I came up with...&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.codeproject.com/KB/cs/NETDelegatesAndEvents.aspx"&gt;Read my full article&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4918396109946207501-520205978896324047?l=thedotnethub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thedotnethub.blogspot.com/feeds/520205978896324047/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thedotnethub.blogspot.com/2009/03/net-delegates-and-events.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/520205978896324047'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/520205978896324047'/><link rel='alternate' type='text/html' href='http://thedotnethub.blogspot.com/2009/03/net-delegates-and-events.html' title='.NET Delegates and Events'/><author><name>mohamad halabi</name><uri>http://www.blogger.com/profile/10259946099831243955</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4918396109946207501.post-1758287467390962623</id><published>2009-03-13T15:41:00.000+03:00</published><updated>2009-03-13T15:48:45.614+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ASPNET'/><title type='text'>ASP.NET Viewstate and Page Life Cycle</title><content type='html'>Viewstate and page life cycle are amazingly interesting topics to dig into. once you understand these you have a different perspective about ASP.NET development. My published article has won the article of the month competition at code project.&lt;br /&gt;Enjoy!&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.codeproject.com/KB/aspnet/aspnetviewstatepagecycle.aspx"&gt;Read my article&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4918396109946207501-1758287467390962623?l=thedotnethub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thedotnethub.blogspot.com/feeds/1758287467390962623/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thedotnethub.blogspot.com/2009/03/aspnet-viewstate-and-page-life-cycle.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/1758287467390962623'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/1758287467390962623'/><link rel='alternate' type='text/html' href='http://thedotnethub.blogspot.com/2009/03/aspnet-viewstate-and-page-life-cycle.html' title='ASP.NET Viewstate and Page Life Cycle'/><author><name>mohamad halabi</name><uri>http://www.blogger.com/profile/10259946099831243955</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4918396109946207501.post-8844555958916623361</id><published>2009-03-13T15:37:00.000+03:00</published><updated>2009-03-13T15:48:54.920+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ASPNET'/><title type='text'>ASP.NET Request Architecture</title><content type='html'>ASP.NET request architecture is a must know topic for any ASP.NET advanced developer or architect. my article below aims at explaining the topic inside out.&lt;br /&gt;&lt;BR&gt;&lt;br /&gt;&lt;a href="http://www.codeproject.com/KB/aspnet/aspnetrequestarchitecture.aspx"&gt;Read my article&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4918396109946207501-8844555958916623361?l=thedotnethub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thedotnethub.blogspot.com/feeds/8844555958916623361/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thedotnethub.blogspot.com/2009/03/aspnet-request-architecture_13.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/8844555958916623361'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/8844555958916623361'/><link rel='alternate' type='text/html' href='http://thedotnethub.blogspot.com/2009/03/aspnet-request-architecture_13.html' title='ASP.NET Request Architecture'/><author><name>mohamad halabi</name><uri>http://www.blogger.com/profile/10259946099831243955</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4918396109946207501.post-4542047375738513277</id><published>2009-03-09T06:23:00.000+03:00</published><updated>2009-03-09T06:26:34.756+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='BizTalk'/><title type='text'>SSO Security Configuration Error</title><content type='html'>I was configuring BTS 2006 R2 on a machine. After I ran the configuration wizard I got an error saying that “login failed for user &lt;username&gt; on SQL server. Cannot create database SSO”.&lt;br /&gt;&lt;br /&gt;The logical resolution was to go to SQL Server and give the specified user the appropriate permissions; which I did. I re-ran the configuration again and again I got the same error.&lt;br /&gt;&lt;br /&gt;Puzzled for a couple of minutes, I checked the event viewer and there it was: I found the exact error reason:&lt;br /&gt;&lt;br /&gt;&lt;i&gt;“Cannot create file 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\SSODB.mdf' because it already exists. Change the file path or the file name, and retry the operation.”&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;It turned out that I had a previous installation of the SSO database on the same machine, and it was not deleted automatically (for some reason which I cannot remember frankly). So I manually deleted the “mdf” and “ldf” files, re-ran the configuration, and this time it worked fine.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Moral of the story:&lt;/b&gt; some error messages can be misleading. Always check the event viewer when working with BizTalk Server because many times the real reason of a problem will only be found there.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4918396109946207501-4542047375738513277?l=thedotnethub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thedotnethub.blogspot.com/feeds/4542047375738513277/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thedotnethub.blogspot.com/2009/03/sso-security-configuration-error.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/4542047375738513277'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/4542047375738513277'/><link rel='alternate' type='text/html' href='http://thedotnethub.blogspot.com/2009/03/sso-security-configuration-error.html' title='SSO Security Configuration Error'/><author><name>mohamad halabi</name><uri>http://www.blogger.com/profile/10259946099831243955</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4918396109946207501.post-4300264957094202942</id><published>2009-03-09T06:12:00.000+03:00</published><updated>2009-03-09T06:23:01.724+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Azure'/><title type='text'>Azure Invitation Codes Activation</title><content type='html'>&lt;p&gt;Invitation codes for Microsoft’s Azure services platform currently come in three flavors:&lt;br /&gt;- Code for .NET Services and SQL Data Services&lt;br /&gt;- Code for Live Services API and Live Framework CTP&lt;br /&gt;- Code for Windows Azure (hosted services, deployments, and storage accounts)&lt;/p&gt;&lt;p&gt;Once you get your tokens you need to activate them (associate these with your Windows Live ID). &lt;/p&gt;&lt;p&gt;For the .NET Services and SQL Data Services, follow the following URL “http://go.microsoft.com/fwlink/?LinkID=129428”. Sign in using your token as shown below:&lt;/p&gt;&lt;a href="http://4.bp.blogspot.com/_oG_VVyp2tR4/SbSJkmnn9wI/AAAAAAAAAAs/6K8KRE6vUeg/s1600-h/NETSDSActivation1.JPG"&gt;&lt;img style="WIDTH: 320px; HEIGHT: 142px; CURSOR: hand" id="BLOGGER_PHOTO_ID_5311021122511697666" border="0" alt="" src="http://4.bp.blogspot.com/_oG_VVyp2tR4/SbSJkmnn9wI/AAAAAAAAAAs/6K8KRE6vUeg/s320/NETSDSActivation1.JPG" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;For the Windows Azure and Live Services tokens, follow the following URL “http://lx.azure.microsoft.com”. Redeem your token by associating it with your Live ID. Once done you can click on the “Account” tab to see the services that you get as a result of redeeming the two tokens. The following image shows what are these services (again note that the .NET Services and SQL Data Services are not included here as they have their own portal).&lt;/p&gt;&lt;a href="http://2.bp.blogspot.com/_oG_VVyp2tR4/SbSJ5KNPeRI/AAAAAAAAAA0/pySrvVangms/s1600-h/Azure1.JPG"&gt;&lt;img style="WIDTH: 400px; HEIGHT: 200px; CURSOR: hand" id="BLOGGER_PHOTO_ID_5311021475662100754" border="0" alt="" src="http://2.bp.blogspot.com/_oG_VVyp2tR4/SbSJ5KNPeRI/AAAAAAAAAA0/pySrvVangms/s320/Azure1.JPG" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4918396109946207501-4300264957094202942?l=thedotnethub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://thedotnethub.blogspot.com/feeds/4300264957094202942/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://thedotnethub.blogspot.com/2009/03/invitation-codes-for-microsofts-azure.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/4300264957094202942'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4918396109946207501/posts/default/4300264957094202942'/><link rel='alternate' type='text/html' href='http://thedotnethub.blogspot.com/2009/03/invitation-codes-for-microsofts-azure.html' title='Azure Invitation Codes Activation'/><author><name>mohamad halabi</name><uri>http://www.blogger.com/profile/10259946099831243955</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_oG_VVyp2tR4/SbSJkmnn9wI/AAAAAAAAAAs/6K8KRE6vUeg/s72-c/NETSDSActivation1.JPG' height='72' width='72'/><thr:total>0</thr:total></entry></feed>
