<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Scott's Breeze Blog - Integration, BizTalk, Cloud - WCF</title>
    <link>http://blogs.breeze.net/scotts/</link>
    <description>...and everything in between</description>
    <language>en-us</language>
    <copyright>Breeze</copyright>
    <lastBuildDate>Tue, 21 Feb 2012 09:59:00 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.3.9074.18820</generator>
    <managingEditor>scotts@breezetraining.com.au</managingEditor>
    <webMaster>scotts@breezetraining.com.au</webMaster>
    <item>
      <trackback:ping>http://blogs.breeze.net/scotts/Trackback.aspx?guid=42dae826-7a1b-47d2-8752-2c3daa4f09c1</trackback:ping>
      <pingback:server>http://blogs.breeze.net/scotts/pingback.aspx</pingback:server>
      <pingback:target>http://blogs.breeze.net/scotts/PermaLink,guid,42dae826-7a1b-47d2-8752-2c3daa4f09c1.aspx</pingback:target>
      <dc:creator>Scott Scovell</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
New Tech Article posted over on the <a href="http://www.breeze.net/" target="_blank">Breeze</a> website:
</p>
        <p>
          <a href="http://www.breeze.net/news/techarticles/receiving-messages-from-a-windows-azure-service-bus-queues-in-biztalk-server.aspx" target="_blank">Receiving
messages from Windows Azure Service Bus Queues in BizTalk Server</a>
        </p>
        <p>
          <a href="http://blogs.breeze.net/scotts/content/binary/Windows-Live-Writer/ff55cba17049_1264B/Windows%20Azure%20Service%20Bus%20Queues_2.png">
            <img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="Windows Azure Service Bus Queues" border="0" alt="Windows Azure Service Bus Queues" src="http://blogs.breeze.net/scotts/content/binary/Windows-Live-Writer/ff55cba17049_1264B/Windows%20Azure%20Service%20Bus%20Queues_thumb.png" width="454" height="297" />
          </a>
        </p>
        <p>
Be sure to download the PDF article and walkthrough the BizTalk Server 2010 scenario.
</p>
        <img width="0" height="0" src="http://blogs.breeze.net/scotts/aggbug.ashx?id=42dae826-7a1b-47d2-8752-2c3daa4f09c1" />
      </body>
      <title>Receiving messages from Windows Azure Service Bus Queues in BizTalk Server</title>
      <guid isPermaLink="false">http://blogs.breeze.net/scotts/PermaLink,guid,42dae826-7a1b-47d2-8752-2c3daa4f09c1.aspx</guid>
      <link>http://blogs.breeze.net/scotts/2012/02/21/ReceivingMessagesFromWindowsAzureServiceBusQueuesInBizTalkServer.aspx</link>
      <pubDate>Tue, 21 Feb 2012 09:59:00 GMT</pubDate>
      <description>&lt;p&gt;
New Tech Article posted over on the &lt;a href="http://www.breeze.net/" target="_blank"&gt;Breeze&lt;/a&gt; website:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.breeze.net/news/techarticles/receiving-messages-from-a-windows-azure-service-bus-queues-in-biztalk-server.aspx" target="_blank"&gt;Receiving
messages from Windows Azure Service Bus Queues in BizTalk Server&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blogs.breeze.net/scotts/content/binary/Windows-Live-Writer/ff55cba17049_1264B/Windows%20Azure%20Service%20Bus%20Queues_2.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="Windows Azure Service Bus Queues" border="0" alt="Windows Azure Service Bus Queues" src="http://blogs.breeze.net/scotts/content/binary/Windows-Live-Writer/ff55cba17049_1264B/Windows%20Azure%20Service%20Bus%20Queues_thumb.png" width="454" height="297"&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
Be sure to download the PDF article and walkthrough the BizTalk Server 2010 scenario.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blogs.breeze.net/scotts/aggbug.ashx?id=42dae826-7a1b-47d2-8752-2c3daa4f09c1" /&gt;</description>
      <category>BizTalk General</category>
      <category>Cloud Services</category>
      <category>WCF</category>
      <category>Windows Azure</category>
    </item>
    <item>
      <trackback:ping>http://blogs.breeze.net/scotts/Trackback.aspx?guid=ac42d41d-0628-4177-b9a5-7c08294f4d07</trackback:ping>
      <pingback:server>http://blogs.breeze.net/scotts/pingback.aspx</pingback:server>
      <pingback:target>http://blogs.breeze.net/scotts/PermaLink,guid,ac42d41d-0628-4177-b9a5-7c08294f4d07.aspx</pingback:target>
      <dc:creator>Scott Scovell</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
If you are using BizTalk Server 2010 and wanting to send or receive messages using
Windows Azure Service Bus queues, you may find you’re missing the brokered message
bindings in the transport properties dialog. 
</p>
        <p>
          <a href="http://blogs.breeze.net/scotts/content/binary/Windows-Live-Writer/b881f22e5de4_8F38/image_2.png">
            <img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.breeze.net/scotts/content/binary/Windows-Live-Writer/b881f22e5de4_8F38/image_thumb.png" width="242" height="332" />
          </a>
        </p>
        <p>
First check you have the <a href="http://www.microsoft.com/download/en/details.aspx?displaylang=en&amp;id=28045" target="_blank">Windows
Azure Libraries for .NET</a> installed (formally known as Windows Azure AppFabric
SDK). Then you’ll need to add a few entries to the machine.config (32-bit and 64-bit)
to have these show up:
</p>
        <p>
1. Add the following binding element extension to the <strong>&lt;bindingElementExtensions&gt;</strong> section
</p>
        <div class="csharpcode">
          <pre class="alt">&lt;add name=<span class="str">"netMessagingTransport"</span> type=<span class="str">"Microsoft.ServiceBus.Messaging.Configuration.NetMessagingTransportExtensionElement,
Microsoft.ServiceBus, Version=1.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"</span>/&gt;</pre>
        </div>
        <style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
        <p>
 
</p>
        <p>
2. Add the following binding extension to the <strong>&lt;bindingExtensions&gt;</strong> section
</p>
        <div class="csharpcode">
          <pre class="alt">&lt;add name=<span class="str">"netMessagingBinding"</span> type=<span class="str">"Microsoft.ServiceBus.Messaging.Configuration.NetMessagingBindingCollectionElement,
Microsoft.ServiceBus, Version=1.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"</span>/&gt;</pre>
        </div>
        <style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
        <p>
Restart the BizTalk Server Administration Console and they’ll show up.
</p>
        <img width="0" height="0" src="http://blogs.breeze.net/scotts/aggbug.ashx?id=ac42d41d-0628-4177-b9a5-7c08294f4d07" />
      </body>
      <title>Missing netMessagingBinding in BizTalk Server 2010</title>
      <guid isPermaLink="false">http://blogs.breeze.net/scotts/PermaLink,guid,ac42d41d-0628-4177-b9a5-7c08294f4d07.aspx</guid>
      <link>http://blogs.breeze.net/scotts/2012/02/18/MissingNetMessagingBindingInBizTalkServer2010.aspx</link>
      <pubDate>Sat, 18 Feb 2012 23:32:28 GMT</pubDate>
      <description>&lt;p&gt;
If you are using BizTalk Server 2010 and wanting to send or receive messages using
Windows Azure Service Bus queues, you may find you’re missing the brokered message
bindings in the transport properties dialog. 
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blogs.breeze.net/scotts/content/binary/Windows-Live-Writer/b881f22e5de4_8F38/image_2.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.breeze.net/scotts/content/binary/Windows-Live-Writer/b881f22e5de4_8F38/image_thumb.png" width="242" height="332"&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
First check you have the &lt;a href="http://www.microsoft.com/download/en/details.aspx?displaylang=en&amp;amp;id=28045" target="_blank"&gt;Windows
Azure Libraries for .NET&lt;/a&gt; installed (formally known as Windows Azure AppFabric
SDK). Then you’ll need to add a few entries to the machine.config (32-bit and 64-bit)
to have these show up:
&lt;/p&gt;
&lt;p&gt;
1. Add the following binding element extension to the &lt;strong&gt;&amp;lt;bindingElementExtensions&amp;gt;&lt;/strong&gt; section
&lt;/p&gt;
&lt;div class="csharpcode"&gt;&lt;pre class="alt"&gt;&amp;lt;add name=&lt;span class="str"&gt;"netMessagingTransport"&lt;/span&gt; type=&lt;span class="str"&gt;"Microsoft.ServiceBus.Messaging.Configuration.NetMessagingTransportExtensionElement,
Microsoft.ServiceBus, Version=1.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"&lt;/span&gt;/&amp;gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
2. Add the following binding extension to the &lt;strong&gt;&amp;lt;bindingExtensions&amp;gt;&lt;/strong&gt; section
&lt;/p&gt;
&lt;div class="csharpcode"&gt;&lt;pre class="alt"&gt;&amp;lt;add name=&lt;span class="str"&gt;"netMessagingBinding"&lt;/span&gt; type=&lt;span class="str"&gt;"Microsoft.ServiceBus.Messaging.Configuration.NetMessagingBindingCollectionElement,
Microsoft.ServiceBus, Version=1.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"&lt;/span&gt;/&amp;gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;p&gt;
Restart the BizTalk Server Administration Console and they’ll show up.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blogs.breeze.net/scotts/aggbug.ashx?id=ac42d41d-0628-4177-b9a5-7c08294f4d07" /&gt;</description>
      <category>BizTalk General</category>
      <category>Cloud Services</category>
      <category>WCF</category>
      <category>Windows Azure</category>
    </item>
    <item>
      <trackback:ping>http://blogs.breeze.net/scotts/Trackback.aspx?guid=bba4a3a0-7d6c-414d-bac0-bdc2ee8325b6</trackback:ping>
      <pingback:server>http://blogs.breeze.net/scotts/pingback.aspx</pingback:server>
      <pingback:target>http://blogs.breeze.net/scotts/PermaLink,guid,bba4a3a0-7d6c-414d-bac0-bdc2ee8325b6.aspx</pingback:target>
      <dc:creator>Scott Scovell</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
A recent project of ours has made the <a href="http://www.itnews.com.au/News/271318,centrebet-deploys-app-integration-platform.aspx" target="_blank">news</a> this
week &gt; <a title="Centrebet deploys app integration platform" href="http://www.itnews.com.au/News/271318,centrebet-deploys-app-integration-platform.aspx">Centrebet
deploys app integration platform</a>.
</p>
        <p>
This was a great project to be involved in, consisting of a great mix of technology:
</p>
        <ul>
          <li>
Microsoft BizTalk Server</li>
          <li>
Windows Server AppFabric</li>
          <li>
Windows Azure AppFabric Service Bus</li>
          <li>
Windows Azure Hosted Services</li>
          <li>
F# asynchronous programming</li>
        </ul>
        <p>
          <a href="http://blogs.breeze.net/scotts/content/binary/Windows-Live-Writer/51c2c55200e0_7499/Case_Study_Overview_2.png">
            <img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="Case_Study_Overview" border="0" alt="Case_Study_Overview" src="http://blogs.breeze.net/scotts/content/binary/Windows-Live-Writer/51c2c55200e0_7499/Case_Study_Overview_thumb.png" width="599" height="430" />
          </a>
        </p>
        <p>
A real software engineering project that had to meet high throughput and low latency
requirements, incorporate new technologies and come in on very (very) tight time frames.
Credit to go out to the team at Breeze for getting this over the line. 
</p>
        <img width="0" height="0" src="http://blogs.breeze.net/scotts/aggbug.ashx?id=bba4a3a0-7d6c-414d-bac0-bdc2ee8325b6" />
      </body>
      <title>Breeze Integration News</title>
      <guid isPermaLink="false">http://blogs.breeze.net/scotts/PermaLink,guid,bba4a3a0-7d6c-414d-bac0-bdc2ee8325b6.aspx</guid>
      <link>http://blogs.breeze.net/scotts/2011/09/08/BreezeIntegrationNews.aspx</link>
      <pubDate>Thu, 08 Sep 2011 22:59:08 GMT</pubDate>
      <description>&lt;p&gt;
A recent project of ours has made the &lt;a href="http://www.itnews.com.au/News/271318,centrebet-deploys-app-integration-platform.aspx" target="_blank"&gt;news&lt;/a&gt; this
week &amp;gt; &lt;a title="Centrebet deploys app integration platform" href="http://www.itnews.com.au/News/271318,centrebet-deploys-app-integration-platform.aspx"&gt;Centrebet
deploys app integration platform&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
This was a great project to be involved in, consisting of a great mix of technology:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Microsoft BizTalk Server&lt;/li&gt;
&lt;li&gt;
Windows Server AppFabric&lt;/li&gt;
&lt;li&gt;
Windows Azure AppFabric Service Bus&lt;/li&gt;
&lt;li&gt;
Windows Azure Hosted Services&lt;/li&gt;
&lt;li&gt;
F# asynchronous programming&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
&lt;a href="http://blogs.breeze.net/scotts/content/binary/Windows-Live-Writer/51c2c55200e0_7499/Case_Study_Overview_2.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="Case_Study_Overview" border="0" alt="Case_Study_Overview" src="http://blogs.breeze.net/scotts/content/binary/Windows-Live-Writer/51c2c55200e0_7499/Case_Study_Overview_thumb.png" width="599" height="430"&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
A real software engineering project that had to meet high throughput and low latency
requirements, incorporate new technologies and come in on very (very) tight time frames.
Credit to go out to the team at Breeze for getting this over the line. 
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blogs.breeze.net/scotts/aggbug.ashx?id=bba4a3a0-7d6c-414d-bac0-bdc2ee8325b6" /&gt;</description>
      <category>BizTalk General</category>
      <category>Breeze</category>
      <category>Cloud Services</category>
      <category>F#</category>
      <category>WCF</category>
      <category>Windows Azure</category>
      <category>Windows Server AppFabric</category>
    </item>
    <item>
      <trackback:ping>http://blogs.breeze.net/scotts/Trackback.aspx?guid=ae403da7-6bf9-4ff9-81ce-a0d48f9dafbe</trackback:ping>
      <pingback:server>http://blogs.breeze.net/scotts/pingback.aspx</pingback:server>
      <pingback:target>http://blogs.breeze.net/scotts/PermaLink,guid,ae403da7-6bf9-4ff9-81ce-a0d48f9dafbe.aspx</pingback:target>
      <dc:creator>Scott Scovell</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Hit this little hurdle recently while creating WCF Data Service against Azure Table
Storage. At the moment only a handful of operators are supported by the client library
when using the Table Storage Service.
</p>
        <p>
          <u>Supported Query Operators</u>
        </p>
        <p>
          <table border="1" cellspacing="0" cellpadding="0">
            <tbody>
              <tr>
                <td valign="top" width="158">
                  <p>
                    <strong>LINQ operator </strong>
                  </p>
                </td>
                <td valign="top" width="174">
                  <p>
                    <strong>Table service support </strong>
                  </p>
                </td>
                <td valign="top">
                  <p>
                    <strong>Additional information</strong>
                  </p>
                </td>
              </tr>
              <tr>
                <td valign="top" width="158">
                  <p>
                    <b>From</b>
                  </p>
                </td>
                <td valign="top" width="174">
                  <p>
Supported as defined.
</p>
                </td>
                <td valign="top">
 </td>
              </tr>
              <tr>
                <td valign="top" width="158">
                  <p>
                    <b>Where</b>
                  </p>
                </td>
                <td valign="top" width="174">
                  <p>
Supported as defined.
</p>
                </td>
                <td valign="top">
 </td>
              </tr>
              <tr>
                <td valign="top" width="158">
                  <p>
                    <b>Take</b>
                  </p>
                </td>
                <td valign="top" width="174">
                  <p>
Supported, with some restrictions.
</p>
                </td>
                <td valign="top">
                  <p>
The value specified for the <b>Take</b> operator must be less than or equal to 1,000.
If it is greater than 1,000, the service returns status code 400 (Bad Request). 
</p>
                  <p>
If the <b>Take</b> operator is not specified, a maximum of 1,000 entries will be returned.
</p>
                </td>
              </tr>
              <tr>
                <td valign="top" width="158">
                  <p>
                    <b>First, FirstOrDefault</b>
                  </p>
                </td>
                <td valign="top" width="174">
                  <p>
Supported.
</p>
                </td>
                <td valign="top">
 </td>
              </tr>
            </tbody>
          </table>
        </p>
        <p>
What this means is that we can not perform LINQ queries that group, order by, distinct
or even return single entity properties from the query (we must always return the
entire entity). In most situations the solution is to construct our LINQ queries that
first make use of the supported operators and then use AsEnumerable() followed by
any operations that are not supported. This generates two parts to the LINQ query.
The first part (everything before the AsEnumerable) gets sent to the backend (Azure
Table Storage in this case) and the remaining parts execute locally against the results
of the first (in-memory). This helps get over the road-block but as you can image
you are bringing a greater chunk of data down to the client and continuing processing
there.
</p>
        <p>
          <u>Some examples:</u>
        </p>
        <p>
Using Distinct() 
</p>
        <div>
          <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">var query = myTableServiceContext.MyEntity.Where(e =&gt; e.Category == someCatgeory).<strong><font color="#ff0000">AsEnumerable</font></strong>().Select(c
=&gt; c.Name).Distinct();</pre>
        </div>
        <div> 
</div>
        <div>Select next 5 entities after a given date and time (using OrderBy together with
Take)
</div>
        <div> 
</div>
        <div>
          <div id="codeSnippetWrapper">
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">var query = myTableServiceContext.MyEntity.Where(e =&gt; e.Category == someCatgeory &amp; e.StartDate &gt; DateTime.UtcNow).<strong><font color="#ff0000">AsEnumerable</font></strong>().OrderBy(o
=&gt; o.StartDate).Take(5);</pre>
            <br />
          </div>
        </div>
        <p>
For further details check out the <a href="http://msdn.microsoft.com/en-us/library/dd135725.aspx" target="_blank">online
documentation</a>.
</p>
        <img width="0" height="0" src="http://blogs.breeze.net/scotts/aggbug.ashx?id=ae403da7-6bf9-4ff9-81ce-a0d48f9dafbe" />
      </body>
      <title>Supported LINQ Query Operators for Azure Table Storage Service</title>
      <guid isPermaLink="false">http://blogs.breeze.net/scotts/PermaLink,guid,ae403da7-6bf9-4ff9-81ce-a0d48f9dafbe.aspx</guid>
      <link>http://blogs.breeze.net/scotts/2011/04/07/SupportedLINQQueryOperatorsForAzureTableStorageService.aspx</link>
      <pubDate>Thu, 07 Apr 2011 10:32:00 GMT</pubDate>
      <description>&lt;p&gt;
Hit this little hurdle recently while creating WCF Data Service against Azure Table
Storage. At the moment only a handful of operators are supported by the client library
when using the Table Storage Service.
&lt;/p&gt;
&lt;p&gt;
&lt;u&gt;Supported Query Operators&lt;/u&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;table border="1" cellspacing="0" cellpadding="0"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top" width="158"&gt;
&lt;p&gt;
&lt;strong&gt;LINQ operator &lt;/strong&gt;
&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top" width="174"&gt;
&lt;p&gt;
&lt;strong&gt;Table service support &lt;/strong&gt;
&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;p&gt;
&lt;strong&gt;Additional information&lt;/strong&gt; 
&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="158"&gt;
&lt;p&gt;
&lt;b&gt;From&lt;/b&gt;
&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top" width="174"&gt;
&lt;p&gt;
Supported as defined.
&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top"&gt;
&amp;nbsp;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="158"&gt;
&lt;p&gt;
&lt;b&gt;Where&lt;/b&gt;
&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top" width="174"&gt;
&lt;p&gt;
Supported as defined.
&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top"&gt;
&amp;nbsp;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="158"&gt;
&lt;p&gt;
&lt;b&gt;Take&lt;/b&gt;
&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top" width="174"&gt;
&lt;p&gt;
Supported, with some restrictions.
&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;p&gt;
The value specified for the &lt;b&gt;Take&lt;/b&gt; operator must be less than or equal to 1,000.
If it is greater than 1,000, the service returns status code 400 (Bad Request). 
&lt;p&gt;
If the &lt;b&gt;Take&lt;/b&gt; operator is not specified, a maximum of 1,000 entries will be returned.
&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="158"&gt;
&lt;p&gt;
&lt;b&gt;First, FirstOrDefault&lt;/b&gt;
&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top" width="174"&gt;
&lt;p&gt;
Supported.
&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top"&gt;
&amp;nbsp;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/p&gt;
&lt;p&gt;
What this means is that we can not perform LINQ queries that group, order by, distinct
or even return single entity properties from the query (we must always return the
entire entity). In most situations the solution is to construct our LINQ queries that
first make use of the supported operators and then use AsEnumerable() followed by
any operations that are not supported. This generates two parts to the LINQ query.
The first part (everything before the AsEnumerable) gets sent to the backend (Azure
Table Storage in this case) and the remaining parts execute locally against the results
of the first (in-memory). This helps get over the road-block but as you can image
you are bringing a greater chunk of data down to the client and continuing processing
there.
&lt;/p&gt;
&lt;p&gt;
&lt;u&gt;Some examples:&lt;/u&gt;
&lt;/p&gt;
&lt;p&gt;
Using Distinct() 
&lt;/p&gt;
&lt;div&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;var query = myTableServiceContext.MyEntity.Where(e =&amp;gt; e.Category == someCatgeory).&lt;strong&gt;&lt;font color="#ff0000"&gt;AsEnumerable&lt;/font&gt;&lt;/strong&gt;().Select(c
=&amp;gt; c.Name).Distinct();&lt;/pre&gt;
&lt;/div&gt;
&lt;div&gt;&amp;nbsp;
&lt;/div&gt;
&lt;div&gt;Select next 5 entities after a given date and time (using OrderBy together with
Take)
&lt;/div&gt;
&lt;div&gt;&amp;nbsp;
&lt;/div&gt;
&lt;div&gt;
&lt;div id="codeSnippetWrapper"&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;var query = myTableServiceContext.MyEntity.Where(e =&amp;gt; e.Category == someCatgeory &amp;amp; e.StartDate &amp;gt; DateTime.UtcNow).&lt;strong&gt;&lt;font color="#ff0000"&gt;AsEnumerable&lt;/font&gt;&lt;/strong&gt;().OrderBy(o
=&amp;gt; o.StartDate).Take(5);&lt;/pre&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;
For further details check out the &lt;a href="http://msdn.microsoft.com/en-us/library/dd135725.aspx" target="_blank"&gt;online
documentation&lt;/a&gt;.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blogs.breeze.net/scotts/aggbug.ashx?id=ae403da7-6bf9-4ff9-81ce-a0d48f9dafbe" /&gt;</description>
      <category>.NET Framework</category>
      <category>WCF</category>
      <category>Windows Azure</category>
    </item>
    <item>
      <trackback:ping>http://blogs.breeze.net/scotts/Trackback.aspx?guid=3104f6ac-cbe5-446d-87d0-dd4707a50ba7</trackback:ping>
      <pingback:server>http://blogs.breeze.net/scotts/pingback.aspx</pingback:server>
      <pingback:target>http://blogs.breeze.net/scotts/PermaLink,guid,3104f6ac-cbe5-446d-87d0-dd4707a50ba7.aspx</pingback:target>
      <dc:creator>Scott Scovell</dc:creator>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
On a recent project I needed to resolve the identity of clients calling an orchestration
exposed as a WCF service. Clients would use a X.509 certificate to sign the message.
Configuring the WCF service was easy enough but I was not getting the party resolution
piece working correctly. The WCF adapter (I was using WCF-CustomIsolated) was not
populating the context property (BTS.SignatureCertificate) that the party resolution
component uses to lookup the party even though the client certificate was being validated.
The WCF adapter was dumping the soap headers into the context. I was left either to
parse the headers manually and find a way to grab details of the signing certificate
or somehow get the WCF adapter to do this work for me (as it was already validating
the client certificate and checking we had the corresponding public key in the certificate
store). Fortunately, I found a way we can get the adapter to help out.
</p>
        <p>
The solution was to create a WCF service behavior extension to intercept message processing
by the adapter (note this takes place before the message is presented to the receive
pipeline). The custom behavior looks for a client certificate and if found writes
the thumbprint into a custom soap header. The WCF Adapter would then write my custom
header into the message context and I could grab it in a custom pipeline component.
I chose to write a component to execute before the OOTB party resolution component
and populate the BTS.SignatureCertificate context property with the value of certificate
thumbprint. I could of done this all in one component and performed custom party resolution
but thought this might be a bit cleaner.
</p>
        <p>
So looking at the WCF service behavior
</p>
        <div class="csharpcode">
          <pre class="alt">
            <span class="lnum"> 1: </span>
            <span class="kwrd">using</span> System;</pre>
          <pre>
            <span class="lnum"> 2: </span>
            <span class="kwrd">using</span> System.ServiceModel;</pre>
          <pre class="alt">
            <span class="lnum"> 3: </span>
            <span class="kwrd">using</span> System.ServiceModel.Dispatcher;</pre>
          <pre>
            <span class="lnum"> 4: </span>
            <span class="kwrd">using</span> System.ServiceModel.Channels;</pre>
          <pre class="alt">
            <span class="lnum"> 5: </span>
            <span class="kwrd">using</span> System.ServiceModel.Description;</pre>
          <pre>
            <span class="lnum"> 6: </span>
            <span class="kwrd">using</span> System.IdentityModel.Claims;</pre>
          <pre class="alt">
            <span class="lnum"> 7: </span>
            <span class="kwrd">using</span> System.ServiceModel.Configuration;</pre>
          <pre>
            <span class="lnum"> 8: </span> </pre>
          <pre class="alt">
            <span class="lnum"> 9: </span>
            <span class="kwrd">namespace</span> Breeze.WCF.ClientCertificateContext</pre>
          <pre>
            <span class="lnum"> 10: </span>{</pre>
          <pre class="alt">
            <span class="lnum"> 11: </span>
            <span class="kwrd">public</span>
            <span class="kwrd">class</span> MessageInspector
: IDispatchMessageInspector, IServiceBehavior</pre>
          <pre>
            <span class="lnum"> 12: </span> {</pre>
          <pre class="alt">
            <span class="lnum"> 13: </span>
            <span class="preproc">#region</span> IDispatchMessageInspector
Members</pre>
          <pre>
            <span class="lnum"> 14: </span> </pre>
          <pre class="alt">
            <span class="lnum"> 15: </span>
            <span class="kwrd">object</span> IDispatchMessageInspector.AfterReceiveRequest(<span class="kwrd">ref</span> Message
request, IClientChannel channel, InstanceContext instanceContext)</pre>
          <pre>
            <span class="lnum"> 16: </span> {</pre>
          <pre class="alt">
            <span class="lnum"> 17: </span>
            <span class="kwrd">object</span> correlationState
= <span class="kwrd">null</span>;</pre>
          <pre>
            <span class="lnum"> 18: </span>
            <span class="kwrd">string</span> thumbprint
= <span class="str">""</span>;</pre>
          <pre class="alt">
            <span class="lnum"> 19: </span> </pre>
          <pre>
            <span class="lnum"> 20: </span>
            <span class="kwrd">try</span>
          </pre>
          <pre class="alt">
            <span class="lnum"> 21: </span> {</pre>
          <pre>
            <span class="lnum"> 22: </span>
            <span class="rem">//
Gather thumbprint of signing certificate used by the client</span>
          </pre>
          <pre class="alt">
            <span class="lnum"> 23: </span>
            <span class="kwrd">foreach</span> (ClaimSet
set <span class="kwrd">in</span> request.Properties.Security.ServiceSecurityContext.AuthorizationContext.ClaimSets)</pre>
          <pre>
            <span class="lnum"> 24: </span> {</pre>
          <pre class="alt">
            <span class="lnum"> 25: </span>
            <span class="kwrd">foreach</span> (Claim
claim <span class="kwrd">in</span> set.FindClaims(ClaimTypes.Thumbprint, Rights.Identity))</pre>
          <pre>
            <span class="lnum"> 26: </span> {</pre>
          <pre class="alt">
            <span class="lnum"> 27: </span> thumbprint
= BitConverter.ToString((<span class="kwrd">byte</span>[])claim.Resource);</pre>
          <pre>
            <span class="lnum"> 28: </span> thumbprint
= thumbprint.Replace(<span class="str">"-"</span>, <span class="str">""</span>);</pre>
          <pre class="alt">
            <span class="lnum"> 29: </span> }</pre>
          <pre>
            <span class="lnum"> 30: </span> }</pre>
          <pre class="alt">
            <span class="lnum"> 31: </span> </pre>
          <pre>
            <span class="lnum"> 32: </span>
            <span class="rem">//
Write this away as a custom message header</span>
          </pre>
          <pre class="alt">
            <span class="lnum"> 33: </span>
            <span class="kwrd">if</span> (!String.IsNullOrEmpty(thumbprint))</pre>
          <pre>
            <span class="lnum"> 34: </span> {</pre>
          <pre class="alt">
            <span class="lnum"> 35: </span> MessageHeader
header = MessageHeader.CreateHeader(<span class="str">"ClientCertificate"</span>, <span class="str">"http://schemas.breeze.net/BizTalk/WCF-properties"</span>,
thumbprint);</pre>
          <pre>
            <span class="lnum"> 36: </span> request.Headers.Add(header);</pre>
          <pre class="alt">
            <span class="lnum"> 37: </span> }</pre>
          <pre>
            <span class="lnum"> 38: </span> </pre>
          <pre class="alt">
            <span class="lnum"> 39: </span> }</pre>
          <pre>
            <span class="lnum"> 40: </span>
            <span class="kwrd">catch</span> (Exception
ex)</pre>
          <pre class="alt">
            <span class="lnum"> 41: </span> {</pre>
          <pre>
            <span class="lnum"> 42: </span> System.Diagnostics.EventLog.WriteEntry(<span class="str">"WCF
MessageInspector"</span>, String.Format(<span class="str">"Exception caught: {0}"</span>,
ex.ToString()));</pre>
          <pre class="alt">
            <span class="lnum"> 43: </span> }</pre>
          <pre>
            <span class="lnum"> 44: </span> </pre>
          <pre class="alt">
            <span class="lnum"> 45: </span>
            <span class="kwrd">return</span> correlationState;</pre>
          <pre>
            <span class="lnum"> 46: </span> }</pre>
          <pre class="alt">
            <span class="lnum"> 47: </span> </pre>
          <pre>
            <span class="lnum"> 48: </span>
            <span class="kwrd">void</span> IDispatchMessageInspector.BeforeSendReply(<span class="kwrd">ref</span> Message
reply, <span class="kwrd">object</span> correlationState)</pre>
          <pre class="alt">
            <span class="lnum"> 49: </span> {</pre>
          <pre>
            <span class="lnum"> 50: </span> }</pre>
          <pre class="alt">
            <span class="lnum"> 51: </span> </pre>
          <pre>
            <span class="lnum"> 52: </span>
            <span class="preproc">#endregion</span>
          </pre>
          <pre class="alt">
            <span class="lnum"> 53: </span> </pre>
          <pre>
            <span class="lnum"> 54: </span>
            <span class="preproc">#region</span> IServiceBehavior
Members</pre>
          <pre class="alt">
            <span class="lnum"> 55: </span> </pre>
          <pre>
            <span class="lnum"> 56: </span>
            <span class="kwrd">public</span>
            <span class="kwrd">void</span> AddBindingParameters(ServiceDescription
serviceDescription, ServiceHostBase serviceHostBase, </pre>
          <pre>                                                System.Collections.ObjectModel.Collection&lt;ServiceEndpoint&gt; endpoints, BindingParameterCollection bindingParameters)</pre>
          <pre class="alt">
            <span class="lnum"> 57: </span> {</pre>
          <pre>
            <span class="lnum"> 58: </span>
            <span class="kwrd">return</span>;</pre>
          <pre class="alt">
            <span class="lnum"> 59: </span> }</pre>
          <pre>
            <span class="lnum"> 60: </span> </pre>
          <pre class="alt">
            <span class="lnum"> 61: </span>
            <span class="kwrd">public</span>
            <span class="kwrd">void</span> ApplyDispatchBehavior(ServiceDescription
serviceDescription, ServiceHostBase serviceHostBase)</pre>
          <pre>
            <span class="lnum"> 62: </span> {</pre>
          <pre class="alt">
            <span class="lnum"> 63: </span>
            <span class="kwrd">foreach</span> (ChannelDispatcher
channelDispatcher <span class="kwrd">in</span> serviceHostBase.ChannelDispatchers)</pre>
          <pre>
            <span class="lnum"> 64: </span> {</pre>
          <pre class="alt">
            <span class="lnum"> 65: </span>
            <span class="kwrd">foreach</span> (EndpointDispatcher
endpointDispatcher <span class="kwrd">in</span> channelDispatcher.Endpoints)</pre>
          <pre>
            <span class="lnum"> 66: </span> {</pre>
          <pre class="alt">
            <span class="lnum"> 67: </span> endpointDispatcher.DispatchRuntime.MessageInspectors.Add(<span class="kwrd">this</span>);</pre>
          <pre>
            <span class="lnum"> 68: </span> }</pre>
          <pre class="alt">
            <span class="lnum"> 69: </span> }</pre>
          <pre>
            <span class="lnum"> 70: </span> }</pre>
          <pre class="alt">
            <span class="lnum"> 71: </span> </pre>
          <pre>
            <span class="lnum"> 72: </span>
            <span class="kwrd">public</span>
            <span class="kwrd">void</span> Validate(ServiceDescription
serviceDescription, ServiceHostBase serviceHostBase)</pre>
          <pre class="alt">
            <span class="lnum"> 73: </span> {</pre>
          <pre>
            <span class="lnum"> 74: </span>
            <span class="kwrd">return</span>;</pre>
          <pre class="alt">
            <span class="lnum"> 75: </span> }</pre>
          <pre>
            <span class="lnum"> 76: </span> </pre>
          <pre class="alt">
            <span class="lnum"> 77: </span>
            <span class="preproc">#endregion</span>
          </pre>
          <pre>
            <span class="lnum"> 78: </span> }</pre>
          <pre class="alt">
            <span class="lnum"> 79: </span> </pre>
          <pre>
            <span class="lnum"> 80: </span>
            <span class="kwrd">public</span>
            <span class="kwrd">class</span> MessageInspectorElement
: BehaviorExtensionElement</pre>
          <pre class="alt">
            <span class="lnum"> 81: </span> {</pre>
          <pre>
            <span class="lnum"> 82: </span>
            <span class="kwrd">public</span>
            <span class="kwrd">override</span> Type
BehaviorType</pre>
          <pre class="alt">
            <span class="lnum"> 83: </span> {</pre>
          <pre>
            <span class="lnum"> 84: </span> get
{ <span class="kwrd">return</span><span class="kwrd">typeof</span>(MessageInspector);
}</pre>
          <pre class="alt">
            <span class="lnum"> 85: </span> }</pre>
          <pre>
            <span class="lnum"> 86: </span> </pre>
          <pre class="alt">
            <span class="lnum"> 87: </span>
            <span class="kwrd">protected</span>
            <span class="kwrd">override</span>
            <span class="kwrd">object</span> CreateBehavior()</pre>
          <pre>
            <span class="lnum"> 88: </span> {</pre>
          <pre class="alt">
            <span class="lnum"> 89: </span>
            <span class="kwrd">return</span>
            <span class="kwrd">new</span> MessageInspector();</pre>
          <pre>
            <span class="lnum"> 90: </span> }</pre>
          <pre class="alt">
            <span class="lnum"> 91: </span> }</pre>
          <pre>
            <span class="lnum"> 92: </span> </pre>
          <pre class="alt">
            <span class="lnum"> 93: </span> </pre>
          <pre>
            <span class="lnum"> 94: </span>}</pre>
        </div>
        <style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
        <p>
 
</p>
        <p>
          <strong>Tip</strong>: Don't forget to implement the BehaviorExtensionElement. You’ll
need this to apply the service behavior via configuration (in the receive location)
rather then having to do it programmatically. You will also need to sign, GAC and
register the service behavior extension element in the machine.config (or service’s
web.config in IIS)
</p>
        <p>
With the WCF service behavior bits done, we need to add it to our receive location:
</p>
        <p>
          <a href="http://blogs.breeze.net/scotts/content/binary/WindowsLiveWriter/BizTalkPartyResolutionusingWCFAdapterand_9284/image_2.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.breeze.net/scotts/content/binary/WindowsLiveWriter/BizTalkPartyResolutionusingWCFAdapterand_9284/image_thumb.png" width="505" height="440" />
          </a>
        </p>
        <p>
If you were to test the solution now, you’ll get the thumbprint of the client certificate
written to your custom context property (<a href="http://schemas.breeze.net/BizTalk/WCF-properties#ClientCertificate">http://schemas.breeze.net/BizTalk/WCF-properties#ClientCertificate</a>)
and will look something like this:
</p>
        <div class="csharpcode">
          <pre class="alt">
            <span class="lnum"> 1: </span>
            <span class="kwrd">&lt;</span>
            <span class="html">ClientCertificate</span>
            <span class="attr">xmlns</span>
            <span class="kwrd">="http://schemas.breeze.net/BizTalk/WCF-properties"</span>
            <span class="kwrd">&gt;</span>11C3E164C41ADC8DBA0EA6558784B9FAE19E398D<span class="kwrd">&lt;/</span><span class="html">ClientCertificate</span><span class="kwrd">&gt;</span></pre>
        </div>
        <p>
 
</p>
        <p>
I had thought I might be able to get away with writing this directly into the BTS.SignatureCertificate
context property but the format is clearly different. The BTS.SignatureCertificate
property needs just the certificate thumbprint string and obviously we have the xml
wrapper. So we must create a simple pipeline component to sit somewhere before the
party resolution component to grab the certificate thumbprint out of our custom context
property and write it into the context property the party resolver component is looking
for.
</p>
        <p>
          <a href="http://blogs.breeze.net/scotts/content/binary/WindowsLiveWriter/BizTalkPartyResolutionusingWCFAdapterand_9284/image_4.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.breeze.net/scotts/content/binary/WindowsLiveWriter/BizTalkPartyResolutionusingWCFAdapterand_9284/image_thumb_1.png" width="217" height="608" />
          </a>
        </p>
        <p>
After deploying and setting the receive pipeline to use the custom one above, I got
party resolution working like a bought one with the BTS.SigningCertificate, BTS.SourcePartyID
and MessageTracking.PartyName context properties populated.
</p>
        <p>
I guess I was a little surprised that all this was needed. WCF does a great job of
abstracting out all the transport and security bits and moving them to configuration
time (no additional code in our service or client). In the HTTP and SOAP adapter days,
the MIME/SMIME pipeline component was used to decrypt and validate the signing certificate
as well as populating the required context properties. Why doesn’t the WCF Adapter
perform this part in the same way? I mean, its doing the decoding, decrypting and
certificate validation. So why not the populating of these context properties? Perhaps
there is secret squirrel checkbox somewhere I missed. Love to hear comments if anyone
has done this differently?
</p>
        <p>
          <font color="#ff0000">[Updated: 19-10-2010]</font>
        </p>
        <p>
Thanks to <a href="http://connectedthoughts.wordpress.com/" target="_blank">Thiago</a> (see
comments section) we have been able to simplify this further. The WCF adapter provides
some “special” namespaces that allow us to instruct the adapter to write context properties
in a more controlled way. Specifically we can instruct the adapter to write directly
into defined property schema elements (e.g. OOTB BizTalk property schemas or deployed
custom property schemas). This allows us to write the certificate thumbprint directly
into the BTS.SigningCertificate context property and avoid the need for the custom
pipeline component to move the value from the custom header property into the BTS.SigningCertificate
property as described above.
</p>
        <p>
To do this we simply change the IDispatchMessageInspector.AfterReceiveRequest to make
use of these special namespaces.
</p>
        <div class="csharpcode">
          <pre class="alt">
            <span class="rem">// Write
this away as a custom message header</span>
          </pre>
          <pre>
            <span class="kwrd">if</span> (!String.IsNullOrEmpty(thumbprint))</pre>
          <pre class="alt">                {</pre>
          <pre>
            <span class="rem">//
Write the thumbprint directly to the BTS.SigningCertificate context property</span>
          </pre>
          <pre class="alt">
            <span class="rem">//
Thanks to Thiago http://connectedthoughts.wordpress.com</span>
          </pre>
          <pre> </pre>
          <pre class="alt">
            <span class="rem">//
Create a collection of context properties we want the adapter to write/promote for
us </span>
          </pre>
          <pre>                    XmlQualifiedName clientCertificateProp = </pre>
          <pre class="alt">
            <span class="kwrd">new</span> XmlQualifiedName(<span class="str">"SignatureCertificate"</span>, <span class="str">"http://schemas.microsoft.com/BizTalk/2003/system-properties"</span>); <span class="rem">//Maps
to BTS.SignatureCertificate</span></pre>
          <pre>                    List&lt;KeyValuePair&lt;XmlQualifiedName, <span class="kwrd">object</span>&gt;&gt;
promoteProps = <span class="kwrd">new</span> List&lt;KeyValuePair&lt;XmlQualifiedName, <span class="kwrd">object</span>&gt;&gt;();</pre>
          <pre class="alt">                    promoteProps.Add(<span class="kwrd">new</span> KeyValuePair&lt;XmlQualifiedName, <span class="kwrd">object</span>&gt;(clientCertificateProp,
thumbprint));</pre>
          <pre> </pre>
          <pre class="alt">
            <span class="rem">//
Add the property collection to the request</span>
          </pre>
          <pre>
            <span class="rem">//
Use the http://..../Promote to have the adapter promote the context prop</span>
          </pre>
          <pre class="alt">
            <span class="rem">//
or use http:/...../WriteToContext to just have the property written but not promoted.</span>
          </pre>
          <pre>                    request.Properties.Add(<span class="str">"http://schemas.microsoft.com/BizTalk/2006/01/Adapters/WCF-properties/Promote"</span>,
promoteProps); </pre>
          <pre class="alt">                }</pre>
        </div>
        <style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
        <p>
 
</p>
        <p>
Now we can do away with the custom pipeline component bits and use the OOTB XMLReceive
pipeline (as it contains the party resolver component already). The certificate thumbprint
will be written directly into the BTS.SigningCertificate context property (and promoted)
ready for the party resolver component to use.
</p>
        <p>
Nice work Thiago. <img alt="thumbs_up" src="http://spaces.live.com/rte/emoticons/thumbs_up.gif" /></p>
        <img width="0" height="0" src="http://blogs.breeze.net/scotts/aggbug.ashx?id=3104f6ac-cbe5-446d-87d0-dd4707a50ba7" />
      </body>
      <title>BizTalk Party Resolution using WCF Adapter and Client Certificates</title>
      <guid isPermaLink="false">http://blogs.breeze.net/scotts/PermaLink,guid,3104f6ac-cbe5-446d-87d0-dd4707a50ba7.aspx</guid>
      <link>http://blogs.breeze.net/scotts/2010/10/18/BizTalkPartyResolutionUsingWCFAdapterAndClientCertificates.aspx</link>
      <pubDate>Mon, 18 Oct 2010 01:50:22 GMT</pubDate>
      <description>&lt;p&gt;
On a recent project I needed to resolve the identity of clients calling an orchestration
exposed as a WCF service. Clients would use a X.509 certificate to sign the message.
Configuring the WCF service was easy enough but I was not getting the party resolution
piece working correctly. The WCF adapter (I was using WCF-CustomIsolated) was not
populating the context property (BTS.SignatureCertificate) that the party resolution
component uses to lookup the party even though the client certificate was being validated.
The WCF adapter was dumping the soap headers into the context. I was left either to
parse the headers manually and find a way to grab details of the signing certificate
or somehow get the WCF adapter to do this work for me (as it was already validating
the client certificate and checking we had the corresponding public key in the certificate
store). Fortunately, I found a way we can get the adapter to help out.
&lt;/p&gt;
&lt;p&gt;
The solution was to create a WCF service behavior extension to intercept message processing
by the adapter (note this takes place before the message is presented to the receive
pipeline). The custom behavior looks for a client certificate and if found writes
the thumbprint into a custom soap header. The WCF Adapter would then write my custom
header into the message context and I could grab it in a custom pipeline component.
I chose to write a component to execute before the OOTB party resolution component
and populate the BTS.SignatureCertificate context property with the value of certificate
thumbprint. I could of done this all in one component and performed custom party resolution
but thought this might be a bit cleaner.
&lt;/p&gt;
&lt;p&gt;
So looking at the WCF service behavior
&lt;/p&gt;
&lt;div class="csharpcode"&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 1: &lt;/span&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt; 2: &lt;/span&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.ServiceModel;&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 3: &lt;/span&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.ServiceModel.Dispatcher;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt; 4: &lt;/span&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.ServiceModel.Channels;&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 5: &lt;/span&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.ServiceModel.Description;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt; 6: &lt;/span&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.IdentityModel.Claims;&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 7: &lt;/span&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.ServiceModel.Configuration;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt; 8: &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 9: &lt;/span&gt;&lt;span class="kwrd"&gt;namespace&lt;/span&gt; Breeze.WCF.ClientCertificateContext&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt; 10: &lt;/span&gt;{&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 11: &lt;/span&gt; &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; MessageInspector
: IDispatchMessageInspector, IServiceBehavior&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt; 12: &lt;/span&gt; {&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 13: &lt;/span&gt; &lt;span class="preproc"&gt;#region&lt;/span&gt; IDispatchMessageInspector
Members&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt; 14: &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 15: &lt;/span&gt; &lt;span class="kwrd"&gt;object&lt;/span&gt; IDispatchMessageInspector.AfterReceiveRequest(&lt;span class="kwrd"&gt;ref&lt;/span&gt; Message
request, IClientChannel channel, InstanceContext instanceContext)&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt; 16: &lt;/span&gt; {&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 17: &lt;/span&gt; &lt;span class="kwrd"&gt;object&lt;/span&gt; correlationState
= &lt;span class="kwrd"&gt;null&lt;/span&gt;;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt; 18: &lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; thumbprint
= &lt;span class="str"&gt;""&lt;/span&gt;;&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 19: &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt; 20: &lt;/span&gt; &lt;span class="kwrd"&gt;try&lt;/span&gt;&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 21: &lt;/span&gt; {&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt; 22: &lt;/span&gt; &lt;span class="rem"&gt;//
Gather thumbprint of signing certificate used by the client&lt;/span&gt;&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 23: &lt;/span&gt; &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (ClaimSet
set &lt;span class="kwrd"&gt;in&lt;/span&gt; request.Properties.Security.ServiceSecurityContext.AuthorizationContext.ClaimSets)&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt; 24: &lt;/span&gt; {&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 25: &lt;/span&gt; &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (Claim
claim &lt;span class="kwrd"&gt;in&lt;/span&gt; set.FindClaims(ClaimTypes.Thumbprint, Rights.Identity))&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt; 26: &lt;/span&gt; {&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 27: &lt;/span&gt; thumbprint
= BitConverter.ToString((&lt;span class="kwrd"&gt;byte&lt;/span&gt;[])claim.Resource);&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt; 28: &lt;/span&gt; thumbprint
= thumbprint.Replace(&lt;span class="str"&gt;"-"&lt;/span&gt;, &lt;span class="str"&gt;""&lt;/span&gt;);&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 29: &lt;/span&gt; }&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt; 30: &lt;/span&gt; }&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 31: &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt; 32: &lt;/span&gt; &lt;span class="rem"&gt;//
Write this away as a custom message header&lt;/span&gt;&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 33: &lt;/span&gt; &lt;span class="kwrd"&gt;if&lt;/span&gt; (!String.IsNullOrEmpty(thumbprint))&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt; 34: &lt;/span&gt; {&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 35: &lt;/span&gt; MessageHeader
header = MessageHeader.CreateHeader(&lt;span class="str"&gt;"ClientCertificate"&lt;/span&gt;, &lt;span class="str"&gt;"http://schemas.breeze.net/BizTalk/WCF-properties"&lt;/span&gt;,
thumbprint);&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt; 36: &lt;/span&gt; request.Headers.Add(header);&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 37: &lt;/span&gt; }&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt; 38: &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 39: &lt;/span&gt; }&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt; 40: &lt;/span&gt; &lt;span class="kwrd"&gt;catch&lt;/span&gt; (Exception
ex)&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 41: &lt;/span&gt; {&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt; 42: &lt;/span&gt; System.Diagnostics.EventLog.WriteEntry(&lt;span class="str"&gt;"WCF
MessageInspector"&lt;/span&gt;, String.Format(&lt;span class="str"&gt;"Exception caught: {0}"&lt;/span&gt;,
ex.ToString()));&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 43: &lt;/span&gt; }&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt; 44: &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 45: &lt;/span&gt; &lt;span class="kwrd"&gt;return&lt;/span&gt; correlationState;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt; 46: &lt;/span&gt; }&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 47: &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt; 48: &lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; IDispatchMessageInspector.BeforeSendReply(&lt;span class="kwrd"&gt;ref&lt;/span&gt; Message
reply, &lt;span class="kwrd"&gt;object&lt;/span&gt; correlationState)&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 49: &lt;/span&gt; {&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt; 50: &lt;/span&gt; }&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 51: &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt; 52: &lt;/span&gt; &lt;span class="preproc"&gt;#endregion&lt;/span&gt;&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 53: &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt; 54: &lt;/span&gt; &lt;span class="preproc"&gt;#region&lt;/span&gt; IServiceBehavior
Members&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 55: &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt; 56: &lt;/span&gt; &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; AddBindingParameters(ServiceDescription
serviceDescription, ServiceHostBase serviceHostBase, &lt;/pre&gt;&lt;pre&gt;                                                System.Collections.ObjectModel.Collection&amp;lt;ServiceEndpoint&amp;gt; endpoints, BindingParameterCollection bindingParameters)&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 57: &lt;/span&gt; {&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt; 58: &lt;/span&gt; &lt;span class="kwrd"&gt;return&lt;/span&gt;;&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 59: &lt;/span&gt; }&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt; 60: &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 61: &lt;/span&gt; &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; ApplyDispatchBehavior(ServiceDescription
serviceDescription, ServiceHostBase serviceHostBase)&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt; 62: &lt;/span&gt; {&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 63: &lt;/span&gt; &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (ChannelDispatcher
channelDispatcher &lt;span class="kwrd"&gt;in&lt;/span&gt; serviceHostBase.ChannelDispatchers)&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt; 64: &lt;/span&gt; {&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 65: &lt;/span&gt; &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (EndpointDispatcher
endpointDispatcher &lt;span class="kwrd"&gt;in&lt;/span&gt; channelDispatcher.Endpoints)&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt; 66: &lt;/span&gt; {&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 67: &lt;/span&gt; endpointDispatcher.DispatchRuntime.MessageInspectors.Add(&lt;span class="kwrd"&gt;this&lt;/span&gt;);&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt; 68: &lt;/span&gt; }&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 69: &lt;/span&gt; }&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt; 70: &lt;/span&gt; }&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 71: &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt; 72: &lt;/span&gt; &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Validate(ServiceDescription
serviceDescription, ServiceHostBase serviceHostBase)&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 73: &lt;/span&gt; {&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt; 74: &lt;/span&gt; &lt;span class="kwrd"&gt;return&lt;/span&gt;;&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 75: &lt;/span&gt; }&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt; 76: &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 77: &lt;/span&gt; &lt;span class="preproc"&gt;#endregion&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt; 78: &lt;/span&gt; }&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 79: &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt; 80: &lt;/span&gt; &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; MessageInspectorElement
: BehaviorExtensionElement&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 81: &lt;/span&gt; {&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt; 82: &lt;/span&gt; &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; Type
BehaviorType&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 83: &lt;/span&gt; {&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt; 84: &lt;/span&gt; get
{ &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(MessageInspector);
}&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 85: &lt;/span&gt; }&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt; 86: &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 87: &lt;/span&gt; &lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;object&lt;/span&gt; CreateBehavior()&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt; 88: &lt;/span&gt; {&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 89: &lt;/span&gt; &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; MessageInspector();&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt; 90: &lt;/span&gt; }&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 91: &lt;/span&gt; }&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt; 92: &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 93: &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt; 94: &lt;/span&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Tip&lt;/strong&gt;: Don't forget to implement the BehaviorExtensionElement. You’ll
need this to apply the service behavior via configuration (in the receive location)
rather then having to do it programmatically. You will also need to sign, GAC and
register the service behavior extension element in the machine.config (or service’s
web.config in IIS)
&lt;/p&gt;
&lt;p&gt;
With the WCF service behavior bits done, we need to add it to our receive location:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blogs.breeze.net/scotts/content/binary/WindowsLiveWriter/BizTalkPartyResolutionusingWCFAdapterand_9284/image_2.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.breeze.net/scotts/content/binary/WindowsLiveWriter/BizTalkPartyResolutionusingWCFAdapterand_9284/image_thumb.png" width="505" height="440"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
If you were to test the solution now, you’ll get the thumbprint of the client certificate
written to your custom context property (&lt;a href="http://schemas.breeze.net/BizTalk/WCF-properties#ClientCertificate"&gt;http://schemas.breeze.net/BizTalk/WCF-properties#ClientCertificate&lt;/a&gt;)
and will look something like this:
&lt;/p&gt;
&lt;div class="csharpcode"&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 1: &lt;/span&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ClientCertificate&lt;/span&gt; &lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;="http://schemas.breeze.net/BizTalk/WCF-properties"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;11C3E164C41ADC8DBA0EA6558784B9FAE19E398D&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;ClientCertificate&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
I had thought I might be able to get away with writing this directly into the BTS.SignatureCertificate
context property but the format is clearly different. The BTS.SignatureCertificate
property needs just the certificate thumbprint string and obviously we have the xml
wrapper. So we must create a simple pipeline component to sit somewhere before the
party resolution component to grab the certificate thumbprint out of our custom context
property and write it into the context property the party resolver component is looking
for.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blogs.breeze.net/scotts/content/binary/WindowsLiveWriter/BizTalkPartyResolutionusingWCFAdapterand_9284/image_4.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.breeze.net/scotts/content/binary/WindowsLiveWriter/BizTalkPartyResolutionusingWCFAdapterand_9284/image_thumb_1.png" width="217" height="608"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
After deploying and setting the receive pipeline to use the custom one above, I got
party resolution working like a bought one with the BTS.SigningCertificate, BTS.SourcePartyID
and MessageTracking.PartyName context properties populated.
&lt;/p&gt;
&lt;p&gt;
I guess I was a little surprised that all this was needed. WCF does a great job of
abstracting out all the transport and security bits and moving them to configuration
time (no additional code in our service or client). In the HTTP and SOAP adapter days,
the MIME/SMIME pipeline component was used to decrypt and validate the signing certificate
as well as populating the required context properties. Why doesn’t the WCF Adapter
perform this part in the same way? I mean, its doing the decoding, decrypting and
certificate validation. So why not the populating of these context properties? Perhaps
there is secret squirrel checkbox somewhere I missed. Love to hear comments if anyone
has done this differently?
&lt;/p&gt;
&lt;p&gt;
&lt;font color="#ff0000"&gt;[Updated: 19-10-2010]&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
Thanks to &lt;a href="http://connectedthoughts.wordpress.com/" target="_blank"&gt;Thiago&lt;/a&gt; (see
comments section) we have been able to simplify this further. The WCF adapter provides
some “special” namespaces that allow us to instruct the adapter to write context properties
in a more controlled way. Specifically we can instruct the adapter to write directly
into defined property schema elements (e.g. OOTB BizTalk property schemas or deployed
custom property schemas). This allows us to write the certificate thumbprint directly
into the BTS.SigningCertificate context property and avoid the need for the custom
pipeline component to move the value from the custom header property into the BTS.SigningCertificate
property as described above.
&lt;/p&gt;
&lt;p&gt;
To do this we simply change the IDispatchMessageInspector.AfterReceiveRequest to make
use of these special namespaces.
&lt;/p&gt;
&lt;div class="csharpcode"&gt;&lt;pre class="alt"&gt;                &lt;span class="rem"&gt;// Write
this away as a custom message header&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;                &lt;span class="kwrd"&gt;if&lt;/span&gt; (!String.IsNullOrEmpty(thumbprint))&lt;/pre&gt;&lt;pre class="alt"&gt;                {&lt;/pre&gt;&lt;pre&gt;                    &lt;span class="rem"&gt;//
Write the thumbprint directly to the BTS.SigningCertificate context property&lt;/span&gt;&lt;/pre&gt;&lt;pre class="alt"&gt;                    &lt;span class="rem"&gt;//
Thanks to Thiago http://connectedthoughts.wordpress.com&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre class="alt"&gt;                    &lt;span class="rem"&gt;//
Create a collection of context properties we want the adapter to write/promote for
us &lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;                    XmlQualifiedName clientCertificateProp = &lt;/pre&gt;&lt;pre class="alt"&gt;                        &lt;span class="kwrd"&gt;new&lt;/span&gt; XmlQualifiedName(&lt;span class="str"&gt;"SignatureCertificate"&lt;/span&gt;, &lt;span class="str"&gt;"http://schemas.microsoft.com/BizTalk/2003/system-properties"&lt;/span&gt;); &lt;span class="rem"&gt;//Maps
to BTS.SignatureCertificate&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;                    List&amp;lt;KeyValuePair&amp;lt;XmlQualifiedName, &lt;span class="kwrd"&gt;object&lt;/span&gt;&amp;gt;&amp;gt;
promoteProps = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;KeyValuePair&amp;lt;XmlQualifiedName, &lt;span class="kwrd"&gt;object&lt;/span&gt;&amp;gt;&amp;gt;();&lt;/pre&gt;&lt;pre class="alt"&gt;                    promoteProps.Add(&lt;span class="kwrd"&gt;new&lt;/span&gt; KeyValuePair&amp;lt;XmlQualifiedName, &lt;span class="kwrd"&gt;object&lt;/span&gt;&amp;gt;(clientCertificateProp,
thumbprint));&lt;/pre&gt;&lt;pre&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre class="alt"&gt;                    &lt;span class="rem"&gt;//
Add the property collection to the request&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;                    &lt;span class="rem"&gt;//
Use the http://..../Promote to have the adapter promote the context prop&lt;/span&gt;&lt;/pre&gt;&lt;pre class="alt"&gt;                    &lt;span class="rem"&gt;//
or use http:/...../WriteToContext to just have the property written but not promoted.&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;                    request.Properties.Add(&lt;span class="str"&gt;"http://schemas.microsoft.com/BizTalk/2006/01/Adapters/WCF-properties/Promote"&lt;/span&gt;,
promoteProps); &lt;/pre&gt;&lt;pre class="alt"&gt;                }&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
Now we can do away with the custom pipeline component bits and use the OOTB XMLReceive
pipeline (as it contains the party resolver component already). The certificate thumbprint
will be written directly into the BTS.SigningCertificate context property (and promoted)
ready for the party resolver component to use.
&lt;/p&gt;
&lt;p&gt;
Nice work Thiago. &lt;img alt="thumbs_up" src="http://spaces.live.com/rte/emoticons/thumbs_up.gif"&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blogs.breeze.net/scotts/aggbug.ashx?id=3104f6ac-cbe5-446d-87d0-dd4707a50ba7" /&gt;</description>
      <category>BizTalk General</category>
      <category>WCF</category>
    </item>
  </channel>
</rss>