<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Paolo Salvatori's Blog</title><link>http://blogs.msdn.com/paolos/default.aspx</link><description>Adventures and Findings in the Magic World of BizTalk Server.</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Customizing and Extending the BizTalk WCF Adapters</title><link>http://blogs.msdn.com/paolos/archive/2009/11/17/customizing-and-extending-the-biztalk-wcf-adapters.aspx</link><pubDate>Tue, 17 Nov 2009 11:15:37 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9923499</guid><dc:creator>leprino</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/paolos/comments/9923499.aspx</comments><wfw:commentRss>http://blogs.msdn.com/paolos/commentrss.aspx?PostID=9923499</wfw:commentRss><wfw:comment>http://blogs.msdn.com/paolos/rsscomments.aspx?PostID=9923499</wfw:comment><description>&lt;p align="justify"&gt;The contents of the following post are taken from a presentation I created and delivered at TechReady 9 in July 2009 and replicated with &lt;a href="http://blogs.msdn.com/skaufman/"&gt;Stephen Kaufman&lt;/a&gt; at Tech-Ed Europe 2009 .&lt;/p&gt;  &lt;p align="justify"&gt;&lt;font color="#ff9914"&gt;&lt;strong&gt;The ABC of WCF&lt;/strong&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p align="justify"&gt;Windows Communication Foundation (WCF) is a runtime and a set of APIs for exchanging messages between components and applications. WCF was designed according to the tenets of service orientation and unified the existing communication technologies like .NET Remoting and ASMX web service into a single programming model and consistent architecture which provides high levels of functionality, interoperability and extensibility. As you know, a typical WCF service can expose one or multiple endpoints. In general, endpoints provide clients access to the functionality offered by a WCF service. Each endpoint consists of 3 properties as depicted in the picture below:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;div align="justify"&gt;An address that indicates where the endpoint can be found. &lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;A binding that specifies how a client app can communicate with the endpoint. &lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;A contract that identifies the operations exposed by the endpoint. &lt;/div&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p align="justify"&gt;&lt;a href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/BizTalkServerWCFAdapters_929A/WCF_ABC_2.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="WCF_ABC" border="0" alt="WCF_ABC" src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/BizTalkServerWCFAdapters_929A/WCF_ABC_thumb.jpg" width="769" height="251" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p align="justify"&gt;&lt;strong&gt;&lt;font color="#ff9914"&gt;WCF Architecture: Messaging Runtime&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;The WCF runtime is divided into 2 primary layers as shown by the following picture:      &lt;br /&gt;The &lt;font color="#ff9914"&gt;Service Layer&lt;/font&gt; aka Service Model defines the mechanisms and attributes used by developers to define and decorate service, message and data contracts. &lt;/li&gt;    &lt;li&gt;The&amp;#160; &lt;font color="#ff9914"&gt;Messaging Layer&lt;/font&gt;&amp;#160; is responsible for preparing a WCF message for transmission on the send side and produce a WCF message for the dispatcher on the receive side. The messaging layer accomplishes this task using a &lt;font color="#ff9914"&gt;Channel Stack&lt;/font&gt;. This latter is a pipeline of channel components that handle different processing tasks.&amp;#160; Each channel stack is composed of exactly one transport channel, one message encoder, and zero or more protocol channels. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/BizTalkServerWCFAdapters_929A/WCF_Layers_2.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="WCF_Layers" border="0" alt="WCF_Layers" src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/BizTalkServerWCFAdapters_929A/WCF_Layers_thumb.jpg" width="673" height="673" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p align="justify"&gt;It’s the responsibility of the proxy component on the client side and dispatcher component on the service side to mediate and translate between the two layers. In particular, the proxy component transforms .NET method calls into Message objects, whereas the dispatcher component turns WCF Messages into .NET method calls. WCF uses the &lt;font color="#ff9914"&gt;Message&lt;/font&gt; class to model all incoming/outgoing messages within the Messaging Layer. The message represents a a SOAP Envelope, and therefore it’s composed of a payload and a set of headers. A typical WCF communication can be described as follows:     &lt;br /&gt;&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;     &lt;div align="justify"&gt;The client application creates one or more input parameters. Each of these parameters is defined by a data contract.&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;The client application invokes one of the methods of the service contract exposed by the proxy. &lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;The proxy delivers a WCF Message object to the channel stack. &lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;At this point each protocol channel has a chance to operate on the message before the transport channel uses a message encoder to transmit the final Message as a sequence of bytes to the target service. Each protocol channel can modify the content or the headers of the message to implement specific functionalities or WS-* protocols like WS-AtomicTransaction, WS-Security.&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;The raw stream of data is transmitted over the wire. &lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;On the service side, the transport channel receives the stream of data and uses a message encoder to interpret the bytes and to produce a WCF Message object that can continue up the channel stack. At this point each protocol channel has a chance to work on the message.&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;The final Message is passed to the Dispatcher.&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;The Dispatcher receives the WCF Message from the underlying channel stack, individuates the target service endpoint using the destination address and Action property contained in the Message, deserializes the content of the WCF Message into objects.&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;Finally the target service method is invoked. &lt;/div&gt;   &lt;/li&gt; &lt;/ol&gt;  &lt;p align="justify"&gt;&lt;strong&gt;&lt;font color="#ff9914"&gt;WCF Binding Comparison&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p align="justify"&gt;Bindings provide a mechanism for configuring channel stacks. A binding defines a precise recipe for building a channel stack using a transport channel, a message encoder, and a set of protocol channels.    &lt;br /&gt;WCF ships with several built-in bindings that target common communication scenarios. &lt;/p&gt;  &lt;table border="1" cellspacing="0" cellpadding="5" bgcolor="#ffffff"&gt;&lt;tbody&gt;     &lt;tr bgcolor="#333333"&gt;       &lt;td width="184"&gt;&lt;b&gt;Binding Class Name &lt;/b&gt;&lt;/td&gt;        &lt;td width="112"&gt;&lt;b&gt;Transport &lt;/b&gt;&lt;/td&gt;        &lt;td width="144"&gt;&lt;b&gt;Message Encoding &lt;/b&gt;&lt;/td&gt;        &lt;td width="128"&gt;&lt;b&gt;Message Version &lt;/b&gt;&lt;/td&gt;        &lt;td width="128"&gt;&lt;b&gt;Security Mode &lt;/b&gt;&lt;/td&gt;        &lt;td width="104"&gt;&lt;b&gt;Reliable Messaging &lt;/b&gt;&lt;/td&gt;        &lt;td width="104"&gt;&lt;b&gt;Tx Flow* &lt;/b&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td width="184"&gt;&lt;font color="#333333"&gt;BasicHttpBinding &lt;/font&gt;&lt;/td&gt;        &lt;td width="112"&gt;&lt;font color="#333333"&gt;HTTP &lt;/font&gt;&lt;/td&gt;        &lt;td width="144"&gt;&lt;font color="#333333"&gt;Text &lt;/font&gt;&lt;/td&gt;        &lt;td width="128"&gt;&lt;font color="#333333"&gt;SOAP 1.1 &lt;/font&gt;&lt;/td&gt;        &lt;td width="128"&gt;&lt;font color="#333333"&gt;None &lt;/font&gt;&lt;/td&gt;        &lt;td width="104"&gt;&lt;font color="#333333"&gt;X &lt;/font&gt;&lt;/td&gt;        &lt;td width="104"&gt;&lt;font color="#333333"&gt;X &lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td width="184"&gt;&lt;font color="#333333"&gt;WSHttpBinding &lt;/font&gt;&lt;/td&gt;        &lt;td width="112"&gt;&lt;font color="#333333"&gt;HTTP &lt;/font&gt;&lt;/td&gt;        &lt;td width="144"&gt;&lt;font color="#333333"&gt;Text &lt;/font&gt;&lt;/td&gt;        &lt;td width="128"&gt;&lt;font color="#333333"&gt;SOAP 1.2 &lt;/font&gt;&lt;font color="#333333"&gt;WS-A 1.0 &lt;/font&gt;&lt;/td&gt;        &lt;td width="128"&gt;&lt;font color="#333333"&gt;Message &lt;/font&gt;&lt;/td&gt;        &lt;td width="104"&gt;&lt;font color="#333333"&gt;Disabled &lt;/font&gt;&lt;/td&gt;        &lt;td width="104"&gt;&lt;font color="#333333"&gt;WS-AT &lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td width="184"&gt;&lt;font color="#333333"&gt;NetTcpBinding &lt;/font&gt;&lt;/td&gt;        &lt;td width="112"&gt;&lt;font color="#333333"&gt;TCP &lt;/font&gt;&lt;/td&gt;        &lt;td width="144"&gt;&lt;font color="#333333"&gt;Binary &lt;/font&gt;&lt;/td&gt;        &lt;td width="128"&gt;&lt;font color="#333333"&gt;SOAP 1.2 &lt;/font&gt;&lt;/td&gt;        &lt;td width="128"&gt;&lt;font color="#333333"&gt;Transport &lt;/font&gt;&lt;/td&gt;        &lt;td width="104"&gt;&lt;font color="#333333"&gt;Disabled &lt;/font&gt;&lt;/td&gt;        &lt;td width="104"&gt;&lt;font color="#333333"&gt;OleTx &lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td width="184"&gt;&lt;font color="#333333"&gt;NetNamedPipesBinding &lt;/font&gt;&lt;/td&gt;        &lt;td width="112"&gt;&lt;font color="#333333"&gt;Named Pipes &lt;/font&gt;&lt;/td&gt;        &lt;td width="144"&gt;&lt;font color="#333333"&gt;Binary &lt;/font&gt;&lt;/td&gt;        &lt;td width="128"&gt;&lt;font color="#333333"&gt;SOAP 1.2 &lt;/font&gt;&lt;/td&gt;        &lt;td width="128"&gt;&lt;font color="#333333"&gt;Transport &lt;/font&gt;&lt;/td&gt;        &lt;td width="104"&gt;&lt;font color="#333333"&gt;X &lt;/font&gt;&lt;/td&gt;        &lt;td width="104"&gt;&lt;font color="#333333"&gt;OleTx &lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td width="184"&gt;&lt;font color="#333333"&gt;NetMsmqBinding &lt;/font&gt;&lt;/td&gt;        &lt;td width="112"&gt;&lt;font color="#333333"&gt;MSMQ &lt;/font&gt;&lt;/td&gt;        &lt;td width="144"&gt;&lt;font color="#333333"&gt;Binary &lt;/font&gt;&lt;/td&gt;        &lt;td width="128"&gt;&lt;font color="#333333"&gt;SOAP 1.2 &lt;/font&gt;&lt;/td&gt;        &lt;td width="128"&gt;&lt;font color="#333333"&gt;Message &lt;/font&gt;&lt;/td&gt;        &lt;td width="104"&gt;&lt;font color="#333333"&gt;X &lt;/font&gt;&lt;/td&gt;        &lt;td width="104"&gt;&lt;font color="#333333"&gt;X &lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td width="184"&gt;&lt;font color="#333333"&gt;CustomBinding &lt;/font&gt;&lt;/td&gt;        &lt;td width="112"&gt;&lt;font color="#333333"&gt;You decide &lt;/font&gt;&lt;/td&gt;        &lt;td width="144"&gt;&lt;font color="#333333"&gt;You decide &lt;/font&gt;&lt;/td&gt;        &lt;td width="128"&gt;&lt;font color="#333333"&gt;You decide &lt;/font&gt;&lt;/td&gt;        &lt;td width="128"&gt;&lt;font color="#333333"&gt;You decide &lt;/font&gt;&lt;/td&gt;        &lt;td width="104"&gt;&lt;font color="#333333"&gt;You decide &lt;/font&gt;&lt;/td&gt;        &lt;td width="104"&gt;&lt;font color="#333333"&gt;You decide&lt;/font&gt;           &lt;p&gt;&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p align="justify"&gt;You should select the most appropriate binding based on your needs:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;div align="justify"&gt;For example, &lt;font color="#ff9914"&gt;BasicHttpBinding&lt;/font&gt; is designed for interoperability with simple web services that conform to the SOAP 1.1 message version. &lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;Instead the &lt;font color="#ff9914"&gt;WSHttpBinding&lt;/font&gt; is designed for interoperability with more advanced web services that might leverage different WS-* protocols. Both of these bindings use HTTP for the transport and the text message encoding because they are designed for maximum interoperability. &lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;&lt;font color="#ff9914"&gt;NetTcpBinding&lt;/font&gt; and &lt;font color="#ff9914"&gt;NetNamedPipeBinding&lt;/font&gt;, on the other hand, are designed for efficient and performant communication with other WCF applications across machines or on the same machine respectively. &lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;If you need maximum flexibility and you need to use one or multiple custom protocol channels at runtime, you can use the &lt;font color="#ff9914"&gt;CustomBinding&lt;/font&gt; that gives you the possibility to decide which binding elements compose your binding.&lt;/div&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p align="justify"&gt;Bindings have different characteristics in terms of response time and throughput, so the general advice to increase performance is using the NetTcpBindind and NetNamesPipeBinding whenever possible. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;font color="#ff9914"&gt;BizTalkServiceInstance Class&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p align="justify"&gt;Each WCF Receive Location in BizTalk Server is indeed an instance of a WCF Service Class called &lt;a href="http://msdn.microsoft.com/en-us/library/bb727883(BTS.10).aspx"&gt;BizTalkServiceInstance&lt;/a&gt;&lt;font color="#ff9914"&gt;&lt;/font&gt; hosted by a separate instance of a ServiceHost-derived class&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;div align="justify"&gt;the &lt;font color="#ff9914"&gt;BtsServiceHost&lt;/font&gt; for RLs running in an in-process host&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;the &lt;font color="#ff9914"&gt;WebServiceHost&lt;/font&gt; for RLs running in an isolated host&lt;/div&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p align="justify"&gt;When you “enable” a WCF receive location, the adapter initializes and opens the ServiceHost, which dynamically builds the WCF runtime components within the BizTalk service process (BtsNtSvc.exe for in in-process host, w3wp.exe for an isolated host). This includes the channel stack, dispatcher, and the singleton service instance. WCF Receive and Send Ports are message-type agnostic or if you prefer untyped. This design comes in handy when you need to configure a single Receive Port to accept numerous message types or versions that you can normalize (via BizTalk maps or using a custom pipeline component) into a common message type before being posted the BizTalkMsgBoxDb. However, this design also implies that the WCF adapters will need to build on generic service contracts in order to remain message-type agnostic within the WCF implementation.&lt;/p&gt;  &lt;p align="justify"&gt;WCF Receive Locations have the responsibility to receive the incoming message bytes, perform any necessary SOAP and WS-* processing, and publish the message (or some part of it) to the message box. The WCF Adapters create a separate ServiceHost and singleton service object of this class for each receive location to handle client requests for the lifetime of the BizTalk Host instance running WCF receive locations. The service object uses multiple threads to process messages concurrently unless the WCF-NetMsmq receive locations are used with the Ordered processing property being selected.. As shown in the picture below, the class is decorated with the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.servicebehaviorattribute.aspx"&gt;ServiceBehavior&lt;/a&gt; attribute:&lt;/p&gt;  &lt;p align="justify"&gt;&amp;#160;&lt;/p&gt;  &lt;table border="1" cellspacing="0" cellpadding="5" width="800" bgcolor="#ffffff"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="800"&gt;         &lt;pre class="csharpcode"&gt;[&lt;font color="#2b91af"&gt;ServiceBehavior&lt;/font&gt;(InstanceContextMode = &lt;font color="#2b91af"&gt;InstanceContextMode&lt;/font&gt;.Single, ConcurrencyMode = &lt;font color="#2b91af"&gt;ConcurrencyMode&lt;/font&gt;.Multiple)]
&lt;span class="kwrd"&gt;internal&lt;/span&gt; &lt;span class="kwrd"&gt;sealed&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; &lt;font color="#2b91af"&gt;BizTalkServiceInstance&lt;/font&gt; : ITwoWayAsync, 
                                               ITwoWayAsyncVoid, 
                                               IOneWayAsync, 
                                               IOneWayAsyncTxn, 
                                               ITwoWayAsyncVoidTxn
{
    ...
}&lt;/pre&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;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p align="justify"&gt;In particular, you can note that:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;div align="justify"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.servicebehaviorattribute.instancecontextmode.aspx"&gt;InstanceContextMode&lt;/a&gt; = InstanceContextMode.Single&lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.servicebehaviorattribute.concurrencymode.aspx"&gt;ConcurrencyMode&lt;/a&gt; = ConcurrencyMode.Multiple&lt;/div&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p align="justify"&gt;Hence, all incoming messages to a WCF Receive Location are received and processed by a single well-known instance of the BizTalkServiceInstance class. This allows to avoid service activation/deactivation costs and improve performance/scalability.&lt;/p&gt;

&lt;p align="justify"&gt;The BizTalkServiceInstance class implements multiple untyped, generic service contracts.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;div align="justify"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/bb727707(BTS.10).aspx"&gt;IOneWayAsync&lt;/a&gt;&lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/bb743620(BTS.10).aspx"&gt;IOneWayAsyncTxn&lt;/a&gt;&lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/bb727810(BTS.10).aspx"&gt;ITwoWayAsync&lt;/a&gt;&lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/bb743686(BTS.10).aspx"&gt;ITwoWayAsyncVoid&lt;/a&gt;&lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/bb743549(BTS.10).aspx"&gt;ITwoWayAsyncVoidTxn&lt;/a&gt;&lt;/div&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p align="justify"&gt;Each contract was designed for a different scope (as suggested by their name): &lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;div align="justify"&gt;OneWay vs TwoWay Message Exchange&amp;#160; Pattern&lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;Transactional vs Non-Transactional Communication&lt;/div&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;table border="1" cellspacing="0" cellpadding="5" width="800" bgcolor="#ffffff"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="800"&gt;
        &lt;pre class="csharpcode"&gt;[&lt;font color="#2b91af"&gt;ServiceContract&lt;/font&gt;(Namespace = &lt;span class="str"&gt;&amp;quot;http://www.microsoft.com/biztalk/2006/r2/wcf-adapter&amp;quot;&lt;/span&gt;)]
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;interface&lt;/span&gt; IOneWayAsync
{
    &lt;span class="rem"&gt;// Methods&lt;/span&gt;
    [&lt;font color="#2b91af"&gt;OperationContract&lt;/font&gt;(AsyncPattern = &lt;span class="kwrd"&gt;true&lt;/span&gt;, IsOneWay = &lt;span class="kwrd"&gt;true&lt;/span&gt;, Action = &lt;span class="str"&gt;&amp;quot;*&amp;quot;&lt;/span&gt;)]
    &lt;font color="#2b91af"&gt;IAsyncResult&lt;/font&gt; BeginOneWayMethod(&lt;font color="#2b91af"&gt;Message&lt;/font&gt; message, &lt;font color="#2b91af"&gt;AsyncCallback&lt;/font&gt; callback, &lt;span class="kwrd"&gt;object&lt;/span&gt; state);
    [&lt;font color="#2b91af"&gt;OperationContract&lt;/font&gt;(IsOneWay = &lt;span class="kwrd"&gt;true&lt;/span&gt;, Action = &lt;span class="str"&gt;&amp;quot;BizTalkSubmit&amp;quot;&lt;/span&gt;)]
    &lt;span class="kwrd"&gt;void&lt;/span&gt; BizTalkSubmit(&lt;font color="#2b91af"&gt;Message&lt;/font&gt; message);
    &lt;span class="kwrd"&gt;void&lt;/span&gt; EndOneWayMethod(&lt;font color="#2b91af"&gt;IAsyncResult&lt;/font&gt; result);
}

[&lt;font color="#2b91af"&gt;ServiceContract&lt;/font&gt;(Namespace = &lt;span class="str"&gt;&amp;quot;http://www.microsoft.com/biztalk/2006/r2/wcf-adapter&amp;quot;&lt;/span&gt;)]
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;interface&lt;/span&gt; IOneWayAsyncTxn
{
    &lt;span class="rem"&gt;// Methods&lt;/span&gt;
    [&lt;font color="#2b91af"&gt;OperationContract&lt;/font&gt;(AsyncPattern = &lt;span class="kwrd"&gt;true&lt;/span&gt;, IsOneWay = &lt;span class="kwrd"&gt;true&lt;/span&gt;, Action = &lt;span class="str"&gt;&amp;quot;*&amp;quot;&lt;/span&gt;)]
    &lt;font color="#2b91af"&gt;IAsyncResult&lt;/font&gt; BeginOneWayMethod(&lt;font color="#2b91af"&gt;Message&lt;/font&gt; message, &lt;font color="#2b91af"&gt;AsyncCallback&lt;/font&gt; callback, &lt;span class="kwrd"&gt;object&lt;/span&gt; state);
    [&lt;font color="#2b91af"&gt;OperationContract&lt;/font&gt;(IsOneWay = &lt;span class="kwrd"&gt;true&lt;/span&gt;, Action = &lt;span class="str"&gt;&amp;quot;BizTalkSubmit&amp;quot;&lt;/span&gt;)]
    &lt;span class="kwrd"&gt;void&lt;/span&gt; BizTalkSubmit(&lt;font color="#2b91af"&gt;Message&lt;/font&gt; message);
    &lt;span class="kwrd"&gt;void&lt;/span&gt; EndOneWayMethod(&lt;font color="#2b91af"&gt;IAsyncResult&lt;/font&gt; result);
}

[&lt;font color="#2b91af"&gt;ServiceContract&lt;/font&gt;(Namespace = &lt;span class="str"&gt;&amp;quot;http://www.microsoft.com/biztalk/2006/r2/wcf-adapter&amp;quot;&lt;/span&gt;)]
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;interface&lt;/span&gt; ITwoWayAsync
{
    &lt;span class="rem"&gt;// Methods&lt;/span&gt;
    [&lt;font color="#2b91af"&gt;OperationContract&lt;/font&gt;(AsyncPattern = &lt;span class="kwrd"&gt;true&lt;/span&gt;, IsOneWay = &lt;span class="kwrd"&gt;false&lt;/span&gt;, Action = &lt;span class="str"&gt;&amp;quot;*&amp;quot;&lt;/span&gt;, ReplyAction = &lt;span class="str"&gt;&amp;quot;*&amp;quot;&lt;/span&gt;)]
    &lt;font color="#2b91af"&gt;IAsyncResult&lt;/font&gt; BeginTwoWayMethod(&lt;font color="#2b91af"&gt;Message&lt;/font&gt; message, &lt;font color="#2b91af"&gt;AsyncCallback&lt;/font&gt; callback, &lt;span class="kwrd"&gt;object&lt;/span&gt; state);
    [&lt;font color="#2b91af"&gt;OperationContract&lt;/font&gt;(IsOneWay = &lt;span class="kwrd"&gt;false&lt;/span&gt;, Action = &lt;span class="str"&gt;&amp;quot;BizTalkSubmit&amp;quot;&lt;/span&gt;)]
    Message BizTalkSubmit(&lt;font color="#2b91af"&gt;Message&lt;/font&gt; message);
    Message EndTwoWayMethod(&lt;font color="#2b91af"&gt;IAsyncResult&lt;/font&gt; result);
}

[&lt;font color="#2b91af"&gt;ServiceContract&lt;/font&gt;(Namespace = &lt;span class="str"&gt;&amp;quot;http://www.microsoft.com/biztalk/2006/r2/wcf-adapter&amp;quot;&lt;/span&gt;)]
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;interface&lt;/span&gt; ITwoWayAsyncVoid
{
    &lt;span class="rem"&gt;// Methods&lt;/span&gt;
    [&lt;font color="#2b91af"&gt;OperationContract&lt;/font&gt;(AsyncPattern = &lt;span class="kwrd"&gt;true&lt;/span&gt;, IsOneWay = &lt;span class="kwrd"&gt;false&lt;/span&gt;, Action = &lt;span class="str"&gt;&amp;quot;*&amp;quot;&lt;/span&gt;, ReplyAction = &lt;span class="str"&gt;&amp;quot;*&amp;quot;&lt;/span&gt;)]
    &lt;font color="#2b91af"&gt;IAsyncResult&lt;/font&gt; BeginTwoWayMethod(&lt;font color="#2b91af"&gt;Message&lt;/font&gt; message, &lt;font color="#2b91af"&gt;AsyncCallback&lt;/font&gt; callback, &lt;span class="kwrd"&gt;object&lt;/span&gt; state);
    [&lt;font color="#2b91af"&gt;OperationContract&lt;/font&gt;(IsOneWay = &lt;span class="kwrd"&gt;false&lt;/span&gt;, Action = &lt;span class="str"&gt;&amp;quot;BizTalkSubmit&amp;quot;&lt;/span&gt;)]
    &lt;span class="kwrd"&gt;void&lt;/span&gt; BizTalkSubmit(&lt;font color="#2b91af"&gt;Message&lt;/font&gt; message);
    &lt;span class="kwrd"&gt;void&lt;/span&gt; EndTwoWayMethod(&lt;font color="#2b91af"&gt;IAsyncResult&lt;/font&gt; result);
}

[&lt;font color="#2b91af"&gt;ServiceContract&lt;/font&gt;(Namespace = &lt;span class="str"&gt;&amp;quot;http://www.microsoft.com/biztalk/2006/r2/wcf-adapter&amp;quot;&lt;/span&gt;)]
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;interface&lt;/span&gt; ITwoWayAsyncVoidTxn
{
    &lt;span class="rem"&gt;// Methods&lt;/span&gt;
    [&lt;font color="#2b91af"&gt;TransactionFlow&lt;/font&gt;(&lt;font color="#2b91af"&gt;TransactionFlowOption&lt;/font&gt;.Mandatory)]&lt;br /&gt;    [&lt;font color="#2b91af"&gt;OperationContract&lt;/font&gt;(AsyncPattern = &lt;span class="kwrd"&gt;true&lt;/span&gt;, IsOneWay = &lt;span class="kwrd"&gt;false&lt;/span&gt;, Action = &lt;span class="str"&gt;&amp;quot;*&amp;quot;&lt;/span&gt;, ReplyAction = &lt;span class="str"&gt;&amp;quot;*&amp;quot;&lt;/span&gt;)]
    &lt;font color="#2b91af"&gt;IAsyncResult&lt;/font&gt; BeginTwoWayMethod(&lt;font color="#2b91af"&gt;Message&lt;/font&gt; message, &lt;font color="#2b91af"&gt;AsyncCallback&lt;/font&gt; callback, &lt;span class="kwrd"&gt;object&lt;/span&gt; state);
    [&lt;font color="#2b91af"&gt;TransactionFlow&lt;/font&gt;(&lt;font color="#2b91af"&gt;TransactionFlowOption&lt;/font&gt;.Mandatory), OperationContract(IsOneWay = &lt;span class="kwrd"&gt;false&lt;/span&gt;, Action = &lt;span class="str"&gt;&amp;quot;BizTalkSubmit&amp;quot;&lt;/span&gt;)]
    &lt;span class="kwrd"&gt;void&lt;/span&gt; BizTalkSubmit(&lt;font color="#2b91af"&gt;Message&lt;/font&gt; message);
    &lt;span class="kwrd"&gt;void&lt;/span&gt; EndTwoWayMethod(&lt;font color="#2b91af"&gt;IAsyncResult&lt;/font&gt; result);
}&lt;/pre&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;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p align="justify"&gt;All the methods exposed by these service contracts are generic, asynchronous and untyped. In fact, as shown in the picture above, each of this method is decorated by the &lt;font color="#ff9914"&gt;OperationContract&lt;/font&gt; attribute and in particular:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;div align="justify"&gt;&lt;font color="#ff9914"&gt;AsyncPattern&lt;/font&gt; = True&amp;#160; indicates that an operation is implemented asynchronously using a Begin&amp;lt;methodName&amp;gt; and End&amp;lt;methodName&amp;gt; method pair in a service contractAction = “*” means that the method accepts a message with any Action.&lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;&lt;font color="#ff9914"&gt;ReplyAction&lt;/font&gt; = “*” means that the method can return a message with any Action.&lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;Every method accepts as parameter or returns a generic WCF Message.&lt;/div&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p align="justify"&gt;As a consequence, each WCF Receive Location can accept multiple&amp;#160; message types and versions that can be normalized into a canonical format using a different map before being published to the MessageBox. 
  &lt;br /&gt;Also Send Ports are message-type agnostic.&lt;/p&gt;

&lt;p align="justify"&gt;&lt;strong&gt;&lt;font color="#ff9914"&gt;One-Way WCF Receive Locations&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p align="justify"&gt;When you define a One-Way WCF Receive Location that uses the NetMsmqBinding, the underlying WCF service will expose an endpoint which uses the IOneWayAsync service interface. If instead the One-Way WCF Receive Location is not configured to use NetMsmqBinding, the underlying WCF service will expose an endpoint using the ITwoWayAsyncVoid contract interface that returns an acknowledgment message. Otherwise, when you define a two-way WCF receive location, the underlying WCF service will expose an endpoint using the ITwoWayASync service interface.&lt;/p&gt;

&lt;p align="justify"&gt;As you can note in the picture above, the IOneWayAsync service contract has a single logical operation named OneWayMethod that matches all incoming messages (Action=”*”). It’s implemented with the WCF asynchronous programming model that ties two methods – BeginOneWayMethod and EndOneWayMethod – together via AsyncPattern=true. 
  &lt;br /&gt;ITwoWayAsyncVoid is similar in design except that it also returns a WCF Message object (notice the addition of ReplyAction=”*”) and the operation is not marked as one-way. The only difference with ITwoWayAsync is that it also returns a Message object in order to properly model two-way ports.&amp;#160; The following picture depicts what happens when a message is received and processed through a One-way WCF Receive location.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;The Raw Message Data are sent over the wire. &lt;/li&gt;

  &lt;li&gt;The Transport Channel receives and decodes the incoming stream of bytes and creates a WCF Message that is processed through the Channel Stack. &lt;/li&gt;

  &lt;li&gt;The WCF message is passed on to the Dispatcher &lt;/li&gt;

  &lt;li&gt;The WCF message is passed on to the BizTalkServiceInstance. &lt;/li&gt;

  &lt;li&gt;Based on the RL configuration, the entire SOAP Envelope, the Body of the SOAP message or a specific Xml Element is used as content of the BizTalk message. &lt;/li&gt;

  &lt;li&gt;The BizTalk message is processed through the pipeline. &lt;/li&gt;

  &lt;li&gt;A Map is eventually applied. &lt;/li&gt;

  &lt;li&gt;The BizTalk message is published to the MessageBox. &lt;/li&gt;
&lt;/ol&gt;

&lt;p align="justify"&gt;&lt;a href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/BizTalkServerWCFAdapters_929A/WCF_OneWay_2.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="WCF_OneWay" border="0" alt="WCF_OneWay" src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/BizTalkServerWCFAdapters_929A/WCF_OneWay_thumb.jpg" width="398" height="965" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p align="justify"&gt;&lt;strong&gt;&lt;font color="#ff9914"&gt;WCF Adapters&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The WCF Adapters provided by BizTalk correspond 1:1 to the most commonly used WCF bindings.&lt;/p&gt;

&lt;table border="1" cellspacing="0" cellpadding="5" bgcolor="#ffffff"&gt;&lt;tbody&gt;
    &lt;tr bgcolor="#333333"&gt;
      &lt;td width="296"&gt;&lt;b&gt;Adapter Name &lt;/b&gt;&lt;/td&gt;

      &lt;td width="296"&gt;&lt;b&gt;WCF Binding Name &lt;/b&gt;&lt;/td&gt;

      &lt;td width="296"&gt;&lt;b&gt;When to use? &lt;/b&gt;&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
      &lt;td width="296"&gt;&lt;font color="#333333"&gt;WCF-BasicHttp &lt;/font&gt;&lt;/td&gt;

      &lt;td width="296"&gt;&lt;font color="#333333"&gt;BasicHttpBinding &lt;/font&gt;&lt;/td&gt;

      &lt;td width="296"&gt;&lt;font color="#333333"&gt;When you need interoperability with WS-I Basic Profile 1.1 services, such as those created with ASP.NET Web services (ASMX) or other first-generation service frameworks &lt;/font&gt;&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
      &lt;td width="296"&gt;&lt;font color="#333333"&gt;WCF-WSHttp &lt;/font&gt;&lt;/td&gt;

      &lt;td width="296"&gt;&lt;font color="#333333"&gt;WSHttpBinding &lt;/font&gt;&lt;/td&gt;

      &lt;td width="296"&gt;&lt;font color="#333333"&gt;When you need interoperability with more advanced services that leverage WS-* protocols, such as those created with WCF or other modern service frameworks &lt;/font&gt;&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
      &lt;td width="296"&gt;&lt;font color="#333333"&gt;WCF-NetTcp &lt;/font&gt;&lt;/td&gt;

      &lt;td width="296"&gt;&lt;font color="#333333"&gt;NetTcpBinding &lt;/font&gt;&lt;/td&gt;

      &lt;td width="296"&gt;&lt;font color="#333333"&gt;When you need efficient inter-machine communication with other WCF applications &lt;/font&gt;&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
      &lt;td width="296"&gt;&lt;font color="#333333"&gt;WCF-NetNamedPipe &lt;/font&gt;&lt;/td&gt;

      &lt;td width="296"&gt;&lt;font color="#333333"&gt;NetNamedPipeBinding &lt;/font&gt;&lt;/td&gt;

      &lt;td width="296"&gt;&lt;font color="#333333"&gt;When you need efficient intra-machine communication with other WCF applications &lt;/font&gt;&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
      &lt;td width="296"&gt;&lt;font color="#333333"&gt;WCF-NetMsmq &lt;/font&gt;&lt;/td&gt;

      &lt;td width="296"&gt;&lt;font color="#333333"&gt;NetMsmqBinding &lt;/font&gt;&lt;/td&gt;

      &lt;td width="296"&gt;&lt;font color="#333333"&gt;When you need durable, asynchronous communication with other WCF applications (using MSMQ as the underlying transport) &lt;/font&gt;&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
      &lt;td width="296"&gt;&lt;font color="#333333"&gt;WCF-Custom &lt;/font&gt;&lt;/td&gt;

      &lt;td width="296"&gt;&lt;font color="#333333"&gt;Any &lt;/font&gt;&lt;/td&gt;

      &lt;td width="296"&gt;&lt;font color="#333333"&gt;When you need to define a custom binding configuration for an “in-process” host &lt;/font&gt;&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
      &lt;td width="296"&gt;&lt;font color="#333333"&gt;WCF-CustomIsolated &lt;/font&gt;&lt;/td&gt;

      &lt;td width="296"&gt;&lt;font color="#333333"&gt;Any &lt;/font&gt;&lt;/td&gt;

      &lt;td width="296"&gt;&lt;font color="#333333"&gt;When you need to define a custom binding configuration for an “isolated” host – this is only a receive adapter, not used on send ports&lt;/font&gt; &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;&lt;strong&gt;&lt;font color="#ff9914"&gt;WCF-Custom-WCF-CustomIsolated Adapters&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p align="justify"&gt;The WCF-Custom and WCF-CustomIsolated adapters offer you complete control over the channel stack and behaviors configuration, and as a consequence, they are the only WCF adapters you really need. Compared with the other WCF Adapters, they are the only ones to provide the possibility to:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;div align="justify"&gt;Implement and exploit extensibility points.&lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;Have full access to properties exposed by bindings/behaviors.&lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;Enable the use of the bamInterceptor endpoint behavior.&lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;Export/Import the binding configuration.&lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;Disable a receive location on failure.&lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;Run an http-based RL within an in-process host.&lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;Use bindings (e.g. wsDualHttpBinding) for which a WCF Adapter does not exist.&lt;/div&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p align="justify"&gt;WCF allows developers to modify and extend its standard runtime behavior with several extensibility points, some of which are not supported by BizTalk Server: for example you cannot customize the BizTalkServiceInstance class, create you own ServiceHost or create a custom ContractBehavior. BizTalk Server supports the following extensibility points:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;div align="justify"&gt;Custom Behaviors&lt;/div&gt;
  &lt;/li&gt;

  &lt;ul&gt;
    &lt;li&gt;
      &lt;div align="justify"&gt;Service Behaviors: they enable the customization of the entire service runtime including the ServiceHost.&lt;/div&gt;
    &lt;/li&gt;

    &lt;li&gt;
      &lt;div align="justify"&gt;Endpoint Behaviors: they enable the customization of service endpoints and their associated EndpointDispatcher. The most common technique is creating an endpoint behavior to add a Message Inspector to the collection of Message Inspectors used at run time by a proxy/dispatcher. This allows to intercept an in-flight incoming/outgoing WCF message before this latter is passed/transmitted to the intended operation/target service, inspect and eventually change its content (headers or body).&lt;/div&gt;
    &lt;/li&gt;
  &lt;/ul&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;Custom Binding Elements, Channels Binding Elements, Channels, Channel Factories, Binding Element Extension, etc. This technique is more complex, because in order to register and execute at runtime a custom channel within the channel stack used by a WCF Receive Location or Send Port, it’s necessary to create and properly register multiple components:&lt;/div&gt;
  &lt;/li&gt;

  &lt;ul&gt;
    &lt;li&gt;
      &lt;div align="justify"&gt;Custom BindingElementExtensionElement.&lt;/div&gt;
    &lt;/li&gt;

    &lt;li&gt;
      &lt;div align="justify"&gt;Custom BindingElement.&lt;/div&gt;
    &lt;/li&gt;

    &lt;li&gt;
      &lt;div align="justify"&gt;Custom ChannelFactory&lt;/div&gt;
    &lt;/li&gt;

    &lt;li&gt;
      &lt;div align="justify"&gt;Custom Channel.&lt;/div&gt;
    &lt;/li&gt;
  &lt;/ul&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;Custom Bindings: the &lt;a href="http://www.microsoft.com/downloads/details.aspx?familyid=47AB6F21-0D8B-4C90-A8B9-E8647281B164&amp;amp;displaylang=en"&gt;WCF LOB Adapter SDK&lt;/a&gt; allows developers to create&amp;#160; new bindings to use with WCF-Custom and WCF-CustomIsolated Adapters. For example, the &lt;a href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;amp;FamilyID=ceb0bb34-f9d2-4d14-8bbe-0311d227b091"&gt;WCF based SQL Adapter&lt;/a&gt; (WCF-SQL) is based on a new binding called &lt;font color="#ff9914"&gt;sqlBinding&lt;/font&gt; that is properly registered in the machine.config when installing the Adapter.&lt;/div&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p align="justify"&gt;In my previous post&amp;#160; called &lt;a href="http://blogs.msdn.com/paolos/archive/2009/05/22/how-to-throw-typed-fault-exceptions-from-orchestrations-published-as-wcf-services.aspx"&gt;How to Throw Typed Fault Exceptions from Orchestrations Published as WCF Services&lt;/a&gt; I created 2 different Endpoint Behaviors to customize the default runtime behavior of the WCF-Custom/WCF-CustomIsolated Adapter. In my next post I will show how to create a custom channel to debatch (on a WCF Send Port) an inbound message containing a collection of operations and make multiple calls to the underlying WCF service, one for each operation.&lt;/p&gt;

&lt;p align="justify"&gt;&lt;strong&gt;&lt;font color="#ff9914"&gt;Conclusion&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p align="justify"&gt;I strongly suggest you to read the following whitepapers to have a better insight in WCF Adapters and their extensibility points.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The &lt;a href="http://www.microsoft.com/downloads/details.aspx?familyid=a976dc7d-2296-4f88-be4d-0d314fca9e59&amp;amp;displaylang=en&amp;amp;tm"&gt;Using the Windows Communication Foundation (WCF) Adapters in BizTalk Server&lt;/a&gt; whitepaper describes the use of the WCF adapters in BizTalk Server.&lt;/li&gt;

  &lt;li&gt;The &lt;a href="http://www.microsoft.com/downloads/details.aspx?familyid=70BADD79-CE7E-4CCB-BE5C-3FF74CA3A8C4&amp;amp;displaylang=en"&gt;Consuming and Hosting WCF Services with Custom Bindings in BizTalk Server&lt;/a&gt; whitepaper provides an in-depth explanation on how to use the BizTalk Server WCF adapters for hosting and consuming Windows Communication Foundation (WCF) services with custom bindings. The paper compiles a series of lessons learned based on a real-world implementation of integrating a custom WCF binding with the WCF adapters. Furthermore, key industrial infrastructure concerns such as transaction management and security are discussed in the context of integrating custom WCF bindings and behaviors with the BizTalk Messaging Engine. Also emphasized are a few pragmatic paradigms such as the use of dynamic ports in consuming WCF services. Finally, some key integration challenges are discussed to streamline the correct use of the adapters for solving complex business problems.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Moreover, I recommend to download and review the following WCF Adapters samples on MSDN:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href="http://go.microsoft.com/fwlink/?LinkId=146111"&gt;Using Custom Behaviors with the BizTalk WCF Adapters&lt;/a&gt;: Extend WCF services through custom behaviors and the WCF adapters. &lt;/li&gt;

  &lt;li&gt;&lt;a href="http://go.microsoft.com/fwlink/?LinkId=146112"&gt;Using a Custom Behavior to Secure a Receive Location with the WCF Adapters&lt;/a&gt;: Secure access to a BizTalk receive location by using a custom authorization behavior with the WCF adapters. &lt;/li&gt;

  &lt;li&gt;&lt;a href="http://go.microsoft.com/fwlink/?LinkId=146113"&gt;Using a Pipeline Intermediary with the WCF Adapters&lt;/a&gt;: Use an intermediary BizTalk Server custom pipeline to dynamically channel an incoming WCF client call to the correct version of a WCF service. &lt;/li&gt;

  &lt;li&gt;&lt;a href="http://go.microsoft.com/fwlink/?LinkId=146114"&gt;Using Transactions with Message Interception and the WCF Adapters&lt;/a&gt;: Custom message interception during BizTalk Server’s binding processing of an outgoing WCF message. &lt;/li&gt;

  &lt;li&gt;&lt;a href="http://go.microsoft.com/fwlink/?LinkId=146115"&gt;Using BizTalk Server Messaging with the WCF Adapters&lt;/a&gt;: Use BizTalk Server messaging and the WCF adapters to send WCF messages from a WCF client application to a WCF service. &lt;/li&gt;

  &lt;li&gt;&lt;a href="http://go.microsoft.com/fwlink/?LinkId=146116"&gt;Using Dynamic Send Ports with the WCF Adapters&lt;/a&gt;: Configure dynamic send ports by using WCF adapter context properties for the WCF-NetTcp transport and for the WCF-Custom transport with the WCF-NetTcp binding. &lt;/li&gt;

  &lt;li&gt;&lt;a href="http://go.microsoft.com/fwlink/?LinkId=146117"&gt;Handling Exceptions in Orchestrations with the WCF Adapters&lt;/a&gt;: Handle typed fault exceptions in orchestrations. &lt;/li&gt;

  &lt;li&gt;&lt;a href="http://go.microsoft.com/fwlink/?LinkId=146118"&gt;Using Custom SOAP Headers with the WCF Adapters&lt;/a&gt;: Access custom SOAP headers in inbound WCF messages, and add custom SOAP headers to outbound WCF messages. &lt;/li&gt;

  &lt;li&gt;&lt;a href="http://go.microsoft.com/fwlink/?LinkId=146119"&gt;Programmatically Submitting a WCF Message Using the WCF Adapters&lt;/a&gt;: Submit a WCF message to an orchestration exposed as a WCF service. The WCF adapter uses an XPath command to extract specific SOAP property elements from the incoming message. &lt;/li&gt;

  &lt;li&gt;&lt;a href="http://go.microsoft.com/fwlink/?LinkId=146120"&gt;Using the Messages Tab with the WCF Adapters&lt;/a&gt;: Use the Messages tab in the Transport Properties dialog box of a WCF adapter to control which part of an incoming WCF message is mapped to the body of the resulting BizTalk message. &lt;/li&gt;

  &lt;li&gt;&lt;a href="http://go.microsoft.com/fwlink/?LinkId=146121"&gt;WCF Adapter Walkthroughs&lt;/a&gt;: Get sample code for the WCF adapter walkthroughs outlined in the &lt;a href="http://go.microsoft.com/fwlink/?LinkId=93282"&gt;WCF Adapter Walkthroughs&lt;/a&gt; topic of the MSDN Library.&lt;/li&gt;
&lt;/ul&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9923499" width="1" height="1"&gt;</description></item><item><title>Using Visual Studio 2005/2008 To Generate Load Against a Two-Way Request-Response WCF Receive Location: ERRATA CORRIGE</title><link>http://blogs.msdn.com/paolos/archive/2009/09/25/using-visual-studio-2005-2008-to-generate-load-against-a-two-way-request-response-wcf-receive-location-errata-corrige.aspx</link><pubDate>Sat, 26 Sep 2009 00:06:03 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9899708</guid><dc:creator>leprino</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/paolos/comments/9899708.aspx</comments><wfw:commentRss>http://blogs.msdn.com/paolos/commentrss.aspx?PostID=9899708</wfw:commentRss><wfw:comment>http://blogs.msdn.com/paolos/rsscomments.aspx?PostID=9899708</wfw:comment><description>&lt;p align="justify"&gt;Today, while I was driving south to Tuscany, I realized that my &lt;a href="http://blogs.msdn.com/paolos/archive/2009/09/24/using-visual-studio-2005-2008-to-generate-load-against-a-two-way-request-response-wcf-receive-location.aspx"&gt;post&lt;/a&gt; had the following defects:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;div align="justify"&gt;I forgot to include the text of the configuration file used by the project;&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;The code of the HandleException and CloseObjects methods had some imperfections, so I fixed it;&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;One of you (Pablo Alarcon Garcia, thanks mate!) dropped me an email to inform me that I committed a very common error in C#: I used &amp;quot;throw ex;&amp;quot; command rather than &amp;quot;throw;&amp;quot; to re-throw an exception within every catch block of the InvokeTwoWayWCFReceiveLocation method. Indeed, this is not really an error as the value of the exception properties (Message, InnerException, etc.) is preserved when using a “throw ex;” command. Conversely, the value of the StackTrace property is reinitialized to refer the “throw ex;” command within the catch block instead of the line of code that originally raised the exception. If you want to re-throw the exception currently handled by a catch block and preserve the value of its StackTrace property, use the throw statement without arguments: &amp;quot;throw ex;&amp;quot;.&amp;#160; See the following &lt;a href="http://www.tkachenko.com/blog/archives/000352.html"&gt;link&lt;/a&gt; for more information on this topic.&lt;/div&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p align="justify"&gt;So I corrected my post and uploaded the new code &lt;a href="http://cid-09dba4a06b360a65.skydrive.live.com/self.aspx/Pubblica/WCFLoadTest.zip?sa=779508424"&gt;here&lt;/a&gt;. Sorry folks. :-)&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9899708" width="1" height="1"&gt;</description></item><item><title>Using Visual Studio 2005/2008 To Generate Load Against a Two-Way Request-Response WCF Receive Location</title><link>http://blogs.msdn.com/paolos/archive/2009/09/24/using-visual-studio-2005-2008-to-generate-load-against-a-two-way-request-response-wcf-receive-location.aspx</link><pubDate>Thu, 24 Sep 2009 08:26:09 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9898855</guid><dc:creator>leprino</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/paolos/comments/9898855.aspx</comments><wfw:commentRss>http://blogs.msdn.com/paolos/commentrss.aspx?PostID=9898855</wfw:commentRss><wfw:comment>http://blogs.msdn.com/paolos/rsscomments.aspx?PostID=9898855</wfw:comment><description>&lt;p&gt;&lt;strong&gt;&lt;font color="#ff9914"&gt;Introduction&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p align="justify"&gt;We all know that testing is very important for every kind of solution. However, testing and in particular performance testing is often neglected for time or budget reasons. One of the things that I have found when working with customers is that the amount of performance testing done on a project tends to fall into a couple of categories. The first and in my opinion the worst is when no performance testing is done at all. I would call this a write once, go live and cross your fingers approach. The next type is when load/stress testing is performed right at the end of the project lifecycle, typically a few weeks before the go live date. If the application is not able to meet the expected performance goals in terms of scalability and latency, there’s a serious risk that architects and developers will have to spend a considerable amount of time to redesign, rewrite and test large portions of the solution.&lt;/p&gt;  &lt;p align="justify"&gt;Sometimes performance testing is done using a rig that does not accurately reflect the production environment, while in other cases I have seen people using different adapters that do not match those used in the production environment. All these bad practices and factors expose the project to the risk of delays and failure.&lt;/p&gt;  &lt;p align="justify"&gt;BizTalk Server is used in mission and business critical scenarios where it is not just part of the business, it is actually running the entire business. Overlooking performing testing increases the risk of failure which can cause not just technical problems but political problems as well. &lt;/p&gt;  &lt;p align="justify"&gt;The way to minimize the risk of a BizTalk project (and of any software project in general) is to adopt a strong and consistent testing strategy throughout the development phase and before deploying the final solution into production. For this reason, the BizTalk Customer Advisory Team adopts a consistent and reusable methodology when running performance labs with customers. This process is fully documented in the &lt;a href="http://msdn.microsoft.com/en-us/library/ee377045(BTS.10).aspx"&gt;BizTalk Server Performance Testing Methodology&lt;/a&gt; of the &lt;a href="http://msdn.microsoft.com/en-us/library/ee377064(BTS.10).aspx"&gt;Microsoft BizTalk Server 2009 Performance Optimization Guide&lt;/a&gt;. &lt;/p&gt;  &lt;p align="justify"&gt;The best approach is to leverage a test framework like &lt;a href="http://www.codeplex.com/bizunit"&gt;BizUnit&lt;/a&gt; to automate test runs and possibly schedule their execution over night. Another key factor is to individuate the right tool to generate load against the application. To this purpose you can use the &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=c8af583f-7044-48db-b7b9-969072df1689&amp;amp;DisplayLang=en"&gt;BizTalk LoadGen 2007&lt;/a&gt; as I explained in my &lt;a href="http://blogs.msdn.com/paolos/archive/2009/09/21/4-different-ways-to-process-an-xlangmessage-within-an-helper-component-invoked-by-an-orchestration-part-2.aspx"&gt;previous article&lt;/a&gt;. The LoadGen tool offers the following important features and benefits to provide a simple, generic, reliable, and consistent tool for generating message transmission loads. By default, LoadGen supports several transport protocols:&lt;/p&gt;  &lt;table border="1" cellspacing="0" cellpadding="5" bgcolor="#ffffff"&gt;&lt;tbody&gt;     &lt;tr bgcolor="#333333"&gt;       &lt;td width="189"&gt;Transport component&lt;/td&gt;        &lt;td width="745"&gt;Description&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td width="189"&gt;&lt;font color="#000000"&gt;File transport&lt;/font&gt;&lt;/td&gt;        &lt;td width="745"&gt;&lt;font color="#000000"&gt;The File transport creates files including message data in the destination folder.&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td width="189"&gt;&lt;font color="#000000"&gt;HTTP transport&lt;/font&gt;&lt;/td&gt;        &lt;td width="745"&gt;&lt;font color="#000000"&gt;The HTTP transport sends messages with the POST method to the destination location that the BizTalk HTTP receive adapter hosts.&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td width="189"&gt;&lt;font color="#000000"&gt;MQSeries transport&lt;/font&gt;&lt;/td&gt;        &lt;td width="745"&gt;&lt;font color="#000000"&gt;The MQSeries transport sends messages to the target MQSeries queue.&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td width="189"&gt;&lt;font color="#000000"&gt;MSMQLarge transport&lt;/font&gt;&lt;/td&gt;        &lt;td width="745"&gt;&lt;font color="#000000"&gt;The MSMQLarge transport sends messages to the BizTalk MSMQT receive locations. Native message queuing cannot process a message with a body larger than 4 megabytes (MB).&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td width="189"&gt;&lt;font color="#000000"&gt;MSMQ transport&lt;/font&gt;&lt;/td&gt;        &lt;td width="745"&gt;&lt;font color="#000000"&gt;The MSMQ transport sends messages smaller than 4 megabytes (MB) to the target MSMQ queue.&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td width="189"&gt;&lt;font color="#000000"&gt;SOAP transport&lt;/font&gt;&lt;/td&gt;        &lt;td width="745"&gt;&lt;font color="#000000"&gt;The SOAP transport sends messages with the POST method to the target Web service.&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td width="189"&gt;&lt;font color="#000000"&gt;WSE transport&lt;/font&gt;&lt;/td&gt;        &lt;td width="745"&gt;&lt;font color="#000000"&gt;The WSE transport sends messages to the target Web service hosted by Web Services Enhancements (WSE) 2.0.&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td width="189"&gt;&lt;font color="#000000"&gt;WSS transport&lt;/font&gt;&lt;/td&gt;        &lt;td width="745"&gt;&lt;font color="#000000"&gt;The WSS transport sends messages with the PUT method to the target Windows SharePoint Services site.&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td width="189"&gt;&lt;font color="#000000"&gt;WCF transport&lt;/font&gt;&lt;/td&gt;        &lt;td width="745"&gt;&lt;font color="#000000"&gt;The WCF transport sends message data to the target Windows Communication Foundation (WCF) service.&lt;/font&gt; &lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p align="justify"&gt;However, LoadGen is a great tool, but it suffers of the following problems:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;div align="justify"&gt;Test definition is entirely done through XML configuration files. LoadGen does not provide any UI to model and define load tests.&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;It doesn’t provide the possibility to create rules to generate warnings when a give performance counter exceeds a configurable threshold.&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;Generating high loads against a BizTalk application is an intensive task and can easily lead to run out of system resources (CPU, Memory, Disk I/O, Network, etc.). For this reason, when running a performance lab against an enterprise level application is necessary to arrange multiple Test Agent machines in order to generate the expected load. Even though you can start several instances of LoadGen on separate machines, you can’t coordinate their work in a centralized manner. Multiple instances of LoadGen can be started using a script or the LoadGenExecuteStep class provided by BizUnit, but there’s no way to monitor their execution using a console.&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;When invoking a Two-Way Receive Location, LoadGen provides the possibility to save response times to a log file, but not to a centralized database. Of course, when the test is over, it’s possible to collect the log files produced by the different Test Agents, each running on a separate machine, and upload their contents to a SQL Server table with a Bulk Insert. This allows to conduct an in-depth analysis of the test results and eventually run a set of queries to generate statistics and compare key performance indicators of different test runs. Nevertheless, this process must be manually built as it is not provided out of the box by LoadGen.&lt;/div&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p align="justify"&gt;Sometimes customers/partners create a custom multi-threaded application in order to generate load against their BizTalk Application, correlate request and response messages and persist response times to a relational database. This approach requires time and resources to design and develop the multi-threaded application capable to generate the load against the BizTalk platform and store test results to a custom repository. Another common technique adopted by customers is to use a dedicated product like &lt;a href="https://h10078.www1.hp.com/cda/hpms/display/main/hpms_content.jsp?zn=bto&amp;amp;cp=1-11-126-17%5E8_4000_100__"&gt;HP LoadRunner&lt;/a&gt; to measure end-to-end performance, diagnose application and system bottlenecks and tune for better performance. So the question arises: is there any Microsoft product that I can use to perform stress and load tests in a easy way? The answer is yes.&lt;/p&gt;  &lt;p align="justify"&gt;&lt;strong&gt;&lt;font color="#ff9914"&gt;Visual Studio Team System Test Edition &lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p align="justify"&gt;In my opinion, the best solution to design, configure, execute and monitor performance tests against BizTalk is to leverage Visual Studio Team System Test Edition that includes a suite of tools that allow to conduct several kinds of tests (unit tests, load tests, web tests, etc.). In particular, Visual Studio Team System Test Edition provides a tool for creating and running load tests. For more information on this topic see &lt;a href="http://msdn.microsoft.com/en-us/library/ms182562.aspx"&gt;Understanding Load Tests&lt;/a&gt;. Visual Studio Team System Test Edition provides the following advantages:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;div align="justify"&gt;It enables developers to set up a group of computers that generates simulated load for testing. The group consists of a single Controller and one or more Test Agents, each running on a separate machine. Collectively, this group is called a Rig. In particular, a Test Agent is the part of the Rig that is used to run tests and generate simulated load. For more information on this topic see &lt;a href="http://msdn.microsoft.com/en-us/library/ms182634.aspx"&gt;Controllers, Agents, and Rigs&lt;/a&gt;.&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;When you define a load test,&amp;#160; you can choose between two different load patterns:&lt;/div&gt;      &lt;ul&gt;       &lt;li&gt;         &lt;div align="justify"&gt;&lt;font color="#ff9914"&gt;Constant&lt;/font&gt;: the constant load pattern is used to specify a user load that does not change during the load test. For example, when you run a smoke test on a Web application, you might want to set a light, constant load of 10 users.&lt;/div&gt;       &lt;/li&gt;        &lt;li&gt;         &lt;div align="justify"&gt;&lt;font color="#ff9914"&gt;Step&lt;/font&gt;: the step load pattern is used to specify a user load that increases with time up to a defined maximum user load. For stepping loads, you specify the Initial User Count, Maximum User Count, Step Duration (seconds), and Step User Count.For example a Step load with an Initial User count of one, Maximum User Count of 100, Step Duration (seconds) of 10, and a Step User Count of 1 creates a user load pattern that starts at 1, increases by 1 every 10 seconds until it reaches 100 Users. &lt;/div&gt;       &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;It’s possible to create a Load Test Results Repository to store the information gathered during a test run. This repository contains performance counter data and information about any errors. See &lt;a href="http://msdn.microsoft.com/en-us/library/ms318550.aspx"&gt;Load Test Results Repository&lt;/a&gt; for more information on this topic.&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="justify"&gt;When you create a load test, Visual Studio Team System Test Edition lets you specify multiple counter sets. A counter set is collection of performance counters that are useful to monitor during a load test run. Counter sets are part of the load test and apply to all its scenarios. They are organized by technology, for example, ASP.NET, IIS or SQL counter sets. Visual Studio allows developers to create their own Counter Sets to track any performance counters. Counter sets can be defined to gather performance counter data from all the machines composing the performance lab kit. (BizTalk Server, SQL Server, Test Agents, etc.). &lt;/div&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p align="justify"&gt;&lt;a href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/UsingVisualStudio20052008ToGenerateLoadA_D1E2/LoadTestConfig_6.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="LoadTestConfig" border="0" alt="LoadTestConfig" src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/UsingVisualStudio20052008ToGenerateLoadA_D1E2/LoadTestConfig_thumb_2.jpg" width="500" height="579" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;div align="justify"&gt;This feature is extremely helpful because during a test run it allows to collect performance counter data (BizTalk Server, SQL, IIS, etc.) in a central storage and to create multiple diagrams to visualize the most relevant counters. When the test run is over, the summary page allows to browse and analyze test results.&lt;/div&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p align="justify"&gt;&lt;a href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/UsingVisualStudio20052008ToGenerateLoadA_D1E2/LoadTestRunning_2.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="LoadTestRunning" border="0" alt="LoadTestRunning" src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/UsingVisualStudio20052008ToGenerateLoadA_D1E2/LoadTestRunning_thumb.jpg" width="800" height="537" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p align="justify"&gt;&lt;strong&gt;&lt;font color="#ff9914"&gt;How to use Visual Studio to generate load against a Two-Way WCF Receive Location&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p align="justify"&gt;Recently I published an article in 2 parts (&lt;a href="http://blogs.msdn.com/paolos/archive/2009/09/10/4-different-ways-to-process-an-xlangmessage-within-an-helper-component-invoked-by-an-orchestration.aspx"&gt;Part1&lt;/a&gt;, &lt;a href="http://blogs.msdn.com/paolos/archive/2009/09/21/4-different-ways-to-process-an-xlangmessage-within-an-helper-component-invoked-by-an-orchestration-part-2.aspx"&gt;Part2&lt;/a&gt;)&amp;#160; where I compare 4 different techniques to process an XLANGMessage within a method exposed by a business component invoked by an orchestration. In particular, I created a Two-Way Synchronous version and a One-Way Asynchronous version for each of these patterns. All of the 4 synchronous patterns share the same architecture depicted below:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/4Differentwaystoprocessanxlangmessagewit_E2DC/XmlDocumentOrchestration_2.jpg"&gt;&lt;img title="XmlDocumentOrchestration" border="0" alt="XmlDocumentOrchestration" src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/4Differentwaystoprocessanxlangmessagewit_E2DC/XmlDocumentOrchestration_thumb.jpg" width="800" height="264" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#ff9914"&gt;Message Flow:&lt;/font&gt;&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;A WCF-BasicHttp or WCF-Custom Request-Response Receive Location receives a new CalculatorRequest xml document from the Test Agent/Client Application. &lt;/li&gt;    &lt;li&gt;The XML disassembler component within the XMLTransmit pipeline promotes the Method element inside the CalculatorRequest xml document. The Message Agent submits the incoming message to the MessageBox (BizTalkMsgBoxDb). &lt;/li&gt;    &lt;li&gt;The inbound request starts a new instance of a given orchestration. &lt;/li&gt;    &lt;li&gt;The orchestration invokes a method exposed by a business component. &lt;/li&gt;    &lt;li&gt;The method in question returns a response message. &lt;/li&gt;    &lt;li&gt;The orchestration publishes the CalculatorResponse message to the MessageBox (BizTalkMsgBoxDb). &lt;/li&gt;    &lt;li&gt;The response message is retrieved by the Request-Response WCF-BasicHttp or WCF-Custom Receive Location. &lt;/li&gt;    &lt;li&gt;The response message is returned to the Test Agent/Client Application. &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;In order to generate the load against the WCF-Basic and WCF-Custom Receive Locations I proceeded as follows: &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;I started creating a Test Project called WCFLoadTest. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/UsingVisualStudio20052008ToGenerateLoadA_D1E2/TestProject_2.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="TestProject" border="0" alt="TestProject" src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/UsingVisualStudio20052008ToGenerateLoadA_D1E2/TestProject_thumb.jpg" width="600" height="427" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Then I created a Test Class called WCFLoadTest. This class is decorated with the &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.testclassattribute.aspx"&gt;Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute&lt;/a&gt; to indicate that the class contains test methods. &lt;/li&gt;    &lt;li&gt;I defined a Test Method for each combination of the following factors:      &lt;ul&gt;       &lt;li&gt;Receive Location/Transport used to submit messages to BizTalk (WCF-NetTcp, WCF-BasicHttp) &lt;/li&gt;        &lt;li&gt;Message Size (small, medium, large) &lt;/li&gt;        &lt;li&gt;Orchestration Pattern (XmlDocumentOrchestration, StreamOrchestration, MessageClassesOrchestration, CustomBTXMessageOrchestration). &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt;    &lt;li&gt;Each combination of the factors above corresponds to a separate test case. I used the following naming convention for test methods:      &lt;ul&gt;       &lt;li&gt;&amp;lt;Transport&amp;gt;&amp;lt;Message Size&amp;gt;&amp;lt;Orchestration Pattern&amp;gt; &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt;    &lt;li&gt;I created an helper method called InvokeTwoWayWCFReceiveLocation to allow test methods to exchange messages with a Request Response WCF Receive Location. This methods expects the following input parameters      &lt;ul&gt;       &lt;li&gt;&lt;font color="#ff9914"&gt;endpointConfigurationName&lt;/font&gt;: the name of one of the service endpoints defined in the app.config configuration. &lt;/li&gt;        &lt;li&gt;&lt;font color="#ff9914"&gt;requestMessageFolder&lt;/font&gt;: the path of the folder containing the request documents. &lt;/li&gt;        &lt;li&gt;&lt;font color="#ff9914"&gt;requestMessageName&lt;/font&gt;: the name of the request document to send. &lt;/li&gt;        &lt;li&gt;&lt;font color="#ff9914"&gt;messageVersion&lt;/font&gt;: specifies the version of SOAP and WS-Addressing of the request and response messages. &lt;/li&gt;        &lt;li&gt;&lt;font color="#ff9914"&gt;sessionMode&lt;/font&gt;: indicates the support for reliable sessions (Allowed, Required, NotAllowed). &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt;    &lt;li&gt;Each test method invokes the InvokeTwoWayWCFReceiveLocation passing a different combination of parameters. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;The client endpoints used by the InvokeTwoWayWCFReceiveLocation&amp;#160; method to exchange messages with the WCF Receive Locations are defined in the configuration file (App.config) of the project.&lt;/p&gt;  &lt;table border="1" cellspacing="0" cellpadding="5" width="1000" bgcolor="#ffffff"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="800"&gt;         &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;?&lt;/span&gt;&lt;span class="html"&gt;xml&lt;/span&gt; &lt;span class="attr"&gt;version&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;1.0&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;encoding&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;utf-8&amp;quot;&lt;/span&gt; ?&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;configuration&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;system.serviceModel&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="rem"&gt;&amp;lt;!-- Bindings used by client endpoints --&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;bindings&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;netTcpBinding&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;binding&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;netTcpBinding&amp;quot;&lt;/span&gt;
                         &lt;span class="attr"&gt;closeTimeout&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;01:10:00&amp;quot;&lt;/span&gt;
                         &lt;span class="attr"&gt;openTimeout&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;01:10:00&amp;quot;&lt;/span&gt;
                         &lt;span class="attr"&gt;receiveTimeout&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;01:10:00&amp;quot;&lt;/span&gt;
                         &lt;span class="attr"&gt;sendTimeout&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;01:10:00&amp;quot;&lt;/span&gt;
                         &lt;span class="attr"&gt;transactionFlow&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;false&amp;quot;&lt;/span&gt;
                         &lt;span class="attr"&gt;transferMode&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Buffered&amp;quot;&lt;/span&gt;
                         &lt;span class="attr"&gt;transactionProtocol&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;OleTransactions&amp;quot;&lt;/span&gt;
                         &lt;span class="attr"&gt;hostNameComparisonMode&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;StrongWildcard&amp;quot;&lt;/span&gt;
                         &lt;span class="attr"&gt;listenBacklog&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;100&amp;quot;&lt;/span&gt;
                         &lt;span class="attr"&gt;maxBufferPoolSize&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;1048576&amp;quot;&lt;/span&gt;
                         &lt;span class="attr"&gt;maxBufferSize&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;10485760&amp;quot;&lt;/span&gt;
                         &lt;span class="attr"&gt;maxConnections&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;200&amp;quot;&lt;/span&gt;
                         &lt;span class="attr"&gt;maxReceivedMessageSize&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;10485760&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;readerQuotas&lt;/span&gt; &lt;span class="attr"&gt;maxDepth&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;32&amp;quot;&lt;/span&gt;
                                  &lt;span class="attr"&gt;maxStringContentLength&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;8192&amp;quot;&lt;/span&gt;
                                  &lt;span class="attr"&gt;maxArrayLength&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;16384&amp;quot;&lt;/span&gt;
                                  &lt;span class="attr"&gt;maxBytesPerRead&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;4096&amp;quot;&lt;/span&gt;
                                  &lt;span class="attr"&gt;maxNameTableCharCount&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;16384&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
                    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;reliableSession&lt;/span&gt; &lt;span class="attr"&gt;ordered&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt;
                                     &lt;span class="attr"&gt;inactivityTimeout&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;00:10:00&amp;quot;&lt;/span&gt;
                                     &lt;span class="attr"&gt;enabled&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;false&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
                    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;security&lt;/span&gt; &lt;span class="attr"&gt;mode&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;None&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;transport&lt;/span&gt; &lt;span class="attr"&gt;clientCredentialType&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Windows&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;protectionLevel&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;EncryptAndSign&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
                        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;message&lt;/span&gt; &lt;span class="attr"&gt;clientCredentialType&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Windows&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
                    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;security&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;binding&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;netTcpBinding&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;basicHttpBinding&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;binding&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;basicHttpBinding&amp;quot;&lt;/span&gt;
                         &lt;span class="attr"&gt;closeTimeout&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;00:10:00&amp;quot;&lt;/span&gt;
                         &lt;span class="attr"&gt;openTimeout&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;00:10:00&amp;quot;&lt;/span&gt;
                         &lt;span class="attr"&gt;receiveTimeout&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;00:10:00&amp;quot;&lt;/span&gt;
                         &lt;span class="attr"&gt;sendTimeout&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;00:10:00&amp;quot;&lt;/span&gt;
                         &lt;span class="attr"&gt;allowCookies&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;false&amp;quot;&lt;/span&gt;
                         &lt;span class="attr"&gt;bypassProxyOnLocal&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;false&amp;quot;&lt;/span&gt;
                         &lt;span class="attr"&gt;hostNameComparisonMode&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;StrongWildcard&amp;quot;&lt;/span&gt;
                         &lt;span class="attr"&gt;maxBufferSize&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;10485760&amp;quot;&lt;/span&gt;
                         &lt;span class="attr"&gt;maxBufferPoolSize&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;524288&amp;quot;&lt;/span&gt;
                         &lt;span class="attr"&gt;maxReceivedMessageSize&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;10485760&amp;quot;&lt;/span&gt;
                         &lt;span class="attr"&gt;messageEncoding&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Text&amp;quot;&lt;/span&gt;
                         &lt;span class="attr"&gt;textEncoding&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;utf-8&amp;quot;&lt;/span&gt;
                         &lt;span class="attr"&gt;transferMode&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Buffered&amp;quot;&lt;/span&gt;
                         &lt;span class="attr"&gt;useDefaultWebProxy&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;readerQuotas&lt;/span&gt; &lt;span class="attr"&gt;maxDepth&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;32&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;maxStringContentLength&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;8192&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;maxArrayLength&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;16384&amp;quot;&lt;/span&gt;
                        &lt;span class="attr"&gt;maxBytesPerRead&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;4096&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;maxNameTableCharCount&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;16384&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
                    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;security&lt;/span&gt; &lt;span class="attr"&gt;mode&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;None&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;transport&lt;/span&gt; &lt;span class="attr"&gt;clientCredentialType&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;None&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;proxyCredentialType&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;None&amp;quot;&lt;/span&gt;
                            &lt;span class="attr"&gt;realm&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
                        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;message&lt;/span&gt; &lt;span class="attr"&gt;clientCredentialType&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;UserName&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;algorithmSuite&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Default&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
                    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;security&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;binding&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;basicHttpBinding&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;bindings&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;client&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="rem"&gt;&amp;lt;!-- Client endpoints used by client excahnge messages with the WCF Receive Locations --&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;endpoint&lt;/span&gt; &lt;span class="attr"&gt;address&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;net.tcp://localhost:8123/calculator&amp;quot;&lt;/span&gt;
                      &lt;span class="attr"&gt;binding&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;netTcpBinding&amp;quot;&lt;/span&gt;
                      &lt;span class="attr"&gt;bindingConfiguration&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;netTcpBinding&amp;quot;&lt;/span&gt;
                      &lt;span class="attr"&gt;contract&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;System.ServiceModel.Channels.IRequestChannel&amp;quot;&lt;/span&gt;
                      &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;netTcpCalculatorServiceReceiveLocationEndpoint&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;endpoint&lt;/span&gt; &lt;span class="attr"&gt;address&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;http://localhost/CalculatorServiceReceiveLocation/CalculatorService.svc&amp;quot;&lt;/span&gt;
                      &lt;span class="attr"&gt;binding&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;basicHttpBinding&amp;quot;&lt;/span&gt;
                      &lt;span class="attr"&gt;bindingConfiguration&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;basicHttpBinding&amp;quot;&lt;/span&gt;
                      &lt;span class="attr"&gt;contract&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;System.ServiceModel.Channels.IRequestChannel&amp;quot;&lt;/span&gt;
                      &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;basicHttpCalculatorServiceReceiveLocationEndpoint&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;client&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;system.serviceModel&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;appSettings&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="rem"&gt;&amp;lt;!-- Folder containing test messages --&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;add&lt;/span&gt; &lt;span class="attr"&gt;key&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;testMessageFolder&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;value&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;C:\Projects\HandleXLANGMessages\WCFLoadTest\TestMessages&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;appSettings&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;configuration&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&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;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;The following table contains the code of the WCFLoadTest class:&lt;/p&gt;

&lt;table border="1" cellspacing="0" cellpadding="5" width="1000" bgcolor="#ffffff"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top"&gt;
        &lt;pre class="csharpcode"&gt;&lt;span class="preproc"&gt;#region&lt;/span&gt; Copyright
&lt;span class="rem"&gt;//-------------------------------------------------&lt;/span&gt;
&lt;span class="rem"&gt;// Author:  Paolo Salvatori&lt;/span&gt;
&lt;span class="rem"&gt;// Email:   paolos@microsoft.com&lt;/span&gt;
&lt;span class="rem"&gt;// History: 2009-09-20 Created&lt;/span&gt;
&lt;span class="rem"&gt;//-------------------------------------------------&lt;/span&gt;
&lt;span class="preproc"&gt;#endregion&lt;/span&gt;

&lt;span class="preproc"&gt;#region&lt;/span&gt; Using Directives
&lt;span class="kwrd"&gt;using&lt;/span&gt; System;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.IO;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Diagnostics;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Text;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Configuration;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Collections.Generic;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Linq;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Xml;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.ServiceModel;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.ServiceModel.Channels;
&lt;span class="kwrd"&gt;using&lt;/span&gt; Microsoft.VisualStudio.TestTools.UnitTesting;
&lt;span class="preproc"&gt;#endregion&lt;/span&gt;

&lt;span class="kwrd"&gt;namespace&lt;/span&gt; Microsoft.BizTalk.CAT.Samples.HandleXLANGMessages.WCFLoadTest
{
    &lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
    &lt;span class="rem"&gt;/// Summary description for UnitTest1&lt;/span&gt;
    &lt;span class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
    [TestClass]
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; WCFLoadTest
    {
        &lt;span class="preproc"&gt;#region&lt;/span&gt; Constants
        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;const&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; MaxBufferSize = 2097152;
        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;const&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Source = &lt;span class="str"&gt;&amp;quot;WCF Load Test&amp;quot;&lt;/span&gt;;
        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;const&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Star = &lt;span class="str"&gt;&amp;quot;*&amp;quot;&lt;/span&gt;;
        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;const&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; TestMessageFolderParameter = &lt;span class="str"&gt;&amp;quot;testMessageFolder&amp;quot;&lt;/span&gt;;
        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;const&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; TestMessageFolderDefault = &lt;span class="str"&gt;@&amp;quot;C:\Projects\HandleXLANGMessages\WCFLoadTest\TestMessages&amp;quot;&lt;/span&gt;;
        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;const&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; TestMessageFolderFormat = &lt;span class="str"&gt;@&amp;quot;Test Message Folder = {0}&amp;quot;&lt;/span&gt;;
        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;const&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; NetTcpCalculatorServiceReceiveLocationEndpoint = &lt;span class="str"&gt;&amp;quot;netTcpCalculatorServiceReceiveLocationEndpoint&amp;quot;&lt;/span&gt;;
        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;const&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; BasicHttpCalculatorServiceReceiveLocationEndpoint = &lt;span class="str"&gt;&amp;quot;basicHttpCalculatorServiceReceiveLocationEndpoint&amp;quot;&lt;/span&gt;;
        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;const&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; SmallCustomBtxMessageOrchestration = &lt;span class="str"&gt;&amp;quot;SmallCustomBtxMessageOrchestration.xml&amp;quot;&lt;/span&gt;;
        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;const&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; SmallMessageClassesOrchestration = &lt;span class="str"&gt;&amp;quot;SmallMessageClassesOrchestration.xml&amp;quot;&lt;/span&gt;;
        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;const&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; SmallStreamOrchestration = &lt;span class="str"&gt;&amp;quot;SmallStreamOrchestration.xml&amp;quot;&lt;/span&gt;;
        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;const&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; SmallXmlDocumentOrchestration = &lt;span class="str"&gt;&amp;quot;SmallXmlDocumentOrchestration.xml&amp;quot;&lt;/span&gt;;
        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;const&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; MediumCustomBtxMessageOrchestration = &lt;span class="str"&gt;&amp;quot;MediumCustomBtxMessageOrchestration.xml&amp;quot;&lt;/span&gt;;
        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;const&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; MediumMessageClassesOrchestration = &lt;span class="str"&gt;&amp;quot;MediumMessageClassesOrchestration.xml&amp;quot;&lt;/span&gt;;
        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;const&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; MediumStreamOrchestration = &lt;span class="str"&gt;&amp;quot;MediumStreamOrchestration.xml&amp;quot;&lt;/span&gt;;
        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;const&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; MediumXmlDocumentOrchestration = &lt;span class="str"&gt;&amp;quot;MediumXmlDocumentOrchestration.xml&amp;quot;&lt;/span&gt;;
        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;const&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; LargeCustomBtxMessageOrchestration = &lt;span class="str"&gt;&amp;quot;LargeCustomBtxMessageOrchestration.xml&amp;quot;&lt;/span&gt;;
        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;const&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; LargeMessageClassesOrchestration = &lt;span class="str"&gt;&amp;quot;LargeMessageClassesOrchestration.xml&amp;quot;&lt;/span&gt;;
        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;const&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; LargeStreamOrchestration = &lt;span class="str"&gt;&amp;quot;LargeStreamOrchestration.xml&amp;quot;&lt;/span&gt;;
        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;const&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; LargeXmlDocumentOrchestration = &lt;span class="str"&gt;&amp;quot;LargeXmlDocumentOrchestration.xml&amp;quot;&lt;/span&gt;;
        &lt;span class="preproc"&gt;#endregion&lt;/span&gt;

        &lt;span class="preproc"&gt;#region&lt;/span&gt; Private Instance Fields
        &lt;span class="kwrd"&gt;private&lt;/span&gt; TestContext testContextInstance;
        &lt;span class="preproc"&gt;#endregion&lt;/span&gt;

        &lt;span class="preproc"&gt;#region&lt;/span&gt; Private Static Fields
        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; testMessageFolder = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
        &lt;span class="preproc"&gt;#endregion&lt;/span&gt;

        &lt;span class="preproc"&gt;#region&lt;/span&gt; Public Instance Constructor
        &lt;span class="kwrd"&gt;public&lt;/span&gt; WCFLoadTest()
        {
        }
        &lt;span class="preproc"&gt;#endregion&lt;/span&gt;

        &lt;span class="preproc"&gt;#region&lt;/span&gt; Public Static Constructor
        &lt;span class="kwrd"&gt;static&lt;/span&gt; WCFLoadTest()
        {
            &lt;span class="kwrd"&gt;try&lt;/span&gt;
            {
                testMessageFolder = ConfigurationManager.AppSettings[TestMessageFolderParameter];
                &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;string&lt;/span&gt;.IsNullOrEmpty(testMessageFolder))
                {
                    testMessageFolder = TestMessageFolderDefault;
                }
            }
            &lt;span class="kwrd"&gt;catch&lt;/span&gt; (Exception ex)
            {
                Trace.WriteLine(ex.Message);
                EventLog.WriteEntry(Source, ex.Message, EventLogEntryType.Error);
            }
        }
        &lt;span class="preproc"&gt;#endregion&lt;/span&gt;

        &lt;span class="preproc"&gt;#region&lt;/span&gt; Public Properties
        &lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
        &lt;span class="rem"&gt;///Gets or sets the test context which provides&lt;/span&gt;
        &lt;span class="rem"&gt;///information about and functionality for the current test run.&lt;/span&gt;
        &lt;span class="rem"&gt;///&amp;lt;/summary&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;public&lt;/span&gt; TestContext TestContext
        {
            get
            {
                &lt;span class="kwrd"&gt;return&lt;/span&gt; testContextInstance;
            }
            set
            {
                testContextInstance = &lt;span class="kwrd"&gt;value&lt;/span&gt;;
            }
        }
        &lt;span class="preproc"&gt;#endregion&lt;/span&gt;

        &lt;span class="preproc"&gt;#region&lt;/span&gt; Test Methods
        [TestMethod]
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; BasicHttpSmallCustomBtxMessageOrchestration()
        {
            InvokeTwoWayWCFReceiveLocation(BasicHttpCalculatorServiceReceiveLocationEndpoint,
                                           testMessageFolder,
                                           SmallCustomBtxMessageOrchestration,
                                           MessageVersion.Soap11,
                                           SessionMode.Allowed);
        }

        [TestMethod]
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; BasicHttpSmallMessageClassesOrchestration()
        {
            InvokeTwoWayWCFReceiveLocation(BasicHttpCalculatorServiceReceiveLocationEndpoint,
                                           testMessageFolder,
                                           SmallMessageClassesOrchestration,
                                           MessageVersion.Soap11,
                                           SessionMode.Allowed);
        }

        [TestMethod]
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; BasicHttpSmallStreamOrchestration()
        {
            InvokeTwoWayWCFReceiveLocation(BasicHttpCalculatorServiceReceiveLocationEndpoint,
                                           testMessageFolder,
                                           SmallStreamOrchestration,
                                           MessageVersion.Soap11,
                                           SessionMode.Allowed);
        }

        [TestMethod]
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; BasicHttpSmallXmlDocumentOrchestration()
        {
            InvokeTwoWayWCFReceiveLocation(BasicHttpCalculatorServiceReceiveLocationEndpoint,
                                           testMessageFolder,
                                           SmallXmlDocumentOrchestration,
                                           MessageVersion.Soap11,
                                           SessionMode.Allowed);
        }

        [TestMethod]
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; BasicHttpMediumCustomBtxMessageOrchestration()
        {
            InvokeTwoWayWCFReceiveLocation(BasicHttpCalculatorServiceReceiveLocationEndpoint,
                                           testMessageFolder,
                                           MediumCustomBtxMessageOrchestration,
                                           MessageVersion.Soap11,
                                           SessionMode.Allowed);
        }

        [TestMethod]
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; BasicHttpMediumMessageClassesOrchestration()
        {
            InvokeTwoWayWCFReceiveLocation(BasicHttpCalculatorServiceReceiveLocationEndpoint,
                                           testMessageFolder,
                                           MediumMessageClassesOrchestration,
                                           MessageVersion.Soap11,
                                           SessionMode.Allowed);
        }

        [TestMethod]
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; BasicHttpMediumStreamOrchestration()
        {
            InvokeTwoWayWCFReceiveLocation(BasicHttpCalculatorServiceReceiveLocationEndpoint,
                                           testMessageFolder,
                                           MediumStreamOrchestration,
                                           MessageVersion.Soap11,
                                           SessionMode.Allowed);
        }

        [TestMethod]
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; BasicHttpMediumXmlDocumentOrchestration()
        {
            InvokeTwoWayWCFReceiveLocation(BasicHttpCalculatorServiceReceiveLocationEndpoint,
                                           testMessageFolder,
                                           MediumXmlDocumentOrchestration,
                                           MessageVersion.Soap11,
                                           SessionMode.Allowed);
        }

        [TestMethod]
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; BasicHttpLargeCustomBtxMessageOrchestration()
        {
            InvokeTwoWayWCFReceiveLocation(BasicHttpCalculatorServiceReceiveLocationEndpoint,
                                           testMessageFolder,
                                           LargeCustomBtxMessageOrchestration,
                                           MessageVersion.Soap11,
                                           SessionMode.Allowed);
        }

        [TestMethod]
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; BasicHttpLargeMessageClassesOrchestration()
        {
            InvokeTwoWayWCFReceiveLocation(BasicHttpCalculatorServiceReceiveLocationEndpoint,
                                           testMessageFolder,
                                           LargeMessageClassesOrchestration,
                                           MessageVersion.Soap11,
                                           SessionMode.Allowed);
        }

        [TestMethod]
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; BasicHttpLargeStreamOrchestration()
        {
            InvokeTwoWayWCFReceiveLocation(BasicHttpCalculatorServiceReceiveLocationEndpoint,
                                           testMessageFolder,
                                           LargeStreamOrchestration,
                                           MessageVersion.Soap11,
                                           SessionMode.Allowed);
        }

        [TestMethod]
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; BasicHttpLargeXmlDocumentOrchestration()
        {
            InvokeTwoWayWCFReceiveLocation(BasicHttpCalculatorServiceReceiveLocationEndpoint,
                                           testMessageFolder,
                                           LargeXmlDocumentOrchestration,
                                           MessageVersion.Soap11,
                                           SessionMode.Allowed);
        }

        [TestMethod]
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; NetTcpSmallCustomBtxMessageOrchestration()
        {
            InvokeTwoWayWCFReceiveLocation(NetTcpCalculatorServiceReceiveLocationEndpoint,
                                           testMessageFolder,
                                           SmallCustomBtxMessageOrchestration,
                                           MessageVersion.Default,
                                           SessionMode.Allowed);
        }

        [TestMethod]
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; NetTcpSmallMessageClassesOrchestration()
        {
            InvokeTwoWayWCFReceiveLocation(NetTcpCalculatorServiceReceiveLocationEndpoint,
                                           testMessageFolder,
                                           SmallMessageClassesOrchestration,
                                           MessageVersion.Default,
                                           SessionMode.Allowed);
        }

        [TestMethod]
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; NetTcpSmallStreamOrchestration()
        {
            InvokeTwoWayWCFReceiveLocation(NetTcpCalculatorServiceReceiveLocationEndpoint,
                                           testMessageFolder,
                                           SmallStreamOrchestration,
                                           MessageVersion.Default,
                                           SessionMode.Allowed);
        }

        [TestMethod]
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; NetTcpSmallXmlDocumentOrchestration()
        {
            InvokeTwoWayWCFReceiveLocation(NetTcpCalculatorServiceReceiveLocationEndpoint,
                                           testMessageFolder,
                                           SmallXmlDocumentOrchestration,
                                           MessageVersion.Default,
                                           SessionMode.Allowed);
        }

        [TestMethod]
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; NetTcpMediumCustomBtxMessageOrchestration()
        {
            InvokeTwoWayWCFReceiveLocation(NetTcpCalculatorServiceReceiveLocationEndpoint,
                                           testMessageFolder,
                                           MediumCustomBtxMessageOrchestration,
                                           MessageVersion.Default,
                                           SessionMode.Allowed);
        }

        [TestMethod]
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; NetTcpMediumMessageClassesOrchestration()
        {
            InvokeTwoWayWCFReceiveLocation(NetTcpCalculatorServiceReceiveLocationEndpoint,
                                           testMessageFolder,
                                           MediumMessageClassesOrchestration,
                                           MessageVersion.Default,
                                           SessionMode.Allowed);
        }

        [TestMethod]
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; NetTcpMediumStreamOrchestration()
        {
            InvokeTwoWayWCFReceiveLocation(NetTcpCalculatorServiceReceiveLocationEndpoint,
                                           testMessageFolder,
                                           MediumStreamOrchestration,
                                           MessageVersion.Default,
                                           SessionMode.Allowed);
        }

        [TestMethod]
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; NetTcpMediumXmlDocumentOrchestration()
        {
            InvokeTwoWayWCFReceiveLocation(NetTcpCalculatorServiceReceiveLocationEndpoint,
                                           testMessageFolder,
                                           MediumXmlDocumentOrchestration,
                                           MessageVersion.Default,
                                           SessionMode.Allowed);
        }

        [TestMethod]
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; NetTcpLargeCustomBtxMessageOrchestration()
        {
            InvokeTwoWayWCFReceiveLocation(NetTcpCalculatorServiceReceiveLocationEndpoint,
                                           testMessageFolder,
                                           LargeCustomBtxMessageOrchestration,
                                           MessageVersion.Default,
                                           SessionMode.Allowed);
        }

        [TestMethod]
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; NetTcpLargeMessageClassesOrchestration()
        {
            InvokeTwoWayWCFReceiveLocation(NetTcpCalculatorServiceReceiveLocationEndpoint,
                                           testMessageFolder,
                                           LargeMessageClassesOrchestration,
                                           MessageVersion.Default,
                                           SessionMode.Allowed);
        }

        [TestMethod]
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; NetTcpLargeStreamOrchestration()
        {
            InvokeTwoWayWCFReceiveLocation(NetTcpCalculatorServiceReceiveLocationEndpoint,
                                           testMessageFolder,
                                           LargeStreamOrchestration,
                                           MessageVersion.Default,
                                           SessionMode.Allowed);
        }

        [TestMethod]
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; NetTcpLargeXmlDocumentOrchestration()
        {
            InvokeTwoWayWCFReceiveLocation(NetTcpCalculatorServiceReceiveLocationEndpoint,
                                           testMessageFolder,
                                           LargeXmlDocumentOrchestration,
                                           MessageVersion.Default,
                                           SessionMode.Allowed);
        }
        &lt;span class="preproc"&gt;#endregion&lt;/span&gt;

        &lt;span class="preproc"&gt;#region&lt;/span&gt; Helper Methods
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; InvokeTwoWayWCFReceiveLocation(&lt;span class="kwrd"&gt;string&lt;/span&gt; endpointConfigurationName,
                                                   &lt;span class="kwrd"&gt;string&lt;/span&gt; requestMessageFolder,
                                                   &lt;span class="kwrd"&gt;string&lt;/span&gt; requestMessageName,
                                                   MessageVersion messageVersion,
                                                   SessionMode sessionMode)
        {
            ChannelFactory&amp;lt;IRequestChannel&amp;gt; channelFactory = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
            IRequestChannel channel = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
            XmlTextReader xmlTextReader = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
            Message requestMessage = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
            Message responseMessage = &lt;span class="kwrd"&gt;null&lt;/span&gt;;

            &lt;span class="kwrd"&gt;try&lt;/span&gt;
            {

                channelFactory = &lt;span class="kwrd"&gt;new&lt;/span&gt; ChannelFactory&amp;lt;IRequestChannel&amp;gt;(endpointConfigurationName);
                channelFactory.Endpoint.Contract.SessionMode = sessionMode;
                channel = channelFactory.CreateChannel();
                &lt;span class="kwrd"&gt;string&lt;/span&gt; path = Path.Combine(requestMessageFolder, requestMessageName);
                xmlTextReader = &lt;span class="kwrd"&gt;new&lt;/span&gt; XmlTextReader(path);
                requestMessage = Message.CreateMessage(messageVersion, Star, xmlTextReader);
                TestContext.BeginTimer(requestMessageName);
                responseMessage = channel.Request(requestMessage);
                channel.Close();
                channelFactory.Close();
            }
            &lt;span class="kwrd"&gt;catch&lt;/span&gt; (FaultException ex)
            {
                HandleException(&lt;span class="kwrd"&gt;ref&lt;/span&gt; channelFactory,
                                &lt;span class="kwrd"&gt;ref&lt;/span&gt; channel,
                                ex);
                &lt;span class="kwrd"&gt;throw&lt;/span&gt;;
            }
            &lt;span class="kwrd"&gt;catch&lt;/span&gt; (CommunicationException ex)
            {
                HandleException(&lt;span class="kwrd"&gt;ref&lt;/span&gt; channelFactory,
                                &lt;span class="kwrd"&gt;ref&lt;/span&gt; channel,
                                ex);
                &lt;span class="kwrd"&gt;throw&lt;/span&gt;;
            }
            &lt;span class="kwrd"&gt;catch&lt;/span&gt; (TimeoutException ex)
            {
                HandleException(&lt;span class="kwrd"&gt;ref&lt;/span&gt; channelFactory,
                                &lt;span class="kwrd"&gt;ref&lt;/span&gt; channel,
                                ex);
                &lt;span class="kwrd"&gt;throw&lt;/span&gt;;
            }
            &lt;span class="kwrd"&gt;catch&lt;/span&gt; (Exception ex)
            {
                HandleException(&lt;span class="kwrd"&gt;ref&lt;/span&gt; channelFactory,
                                &lt;span class="kwrd"&gt;ref&lt;/span&gt; channel,
                                ex);
                &lt;span class="kwrd"&gt;throw&lt;/span&gt;;
            }
            &lt;span class="kwrd"&gt;finally&lt;/span&gt;
            {
                TestContext.EndTimer(requestMessageName);
                CloseObjects(channelFactory,
                             channel,
                             xmlTextReader,
                             requestMessage,
                             responseMessage);
            }
        }

        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; HandleException(&lt;span class="kwrd"&gt;ref&lt;/span&gt; ChannelFactory&amp;lt;IRequestChannel&amp;gt; channelFactory,
                                     &lt;span class="kwrd"&gt;ref&lt;/span&gt; IRequestChannel channel,
                                     Exception ex)
        {
            &lt;span class="kwrd"&gt;try&lt;/span&gt;
            {
                &lt;span class="kwrd"&gt;if&lt;/span&gt; (channelFactory != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
                {
                    channelFactory.Abort();
                    channelFactory = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
                }
                &lt;span class="kwrd"&gt;if&lt;/span&gt; (channel != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
                {
                    channel.Abort();
                    channel = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
                }
                Trace.WriteLine(ex.Message);
                EventLog.WriteEntry(Source, ex.Message, EventLogEntryType.Error);
            }
            &lt;span class="kwrd"&gt;catch&lt;/span&gt; (Exception)
            {
            }
        }

        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; CloseObjects(ChannelFactory&amp;lt;IRequestChannel&amp;gt; channelFactory,
                                     IRequestChannel channel,
                                     XmlTextReader xmlTextReader,
                                     Message requestMessage,
                                     Message responseMessage)
        {
            &lt;span class="kwrd"&gt;try&lt;/span&gt;
            {
                &lt;span class="kwrd"&gt;if&lt;/span&gt; (channelFactory != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
                {
                    channelFactory.Close();
                }
                &lt;span class="kwrd"&gt;if&lt;/span&gt; (channel != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
                {
                    channel.Close();
                }
                &lt;span class="kwrd"&gt;if&lt;/span&gt; (xmlTextReader != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
                {
                    xmlTextReader.Close();
                }
                &lt;span class="kwrd"&gt;if&lt;/span&gt; (requestMessage != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
                {
                    requestMessage.Close();
                }
                &lt;span class="kwrd"&gt;if&lt;/span&gt; (responseMessage != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
                {
                    responseMessage.Close();
                }
            }
            &lt;span class="kwrd"&gt;catch&lt;/span&gt; (Exception)
            {
            }
        }
        &lt;span class="preproc"&gt;#endregion&lt;/span&gt;
    }
}&lt;/pre&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;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;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p align="justify"&gt;Each test method corresponds to a separate Unit Test. Visual Studio permits to create a Load Test as a composition of one or multiple unit tests. Explaining in detail how creating a Load Test is out of the scope of the present post. This process is fully documented on MSDN at the following link: &lt;a href="http://msdn.microsoft.com/en-us/library/ms182594.aspx"&gt;Walkthrough: Creating and Running a Load Test&lt;/a&gt;. However, for the sake of the completeness I’m going to describe the steps necessary to create a Load Test based on a single Unit Test:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;div align="justify"&gt;Right-click the Test project, expand the Add menu and select the Load Test menu item as shown in the picture below:&lt;/div&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p align="justify"&gt;&lt;a href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/UsingVisualStudio20052008ToGenerateLoadA_D1E2/CreateLoadTest_2.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="CreateLoadTest" border="0" alt="CreateLoadTest" src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/UsingVisualStudio20052008ToGenerateLoadA_D1E2/CreateLoadTest_thumb.jpg" width="800" height="587" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;div align="justify"&gt;This opens a a Wizard that walks you through the creation of a Load Test. Click the Next button. See &lt;a href="http://msdn.microsoft.com/en-us/library/ms182571(VS.80).aspx"&gt;Creating Load Tests&lt;/a&gt; for more information on this topic.&lt;/div&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p align="justify"&gt;&lt;a href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/UsingVisualStudio20052008ToGenerateLoadA_D1E2/NewLoadTestWizard01_2.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="NewLoadTestWizard01" border="0" alt="NewLoadTestWizard01" src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/UsingVisualStudio20052008ToGenerateLoadA_D1E2/NewLoadTestWizard01_thumb.jpg" width="600" height="365" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;div align="justify"&gt;Enter a name for the load test scenario and select one of the available think time profiles (I always choose ‘Do not use think times’ to increase the load against the tested application). Click the Next button. See &lt;a href="http://msdn.microsoft.com/en-us/library/ms182573(VS.80).aspx"&gt;How to: Specify Scenarios&lt;/a&gt; for more information on this step.&lt;/div&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p align="justify"&gt;&lt;a href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/UsingVisualStudio20052008ToGenerateLoadA_D1E2/NewLoadTestWizard02_2.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="NewLoadTestWizard02" border="0" alt="NewLoadTestWizard02" src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/UsingVisualStudio20052008ToGenerateLoadA_D1E2/NewLoadTestWizard02_thumb.jpg" width="600" height="365" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Choose a load pattern for your load test and configure parameters applicable to your choice. Click the Next button. See &lt;a href="http://msdn.microsoft.com/en-us/library/ms182574(VS.80).aspx"&gt;How to: Specify Load Patterns&lt;/a&gt; for more information on this step. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/UsingVisualStudio20052008ToGenerateLoadA_D1E2/NewLoadTestWizard03_2.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="NewLoadTestWizard03" border="0" alt="NewLoadTestWizard03" src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/UsingVisualStudio20052008ToGenerateLoadA_D1E2/NewLoadTestWizard03_thumb.jpg" width="600" height="365" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Choose a Test Mix and click the Next button. See &lt;a href="http://msdn.microsoft.com/en-us/library/ms182576(VS.80).aspx"&gt;How to: Specify Test Mix&lt;/a&gt; for more information on this step. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/UsingVisualStudio20052008ToGenerateLoadA_D1E2/NewLoadTestWizard04_2.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="NewLoadTestWizard04" border="0" alt="NewLoadTestWizard04" src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/UsingVisualStudio20052008ToGenerateLoadA_D1E2/NewLoadTestWizard04_thumb.jpg" width="600" height="365" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;A load test contains one or more scenarios, each of which contains one or more Unit Tests. Press the Add button to add one or multiple Unit Tests to your scenario. See &lt;a href="http://msdn.microsoft.com/en-us/library/ms182577(VS.80).aspx"&gt;How to: Specify Browser Mix&lt;/a&gt; for more information on this step. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/UsingVisualStudio20052008ToGenerateLoadA_D1E2/NewLoadTestWizard05_2.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="NewLoadTestWizard05" border="0" alt="NewLoadTestWizard05" src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/UsingVisualStudio20052008ToGenerateLoadA_D1E2/NewLoadTestWizard05_thumb.jpg" width="600" height="365" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Select one or multiple Unit Tests and click the OK button. One again, each Test Method corresponds to a separate Unit Test. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/UsingVisualStudio20052008ToGenerateLoadA_D1E2/NewLoadTestWizard06_2.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="NewLoadTestWizard06" border="0" alt="NewLoadTestWizard06" src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/UsingVisualStudio20052008ToGenerateLoadA_D1E2/NewLoadTestWizard06_thumb.jpg" width="600" height="370" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;If you selected multiple Unit Tests, as in the picture below, you can select your preferred browser mix by adjusting the sliders in the Distribution column, or by typing the percentage values directly into the % column, then click the Next button to advance to the next step. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/UsingVisualStudio20052008ToGenerateLoadA_D1E2/NewLoadTestWizard07_2.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="NewLoadTestWizard07" border="0" alt="NewLoadTestWizard07" src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/UsingVisualStudio20052008ToGenerateLoadA_D1E2/NewLoadTestWizard07_thumb.jpg" width="600" height="365" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The following dialog allows you specify which computers and counter sets to monitor during a load test run. After completing the wizard, you can define additional counter sets. This is very helpful because it allows to select any performance counters exposed by a product (BizTalk Server in our case) or by your application. When you have done, click the Next button to advance to the next step. See &lt;a href="http://msdn.microsoft.com/en-us/library/ms182579(VS.80).aspx"&gt;How to: Specify Counter Sets&lt;/a&gt; for more information on this step. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/UsingVisualStudio20052008ToGenerateLoadA_D1E2/NewLoadTestWizard08_2.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="NewLoadTestWizard08" border="0" alt="NewLoadTestWizard08" src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/UsingVisualStudio20052008ToGenerateLoadA_D1E2/NewLoadTestWizard08_thumb.jpg" width="600" height="365" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;In this dialog, you can specify Run settings that affect the entire load test. The run settings determine the length of the test, warm-up duration, maximum number of error details reported, sampling rate, connection model (Web tests only), results storage type, validation level and SQL tracing. The run settings should reflect the goals of your load test. For more information, see &lt;a href="http://msdn.microsoft.com/en-us/library/ms182569(VS.80).aspx"&gt;About Run Settings&lt;/a&gt;. When you have done, click the Finish button to complete the Load Test creation. See &lt;a href="http://msdn.microsoft.com/en-us/library/ms182580(VS.80).aspx"&gt;How to: Specify Run Settings&lt;/a&gt; for more information on this step. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/UsingVisualStudio20052008ToGenerateLoadA_D1E2/NewLoadTestWizard09_4.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="NewLoadTestWizard09" border="0" alt="NewLoadTestWizard09" src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/UsingVisualStudio20052008ToGenerateLoadA_D1E2/NewLoadTestWizard09_thumb_1.jpg" width="600" height="365" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;At this point you can open the newly created Load Test, right click the Counter Sets and select Add Custom Counter Set from the drop menu. Rename your new Counter Set ‘BizTalk Server’. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/UsingVisualStudio20052008ToGenerateLoadA_D1E2/NewLoadTestWizard10_2.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="NewLoadTestWizard10" border="0" alt="NewLoadTestWizard10" src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/UsingVisualStudio20052008ToGenerateLoadA_D1E2/NewLoadTestWizard10_thumb.jpg" width="800" height="587" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Now, right click the BizTalk Server Counter Set and click the Add Counters menu item to add the most relevant BizTalk Server, System, .NET and WCF performance counters: 
    &lt;ul&gt;
      &lt;p&gt;&lt;font color="#ff9914"&gt;BizTalk Server performance counters&lt;/font&gt; 

        &lt;br /&gt;\\.\BizTalk:FILE Receive Adapter(*)\* 

        &lt;br /&gt;\\.\BizTalk:FILE Send Adapter(*)\* 

        &lt;br /&gt;\\.\BizTalk:FTP Receive Adapter(*)\* 

        &lt;br /&gt;\\.\BizTalk:FTP Send Adapter(*)\* 

        &lt;br /&gt;\\.\BizTalk:HTTP Receive Adapter(*)\* 

        &lt;br /&gt;\\.\BizTalk:HTTP Send Adapter(*)\* 

        &lt;br /&gt;\\.\BizTalk:Message Agent(*)\* 

        &lt;br /&gt;\\.\BizTalk:Message Box:General Counters(*)\* 

        &lt;br /&gt;\\.\BizTalk:Message Box:Host Counters(*)\* 

        &lt;br /&gt;\\.\BizTalk:Messaging Latency(*)\* 

        &lt;br /&gt;\\.\BizTalk:Messaging(*)\* 

        &lt;br /&gt;\\.\BizTalk:MSMQ Receive Adapter(*)\* 

        &lt;br /&gt;\\.\BizTalk:MSMQ Send Adapter(*)\* 

        &lt;br /&gt;\\.\BizTalk:POP3 Receive Adapter(*)\* 

        &lt;br /&gt;\\.\BizTalk:SMTP Send Adapter(*)\* 

        &lt;br /&gt;\\.\BizTalk:SOAP Receive Adapter(*)\* 

        &lt;br /&gt;\\.\BizTalk:SOAP Send Adapter(*)\* 

        &lt;br /&gt;\\.\BizTalk:SQL Receive Adapter(*)\* 

        &lt;br /&gt;\\.\BizTalk:SQL Send Adapter(*)\* 

        &lt;br /&gt;\\.\BizTalk:TDDS(*)\* 

        &lt;br /&gt;\\.\BizTalk:Windows SharePoint Services Adapter(*)\* 

        &lt;br /&gt;\\.\XLANG/s Orchestrations(*)\*&lt;/p&gt;
    &lt;/ul&gt;

    &lt;ul&gt;
      &lt;p&gt;&lt;font color="#ff9914"&gt;WCF performance counters&lt;/font&gt; 

        &lt;br /&gt;\\.\ServiceModelService 3.0.0.0 

        &lt;br /&gt;\\.\ServiceModelEndpoint 3.0.0.0 

        &lt;br /&gt;\\.\ServiceModelOperation 3.0.0.0 

        &lt;br /&gt;&lt;font color="#ff9914"&gt;
          &lt;br /&gt;.NET performance counters&lt;/font&gt; 

        &lt;br /&gt;\\.\.NET CLR Exceptions(*)\* 

        &lt;br /&gt;\\.\.NET CLR Memory(*)\* &lt;/p&gt;

      &lt;p&gt;&lt;font color="#ff9914"&gt;System performance counters&lt;/font&gt; 

        &lt;br /&gt;\\.\Cache\* 

        &lt;br /&gt;\\.\Distributed Transaction Coordinator\* 

        &lt;br /&gt;\\.\Enterprise SSO(*)\* 

        &lt;br /&gt;\\.\LogicalDisk(*)\* 

        &lt;br /&gt;\\.\Memory\* 

        &lt;br /&gt;\\.\Network Interface(*)\* 

        &lt;br /&gt;\\.\Paging File(*)\* 

        &lt;br /&gt;\\.\PhysicalDisk(*)\* 

        &lt;br /&gt;\\.\Process(*)\* 

        &lt;br /&gt;\\.\Processor(*)\* 

        &lt;br /&gt;\\.\System\* 

        &lt;br /&gt;\\.\TCPv4\*

        &lt;br /&gt;\\.\IPv4\*&lt;/p&gt;
    &lt;/ul&gt;
  &lt;/li&gt;

  &lt;li&gt;Repeat the last step to include the most relevant performance counters on the SQL machine hosting the BizTalkMsgBoxDb. In the list below, the name of the SQL Server instance hosting the BizTalkMsgBoxDb is MSSQL$BTS:&lt;/li&gt;
&lt;/ul&gt;

&lt;ul&gt;
  &lt;blockquote&gt;
    &lt;p&gt;&lt;font color="#ff9914"&gt;SQL Server performance counters&lt;/font&gt; 

      &lt;br /&gt;\\.\MSSQL$BTS:Access Methods\*

      &lt;br /&gt;\\.\MSSQL$BTS:Buffer Manager\*

      &lt;br /&gt;\\.\MSSQL$BTS:Buffer Node(*)\*

      &lt;br /&gt;\\.\MSSQL$BTS:Buffer Partition(*)\*

      &lt;br /&gt;\\.\MSSQL$BTS:Databases(*)\*

      &lt;br /&gt;\\.\MSSQL$BTS:General Statistics\*

      &lt;br /&gt;\\.\MSSQL$BTS:Latches\*

      &lt;br /&gt;\\.\MSSQL$BTS:Locks(*)\*

      &lt;br /&gt;\\.\MSSQL$BTS:Memory Manager\*

      &lt;br /&gt;\\.\MSSQL$BTS:SQL Statistics\*

      &lt;br /&gt;\\.\MSSQL$BTS:Transactions\*

      &lt;br /&gt;\\.\MSSQL$BTS:Wait Statistics(*)\*

      &lt;br /&gt;\\.\MSSQL$BTS:Plan Cache\* &lt;/p&gt;

    &lt;p&gt;&lt;font color="#ff9914"&gt;System performance counters&lt;/font&gt; 

      &lt;br /&gt;\\.\Objects\*

      &lt;br /&gt;\\.\Memory\*

      &lt;br /&gt;\\.\Paging File(*)\*

      &lt;br /&gt;\\.\PhysicalDisk(*)\*

      &lt;br /&gt;\\.\Process(*)\*

      &lt;br /&gt;\\.\Processor(*)\*

      &lt;br /&gt;\\.\Network Interface(*)\*

      &lt;br /&gt;\\.\TCPV4(*)\*

      &lt;br /&gt;\\.\LogicalDisk(*)\*

      &lt;br /&gt;\\.\System\*&lt;/p&gt;
  &lt;/blockquote&gt;
&lt;/ul&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;div align="justify"&gt;Take into account that the WCF adapters do not provide their own performance counters. However, you can monitor the performance counters of Windows Communication Foundation (WCF) to gauge the performance of the WCF Receive Locations. To use the WCF performance counters for the WCF receive locations, you have to enable the performance counters for the host instances running the receive locations. See &lt;a href="http://msdn.microsoft.com/en-us/library/bb743622(BTS.10).aspx"&gt;WCF Adapters Performance Counters&lt;/a&gt; for more information on this topic.&amp;#160; &lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;Another interesting feature provided by Visual Studio is the possibility to define one or multiple threshold rules on individual performance counters to monitor system resource usage or the respect of performance-related SLAs during a load test. Counter set definitions contain predefined threshold rules for many key performance counters, but you can create specific rules for any performance counter. See &lt;a href="http://msdn.microsoft.com/en-us/library/ms404675.aspx"&gt;About Threshold Rules&lt;/a&gt; for more information on this topic.&lt;/div&gt;

    &lt;div align="justify"&gt;Let’s make an example using my use case. During the scope phase of my performance lab I specify the following performance goal:&lt;/div&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;font color="#ff9914"&gt;Latency: &lt;/font&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
  &lt;ul&gt;
    &lt;li&gt;warning: response time &amp;lt; 2 sec for 90% of messages &lt;/li&gt;

    &lt;li&gt;critical: response time &amp;lt; 5 sec for 99% of messages 
      &lt;br /&gt;&lt;/li&gt;
  &lt;/ul&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;In order to be notified during a test run that a response time exceeded one the threshold above, I can create a custom threshold rule. Nice, but how can I accomplish this task and which performance counter should I use? Let’s start asking to this latter question. The suitable performance counters for measuring the latency of a Request-Response WCF Receive Location are the following: 
      &lt;br /&gt;&lt;/div&gt;

    &lt;ul&gt;
      &lt;li&gt;\\.\BizTalk:Messaging Latency(&amp;lt;Host running your WCF Receive Location&amp;gt;)\Request-Response Latency (sec) &lt;/li&gt;

      &lt;li&gt;\\.\ServiceModelService 3.0.0.0(&amp;lt;the service corresponding to your WCF Receive Location&amp;gt;)\Calls Duration &lt;/li&gt;

      &lt;li&gt;\\.\ServiceModelEndpoint 3.0.0.0(&amp;lt;the endpoint used by your WCF Receive Location&amp;gt;)\Calls Duration &lt;/li&gt;

      &lt;li&gt;\\.\ServiceModelEOperation 3.0.0.0(&amp;lt;the endpoint used by your WCF Receive Location&amp;gt;)\Calls Duration 
        &lt;br /&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;In order to create a threshold on the Request-Response Latency (sec) performance counter, you can expand the BizTalk Server Counter Set and browse to the counter. Now right click the corresponding node and select the Add Threshold Rule from the drop menu:&lt;/div&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/UsingVisualStudio20052008ToGenerateLoadA_D1E2/NewLoadTestWizard11_2.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="NewLoadTestWizard11" border="0" alt="NewLoadTestWizard11" src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/UsingVisualStudio20052008ToGenerateLoadA_D1E2/NewLoadTestWizard11_thumb.jpg" width="800" height="587" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;div align="justify"&gt;In the Add Threshold Rule dialog, select Compare Constant in the left panel and assign: 
      &lt;br /&gt;&lt;/div&gt;

    &lt;ul&gt;
      &lt;li&gt;
        &lt;div align="justify"&gt;True to the Alert If Over property to indicate that a threshold violation occurs when the performance counter value is greater then the threshold value.&lt;/div&gt;
      &lt;/li&gt;

      &lt;li&gt;
        &lt;div align="justify"&gt;2 to the Warning Threshold Value property.&lt;/div&gt;
      &lt;/li&gt;

      &lt;li&gt;
        &lt;div align="justify"&gt;5 to the Critical Threshold Value property. &lt;/div&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
  &lt;p align="justify"&gt;Click the OK button to confirm. See &lt;a href="http://msdn.microsoft.com/en-us/library/ms404665.aspx"&gt;How to: Add a Threshold Rule&lt;/a&gt; for more information on this topic&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p align="justify"&gt;&lt;a href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/UsingVisualStudio20052008ToGenerateLoadA_D1E2/NewLoadTestWizard12_4.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="NewLoadTestWizard12" border="0" alt="NewLoadTestWizard12" src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/UsingVisualStudio20052008ToGenerateLoadA_D1E2/NewLoadTestWizard12_thumb_1.jpg" width="649" height="503" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;div align="justify"&gt;You can repeat the same process and set a Threshold Rule to be alerted when the throughput of your application goes below a certain threshold. A good candidate to measure the throughput of a BizTalk application composed by one or multiple orchestration is the&amp;#160; \\.\XLANG/s Orchestrations(&amp;lt;Host&amp;gt;)\Orchestration completed/sec performance counter. However, in this case I will set the value of the Alert If Over property to False to indicate that a threshold violation occurs when the performance counter value is less then the threshold value (in the sample below 20 and 10 are respectively the Warning and Critical Threshold Values).&lt;/div&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/UsingVisualStudio20052008ToGenerateLoadA_D1E2/NewLoadTestWizard13_2.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="NewLoadTestWizard13" border="0" alt="NewLoadTestWizard13" src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/UsingVisualStudio20052008ToGenerateLoadA_D1E2/NewLoadTestWizard13_thumb.jpg" width="649" height="503" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p align="justify"&gt;At runtime, threshold violations can be reviewed clicking the threshold violation link under the Load Test toolbar. If the counter in question is exposed&amp;#160; by a Graph, each threshold violations is signaled with a yellow triangle.&lt;/p&gt;

&lt;p align="justify"&gt;At this point I’m ready to launch a load test, so I can just press the start button. In order to create a custom Graph to monitor most relevant counters I proceed as follows:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;div align="justify"&gt;I click the Add New Graph button on the Load Test toolbar (highlighted in the picture below), I specify a name for my new Graph in the Enter Graph Name dialog and then I press the OK button to confirm.&lt;/div&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p align="justify"&gt;&lt;a href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/UsingVisualStudio20052008ToGenerateLoadA_D1E2/LoadTestCreateGraph_2.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="LoadTestCreateGraph" border="0" alt="LoadTestCreateGraph" src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/UsingVisualStudio20052008ToGenerateLoadA_D1E2/LoadTestCreateGraph_thumb.jpg" width="800" height="587" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;div align="justify"&gt;Now, it’s sufficient to select, drag &amp;amp; drop counters from the Counter panel to the newly created Graph. For the sake of I completeness, during my demo I created a graph called BizTalk Server and I dragged and dropped the following performance counters: 
      &lt;br /&gt;&lt;/div&gt;

    &lt;ul&gt;
      &lt;li&gt;
        &lt;div align="justify"&gt;\\.\BizTalk:Messaging Latency(BizTalkServerIsolatedHost)\Request-Response Latency (sec)&lt;/div&gt;
      &lt;/li&gt;

      &lt;li&gt;
        &lt;div align="justify"&gt;\\.\BizTalk:Messaging (BizTalkServerIsolatedHost)\Documents received/sec&lt;/div&gt;
      &lt;/li&gt;

      &lt;li&gt;
        &lt;div align="justify"&gt;\.\XLANG/s Orchestrations(BizTalkServerApplication)\Orchestration completed/sec &lt;/div&gt;
      &lt;/li&gt;

      &lt;li&gt;
        &lt;div align="justify"&gt;\.\BizTalk:Message Box:General Counters(biztalkmsgboxdb:babo)\Spool Size 
          &lt;br /&gt;&lt;/div&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;I strongly suggest to repeat the process and create a custom Graph to monitor the most relevant performance counters exposed by the SQL Server instance or instances that host the most solicited BizTalk Server databases: 
      &lt;br /&gt;&lt;/div&gt;

    &lt;ul&gt;
      &lt;li&gt;
        &lt;div align="justify"&gt;BizTalkMsgBoxDb and any additional MessageBox.&lt;/div&gt;
      &lt;/li&gt;

      &lt;li&gt;
        &lt;div align="justify"&gt;BizTalkDTADb if global tracking is turned on.&lt;/div&gt;
      &lt;/li&gt;

      &lt;li&gt;
        &lt;div align="justify"&gt;BAMPrimaryImport if the application makes use of BAM.&lt;/div&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
  &lt;p align="justify"&gt;and any custom databases used by the application.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p align="justify"&gt;When the load test is over, you can review the results on the Summary Page:&lt;/p&gt;

&lt;p align="justify"&gt;&lt;a href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/UsingVisualStudio20052008ToGenerateLoadA_D1E2/LoadTestSummary_2.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="LoadTestSummary" border="0" alt="LoadTestSummary" src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/UsingVisualStudio20052008ToGenerateLoadA_D1E2/LoadTestSummary_thumb.jpg" width="800" height="587" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p align="justify"&gt;You can also click the links in the Test Results and Transaction Results tables to navigate to a page where you can review more in detail test results, errors and threshold violations.&lt;/p&gt;

&lt;p align="justify"&gt;&lt;font color="#ff9914"&gt;&lt;strong&gt;Summary&lt;/strong&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p align="justify"&gt;Visual Studio Test Edition is a powerful suite to rapidly build Unit and Load Tests to conduct performance and stress tests against your BizTalk application. We assumed&amp;#160; that the application in question was exposed via a WCF Two-Way Receive Location, but the approach exposed in the present post can be customized and extended to other scenarios where the application makes use of other Adapter to expose its services. &lt;a href="http://cid-09dba4a06b360a65.skydrive.live.com/self.aspx/Pubblica/WCFLoadTest.zip"&gt;Here&lt;/a&gt; you can download the Test Project I used to conduct tests against the HandleXLANGMessages application.&amp;#160; See &lt;a href="http://blogs.msdn.com/paolos/archive/2009/09/10/4-different-ways-to-process-an-xlangmessage-within-an-helper-component-invoked-by-an-orchestration.aspx"&gt;Part1&lt;/a&gt; and &lt;a href="http://blogs.msdn.com/paolos/archive/2009/09/21/4-different-ways-to-process-an-xlangmessage-within-an-helper-component-invoked-by-an-orchestration-part-2.aspx"&gt;Part2&lt;/a&gt; for more information.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9898855" width="1" height="1"&gt;</description></item><item><title>4 Different ways to process an XLANGMessage within an helper component invoked by an orchestration Part 2</title><link>http://blogs.msdn.com/paolos/archive/2009/09/21/4-different-ways-to-process-an-xlangmessage-within-an-helper-component-invoked-by-an-orchestration-part-2.aspx</link><pubDate>Mon, 21 Sep 2009 17:02:43 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9897546</guid><dc:creator>leprino</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/paolos/comments/9897546.aspx</comments><wfw:commentRss>http://blogs.msdn.com/paolos/commentrss.aspx?PostID=9897546</wfw:commentRss><wfw:comment>http://blogs.msdn.com/paolos/rsscomments.aspx?PostID=9897546</wfw:comment><description>&lt;p&gt;&lt;/p&gt;  &lt;p align="justify"&gt;In the &lt;a href="http://blogs.msdn.com/paolos/archive/2009/09/10/4-different-ways-to-process-an-xlangmessage-within-an-helper-component-invoked-by-an-orchestration.aspx"&gt;first part&lt;/a&gt; of the article we introduced and analyzed 4 different techniques to process an &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.xlangs.basetypes.xlangmessage(BTS.10).aspx"&gt;XLANGMessage&lt;/a&gt; within a business component invoked by an orchestration. In the second part we’ll compare these design patterns from a performance perspective. To this purpose I conducted some tests against the asynchronous version of each use case to measure and compare their latency and throughput. In particular, I used a floodgate approach when running test cases in order to isolate orchestration processing from message receiving and sending. To achieve this result I used &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=c8af583f-7044-48db-b7b9-969072df1689&amp;amp;DisplayLang=en"&gt;BizTalk LoadGen 2007&lt;/a&gt; followed the steps below at each test run.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;I ran the &lt;a href="http://msdn.microsoft.com/en-us/library/bb727781(BTS.10).aspx"&gt;bts_CleanupMsgbox&lt;/a&gt; stored procedure to delete any unprocessed or suspended messages and any pending service instances within the BizTalkMsgBoxDb. &lt;/li&gt;    &lt;li&gt;I stopped the BizTalkServerApplication host instance that is responsible for running orchestrations. &lt;/li&gt;    &lt;li&gt;I stopped the BizTalkServerSendHost host instance that is responsible for running send ports. &lt;/li&gt;    &lt;li&gt;I stopped the FILE Send Port which consumes response messages generated by orchestrations. This way the send port subscription remains active and the response documents published to the BizTalkMsgBoxDb by the asynchronous orchestrations become suspended (resumable) messages. &lt;/li&gt;    &lt;li&gt;I stopped all the orchestrations using the BizTalk Administration Console. &lt;/li&gt;    &lt;li&gt;I created and launched a script that exploited &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=c8af583f-7044-48db-b7b9-969072df1689&amp;amp;DisplayLang=en"&gt;BizTalk LoadGen 2007&lt;/a&gt;&amp;#160; to generate a configurable amount of messages within a given folder. &lt;/li&gt;    &lt;li&gt;I started another in-process host instance called BizTalkServerReceiveHost. &lt;/li&gt;    &lt;li&gt;A OneWay FILE Receive Location hosted by BizTalkServerReceiveHost was used to read and publish those messages to the BizTalkMsgBoxDb. &lt;/li&gt;    &lt;li&gt;I started an instance of the Performance Monitor (perfmon.exe) to monitor performance counters. In particular, I used the \\.\BizTalk:Message Box:General Counters(biztalkmsgboxdb:babo)\Spool Size counter to confirm that all messages were successfully published to the BizTalkMsgBoxDb. &lt;/li&gt;    &lt;li&gt;At the this point, on the BizTalk Administration Console I started the orchestration used by the current test case. &lt;/li&gt;    &lt;li&gt;I clicked the Suspended Services Instances link on the Group Overview page within the BizTalk Administration Console to retrieve all suspended messages. &lt;/li&gt;    &lt;li&gt;I right-clicked the summary row containing the total number of resumable messages. &lt;/li&gt;    &lt;li&gt;I launched a script that:      &lt;ul&gt;       &lt;li&gt;stopped the BizTalkServerReceiveHost; &lt;/li&gt;        &lt;li&gt;started the BizTalkServerApplication; &lt;/li&gt;        &lt;li&gt;started the performance log to measure relevant BizTalk, SQL and System performance counter. &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt;    &lt;li&gt;I resumed all messages. This operations started the real test run as each resumed message was processed by a separate orchestration instance. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;In order to automate the steps above, I created a bunch of scripts that you can download &lt;a href="http://cid-09dba4a06b360a65.skydrive.live.com/self.aspx/Pubblica/HandleXLANGMessages.zip"&gt;here&lt;/a&gt; along with the code.     &lt;br /&gt;I conducted my tests using 3 different message sizes:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Small Size Message: 10 operations, 3 KB. &lt;/li&gt;    &lt;li&gt;Medium Size Message: 1,000 operations, 249 KB. &lt;/li&gt;    &lt;li&gt;Large Size Message: 10,000 operations, 2,485 KB. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;For the sake of completeness, I conducted tests on my laptop, not really the kind of harness that should be used for performance testing:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Windows Server 2008 R2 64-bit. &lt;/li&gt;    &lt;li&gt;SQL Server 2008 SP1 EE 64-bit . &lt;/li&gt;    &lt;li&gt;BizTalk Server 2009 64-bit EE &lt;/li&gt;    &lt;li&gt;1 dual-core CPU. &lt;/li&gt;    &lt;li&gt;4 GB RAM &lt;/li&gt; &lt;/ul&gt;  &lt;p align="justify"&gt;The tables below report test results. I encourage you to perform long running tests on a production-like environment composed of multiple machines to obtain more significant and relevant results.&amp;#160; Take into account that I had just the time to run a couple of tests for each use case. Nevertheless, the results obtained are quite interesting and in line with expectations: in fact they confirm that using an XmlDocument to process the content of an XLANGMessage is extremely handy and powerful, but it can easily lead to high memory usage and performance degradation, especially when dealing with large messages.&lt;/p&gt;  &lt;p&gt;&lt;font color="#ff9914"&gt;Small Size Messages&lt;/font&gt;&lt;/p&gt;  &lt;table border="1" cellspacing="0" cellpadding="5" width="940" bgcolor="#ffffff"&gt;&lt;tbody&gt;     &lt;tr bgcolor="#333333"&gt;       &lt;td width="144"&gt;Test Case&lt;/td&gt;        &lt;td width="116"&gt;# Messages/Test&lt;/td&gt;        &lt;td width="153"&gt;# Operations/Message&lt;/td&gt;        &lt;td width="162"&gt;Message Size (Kb)&lt;/td&gt;        &lt;td width="152"&gt;Elapsed Time (Sec)&lt;/td&gt;        &lt;td width="98"&gt;Messages/Sec&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td&gt;&lt;font color="#000000"&gt;AsyncXmlDocumentOrchestration&lt;/font&gt;&lt;/td&gt;        &lt;td&gt;&lt;font color="#000000"&gt;5,000&lt;/font&gt;&lt;/td&gt;        &lt;td&gt;&lt;font color="#000000"&gt;10&lt;/font&gt;&lt;/td&gt;        &lt;td&gt;&lt;font color="#000000"&gt;3&lt;/font&gt;&lt;/td&gt;        &lt;td&gt;&lt;font color="#000000"&gt;104&lt;/font&gt;&lt;/td&gt;        &lt;td&gt;&lt;font color="#000000"&gt;47.204&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td&gt;&lt;font color="#000000"&gt;AsyncStreamOrchestration&lt;/font&gt;&lt;/td&gt;        &lt;td&gt;&lt;font color="#000000"&gt;5,000&lt;/font&gt;&lt;/td&gt;        &lt;td&gt;&lt;font color="#000000"&gt;10&lt;/font&gt;&lt;/td&gt;        &lt;td&gt;&lt;font color="#000000"&gt;3&lt;/font&gt;&lt;/td&gt;        &lt;td&gt;&lt;font color="#000000"&gt;87&lt;/font&gt;&lt;/td&gt;        &lt;td&gt;&lt;font color="#000000"&gt;58.085&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td&gt;&lt;font color="#000000"&gt;AsyncMessageClassesOrchestration&lt;/font&gt;&lt;/td&gt;        &lt;td&gt;&lt;font color="#000000"&gt;5,000&lt;/font&gt;&lt;/td&gt;        &lt;td&gt;&lt;font color="#000000"&gt;10&lt;/font&gt;&lt;/td&gt;        &lt;td&gt;&lt;font color="#000000"&gt;3&lt;/font&gt;&lt;/td&gt;        &lt;td&gt;&lt;font color="#000000"&gt;71&lt;/font&gt;&lt;/td&gt;        &lt;td&gt;&lt;font color="#000000"&gt;71.434&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td&gt;&lt;font color="#000000"&gt;AsyncCustomBTXMessageOrchestration&lt;/font&gt;&lt;/td&gt;        &lt;td&gt;&lt;font color="#000000"&gt;5,000&lt;/font&gt;&lt;/td&gt;        &lt;td&gt;&lt;font color="#000000"&gt;10&lt;/font&gt;&lt;/td&gt;        &lt;td&gt;&lt;font color="#000000"&gt;3&lt;/font&gt;&lt;/td&gt;        &lt;td&gt;&lt;font color="#000000"&gt;66&lt;/font&gt;&lt;/td&gt;        &lt;td&gt;&lt;font color="#000000"&gt;75.099&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;&lt;font color="#ff9914"&gt;Medium Size Messages&lt;/font&gt;&lt;/p&gt;  &lt;table border="1" cellspacing="0" cellpadding="5" width="940" bgcolor="#ffffff"&gt;&lt;tbody&gt;     &lt;tr bgcolor="#333333"&gt;       &lt;td width="144"&gt;Test Case&lt;/td&gt;        &lt;td width="116"&gt;# Messages/Test&lt;/td&gt;        &lt;td width="153"&gt;# Operations/Message&lt;/td&gt;        &lt;td width="162"&gt;Message Size (Kb)&lt;/td&gt;        &lt;td width="152"&gt;Elapsed Time (Sec)&lt;/td&gt;        &lt;td width="98"&gt;Messages/Sec&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td&gt;&lt;font color="#000000"&gt;AsyncXmlDocumentOrchestration&lt;/font&gt;&lt;/td&gt;        &lt;td&gt;&lt;font color="#000000"&gt;10,000&lt;/font&gt;&lt;/td&gt;        &lt;td&gt;&lt;font color="#000000"&gt;1,000&lt;/font&gt;&lt;/td&gt;        &lt;td&gt;&lt;font color="#000000"&gt;249&lt;/font&gt;&lt;/td&gt;        &lt;td&gt;&lt;font color="#000000"&gt;240&lt;/font&gt;&lt;/td&gt;        &lt;td&gt;&lt;font color="#000000"&gt;42.009&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td&gt;&lt;font color="#000000"&gt;AsyncStreamOrchestration&lt;/font&gt;&lt;/td&gt;        &lt;td&gt;&lt;font color="#000000"&gt;10,000&lt;/font&gt;&lt;/td&gt;        &lt;td&gt;&lt;font color="#000000"&gt;1,000&lt;/font&gt;&lt;/td&gt;        &lt;td&gt;&lt;font color="#000000"&gt;249&lt;/font&gt;&lt;/td&gt;        &lt;td&gt;&lt;font color="#000000"&gt;224&lt;/font&gt;&lt;/td&gt;        &lt;td&gt;&lt;font color="#000000"&gt;46.476&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td&gt;&lt;font color="#000000"&gt;AsyncMessageClassesOrchestration&lt;/font&gt;&lt;/td&gt;        &lt;td&gt;&lt;font color="#000000"&gt;10,000&lt;/font&gt;&lt;/td&gt;        &lt;td&gt;&lt;font color="#000000"&gt;1,000&lt;/font&gt;&lt;/td&gt;        &lt;td&gt;&lt;font color="#000000"&gt;249&lt;/font&gt;&lt;/td&gt;        &lt;td&gt;&lt;font color="#000000"&gt;188&lt;/font&gt;&lt;/td&gt;        &lt;td&gt;&lt;font color="#000000"&gt;54.936&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td&gt;&lt;font color="#000000"&gt;AsyncCustomBTXMessageOrchestration&lt;/font&gt;&lt;/td&gt;        &lt;td&gt;&lt;font color="#000000"&gt;10,000&lt;/font&gt;&lt;/td&gt;        &lt;td&gt;&lt;font color="#000000"&gt;1,000&lt;/font&gt;&lt;/td&gt;        &lt;td&gt;&lt;font color="#000000"&gt;249&lt;/font&gt;&lt;/td&gt;        &lt;td&gt;&lt;font color="#000000"&gt;181&lt;/font&gt;&lt;/td&gt;        &lt;td&gt;&lt;font color="#000000"&gt;61.396&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;&lt;font color="#ff9914"&gt;Large Size Messages&lt;/font&gt;&lt;/p&gt;  &lt;table border="1" cellspacing="0" cellpadding="5" width="940" bgcolor="#ffffff"&gt;&lt;tbody&gt;     &lt;tr bgcolor="#333333"&gt;       &lt;td width="144"&gt;Test Case&lt;/td&gt;        &lt;td width="116"&gt;# Messages/Test&lt;/td&gt;        &lt;td width="153"&gt;# Operations/Message&lt;/td&gt;        &lt;td width="162"&gt;Message Size (Kb)&lt;/td&gt;        &lt;td width="152"&gt;Elapsed Time (Sec)&lt;/td&gt;        &lt;td width="98"&gt;Messages/Sec&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td width="144"&gt;&lt;font color="#000000"&gt;AsyncXmlDocumentOrchestration&lt;/font&gt;&lt;/td&gt;        &lt;td width="116"&gt;&lt;font color="#000000"&gt;1,000&lt;/font&gt;&lt;/td&gt;        &lt;td width="153"&gt;&lt;font color="#000000"&gt;10,000&lt;/font&gt;&lt;/td&gt;        &lt;td width="162"&gt;&lt;font color="#000000"&gt;2,485&lt;/font&gt;&lt;/td&gt;        &lt;td width="152"&gt;&lt;font color="#000000"&gt;182&lt;/font&gt;&lt;/td&gt;        &lt;td width="98"&gt;&lt;font color="#000000"&gt;5.521&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td width="144"&gt;&lt;font color="#000000"&gt;AsyncStreamOrchestration&lt;/font&gt;&lt;/td&gt;        &lt;td width="116"&gt;&lt;font color="#000000"&gt;1,000&lt;/font&gt;&lt;/td&gt;        &lt;td width="153"&gt;&lt;font color="#000000"&gt;10,000&lt;/font&gt;&lt;/td&gt;        &lt;td width="162"&gt;&lt;font color="#000000"&gt;2,485&lt;/font&gt;&lt;/td&gt;        &lt;td width="152"&gt;&lt;font color="#000000"&gt;84&lt;/font&gt;&lt;/td&gt;        &lt;td width="98"&gt;&lt;font color="#000000"&gt;11.905&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td width="144"&gt;&lt;font color="#000000"&gt;AsyncMessageClassesOrchestration&lt;/font&gt;&lt;/td&gt;        &lt;td width="116"&gt;&lt;font color="#000000"&gt;1,000&lt;/font&gt;&lt;/td&gt;        &lt;td width="153"&gt;&lt;font color="#000000"&gt;10,000&lt;/font&gt;&lt;/td&gt;        &lt;td width="162"&gt;&lt;font color="#000000"&gt;2,485&lt;/font&gt;&lt;/td&gt;        &lt;td width="152"&gt;&lt;font color="#000000"&gt;93&lt;/font&gt;&lt;/td&gt;        &lt;td width="98"&gt;&lt;font color="#000000"&gt;10.964&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td width="144"&gt;&lt;font color="#000000"&gt;AsyncCustomBTXMessageOrchestration&lt;/font&gt;&lt;/td&gt;        &lt;td width="116"&gt;&lt;font color="#000000"&gt;1,000&lt;/font&gt;&lt;/td&gt;        &lt;td width="153"&gt;&lt;font color="#000000"&gt;10,000&lt;/font&gt;&lt;/td&gt;        &lt;td width="162"&gt;&lt;font color="#000000"&gt;2,485&lt;/font&gt;&lt;/td&gt;        &lt;td width="152"&gt;&lt;font color="#000000"&gt;78&lt;/font&gt;&lt;/td&gt;        &lt;td width="98"&gt;&lt;font color="#000000"&gt;12.718&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;&lt;font color="#ff9914"&gt;Diagrams&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;The following diagrams summarize the results contained in the tables above and visualize the differences among the various use cases in terms of latency (elapsed time) and scalability (messages/sec).&lt;/p&gt;  &lt;p&gt;&lt;font color="#ff9914"&gt;Latency&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/4DifferentwaystoprocessanXLANGMessagewit_D4EC/Latency_2.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Latency" border="0" alt="Latency" src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/4DifferentwaystoprocessanXLANGMessagewit_D4EC/Latency_thumb.jpg" width="771" height="608" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#ff9914"&gt;Throughput&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/4DifferentwaystoprocessanXLANGMessagewit_D4EC/Throughput_2.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Throughput" border="0" alt="Throughput" src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/4DifferentwaystoprocessanXLANGMessagewit_D4EC/Throughput_thumb.jpg" width="771" height="608" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9897546" width="1" height="1"&gt;</description></item><item><title>4 Different ways to process an XLANGMessage within an helper component invoked by an orchestration Part 1</title><link>http://blogs.msdn.com/paolos/archive/2009/09/10/4-different-ways-to-process-an-xlangmessage-within-an-helper-component-invoked-by-an-orchestration.aspx</link><pubDate>Thu, 10 Sep 2009 19:44:23 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9893750</guid><dc:creator>leprino</dc:creator><slash:comments>5</slash:comments><comments>http://blogs.msdn.com/paolos/comments/9893750.aspx</comments><wfw:commentRss>http://blogs.msdn.com/paolos/commentrss.aspx?PostID=9893750</wfw:commentRss><wfw:comment>http://blogs.msdn.com/paolos/rsscomments.aspx?PostID=9893750</wfw:comment><description>&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 .cls { color: #2b91af}
.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 align="justify"&gt;One of the most common scenarios in BizTalk applications is when an orchestration receives and processes an incoming XML document to produce a result message. Sometimes this latter can be generated just transforming the inbound message with a map, but in another cases the orchestration has to invoke&amp;#160; a method exposed by a helper component which contains the necessary business logic to process the request document and produce a new XML response message. Usually the signature of this method is similar to the following code snippet: &lt;/p&gt;  &lt;table border="1" cellspacing="0" cellpadding="5" width="800" bgcolor="#ffffff"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="800"&gt;         &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="cls"&gt;XmlDocument&lt;/span&gt; ProcessRequestReturnXmlDocument(&lt;span class="cls"&gt;XLANGMessage&lt;/span&gt; message)&lt;/pre&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p align="justify"&gt;As you can see, the method above does not return an &lt;font color="#ff9914"&gt;XLANGMessage&lt;/font&gt; object as expected and the reason is quite straightforward: the only constructor exposed by the &lt;font color="#ff9914"&gt;XLANGMessage&lt;/font&gt; class contained in the &lt;font color="#ff9914"&gt;Microsoft.XLANGs.BaseTypes&lt;/font&gt; assembly is protected and inaccessible to user code. The &lt;font color="#ff9914"&gt;XmlDocument&lt;/font&gt; is commonly used by developers to read the entire content of an XML message part using a single line of code (&lt;font color="#ff9914"&gt;document.DocumentElement.OuterXml&lt;/font&gt;)and to access the value of one or multiple elements using an &lt;font color="#ff9914"&gt;XPath&lt;/font&gt; expression and the &lt;font color="#ff9914"&gt;SelectSingleNode&lt;/font&gt;/&lt;font color="#ff9914"&gt;SelectNodes&lt;/font&gt; methods exposed by the class. Using an instance of the &lt;font color="#ff9914"&gt;XmlDocument&lt;/font&gt; class to manipulate the content of an &lt;font color="#ff9914"&gt;XLANGMessage&lt;/font&gt; is a flexible and handy technique, but it can easily lead to out of memory exceptions when dealing with large messages or with a significant amount of medium-size messages within the same host process. In fact, the use of an &lt;font color="#ff9914"&gt;XmlDocument&lt;/font&gt; instance forces the message content to be entirely loaded into memory in order to build the object graph for the DOM and the total amount of memory used by a single instance of this class can grow up to 10 times the actual message size. See the following articles for more information on this topic:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;div align="justify"&gt;“&lt;a href="http://msdn.microsoft.com/en-us/library/ee377042(BTS.10).aspx"&gt;Optimizing Orchestration Performance&lt;/a&gt;” article in the Microsoft BizTalk Server 2009 Performance Optimization Guide.&lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;“&lt;a href="http://msdn.microsoft.com/en-us/library/ee377087(BTS.10).aspx"&gt;Optimizing Memory Usage with Streaming&lt;/a&gt;” article in the Microsoft BizTalk Server 2009 Performance Optimization Guide.&lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;“&lt;a href="http://msdn.microsoft.com/en-us/library/ee377071(BTS.10).aspx"&gt;Optimizing Pipeline Performance&lt;/a&gt;” article in the Microsoft BizTalk Server 2009 Performance Optimization Guide.&lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;“&lt;a href="http://www.masteringbiztalk.com/blogs/jon/PermaLink,guid,e39cd386-0e62-46c6-87b6-3625f9a80d6d.aspx"&gt;Orchestration Performance&lt;/a&gt;” article on&amp;#160; Jon Flanders' Blog for some performance numbers when using the DOM.&lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;“&lt;a href="http://msdn.microsoft.com/en-us/library/ms998530.aspx"&gt;Improving XML Performance&lt;/a&gt;” chapter in the Improving .NET Application Performance and Scalability guide.&lt;/div&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p align="justify"&gt;Some months ago I decided to create a sample to compare the different techniques that can be used when invoking an helper component within an orchestration to process the request message and produce a response XML document. The 4 use cases described below have been fully tested on both BizTalk Server 2006 R2 and BizTalk Server 2009. Below you can find a pointer to the BizTalk Server 2009 version of the code. All the use cases are exposed by the same 2 Request-Response WCF Receive Locations:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;font color="#ff9914"&gt;HXM.Calculator.WCF-BasicHttp.ReceiveLocation&lt;/font&gt;: a WCF-BasicHttp Receive Location hosted by the BizTalkServerIsolatedHost. &lt;/li&gt;

  &lt;li&gt;&lt;font color="#ff9914"&gt;HXM.Calculator.WCF-Custom.ReceiveLocation&lt;/font&gt;: a WCF-Custom Receive Location hosted by an in-process host which uses a CustomBinding&amp;#160; composed of the BinaryMessageEncodingBindingElement + TcpTransportBindingElement. &lt;/li&gt;
&lt;/ul&gt;

&lt;p align="justify"&gt;The 4 test cases implement the same scenario using a different approach. They all process the operations contained within the CalculatorRequest message and&amp;#160; return a CalculatorResponse document containing results.&lt;/p&gt;

&lt;p align="justify"&gt;&lt;font color="#ff9914"&gt;CalculatorRequest&lt;/font&gt; &lt;/p&gt;

&lt;table border="1" cellspacing="0" cellpadding="5" width="800" bgcolor="#ffffff"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="800"&gt;
        &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;CalculatorRequest&lt;/span&gt; &lt;span class="attr"&gt;mlns&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;http://Microsoft.BizTalk.CAT.Samples.HandleXLANGMessages.Schemas.CalculatorRequest&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Method&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;XmlDocumentOrchestration&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Method&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Operations&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Operation&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Operator&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;+&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Operator&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Operand1&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;82&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Operand1&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Operand2&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;18&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Operand2&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Operation&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Operation&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Operator&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;-&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Operator&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Operand1&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;30&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Operand1&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Operand2&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;12&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Operand2&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Operation&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Operation&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Operator&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;*&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Operator&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Operand1&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;25&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Operand1&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Operand2&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;8&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Operand2&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Operation&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Operation&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Operator&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;\&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Operator&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Operand1&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;100&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Operand1&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Operand2&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;25&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Operand2&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Operation&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Operation&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Operator&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;+&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Operator&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Operand1&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;100&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Operand1&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Operand2&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;32&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Operand2&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Operation&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Operations&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;CalculatorRequest&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;&lt;font color="#ff9914"&gt;ResponseMessage&lt;/font&gt;&lt;/p&gt;

&lt;table border="1" cellspacing="0" cellpadding="5" width="800" bgcolor="#ffffff"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="800"&gt;
        &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;CalculatorResponse&lt;/span&gt; &lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;http://Microsoft.BizTalk.CAT.Samples.HandleXLANGMessages.Schemas.CalculatorResponse&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Status&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;Ok&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Status&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Results&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Result&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Value&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;100&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Value&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Error&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;None&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Error&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Result&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Result&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Value&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;18&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Value&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Error&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;None&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Error&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Result&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Result&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Value&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;200&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Value&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Error&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;None&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Error&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Result&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Result&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Value&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;4&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Value&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Error&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;None&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Error&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Result&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Result&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Value&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;132&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Value&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Error&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;None&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Error&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Result&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Results&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;CalculatorResponse&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p align="justify"&gt;I created a BizTalk project called Schemas to create the XML schemas that define and model the structure of the CalculatorRequest and CalculatorResponse messages. Then I created another project called Orchestrations and I implemented a different orchestration for each technique:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;div align="justify"&gt;&lt;font color="#ff9914"&gt;XmlDocumentOrchestration&lt;/font&gt;: the helper component invoked by the orchestration uses an XmlDocument object and in particular the SelectNodes method to read data of each operation within the incoming request message and another XmlDocument instance to create the outbound response document which contains results.&lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;&lt;font color="#ff9914"&gt;StreamOrchestration&lt;/font&gt;: the helper component invoked by the orchestration uses a VirtualStream and an XmlReader to read the content of the request message and uses a VirtualStream and an XmlWriter to generate the response message.&lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;&lt;font color="#ff9914"&gt;MessageClassesOrchestration&lt;/font&gt;: the helper component invoked by the orchestration deserializes the CalculatorRequest message to an instance of the CalculatorRequest .NET class, loops through the collections of operations and stores results within a new instance of the CalculatorResponse class. This latter is then serialized to an XML stream within the orchestration.&lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;&lt;font color="#ff9914"&gt;CustomBtxMessageOrchestration&lt;/font&gt;: This is probably the most tricky and interesting test case. In fact, the helper component uses an XmlReader to process the data contained in the CalculatorRequest&amp;#160; message and a uses VirtualStream and and XmlWriter to generate the response message. However, instead of returning a Stream object as the method invoked by the StreamOrchestration, this method creates and returns a brand new XLANGMessage. See below for more details.&lt;/div&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p align="justify"&gt;I created an asynchronous, one-way version for each of the above use cases. In this case requests are submitted to BizTalk via a one-way FILE Receive Location while the response documents generated by each orchestration are persisted to another folder using a one-way FILE Send Port.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;div align="justify"&gt;&lt;font color="#ff9914"&gt;AsyncXmlDocumentOrchestration&lt;/font&gt;: the helper component invoked by the orchestration uses an XmlDocument object and in particular the SelectNodes method to read data of each operation within the incoming request message and another XmlDocument instance to create the outbound response document which contains results.&lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;&lt;font color="#ff9914"&gt;Async&lt;/font&gt;&lt;font color="#ff9914"&gt;StreamOrchestration&lt;/font&gt;: the helper component invoked by the orchestration uses a VirtualStream and an XmlReader to read the content of the request message and uses a VirtualStream and an XmlWriter to generate the response message.&lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;&lt;font color="#ff9914"&gt;Async&lt;/font&gt;&lt;font color="#ff9914"&gt;MessageClassesOrchestration&lt;/font&gt;: the helper component invoked by the orchestration deserializes the CalculatorRequest message to an instance of the CalculatorRequest .NET class, loops through the collections of operations and stores results within a new instance of the CalculatorResponse class. This latter is then serialized to an XML stream within the orchestration.&lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;&lt;font color="#ff9914"&gt;Async&lt;/font&gt;&lt;font color="#ff9914"&gt;CustomBtxMessageOrchestration&lt;/font&gt;: This is probably the most tricky and interesting test case. In fact, the helper component uses an XmlReader to process the data contained in the CalculatorRequest&amp;#160; message and a uses VirtualStream and and XmlWriter to generate the response message. However, instead of returning a Stream object as the method invoked by the StreamOrchestration, this method creates and returns a brand new XLANGMessage. See below for more details.&lt;/div&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p align="justify"&gt;Let’s review each test case in detail. Take into account that the synchronous and asynchronous version of each use case exploit exactly the same code, so in the code section I will refer only to the synchronous version.&lt;/p&gt;

&lt;p align="justify"&gt;&lt;font color="#ff9914"&gt;&lt;strong&gt;XmlDocumentOrchestration&lt;/strong&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p align="justify"&gt;The following picture depicts the architecture of the XmlDocumentOrchestration test case.&lt;/p&gt;

&lt;p align="justify"&gt;&lt;a href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/4Differentwaystoprocessanxlangmessagewit_E2DC/XmlDocumentOrchestration_2.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="XmlDocumentOrchestration" border="0" alt="XmlDocumentOrchestration" src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/4Differentwaystoprocessanxlangmessagewit_E2DC/XmlDocumentOrchestration_thumb.jpg" width="802" height="265" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;font color="#ff9914"&gt;Message Flow:&lt;/font&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;A WCF-BasicHttp or WCF-Custom Request-Response Receive Location receives a new CalculatorRequest xml document from the Test Agent/Client Application. &lt;/li&gt;

  &lt;li&gt;The XML disassembler component within the XMLTransmit pipeline promotes the Method element inside the CalculatorRequest xml document. The Message Agent submits the incoming message to the MessageBox (BizTalkMsgBoxDb). &lt;/li&gt;

  &lt;li&gt;The inbound request starts a new instance of the XmlDocumentOrchestration. This latter uses a Direct Port receive the CalculatorRequest messages with the Method promoted property = “XmlDocumentOrchestration”. &lt;/li&gt;

  &lt;li&gt;The XmlDocumentOrchestration invokes the ProcessRequestReturnXmlDocument method exposed by the RequestManager helper component. This object processes within a loop all the operations contained in the inbound XLANGMessage. In particular, the ProcessRequestReturnXmlDocument loads the entire message into an XmlDocument object and uses the XmlDocument.SelectNodes(XPathExpression) method to retrieve the operations contained in the inbound document. &lt;/li&gt;

  &lt;li&gt;The ProcessRequestReturnXmlDocument&amp;#160; method returns the response message as an XmlDocument. &lt;/li&gt;

  &lt;li&gt;The XmlDocumentOrchestration publishes the CalculatorResponse message to the MessageBox (BizTalkMsgBoxDb). &lt;/li&gt;

  &lt;li&gt;The response message is retrieved by the Request-Response WCF-BasicHttp or WCF-Custom Receive Location. &lt;/li&gt;

  &lt;li&gt;The response message is returned to the Test Agent/Client Application. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;font color="#ff9914"&gt;Orchestration:&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;The following picture shows the structure of the test XmlDocumentOrchestration.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/4Differentwaystoprocessanxlangmessagewit_E2DC/XmlDocumentOrchestration2_2.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="XmlDocumentOrchestration2" border="0" alt="XmlDocumentOrchestration2" src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/4Differentwaystoprocessanxlangmessagewit_E2DC/XmlDocumentOrchestration2_thumb.jpg" width="602" height="1031" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p align="justify"&gt;&lt;font color="#ff9914"&gt;&lt;strong&gt;AsyncXmlDocumentOrchestration&lt;/strong&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p align="justify"&gt;The following picture depicts the architecture of the AsyncXmlDocumentOrchestration test case.&lt;/p&gt;

&lt;p align="justify"&gt;&lt;a href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/4Differentwaystoprocessanxlangmessagewit_E2DC/AsyncXmlDocumentOrchestration_2.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="AsyncXmlDocumentOrchestration" border="0" alt="AsyncXmlDocumentOrchestration" src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/4Differentwaystoprocessanxlangmessagewit_E2DC/AsyncXmlDocumentOrchestration_thumb.jpg" width="806" height="269" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;font color="#ff9914"&gt;Message Flow:&lt;/font&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;A One-Way FILE Receive Location receives a new CalculatorRequest xml document from the Client Application or &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=c8af583f-7044-48db-b7b9-969072df1689&amp;amp;DisplayLang=en"&gt;Loadgen&lt;/a&gt;. &lt;/li&gt;

  &lt;li&gt;The XML disassembler component within the XMLTransmit pipeline promotes the Method element inside the CalculatorRequest xml document. The Message Agent submits the incoming message to the MessageBox (BizTalkMsgBoxDb). &lt;/li&gt;

  &lt;li&gt;The inbound request starts a new instance of the AsyncXmlDocumentOrchestration. This latter uses a Direct Port receive the CalculatorRequest messages with the Method promoted property = “AsyncXmlDocumentOrchestration”. &lt;/li&gt;

  &lt;li&gt;The AsyncXmlDocumentOrchestration invokes the ProcessRequestReturnXmlDocument method exposed by the RequestManager helper component. This object processes within a loop all the operations contained in the inbound XLANGMessage. In particular, the ProcessRequestReturnXmlDocument loads the entire message into an XmlDocument object and uses the XmlDocument.SelectNodes(XPathExpression) method to retrieve the operations contained in the inbound document. &lt;/li&gt;

  &lt;li&gt;The ProcessRequestReturnXmlDocument&amp;#160; method returns the response message as an XmlDocument. &lt;/li&gt;

  &lt;li&gt;The AsyncXmlDocumentOrchestration publishes the CalculatorResponse message to the MessageBox (BizTalkMsgBoxDb). &lt;/li&gt;

  &lt;li&gt;The response message is retrieved by a One-Way FILE Send Port. &lt;/li&gt;

  &lt;li&gt;The response message is written to an output folder by the One-Way FILE Send Port. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;font color="#ff9914"&gt;Orchestration:&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;The following picture shows the structure of the test AsyncXmlDocumentOrchestration.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/4Differentwaystoprocessanxlangmessagewit_E2DC/AsyncXmlDocumentOrchestration2_2.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="AsyncXmlDocumentOrchestration2" border="0" alt="AsyncXmlDocumentOrchestration2" src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/4Differentwaystoprocessanxlangmessagewit_E2DC/AsyncXmlDocumentOrchestration2_thumb.jpg" width="602" height="1031" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;font color="#ff9900"&gt;Code&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;The XmlDocumentOrchestration receives a request message and returns a response document through a Request-Response Direct Bound Logical Port. The Filter Expression defined on the Activate Receive Shape is configured to receive all the CalculatorRequest messages which Method promoted property equals ‘XmlDocumentOrchestration’. The Expression Shape called BusinessLogic contains the following code: &lt;/p&gt;

&lt;table border="1" cellspacing="0" cellpadding="5" width="800" bgcolor="#ffffff"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="800"&gt;
        &lt;pre class="csharpcode"&gt;logHelper.WriteLine(&lt;span class="str"&gt;&amp;quot;[XmlDocumentOrchestration] Request message received.&amp;quot;&lt;/span&gt;);
xmlDocument = requestManager.ProcessRequestReturnXmlDocument(requestMessage);
logHelper.WriteLine(&lt;span class="str"&gt;&amp;quot;[XmlDocumentOrchestration] Request message successfully processed.&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p align="justify"&gt;while the Message Assignment Shape simply assigns the&amp;#160; XmlDocument returned by the helper component to the response message.&lt;/p&gt;

&lt;table border="1" cellspacing="0" cellpadding="5" width="800" bgcolor="#ffffff"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="800"&gt;
        &lt;pre class="csharpcode"&gt;responseMessage = xmlDocument;&lt;/pre&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;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;This is probably the most common approach used by developers to create and assign an XML document to a new XLANGMessage. Let’s see the code of the method invoked by the XmlDocumentOrchestration: &lt;/p&gt;

&lt;p&gt;&lt;font color="#ff9914"&gt;ProcessRequestReturnXmlDocument Method&lt;/font&gt;&lt;/p&gt;

&lt;table border="1" cellspacing="0" cellpadding="5" width="800" bgcolor="#ffffff"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="800"&gt;&lt;font color="#0000ff" size="2" face="Consolas"&gt;
          &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; XmlDocument ProcessRequestReturnXmlDocument(XLANGMessage message)
{
    XmlDocument responseDocument = &lt;span class="kwrd"&gt;new&lt;/span&gt; XmlDocument();
    List&amp;lt;Response&amp;gt; responseList = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;Response&amp;gt;();
    &lt;span class="kwrd"&gt;string&lt;/span&gt; op = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
    &lt;span class="kwrd"&gt;string&lt;/span&gt; status = Ok;
    &lt;span class="kwrd"&gt;string&lt;/span&gt; error = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
    &lt;span class="kwrd"&gt;double&lt;/span&gt; operand1 = 0;
    &lt;span class="kwrd"&gt;double&lt;/span&gt; operand2 = 0;
    &lt;span class="kwrd"&gt;double&lt;/span&gt; &lt;span class="kwrd"&gt;value&lt;/span&gt; = 0;
    &lt;span class="kwrd"&gt;bool&lt;/span&gt; ok = &lt;span class="kwrd"&gt;true&lt;/span&gt;;
    &lt;span class="kwrd"&gt;bool&lt;/span&gt; succeeded = &lt;span class="kwrd"&gt;true&lt;/span&gt;;
    &lt;span class="kwrd"&gt;int&lt;/span&gt; i = 0;

    &lt;span class="kwrd"&gt;try&lt;/span&gt;
    {
        logHelper.WriteLine(&lt;span class="str"&gt;&amp;quot;[RequestManager][XmlDocumentOrchestration] Request message received.&amp;quot;&lt;/span&gt;);
        XmlDocument xmlDocument = (XmlDocument)message[0].RetrieveAs(&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(XmlDocument));
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (xmlDocument != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
        {
            XmlNodeList nodeList = xmlDocument.SelectNodes(OperationXPath);
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (nodeList != &lt;span class="kwrd"&gt;null&lt;/span&gt; &amp;amp;&amp;amp; nodeList.Count &amp;gt; 0)
            {
                &lt;span class="kwrd"&gt;bool&lt;/span&gt; parsed1 = &lt;span class="kwrd"&gt;true&lt;/span&gt;;
                &lt;span class="kwrd"&gt;bool&lt;/span&gt; parsed2 = &lt;span class="kwrd"&gt;true&lt;/span&gt;;
                &lt;span class="kwrd"&gt;for&lt;/span&gt; (i = 0; i &amp;lt; nodeList.Count; i++)
                {
                    &lt;span class="kwrd"&gt;if&lt;/span&gt; (nodeList[i].HasChildNodes)
                    {
                        succeeded = &lt;span class="kwrd"&gt;true&lt;/span&gt;;
                        error = None;
                        &lt;span class="kwrd"&gt;value&lt;/span&gt; = 0;
                        &lt;span class="kwrd"&gt;for&lt;/span&gt; (&lt;span class="kwrd"&gt;int&lt;/span&gt; j = 0; j &amp;lt; nodeList[i].ChildNodes.Count; j++)
                        {
                            &lt;span class="kwrd"&gt;switch&lt;/span&gt; (nodeList[i].ChildNodes[j].LocalName)
                            {
                                &lt;span class="kwrd"&gt;case&lt;/span&gt; &lt;span class="str"&gt;&amp;quot;Operator&amp;quot;&lt;/span&gt;:
                                    op = nodeList[i].ChildNodes[j].InnerText;
                                    &lt;span class="kwrd"&gt;break&lt;/span&gt;;
                                &lt;span class="kwrd"&gt;case&lt;/span&gt; &lt;span class="str"&gt;&amp;quot;Operand1&amp;quot;&lt;/span&gt;:
                                    parsed1 = &lt;span class="kwrd"&gt;double&lt;/span&gt;.TryParse(nodeList[i].ChildNodes[j].InnerText, &lt;span class="kwrd"&gt;out&lt;/span&gt; operand1);
                                    &lt;span class="kwrd"&gt;break&lt;/span&gt;;
                                &lt;span class="kwrd"&gt;case&lt;/span&gt; &lt;span class="str"&gt;&amp;quot;Operand2&amp;quot;&lt;/span&gt;:
                                    parsed2 = &lt;span class="kwrd"&gt;double&lt;/span&gt;.TryParse(nodeList[i].ChildNodes[j].InnerText, &lt;span class="kwrd"&gt;out&lt;/span&gt; operand2);
                                    &lt;span class="kwrd"&gt;break&lt;/span&gt;;
                            }
                        }
                        &lt;span class="kwrd"&gt;if&lt;/span&gt; (parsed1 &amp;amp;&amp;amp; parsed2)
                        {
                            &lt;span class="kwrd"&gt;switch&lt;/span&gt; (op)
                            {
                                &lt;span class="kwrd"&gt;case&lt;/span&gt; &lt;span class="str"&gt;&amp;quot;+&amp;quot;&lt;/span&gt;:
                                    &lt;span class="kwrd"&gt;value&lt;/span&gt; = operand1 + operand2;
                                    &lt;span class="kwrd"&gt;break&lt;/span&gt;;
                                &lt;span class="kwrd"&gt;case&lt;/span&gt; &lt;span class="str"&gt;&amp;quot;-&amp;quot;&lt;/span&gt;:
                                    &lt;span class="kwrd"&gt;value&lt;/span&gt; = operand1 - operand2;
                                    &lt;span class="kwrd"&gt;break&lt;/span&gt;;
                                &lt;span class="kwrd"&gt;case&lt;/span&gt; &lt;span class="str"&gt;&amp;quot;*&amp;quot;&lt;/span&gt;:
                                    &lt;span class="kwrd"&gt;value&lt;/span&gt; = operand1 * operand2;
                                    &lt;span class="kwrd"&gt;break&lt;/span&gt;;
                                &lt;span class="kwrd"&gt;case&lt;/span&gt; &lt;span class="str"&gt;&amp;quot;/&amp;quot;&lt;/span&gt;:
                                    &lt;span class="kwrd"&gt;value&lt;/span&gt; = operand1 / operand2;
                                    &lt;span class="kwrd"&gt;break&lt;/span&gt;;
                                &lt;span class="kwrd"&gt;default&lt;/span&gt;:
                                    error = &lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(OperationUnknownErrorMessageFormat, op);
                                    status = OperationsFailed;
                                    ok = &lt;span class="kwrd"&gt;false&lt;/span&gt;;
                                    succeeded = &lt;span class="kwrd"&gt;false&lt;/span&gt;;
                                    &lt;span class="kwrd"&gt;break&lt;/span&gt;;
                            }
                        }
                        &lt;span class="kwrd"&gt;else&lt;/span&gt;
                        {
                            succeeded = &lt;span class="kwrd"&gt;false&lt;/span&gt;;
                            ok = &lt;span class="kwrd"&gt;false&lt;/span&gt;;
                            status = OperationsFailed;
                            &lt;span class="kwrd"&gt;if&lt;/span&gt; (!parsed1)
                            {
                                error = &lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(OperandIsNotANumberMessageFormat, 1, i + 1);
                            }
                            &lt;span class="kwrd"&gt;if&lt;/span&gt; (!parsed2)
                            {
                                &lt;span class="kwrd"&gt;if&lt;/span&gt; (parsed1)
                                {
                                    error = &lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(&lt;span class="str"&gt;&amp;quot;{0}\r\n{1}&amp;quot;&lt;/span&gt;, error, &lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(OperandIsNotANumberMessageFormat, 2, i + 1));
                                }
                                &lt;span class="kwrd"&gt;else&lt;/span&gt;
                                {
                                    error = &lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(OperandIsNotANumberMessageFormat, 2, i + 1);
                                }
                            }
                        }
                        &lt;span class="kwrd"&gt;if&lt;/span&gt; (succeeded)
                        {
                            logHelper.WriteLine(&lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(OperationFormat, &lt;span class="str"&gt;&amp;quot;XmlDocumentOrchestration&amp;quot;&lt;/span&gt;, operand1, op, operand2, &lt;span class="kwrd"&gt;value&lt;/span&gt;));
                        }
                        &lt;span class="kwrd"&gt;else&lt;/span&gt;
                        {
                            logHelper.WriteLine(error);
                        }
                        responseList.Add(&lt;span class="kwrd"&gt;new&lt;/span&gt; Response(error, &lt;span class="kwrd"&gt;value&lt;/span&gt;));
                    }
                }
            }
        }
        StringBuilder builder = &lt;span class="kwrd"&gt;new&lt;/span&gt; StringBuilder();
        &lt;span class="kwrd"&gt;using&lt;/span&gt; (XmlWriter writer = XmlWriter.Create(builder))
        {
            writer.WriteStartDocument();
            writer.WriteStartElement(&lt;span class="str"&gt;&amp;quot;CalculatorResponse&amp;quot;&lt;/span&gt;, CalculatorResponseNamespace);
            writer.WriteStartElement(&lt;span class="str"&gt;&amp;quot;Status&amp;quot;&lt;/span&gt;, CalculatorResponseNamespace);
            writer.WriteString(status);
            writer.WriteEndElement();
            writer.WriteStartElement(&lt;span class="str"&gt;&amp;quot;Results&amp;quot;&lt;/span&gt;, CalculatorResponseNamespace);
            &lt;span class="kwrd"&gt;for&lt;/span&gt; (i = 0; i &amp;lt; responseList.Count; i++)
            {
                writer.WriteStartElement(&lt;span class="str"&gt;&amp;quot;Result&amp;quot;&lt;/span&gt;, CalculatorResponseNamespace);
                writer.WriteStartElement(&lt;span class="str"&gt;&amp;quot;Value&amp;quot;&lt;/span&gt;, CalculatorResponseNamespace);
                writer.WriteString(responseList[i].Value.ToString());
                writer.WriteEndElement();
                writer.WriteStartElement(&lt;span class="str"&gt;&amp;quot;Error&amp;quot;&lt;/span&gt;, CalculatorResponseNamespace);
                writer.WriteString(responseList[i].Error);
                writer.WriteEndElement();
                writer.WriteEndElement();
            }
            writer.WriteEndElement();
            writer.WriteEndElement();
        }
        &lt;span class="kwrd"&gt;string&lt;/span&gt; text = builder.ToString();
        responseDocument.LoadXml(text);
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (ok)
        {
            logHelper.WriteLine(&lt;span class="str"&gt;&amp;quot;[RequestManager][XmlDocumentOrchestration] Response message successfully processed.&amp;quot;&lt;/span&gt;);
        }
        &lt;span class="kwrd"&gt;else&lt;/span&gt;
        {
            logHelper.WriteLine(&lt;span class="str"&gt;&amp;quot;[RequestManager][XmlDocumentOrchestration] Request failed.&amp;quot;&lt;/span&gt;);
        }
    }
    &lt;span class="kwrd"&gt;catch&lt;/span&gt; (Exception ex)
    {
        logHelper.WriteLine(ex.Message);
        responseDocument.LoadXml(&lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(ErrorMessageFormat, ex.Message));
    }
    &lt;span class="kwrd"&gt;finally&lt;/span&gt;
    {
        message.Dispose();
    }
    &lt;span class="kwrd"&gt;return&lt;/span&gt; responseDocument;
}&lt;/pre&gt;
        &lt;/font&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;&lt;font color="#ff9914"&gt;Comment&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;As already highlighted above, using an XmlDocument to process the content of an XLANGMessage is extremely handy and powerful, but it can easily lead to high memory usage, especially when dealing with large messages.&lt;/p&gt;

&lt;p align="justify"&gt;&lt;font color="#ff9914"&gt;&lt;strong&gt;StreamOrchestration&lt;/strong&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p align="justify"&gt;The following picture depicts the architecture of the StreamOrchestration test case.&lt;/p&gt;

&lt;p align="justify"&gt;&lt;a href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/4Differentwaystoprocessanxlangmessagewit_E2DC/StreamOrchestration_4.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="StreamOrchestration" border="0" alt="StreamOrchestration" src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/4Differentwaystoprocessanxlangmessagewit_E2DC/StreamOrchestration_thumb_1.jpg" width="802" height="265" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;font color="#ff9914"&gt;Message Flow:&lt;/font&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;A WCF-BasicHttp or WCF-Custom Request-Response Receive Location receives a new CalculatorRequest xml document from the Test Agent/Client Application. &lt;/li&gt;

  &lt;li&gt;The XML disassembler component within the XMLTransmit pipeline promotes the Method element inside the CalculatorRequest xml document. The Message Agent submits the incoming message to the MessageBox (BizTalkMsgBoxDb). &lt;/li&gt;

  &lt;li&gt;The inbound request starts a new instance of the StreamOrchestration. This latter uses a Direct Port receive the CalculatorRequest messages with the Method promoted property = “StreamOrchestration”. &lt;/li&gt;

  &lt;li&gt;The StreamOrchestration invokes the ProcessRequestReturnStream method exposed by the RequestManager helper component. This object processes within a loop all the operations contained in the inbound XLANGMessage. In particular, the ProcessRequestReturnStream uses an XmlReader object to read and process the operations and an XmlWriter and a VirtualStream objects to produce the response message. &lt;/li&gt;

  &lt;li&gt;The ProcessRequestReturnStream&amp;#160; method returns the response message as a Stream (VirtualStream) object. &lt;/li&gt;

  &lt;li&gt;The StreamOrchestration publishes the CalculatorResponse message to the MessageBox (BizTalkMsgBoxDb). &lt;/li&gt;

  &lt;li&gt;The response message is retrieved by the Request-Response WCF-BasicHttp or WCF-Custom Receive Location. &lt;/li&gt;

  &lt;li&gt;The response message is returned to the Test Agent/Client Application. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;font color="#ff9914"&gt;Orchestration:&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;The following picture shows the structure of the test StreamOrchestration.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/4Differentwaystoprocessanxlangmessagewit_E2DC/StreamOrchestration2_4.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="StreamOrchestration2" border="0" alt="StreamOrchestration2" src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/4Differentwaystoprocessanxlangmessagewit_E2DC/StreamOrchestration2_thumb_1.jpg" width="602" height="1031" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p align="justify"&gt;&lt;font color="#ff9914"&gt;&lt;strong&gt;AsyncStreamOrchestration&lt;/strong&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p align="justify"&gt;The following picture depicts the architecture of the AsyncStreamOrchestration test case.&lt;/p&gt;

&lt;p align="justify"&gt;&lt;/p&gt;

&lt;p align="justify"&gt;&lt;a href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/4Differentwaystoprocessanxlangmessagewit_E2DC/AsyncStreamOrchestration_2.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="AsyncStreamOrchestration" border="0" alt="AsyncStreamOrchestration" src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/4Differentwaystoprocessanxlangmessagewit_E2DC/AsyncStreamOrchestration_thumb.jpg" width="802" height="265" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;font color="#ff9914"&gt;Message Flow:&lt;/font&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;A One-Way FILE Receive Location receives a new CalculatorRequest xml document from the Client Application or &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=c8af583f-7044-48db-b7b9-969072df1689&amp;amp;DisplayLang=en"&gt;Loadgen&lt;/a&gt;. &lt;/li&gt;

  &lt;li&gt;The XML disassembler component within the XMLTransmit pipeline promotes the Method element inside the CalculatorRequest xml document. The Message Agent submits the incoming message to the MessageBox (BizTalkMsgBoxDb). &lt;/li&gt;

  &lt;li&gt;The inbound request starts a new instance of the AsyncStreamOrchestration. This latter uses a Direct Port receive the CalculatorRequest messages with the Method promoted property = “AsyncStreamOrchestration”. &lt;/li&gt;

  &lt;li&gt;The AsyncStreamOrchestration invokes the ProcessRequestReturnStream method exposed by the RequestManager helper component. This object processes within a loop all the operations contained in the inbound XLANGMessage. In particular, the ProcessRequestReturnStream uses an XmlReader object to read and process the operations and an XmlWriter and a VirtualStream objects to produce the response message. &lt;/li&gt;

  &lt;li&gt;The ProcessRequestReturnStream&amp;#160; method returns the response message as a Stream (VirtualStream) object. &lt;/li&gt;

  &lt;li&gt;The AsyncStreamOrchestration publishes the CalculatorResponse message to the MessageBox (BizTalkMsgBoxDb). &lt;/li&gt;

  &lt;li&gt;The response message is retrieved by a One-Way FILE Send Port. &lt;/li&gt;

  &lt;li&gt;The response message is written to an output folder by the One-Way FILE Send Port. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;font color="#ff9914"&gt;Orchestration:&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;The following picture shows the structure of the test AsyncStreamOrchestration.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/4Differentwaystoprocessanxlangmessagewit_E2DC/AsyncStreamOrchestration2_2.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="AsyncStreamOrchestration2" border="0" alt="AsyncStreamOrchestration2" src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/4Differentwaystoprocessanxlangmessagewit_E2DC/AsyncStreamOrchestration2_thumb.jpg" width="602" height="1031" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;font color="#ff9914"&gt;Code&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;The StreamOrchestration receives a request message and returns a response document through a Request-Response Direct Bound Logical Port. The Filter Expression defined on the Activate Receive Shape is configured to receive all the CalculatorRequest messages which Method promoted property equals ‘StreamOrchestration’. The Expression Shape called BusinessLogic contains the following code: &lt;/p&gt;

&lt;table border="1" cellspacing="0" cellpadding="5" width="800" bgcolor="#ffffff"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="800"&gt;
        &lt;pre class="csharpcode"&gt;logHelper.WriteLine(&lt;span class="str"&gt;&amp;quot;[StreamOrchestration] Request message received.&amp;quot;&lt;/span&gt;);
stream = requestManager.ProcessRequestReturnStream(requestMessage);
logHelper.WriteLine(&lt;span class="str"&gt;&amp;quot;[StreamOrchestration] Request message successfully processed.&amp;quot;&lt;/span&gt;);&lt;/pre&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;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p align="justify"&gt;As the name suggests, the ProcessRequestReturnStream method exposed by the RequestManager component receives the CalculatorRequest message as XLANGMessage input parameter and returns a Stream object containing the response document. In particular, the method adopts a streaming approach to process the incoming message and generate the response message:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;div align="justify"&gt;It uses a VirtualStream and an XmlReader to read the content of the request message.&lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;It uses a VirtualStream and an XmlWriter to generate the response message.&lt;/div&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p align="justify"&gt;&lt;font color="#ff9914"&gt;ProcessRequestReturnStream Method&lt;/font&gt;&lt;/p&gt;

&lt;p align="justify"&gt;
  &lt;table border="1" cellspacing="0" cellpadding="5" width="800" bgcolor="#ffffff"&gt;&lt;tbody&gt;
      &lt;tr&gt;
        &lt;td valign="top" width="800"&gt;
          &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; Stream ProcessRequestReturnStream(XLANGMessage message)
{
    VirtualStream stream = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
    List&amp;lt;Response&amp;gt; responseList = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;Response&amp;gt;();
    &lt;span class="kwrd"&gt;string&lt;/span&gt; op = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
    &lt;span class="kwrd"&gt;string&lt;/span&gt; status = Ok;
    &lt;span class="kwrd"&gt;string&lt;/span&gt; error = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
    &lt;span class="kwrd"&gt;double&lt;/span&gt; operand1 = 0;
    &lt;span class="kwrd"&gt;double&lt;/span&gt; operand2 = 0;
    &lt;span class="kwrd"&gt;double&lt;/span&gt; &lt;span class="kwrd"&gt;value&lt;/span&gt; = 0;
    &lt;span class="kwrd"&gt;bool&lt;/span&gt; ok = &lt;span class="kwrd"&gt;true&lt;/span&gt;;
    &lt;span class="kwrd"&gt;bool&lt;/span&gt; succeeded = &lt;span class="kwrd"&gt;true&lt;/span&gt;;
    &lt;span class="kwrd"&gt;int&lt;/span&gt; i = 0;

    &lt;span class="kwrd"&gt;try&lt;/span&gt;
    {
        logHelper.WriteLine(&lt;span class="str"&gt;&amp;quot;[RequestManager][StreamOrchestration] Request message received.&amp;quot;&lt;/span&gt;);
        &lt;span class="kwrd"&gt;using&lt;/span&gt; (VirtualStream virtualStream = &lt;span class="kwrd"&gt;new&lt;/span&gt; VirtualStream(bufferSize, thresholdSize))
        {
            &lt;span class="kwrd"&gt;using&lt;/span&gt; (Stream partStream = (Stream)message[0].RetrieveAs(&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(Stream)))
            {
                &lt;span class="kwrd"&gt;using&lt;/span&gt; (XmlReader reader = XmlReader.Create(partStream))
                {
                    &lt;span class="kwrd"&gt;while&lt;/span&gt; (reader.Read() &amp;amp;&amp;amp; ok)
                    {
                        &lt;span class="kwrd"&gt;if&lt;/span&gt; (reader.LocalName == &lt;span class="str"&gt;&amp;quot;Operator&amp;quot;&lt;/span&gt; &amp;amp;&amp;amp;
                            reader.NodeType == XmlNodeType.Element)
                        {
                            succeeded = &lt;span class="kwrd"&gt;true&lt;/span&gt;;
                            error = None;
                            &lt;span class="kwrd"&gt;value&lt;/span&gt; = 0;
                            op = reader.ReadElementContentAsString();
                            reader.MoveToContent();
                            operand1 = reader.ReadElementContentAsDouble();
                            reader.MoveToContent();
                            operand2 = reader.ReadElementContentAsDouble();
                            i++;
                            &lt;span class="kwrd"&gt;switch&lt;/span&gt; (op)
                            {
                                &lt;span class="kwrd"&gt;case&lt;/span&gt; &lt;span class="str"&gt;&amp;quot;+&amp;quot;&lt;/span&gt;:
                                    &lt;span class="kwrd"&gt;value&lt;/span&gt; = operand1 + operand2;
                                    &lt;span class="kwrd"&gt;break&lt;/span&gt;;
                                &lt;span class="kwrd"&gt;case&lt;/span&gt; &lt;span class="str"&gt;&amp;quot;-&amp;quot;&lt;/span&gt;:
                                    &lt;span class="kwrd"&gt;value&lt;/span&gt; = operand1 - operand2;
                                    &lt;span class="kwrd"&gt;break&lt;/span&gt;;
                                &lt;span class="kwrd"&gt;case&lt;/span&gt; &lt;span class="str"&gt;&amp;quot;*&amp;quot;&lt;/span&gt;:
                                    &lt;span class="kwrd"&gt;value&lt;/span&gt; = operand1 * operand2;
                                    &lt;span class="kwrd"&gt;break&lt;/span&gt;;
                                &lt;span class="kwrd"&gt;case&lt;/span&gt; &lt;span class="str"&gt;&amp;quot;/&amp;quot;&lt;/span&gt;:
                                    &lt;span class="kwrd"&gt;value&lt;/span&gt; = operand1 / operand2;
                                    &lt;span class="kwrd"&gt;break&lt;/span&gt;;
                                &lt;span class="kwrd"&gt;default&lt;/span&gt;:
                                    error = &lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(OperationUnknownErrorMessageFormat, op);
                                    status = OperationsFailed;
                                    ok = &lt;span class="kwrd"&gt;false&lt;/span&gt;;
                                    succeeded = &lt;span class="kwrd"&gt;false&lt;/span&gt;;
                                    &lt;span class="kwrd"&gt;break&lt;/span&gt;;
                            }
                            &lt;span class="kwrd"&gt;if&lt;/span&gt; (succeeded)
                            {
                                logHelper.WriteLine(&lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(OperationFormat, &lt;span class="str"&gt;&amp;quot;StreamOrchestration&amp;quot;&lt;/span&gt;, operand1, op, operand2, &lt;span class="kwrd"&gt;value&lt;/span&gt;));
                            }
                            &lt;span class="kwrd"&gt;else&lt;/span&gt;
                            {
                                logHelper.WriteLine(error);
                            }
                            responseList.Add(&lt;span class="kwrd"&gt;new&lt;/span&gt; Response(error, &lt;span class="kwrd"&gt;value&lt;/span&gt;));
                        }
                    }
                }
            }
        }
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (ok)
        {
            stream = &lt;span class="kwrd"&gt;new&lt;/span&gt; VirtualStream(bufferSize, thresholdSize);
            &lt;span class="kwrd"&gt;using&lt;/span&gt; (XmlWriter writer = XmlWriter.Create(stream))
            {
                writer.WriteStartDocument();
                writer.WriteStartElement(&lt;span class="str"&gt;&amp;quot;CalculatorResponse&amp;quot;&lt;/span&gt;, CalculatorResponseNamespace);
                writer.WriteStartElement(&lt;span class="str"&gt;&amp;quot;Status&amp;quot;&lt;/span&gt;, CalculatorResponseNamespace);
                writer.WriteString(status);
                writer.WriteEndElement();
                writer.WriteStartElement(&lt;span class="str"&gt;&amp;quot;Results&amp;quot;&lt;/span&gt;, CalculatorResponseNamespace);
                &lt;span class="kwrd"&gt;for&lt;/span&gt; (i = 0; i &amp;lt; responseList.Count; i++)
                {
                    writer.WriteStartElement(&lt;span class="str"&gt;&amp;quot;Result&amp;quot;&lt;/span&gt;, CalculatorResponseNamespace);
                    writer.WriteStartElement(&lt;span class="str"&gt;&amp;quot;Value&amp;quot;&lt;/span&gt;, CalculatorResponseNamespace);
                    writer.WriteString(responseList[i].Value.ToString());
                    writer.WriteEndElement();
                    writer.WriteStartElement(&lt;span class="str"&gt;&amp;quot;Error&amp;quot;&lt;/span&gt;, CalculatorResponseNamespace);
                    writer.WriteString(responseList[i].Error);
                    writer.WriteEndElement();
                    writer.WriteEndElement();
                }
                writer.WriteEndElement();
                writer.WriteEndElement();
            }
            stream.Seek(0, SeekOrigin.Begin);
            logHelper.WriteLine(&lt;span class="str"&gt;&amp;quot;[RequestManager][StreamOrchestration] Response message successfully processed.&amp;quot;&lt;/span&gt;);
        }
    }
    &lt;span class="kwrd"&gt;catch&lt;/span&gt; (Exception ex)
    {
        logHelper.WriteLine(&lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(&lt;span class="str"&gt;&amp;quot;[RequestManager][StreamOrchestration] {0}&amp;quot;&lt;/span&gt;, ex.Message));
        stream = &lt;span class="kwrd"&gt;new&lt;/span&gt; VirtualStream(bufferSize, thresholdSize);
        &lt;span class="kwrd"&gt;using&lt;/span&gt; (XmlWriter writer = XmlWriter.Create(stream))
        {
            writer.WriteStartDocument();
            writer.WriteStartElement(&lt;span class="str"&gt;&amp;quot;CalculatorResponse&amp;quot;&lt;/span&gt;, CalculatorResponseNamespace);
            writer.WriteStartElement(&lt;span class="str"&gt;&amp;quot;Status&amp;quot;&lt;/span&gt;, CalculatorResponseNamespace);
            writer.WriteString(ex.Message);
            writer.WriteEndElement();
            writer.WriteEndElement();
        }
        stream.Seek(0, SeekOrigin.Begin);
    }
    &lt;span class="kwrd"&gt;finally&lt;/span&gt;
    {
        message.Dispose();
    }
    &lt;span class="kwrd"&gt;return&lt;/span&gt; stream;
}&lt;/pre&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;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;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;/td&gt;
      &lt;/tr&gt;
    &lt;/tbody&gt;&lt;/table&gt;
&lt;/p&gt;

&lt;p&gt;&lt;font color="#ff9914"&gt;VirtualStream and ReadOnlySeekableStream&lt;/font&gt;&lt;/p&gt;

&lt;p align="justify"&gt;The ReadOnlySeekableStream can be used to wrap and read the content of a non-seekable stream in those cases where after reading it’s necessary to reposition the cursor at the beginning of the stream.&amp;#160; While reading the content of the wrapped stream, the ReadOnlySeekableStream copies its content to a temporary file created in the folder specified by the TMP and/or TEMP environment variables. However, the class exposes a &lt;a href="http://technet.microsoft.com/en-us/library/bb747395(BTS.10).aspx"&gt;public constructor&lt;/a&gt; which allows to specify a different persistence stream as alterative to the FileStream (e.g. VirtualStream, MemoryStream):&lt;/p&gt;

&lt;table border="1" cellspacing="0" cellpadding="5" width="800" bgcolor="#ffffff"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="800"&gt;
        &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; ReadOnlySeekableStream (&lt;font color="#2b91af"&gt;Stream&lt;/font&gt; source, &lt;font color="#2b91af"&gt;Stream&lt;/font&gt; persist, &lt;span class="kwrd"&gt;int&lt;/span&gt; maxBuffer)&lt;/pre&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;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;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p align="justify"&gt;The VirtualStream in its turn is very useful when dealing with large messages within a custom pipeline component or a helper component invoked by an orchestration. In fact, if the document size is bigger than a certain threshold, the default is 1MB,&amp;#160; the message is persisted to a temporary file. This file is created inside a folder identified by the TEMP environment variable of the service account used to run the current host instance. So, when parsing, mapping and dealing in general with large messages, it’s a good practice to move the location of the temporary folder for the BizTalk service account to a dedicated local disk separate from the volume hosting the Windows OS. The VirtualStream class exposes a particular &lt;a href="http://technet.microsoft.com/en-us/library/bb747408(BTS.10).aspx"&gt;constructor&lt;/a&gt; (see below) which enables to specify the size of the internal buffer and the size of this threshold, so you can set the best value based on a given scenario. It’s a good practice to expose these 2 variables, the buffer size and the threshold size as properties of custom pipeline components or helper components. &lt;/p&gt;

&lt;table border="1" cellspacing="0" cellpadding="5" width="800" bgcolor="#ffffff"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="800"&gt;
        &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; VirtualStream (&lt;span class="kwrd"&gt;int&lt;/span&gt; bufferSize, &lt;span class="kwrd"&gt;int&lt;/span&gt; thresholdSize)&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;/pre&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;The use of the &lt;a href="http://technet.microsoft.com/en-us/library/microsoft.biztalk.streaming.virtualstream(BTS.10).aspx"&gt;VirtualStream&lt;/a&gt; and &lt;a href="http://technet.microsoft.com/en-us/library/microsoft.biztalk.streaming.readonlyseekablestream(BTS.10).aspx"&gt;ReadOnlySeekableStream&lt;/a&gt; (both classes are contained in the &lt;a href="http://technet.microsoft.com/en-us/library/microsoft.biztalk.streaming(BTS.10).aspx"&gt;Microsoft.BizTalk.Streaming.dll&lt;/a&gt; assembly) can be combined to provide both “seekability” and “overflow to file system” capabilities to custom pipeline components and helper classes. This accommodates the processing of large messages without loading the entire message into memory. The following code could be used in a pipeline component to implement this functionality.&amp;#160; &lt;/p&gt;

&lt;table border="1" cellspacing="0" cellpadding="5" width="800" bgcolor="#ffffff"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="800"&gt;
        &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;int&lt;/span&gt; bufferSize = 0x280;
&lt;span class="kwrd"&gt;int&lt;/span&gt; thresholdSize = 0x100000;
Stream vStream = &lt;span class="kwrd"&gt;new&lt;/span&gt; VirtualStream(bufferSize, thresholdSize);
Stream seekStream = &lt;span class="kwrd"&gt;new&lt;/span&gt; ReadOnlySeekableStream(inboundStream, vStream, bufferSize);&lt;/pre&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;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;As you can see, the VirtualStream is used as persistence storage for the ReadOnlySeekableStream. In this way, if the length of the original stream is lower the threshold size, its content will be persisted to a MemoryStream, otherwise it will be written to a temporary file. 
  &lt;br /&gt;As a rule of thumb, if the original stream is seekable, there's no need to use the ReadOnlySeekableStream and you can use just the VirtualStream. However, some of the streams used by the Messaging Engine are forward-only, non-seekable streams, so when it's necessary to read the content of a message within a custom pipeline component and reposition the cursor at the beginning of the stream at the end, it's a good practice combining the use of the VirtualStream and ReadOnlySeekableStream as shown by the code snippet above. See &lt;a href="http://msdn.microsoft.com/en-us/library/ee377071(BTS.10).aspx"&gt;Optimizing Pipeline Performance&lt;/a&gt; for more information on this topic.&lt;/p&gt;

&lt;p&gt;&lt;font color="#ff9914"&gt;Response Message Assignment&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;To assign the content of the stream returned by the ProcessRequestReturnStream to the response message, the Message Assignment Shape (see the code below) invokes the SetResponse method exposed by another helper component called ResponseManager.&lt;/p&gt;

&lt;table border="1" cellspacing="0" cellpadding="5" width="800" bgcolor="#ffffff"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="800"&gt;
        &lt;pre class="csharpcode"&gt;responseMessage = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
responseManager.SetResponse(responseMessage, stream);&lt;/pre&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;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p align="justify"&gt;This SetResponse method uses the &lt;a href="http://msdn.microsoft.com/en-us/library/ee277291(BTS.10).aspx"&gt;LoadFrom&lt;/a&gt; method exposed by the &lt;a href="http://msdn.microsoft.com/en-us/library/ee277305(BTS.10).aspx"&gt;XLANGPart&lt;/a&gt; class to assign the content of the stream to the message part of the response document.&lt;/p&gt;

&lt;table border="1" cellspacing="0" cellpadding="5" width="800" bgcolor="#ffffff"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="800"&gt;
        &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; SetResponse(XLANGMessage message, Stream stream)
{
    &lt;span class="kwrd"&gt;try&lt;/span&gt;
    {
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (stream != &lt;span class="kwrd"&gt;null&lt;/span&gt; &amp;amp;&amp;amp;
            message != &lt;span class="kwrd"&gt;null&lt;/span&gt; &amp;amp;&amp;amp;
            message.Count &amp;gt; 0)
        {
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (stream.CanSeek)
            {
                stream.Seek(0, SeekOrigin.Begin);
            }
            message[0].LoadFrom(stream);
        }
    }
    &lt;span class="kwrd"&gt;catch&lt;/span&gt; (Exception ex)
    {
        Debug.WriteLine(&lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(&lt;span class="str"&gt;&amp;quot;[ResponseManager] {0}&amp;quot;&lt;/span&gt;, ex.Message));
    }
    &lt;span class="kwrd"&gt;finally&lt;/span&gt;
    {
        message.Dispose();
    }
} &lt;/pre&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;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;&lt;font color="#ff9914"&gt;Comment&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;This streaming approach used by StreamOrchestration is extremely useful and performant especially when dealing with large messages.&lt;/p&gt;

&lt;p&gt;&lt;font color="#ff9914"&gt;&lt;strong&gt;MessageClassesOrchestration&lt;/strong&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p align="justify"&gt;The following picture depicts the architecture of the MessageClassesOrchestration test case.&lt;/p&gt;

&lt;p align="justify"&gt;&lt;a href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/4Differentwaystoprocessanxlangmessagewit_E2DC/MessageClassesOrchestration_2.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="MessageClassesOrchestration" border="0" alt="MessageClassesOrchestration" src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/4Differentwaystoprocessanxlangmessagewit_E2DC/MessageClassesOrchestration_thumb.jpg" width="802" height="265" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;font color="#ff9914"&gt;Message Flow:&lt;/font&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;A WCF-BasicHttp or WCF-Custom Request-Response Receive Location receives a new CalculatorRequest xml document from the Test Agent/Client Application. &lt;/li&gt;

  &lt;li&gt;The XML disassembler component within the XMLTransmit pipeline promotes the Method element inside the CalculatorRequest xml document. The Message Agent submits the incoming message to the MessageBox (BizTalkMsgBoxDb). &lt;/li&gt;

  &lt;li&gt;The inbound request starts a new instance of the MessageClassesOrchestration. This latter uses a Direct Port receive the CalculatorRequest messages with the Method promoted property = “MessageClassesOrchestration”. &lt;/li&gt;

  &lt;li&gt;The MessageClassesOrchestration invokes the ProcessRequestReturnObject method exposed by the RequestManager helper component. This object processes within a loop all the operations contained in the inbound XLANGMessage. In particular, the ProcessRequestReturnObject deserializes the CalculatorRequest message into a new instance of the CalculatorRequest .NET class, processes al the operations contained in this object and accumulates the results inside an instance of the CalculatorResponse .NET class. &lt;/li&gt;

  &lt;li&gt;The ProcessRequestReturnObject&amp;#160; method returns an instance of the CalculatorResponse .NET class. &lt;/li&gt;

  &lt;li&gt;The MessageClassesOrchestration publishes the CalculatorResponse message to the MessageBox (BizTalkMsgBoxDb). &lt;/li&gt;

  &lt;li&gt;The response message is retrieved by the Request-Response WCF-BasicHttp or WCF-Custom Receive Location. &lt;/li&gt;

  &lt;li&gt;The response message is returned to the Test Agent/Client Application. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;font color="#ff9914"&gt;Orchestration:&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;The following picture shows the structure of the test MessageClassesOrchestration.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/4Differentwaystoprocessanxlangmessagewit_E2DC/MessageClassesOrchestration2_2.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="MessageClassesOrchestration2" border="0" alt="MessageClassesOrchestration2" src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/4Differentwaystoprocessanxlangmessagewit_E2DC/MessageClassesOrchestration2_thumb.jpg" width="602" height="1031" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;font color="#ff9914"&gt;&lt;strong&gt;AsyncMessageClassesOrchestration&lt;/strong&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p align="justify"&gt;The following picture depicts the architecture of the AsyncMessageClassesOrchestration test case.&lt;/p&gt;

&lt;p align="justify"&gt;&lt;/p&gt;

&lt;p align="justify"&gt;&lt;a href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/4Differentwaystoprocessanxlangmessagewit_E2DC/AsyncMessageClassesOrchestration_2.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="AsyncMessageClassesOrchestration" border="0" alt="AsyncMessageClassesOrchestration" src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/4Differentwaystoprocessanxlangmessagewit_E2DC/AsyncMessageClassesOrchestration_thumb.jpg" width="802" height="265" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;font color="#ff9914"&gt;Message Flow:&lt;/font&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;A One-Way FILE Receive Location receives a new CalculatorRequest xml document from the Client Application or &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=c8af583f-7044-48db-b7b9-969072df1689&amp;amp;DisplayLang=en"&gt;Loadgen&lt;/a&gt;. &lt;/li&gt;

  &lt;li&gt;The XML disassembler component within the XMLTransmit pipeline promotes the Method element inside the CalculatorRequest xml document. The Message Agent submits the incoming message to the MessageBox (BizTalkMsgBoxDb). &lt;/li&gt;

  &lt;li&gt;The inbound request starts a new instance of the AsyncMessageClassesOrchestration. This latter uses a Direct Port receive the CalculatorRequest messages with the Method promoted property = “AsyncMessageClassesOrchestration”. &lt;/li&gt;

  &lt;li&gt;The AsyncMessageClassesOrchestration invokes the ProcessRequestReturnObject method exposed by the RequestManager helper component. This object processes within a loop all the operations contained in the inbound XLANGMessage. In particular, the ProcessRequestReturnObject deserializes the CalculatorRequest message into a new instance of the CalculatorRequest .NET class, processes al the operations contained in this object and accumulates the results inside an instance of the CalculatorResponse .NET class. &lt;/li&gt;

  &lt;li&gt;The ProcessRequestReturnObject&amp;#160; method returns an instance of the CalculatorResponse .NET class. &lt;/li&gt;

  &lt;li&gt;The AsyncMessageClassesOrchestration publishes the CalculatorResponse message to the MessageBox (BizTalkMsgBoxDb). &lt;/li&gt;

  &lt;li&gt;The response message is retrieved by a One-Way FILE Send Port. &lt;/li&gt;

  &lt;li&gt;The response message is written to an output folder by the One-Way FILE Send Port. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;font color="#ff9914"&gt;Orchestration:&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;The following picture shows the structure of the test AsyncMessageClassesOrchestration.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/4Differentwaystoprocessanxlangmessagewit_E2DC/AsyncMessageClassesOrchestration2_2.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="AsyncMessageClassesOrchestration2" border="0" alt="AsyncMessageClassesOrchestration2" src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/4Differentwaystoprocessanxlangmessagewit_E2DC/AsyncMessageClassesOrchestration2_thumb.jpg" width="602" height="1031" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;font color="#ff9914"&gt;Code&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;The MessageClassesOrchestration receives a request message and returns a response document through a Request-Response Direct Bound Logical Port. The Filter Expression defined on the Activate Receive Shape is configured to receive all the CalculatorRequest messages which Method promoted property equals ‘MessageClassesOrchestration’. The Expression Shape called BusinessLogic contains the following code: &lt;/p&gt;

&lt;table border="1" cellspacing="0" cellpadding="5" width="800" bgcolor="#ffffff"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="800"&gt;
        &lt;pre class="csharpcode"&gt;logHelper.WriteLine(&lt;span class="str"&gt;&amp;quot;[MessageClassesOrchestration] Request message received.&amp;quot;&lt;/span&gt;);
calculatorResponse = requestManager.ProcessRequestReturnObject(requestMessage);
logHelper.WriteLine(&lt;span class="str"&gt;&amp;quot;[MessageClassesOrchestration] Request message successfully processed.&amp;quot;&lt;/span&gt;);&lt;/pre&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;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p align="justify"&gt;The ProcessRequestReturnObject method invoked by the MessageClassesOrchestration expects an XLANGMessage object as inbound parameter. The code of the method retrieves the content of the message part as instance of the CalculatorRequest class. In this case the RetrieveAs method exposed by the XLANGPart class deserializes the content of the message part and creates an instance of the aforementioned class.&amp;#160; &lt;/p&gt;

&lt;p align="justify"&gt;&lt;font color="#ff9914"&gt;ProcessRequestReturnObject Method&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;table border="1" cellspacing="0" cellpadding="5" width="800" bgcolor="#ffffff"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="800"&gt;
        &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; CalculatorResponse ProcessRequestReturnObject(XLANGMessage message)
{
    CalculatorResponse response = &lt;span class="kwrd"&gt;new&lt;/span&gt; CalculatorResponse();
    Operation operation = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
    &lt;span class="kwrd"&gt;string&lt;/span&gt; error = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
    &lt;span class="kwrd"&gt;double&lt;/span&gt; &lt;span class="kwrd"&gt;value&lt;/span&gt; = 0;
    &lt;span class="kwrd"&gt;bool&lt;/span&gt; ok = &lt;span class="kwrd"&gt;true&lt;/span&gt;;
    &lt;span class="kwrd"&gt;bool&lt;/span&gt; succeeded = &lt;span class="kwrd"&gt;true&lt;/span&gt;;

    &lt;span class="kwrd"&gt;try&lt;/span&gt;
    {
        logHelper.WriteLine(&lt;span class="str"&gt;&amp;quot;[RequestManager][MessageClassesOrchestration] Request message received.&amp;quot;&lt;/span&gt;);
        CalculatorRequest request = (CalculatorRequest)message[0].RetrieveAs(&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(CalculatorRequest));
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (request != &lt;span class="kwrd"&gt;null&lt;/span&gt; &amp;amp;&amp;amp;
            request.Operations != &lt;span class="kwrd"&gt;null&lt;/span&gt; &amp;amp;&amp;amp;
            request.Operations.Count &amp;gt; 0)
        {
            response.Status = Ok;
            &lt;span class="kwrd"&gt;for&lt;/span&gt; (&lt;span class="kwrd"&gt;int&lt;/span&gt; i = 0; i &amp;lt; request.Operations.Count; i++)
            {
                operation = (Operation)request.Operations[i];
                error = None;
                &lt;span class="kwrd"&gt;value&lt;/span&gt; = 0;
                succeeded = &lt;span class="kwrd"&gt;true&lt;/span&gt;;
                &lt;span class="kwrd"&gt;switch&lt;/span&gt; (operation.Operator)
                {
                    &lt;span class="kwrd"&gt;case&lt;/span&gt; &lt;span class="str"&gt;&amp;quot;+&amp;quot;&lt;/span&gt;:
                        &lt;span class="kwrd"&gt;value&lt;/span&gt; = operation.Operand1 + operation.Operand2;
                        &lt;span class="kwrd"&gt;break&lt;/span&gt;;
                    &lt;span class="kwrd"&gt;case&lt;/span&gt; &lt;span class="str"&gt;&amp;quot;-&amp;quot;&lt;/span&gt;:
                        &lt;span class="kwrd"&gt;value&lt;/span&gt; = operation.Operand1 - operation.Operand2;
                        &lt;span class="kwrd"&gt;break&lt;/span&gt;;
                    &lt;span class="kwrd"&gt;case&lt;/span&gt; &lt;span class="str"&gt;&amp;quot;*&amp;quot;&lt;/span&gt;:
                        &lt;span class="kwrd"&gt;value&lt;/span&gt; = operation.Operand1 * operation.Operand2;
                        &lt;span class="kwrd"&gt;break&lt;/span&gt;;
                    &lt;span class="kwrd"&gt;case&lt;/span&gt; &lt;span class="str"&gt;&amp;quot;/&amp;quot;&lt;/span&gt;:
                        &lt;span class="kwrd"&gt;value&lt;/span&gt; = operation.Operand1 / operation.Operand2;
                        &lt;span class="kwrd"&gt;break&lt;/span&gt;;
                    &lt;span class="kwrd"&gt;default&lt;/span&gt;:
                        error = &lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(OperationUnknownErrorMessageFormat, operation.Operator);
                        response.Status = OperationsFailed;
                        ok = &lt;span class="kwrd"&gt;false&lt;/span&gt;;
                        succeeded = &lt;span class="kwrd"&gt;false&lt;/span&gt;;
                        &lt;span class="kwrd"&gt;break&lt;/span&gt;;
                }
                &lt;span class="kwrd"&gt;if&lt;/span&gt; (succeeded)
                {
                    logHelper.WriteLine(&lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(OperationFormat, &lt;span class="str"&gt;&amp;quot;MessageClassesOrchestration&amp;quot;&lt;/span&gt;, operation.Operand1, operation.Operator, operation.Operand2, &lt;span class="kwrd"&gt;value&lt;/span&gt;));
                }
                &lt;span class="kwrd"&gt;else&lt;/span&gt;
                {
                    logHelper.WriteLine(error);
                }
                response.Results.Add(&lt;span class="kwrd"&gt;new&lt;/span&gt; Result(&lt;span class="kwrd"&gt;value&lt;/span&gt;, error));
            }
        }
        &lt;span class="kwrd"&gt;else&lt;/span&gt;
        {
            response.Status = RequestDoesNotContainAnyOperationsMessage;
        }
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (ok)
        {
            logHelper.WriteLine(&lt;span class="str"&gt;&amp;quot;[RequestManager][MessageClassesOrchestration] Response message successfully processed.&amp;quot;&lt;/span&gt;);
        }
        &lt;span class="kwrd"&gt;else&lt;/span&gt;
        {
            logHelper.WriteLine(&lt;span class="str"&gt;&amp;quot;[RequestManager][MessageClassesOrchestration] Request failed.&amp;quot;&lt;/span&gt;);
        }
    }
    &lt;span class="kwrd"&gt;catch&lt;/span&gt; (Exception ex)
    {
        logHelper.WriteLine(&lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(&lt;span class="str"&gt;&amp;quot;[RequestManager][MessageClassesOrchestration] {0}&amp;quot;&lt;/span&gt;, ex.Message));
        response.Status = &lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(&lt;span class="str"&gt;&amp;quot;[RequestManager][MessageClassesOrchestration] {0}&amp;quot;&lt;/span&gt;, ex.Message);
        response.Results = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
    }
    &lt;span class="kwrd"&gt;finally&lt;/span&gt;
    {
        message.Dispose();
    }
    &lt;span class="kwrd"&gt;return&lt;/span&gt; response;
}&lt;/pre&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;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;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;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p align="justify"&gt;In this case the &lt;a href="http://msdn.microsoft.com/en-us/library/ee277299(BTS.10).aspx"&gt;RetrieveAs&lt;/a&gt; method exposed by the &lt;a href="http://msdn.microsoft.com/en-us/library/ee277305(BTS.10).aspx"&gt;XLANGPart&lt;/a&gt; class deserializes the content of the message part and creates an instance of the CalculatorRequest class.&amp;#160; The code for both the CalculatorRequest and CalculatorResponse classes was obtained running the xsd.exe tool to build XML serializable objects for each schema.&lt;/p&gt;

&lt;table border="1" cellspacing="0" cellpadding="5" width="800" bgcolor="#ffffff"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="800"&gt;
        &lt;pre class="csharpcode"&gt;xsd /c /n:&lt;span class="str"&gt;&amp;quot;Microsoft.BizTalk.CAT.Samples.HandleXLANGMessages.BusinessLogic&amp;quot;&lt;/span&gt; &lt;span class="str"&gt;&amp;quot;C:\Projects\HandleXLANGMessages\Schemas\CalculatorRequest.xsd&amp;quot;&lt;/span&gt;&lt;/pre&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;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;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p align="justify"&gt;Indeed, I customized the code returned by the xsd.exe tool to replace arrays with Lists, but anyway… not really a big deal!&lt;/p&gt;

&lt;p align="justify"&gt;&lt;font color="#ff9914"&gt;CalculatorRequest Class&lt;/font&gt;&lt;/p&gt;

&lt;table border="1" cellspacing="0" cellpadding="5" width="800" bgcolor="#ffffff"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="800"&gt;
        &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;namespace&lt;/span&gt; Microsoft.BizTalk.CAT.Samples.HandleXLANGMessages.BusinessLogic
{
    [Serializable]
    [XmlType(AnonymousType = &lt;span class="kwrd"&gt;true&lt;/span&gt;, Namespace = &lt;span class="str"&gt;&amp;quot;http://Microsoft.BizTalk.CAT.Samples.HandleXLANGMessages.Schemas.CalculatorRequest&amp;quot;&lt;/span&gt;)]
    [XmlRoot(Namespace = &lt;span class="str"&gt;&amp;quot;http://Microsoft.BizTalk.CAT.Samples.HandleXLANGMessages.Schemas.CalculatorRequest&amp;quot;&lt;/span&gt;, IsNullable = &lt;span class="kwrd"&gt;false&lt;/span&gt;)]
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;partial&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; CalculatorRequest
    {
        &lt;span class="preproc"&gt;#region&lt;/span&gt; Private Fields
        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; method;
        &lt;span class="kwrd"&gt;private&lt;/span&gt; List&amp;lt;Operation&amp;gt; operations = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;Operation&amp;gt;();
        &lt;span class="preproc"&gt;#endregion&lt;/span&gt;

        &lt;span class="preproc"&gt;#region&lt;/span&gt; Public Properties
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Method
        {
            get
            {
                &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;.method;
            }
            set
            {
                &lt;span class="kwrd"&gt;this&lt;/span&gt;.method = &lt;span class="kwrd"&gt;value&lt;/span&gt;;
            }
        }

        [XmlArrayItem(&lt;span class="str"&gt;&amp;quot;Operation&amp;quot;&lt;/span&gt;, Type=&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(Operation), IsNullable = &lt;span class="kwrd"&gt;false&lt;/span&gt;)]
        &lt;span class="kwrd"&gt;public&lt;/span&gt; List&amp;lt;Operation&amp;gt; Operations
        {
            get
            {
                &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;.operations;
            }
            set
            {
                &lt;span class="kwrd"&gt;this&lt;/span&gt;.operations = &lt;span class="kwrd"&gt;value&lt;/span&gt;;
            }
        } 
        &lt;span class="preproc"&gt;#endregion&lt;/span&gt;
    }

    [Serializable]
    [XmlType(AnonymousType = &lt;span class="kwrd"&gt;true&lt;/span&gt;, Namespace = &lt;span class="str"&gt;&amp;quot;http://Microsoft.BizTalk.CAT.Samples.HandleXLANGMessages.Schemas.CalculatorRequest&amp;quot;&lt;/span&gt;)]
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;partial&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Operation
    {
        &lt;span class="preproc"&gt;#region&lt;/span&gt; Private Fields
        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; op;
        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;double&lt;/span&gt; operand1;
        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;double&lt;/span&gt; operand2;
        &lt;span class="preproc"&gt;#endregion&lt;/span&gt;

        &lt;span class="preproc"&gt;#region&lt;/span&gt; Public Constructors
        &lt;span class="kwrd"&gt;public&lt;/span&gt; Operation()
        {
        }
        &lt;span class="preproc"&gt;#endregion&lt;/span&gt;

        &lt;span class="preproc"&gt;#region&lt;/span&gt; Public Properties
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Operator
        {
            get
            {
                &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;.op;
            }
            set
            {
                &lt;span class="kwrd"&gt;this&lt;/span&gt;.op = &lt;span class="kwrd"&gt;value&lt;/span&gt;;
            }
        }

        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;double&lt;/span&gt; Operand1
        {
            get
            {
                &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;.operand1;
            }
            set
            {
                &lt;span class="kwrd"&gt;this&lt;/span&gt;.operand1 = &lt;span class="kwrd"&gt;value&lt;/span&gt;;
            }
        }

        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;double&lt;/span&gt; Operand2
        {
            get
            {
                &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;.operand2;
            }
            set
            {
                &lt;span class="kwrd"&gt;this&lt;/span&gt;.operand2 = &lt;span class="kwrd"&gt;value&lt;/span&gt;;
            }
        } 
        &lt;span class="preproc"&gt;#endregion&lt;/span&gt;
    }
}&lt;/pre&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;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p align="justify"&gt;&lt;font color="#ff9914"&gt;CalculatorResponse Class&lt;/font&gt;&lt;/p&gt;

&lt;table border="1" cellspacing="0" cellpadding="5" width="800" bgcolor="#ffffff"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="800"&gt;
        &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;namespace&lt;/span&gt; Microsoft.BizTalk.CAT.Samples.HandleXLANGMessages.BusinessLogic
{
    [Serializable]
    [XmlType(AnonymousType=&lt;span class="kwrd"&gt;true&lt;/span&gt;, Namespace=&lt;span class="str"&gt;&amp;quot;http://Microsoft.BizTalk.CAT.Samples.HandleXLANGMessages.Schemas.CalculatorResponse&amp;quot;&lt;/span&gt;)]
    [XmlRoot(Namespace=&lt;span class="str"&gt;&amp;quot;http://Microsoft.BizTalk.CAT.Samples.HandleXLANGMessages.Schemas.CalculatorResponse&amp;quot;&lt;/span&gt;, IsNullable=&lt;span class="kwrd"&gt;false&lt;/span&gt;)]
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;partial&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; CalculatorResponse
    {
        &lt;span class="preproc"&gt;#region&lt;/span&gt; Private Fields
        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; status;
        &lt;span class="kwrd"&gt;private&lt;/span&gt; List&amp;lt;Result&amp;gt; results = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;Result&amp;gt;();
        &lt;span class="preproc"&gt;#endregion&lt;/span&gt;

        &lt;span class="preproc"&gt;#region&lt;/span&gt; Public Properties
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Status 
        {
            get 
            {
                &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;.status;
            }
            set 
            {
                &lt;span class="kwrd"&gt;this&lt;/span&gt;.status = &lt;span class="kwrd"&gt;value&lt;/span&gt;;
            }
        }
        
        [XmlArrayItem(&lt;span class="str"&gt;&amp;quot;Result&amp;quot;&lt;/span&gt;, Type=&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(Result), IsNullable=&lt;span class="kwrd"&gt;false&lt;/span&gt;)]
        &lt;span class="kwrd"&gt;public&lt;/span&gt; List&amp;lt;Result&amp;gt; Results 
        {
            get 
            {
                &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;.results;
            }
            set 
            {
                &lt;span class="kwrd"&gt;this&lt;/span&gt;.results = &lt;span class="kwrd"&gt;value&lt;/span&gt;;
            }
        }
        &lt;span class="preproc"&gt;#endregion&lt;/span&gt;
    }

    [Serializable]
    [XmlType(AnonymousType=&lt;span class="kwrd"&gt;true&lt;/span&gt;, Namespace=&lt;span class="str"&gt;&amp;quot;http://Microsoft.BizTalk.CAT.Samples.HandleXLANGMessages.Schemas.CalculatorResponse&amp;quot;&lt;/span&gt;)]
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;partial&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Result
    {
        &lt;span class="preproc"&gt;#region&lt;/span&gt; Private Fields
        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;double&lt;/span&gt; &lt;span class="kwrd"&gt;value&lt;/span&gt;;
        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; error; 
        &lt;span class="preproc"&gt;#endregion&lt;/span&gt;

        &lt;span class="preproc"&gt;#region&lt;/span&gt; Public Constructors
        &lt;span class="kwrd"&gt;public&lt;/span&gt; Result()
        {
            &lt;span class="kwrd"&gt;this&lt;/span&gt;.&lt;span class="kwrd"&gt;value&lt;/span&gt; = &lt;span class="kwrd"&gt;default&lt;/span&gt;(&lt;span class="kwrd"&gt;double&lt;/span&gt;);
            &lt;span class="kwrd"&gt;this&lt;/span&gt;.error = &lt;span class="kwrd"&gt;default&lt;/span&gt;(&lt;span class="kwrd"&gt;string&lt;/span&gt;);
        }

        &lt;span class="kwrd"&gt;public&lt;/span&gt; Result(&lt;span class="kwrd"&gt;double&lt;/span&gt; &lt;span class="kwrd"&gt;value&lt;/span&gt;, &lt;span class="kwrd"&gt;string&lt;/span&gt; error)
        {
            &lt;span class="kwrd"&gt;this&lt;/span&gt;.&lt;span class="kwrd"&gt;value&lt;/span&gt; = &lt;span class="kwrd"&gt;value&lt;/span&gt;;
            &lt;span class="kwrd"&gt;this&lt;/span&gt;.error = error;
        }
        &lt;span class="preproc"&gt;#endregion&lt;/span&gt;

        &lt;span class="preproc"&gt;#region&lt;/span&gt; Public Properties        
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;double&lt;/span&gt; Value
        {
            get
            {
                &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;.&lt;span class="kwrd"&gt;value&lt;/span&gt;;
            }
            set
            {
                &lt;span class="kwrd"&gt;this&lt;/span&gt;.&lt;span class="kwrd"&gt;value&lt;/span&gt; = &lt;span class="kwrd"&gt;value&lt;/span&gt;;
            }
        }
        
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Error
        {
            get
            {
                &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;.error;
            }
            set
            {
                &lt;span class="kwrd"&gt;this&lt;/span&gt;.error = &lt;span class="kwrd"&gt;value&lt;/span&gt;;
            }
        } 
        &lt;span class="preproc"&gt;#endregion&lt;/span&gt;
    }
}&lt;/pre&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;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;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;&lt;font color="#ff9914"&gt;Response Message Assignment&lt;/font&gt; &lt;/p&gt;

&lt;p&gt;To assign the content of the CalculatorResponse object returned by the ProcessRequestReturnObject to the response message, the Message Assignment Shape (see the code below) just assign the calculatorResponse object to the message. The XLANG Engine accepts and interprets this particular syntax as a call to the &lt;a href="http://msdn.microsoft.com/en-us/library/ee277291(BTS.10).aspx"&gt;LoadFrom&lt;/a&gt; method exposed by the &lt;a href="http://msdn.microsoft.com/en-us/library/ee277305(BTS.10).aspx"&gt;XLANGPart&lt;/a&gt; which in its turn serializes the object instance into an XML stream.&lt;/p&gt;

&lt;table border="1" cellspacing="0" cellpadding="5" width="800" bgcolor="#ffffff"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="800"&gt;
        &lt;pre class="csharpcode"&gt;responseMessage = calculatorResponse;&lt;/pre&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;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p align="justify"&gt;&lt;font color="#ff9914"&gt;Comment&lt;/font&gt;&lt;/p&gt;

&lt;p align="justify"&gt;Using the xsd.exe tool you can create a .NET class for each XML schema used by the solution. This approach allows to deserialize an inbound message into an instance of a custom entity class or to to serialize an object to create an XML instance. This technique allows developers to use an object oriented approach when dealing with messages as they can exploit the properties and methods exposed by classes to access and manipulate data instead of using XPath expressions. This approach is valid until the size of messages exchanged and processed by a BizTalk Application is relatively small. As the message size increases, the cost in terms of CPU and Memory usage for deserializing xml messages into objects and serializing objects into xml messages can grow significantly and this technique loses effectiveness. &lt;/p&gt;

&lt;p align="justify"&gt;&lt;strong&gt;&lt;font color="#ff9914"&gt;CustomBtxMessageOrchestration&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p align="justify"&gt;The following picture depicts the architecture of the CustomBtxMessageOrchestration test case.&lt;/p&gt;

&lt;p align="justify"&gt;&lt;a href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/4Differentwaystoprocessanxlangmessagewit_E2DC/CustomBtxMessageOrchestration_2.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="CustomBtxMessageOrchestration" border="0" alt="CustomBtxMessageOrchestration" src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/4Differentwaystoprocessanxlangmessagewit_E2DC/CustomBtxMessageOrchestration_thumb.jpg" width="802" height="265" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;font color="#ff9914"&gt;Message Flow:&lt;/font&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;A WCF-BasicHttp or WCF-Custom Request-Response Receive Location receives a new CalculatorRequest xml document from the Test Agent/Client Application. &lt;/li&gt;

  &lt;li&gt;The XML disassembler component within the XMLTransmit pipeline promotes the Method element inside the CalculatorRequest xml document. The Message Agent submits the incoming message to the MessageBox (BizTalkMsgBoxDb). &lt;/li&gt;

  &lt;li&gt;The inbound request starts a new instance of the CustomBtxMessageOrchestration. This latter uses a Direct Port receive the CalculatorRequest messages with the Method promoted property = “CustomBtxMessageOrchestration”. &lt;/li&gt;

  &lt;li&gt;The CustomBtxMessageOrchestration invokes the ProcessRequestReturnXLANGMessage method exposed by the RequestManager helper component. This object processes within a loop all the operations contained in the inbound XLANGMessage. In particular, the ProcessRequestReturnXLANGMessage uses an XmlReader object to read and process the operations and an XmlWriter and a VirtualStream objects to produce the response message. &lt;/li&gt;

  &lt;li&gt;The ProcessRequestReturnXLANGMessage&amp;#160; method returns a new XLANGMessage. &lt;/li&gt;

  &lt;li&gt;The CustomBtxMessageOrchestration publishes the CalculatorResponse message to the MessageBox (BizTalkMsgBoxDb). &lt;/li&gt;

  &lt;li&gt;The response message is retrieved by the Request-Response WCF-BasicHttp or WCF-Custom Receive Location. &lt;/li&gt;

  &lt;li&gt;The response message is returned to the Test Agent/Client Application. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;font color="#ff9914"&gt;Orchestration:&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;The following picture shows the structure of the test CustomBtxMessageOrchestration .&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/4Differentwaystoprocessanxlangmessagewit_E2DC/CustomBtxMessageOrchestration2_2.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="CustomBtxMessageOrchestration2" border="0" alt="CustomBtxMessageOrchestration2" src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/4Differentwaystoprocessanxlangmessagewit_E2DC/CustomBtxMessageOrchestration2_thumb.jpg" width="602" height="908" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p align="justify"&gt;&lt;strong&gt;&lt;font color="#ff9914"&gt;AsyncCustomBtxMessageOrchestration&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p align="justify"&gt;The following picture depicts the architecture of the AsyncCustomBtxMessageOrchestration test case.&lt;/p&gt;

&lt;p align="justify"&gt;&lt;/p&gt;

&lt;p align="justify"&gt;&lt;/p&gt;

&lt;p align="justify"&gt;&lt;a href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/4Differentwaystoprocessanxlangmessagewit_E2DC/AsyncCustomBTXMessageOrchestration_2.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="AsyncCustomBTXMessageOrchestration" border="0" alt="AsyncCustomBTXMessageOrchestration" src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/4Differentwaystoprocessanxlangmessagewit_E2DC/AsyncCustomBTXMessageOrchestration_thumb.jpg" width="802" height="265" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;font color="#ff9914"&gt;Message Flow:&lt;/font&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;A One-Way FILE Receive Location receives a new CalculatorRequest xml document from the Client Application or &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=c8af583f-7044-48db-b7b9-969072df1689&amp;amp;DisplayLang=en"&gt;Loadgen&lt;/a&gt;. &lt;/li&gt;

  &lt;li&gt;The XML disassembler component within the XMLTransmit pipeline promotes the Method element inside the CalculatorRequest xml document. The Message Agent submits the incoming message to the MessageBox (BizTalkMsgBoxDb). &lt;/li&gt;

  &lt;li&gt;The inbound request starts a new instance of the AsyncCustomBtxMessageOrchestration. This latter uses a Direct Port receive the CalculatorRequest messages with the Method promoted property = “AsyncCustomBtxMessageOrchestration”. &lt;/li&gt;

  &lt;li&gt;The AsyncCustomBtxMessageOrchestration invokes the ProcessRequestReturnXLANGMessage method exposed by the RequestManager helper component. This object processes within a loop all the operations contained in the inbound XLANGMessage. In particular, the ProcessRequestReturnXLANGMessage uses an XmlReader object to read and process the operations and an XmlWriter and a VirtualStream objects to produce the response message. &lt;/li&gt;

  &lt;li&gt;The ProcessRequestReturnXLANGMessage&amp;#160; method returns a new XLANGMessage. &lt;/li&gt;

  &lt;li&gt;The AsyncCustomBtxMessageOrchestration publishes the CalculatorResponse message to the MessageBox (BizTalkMsgBoxDb). &lt;/li&gt;

  &lt;li&gt;The response message is retrieved by a One-Way FILE Send Port. &lt;/li&gt;

  &lt;li&gt;The response message is written to an output folder by the One-Way FILE Send Port. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;font color="#ff9914"&gt;Orchestration:&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;The following picture shows the structure of the test AsyncCustomBtxMessageOrchestration.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/4Differentwaystoprocessanxlangmessagewit_E2DC/AsyncCustomBTXMessageOrchestration2_2.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="AsyncCustomBTXMessageOrchestration2" border="0" alt="AsyncCustomBTXMessageOrchestration2" src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/4Differentwaystoprocessanxlangmessagewit_E2DC/AsyncCustomBTXMessageOrchestration2_thumb.jpg" width="602" height="908" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;font color="#ff9914"&gt;Code&lt;/font&gt;&lt;/p&gt;

&lt;p align="justify"&gt;The CustomBtxMessageOrchestration receives a request message and returns a response document through a Request-Response Direct Bound Logical Port. The Filter Expression defined on the Activate Receive Shape is configured to receive all the CalculatorRequest messages which Method promoted property equals ‘CustomBtxMessageOrchestration ’. The Expression Shape called BusinessLogic contains the following code: &lt;/p&gt;

&lt;table border="1" cellspacing="0" cellpadding="5" width="800" bgcolor="#ffffff"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="800"&gt;
        &lt;pre class="csharpcode"&gt;logHelper.WriteLine(&lt;span class="str"&gt;&amp;quot;[CustomBtxMessageOrchestration] Request message received.&amp;quot;&lt;/span&gt;);
responseMessage = requestManager.ProcessRequestReturnXLANGMessage(requestMessage);
logHelper.WriteLine(&lt;span class="str"&gt;&amp;quot;[CustomBtxMessageOrchestration] Request message successfully processed.&amp;quot;&lt;/span&gt;);&lt;/pre&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;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;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;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p align="justify"&gt;As the name suggests, the ProcessRequestReturnXLANGMessage method exposed by the RequestManager component receives the CalculatorRequest message as XLANGMessage input parameter and returns a XLANGMessage object containing the response document. But…wait a minute, the XLANGMessage class do not exposes any public constructor. So how can we create a brand new XLANGMessage within an helper component? Well, there’s a trick underneath and we’ll see the details in a moment. The ProcessRequestReturnXLANGMessage method adopts the same streaming approach and mostly the same code used by the ProcessRequestReturnStream method to process the incoming message and generate the response message:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;div align="justify"&gt;It uses a VirtualStream and an XmlReader to read the content of the request message.&lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;It uses a VirtualStream and an XmlWriter to generate the response message.&lt;/div&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p align="justify"&gt;However, instead of returning a Stream it returns an XLANGMessage… or better… it returns an instance of the &lt;font color="#ff9914"&gt;CustomBTXMessage&lt;/font&gt; class which inherits from the &lt;font color="#ff9914"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.biztalk.xlangs.btxengine.btxmessage(BTS.10).aspx"&gt;BTXMessage&lt;/a&gt;&amp;#160;&lt;font color="#ffffff"&gt;contained in the&lt;/font&gt; &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.biztalk.xlangs.btxengine(BTS.10).aspx"&gt;Microsoft.XLANGs.BizTalk.Engine&lt;/a&gt; &lt;/font&gt;&lt;font color="#ffffff"&gt;assembly. Therefore, the XLANGMessage object returned by the ProcessRequestReturnXLANGMessage method can be directly assigned to the response message in the Expression Shape without the need to introduce a separate Message Assignment Shape in the orchestration.&lt;/font&gt;&lt;/p&gt;

&lt;p align="justify"&gt;The XLANGMessage indeed is an abstract class so whenever an orchestration invokes a method exposed by a business component and passes an XLANGMessage as parameter, the real type of the object is &lt;font color="#ff9914"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.xlangs.core.messagewrapperforusercode(BTS.10).aspx"&gt;MessageWrapperForUserCode&lt;/a&gt;&lt;/font&gt;. Now the trick to create and return an XLANGMessage object as result of a method call is to create a custom class which inherits from a BizTalk-provided class that in its turn inherits from the XLANGMessage. So i chose to create a custom class called &lt;font color="#ff9914"&gt;CustomBTXMessage&lt;/font&gt;&amp;#160; that inherits from the &lt;font color="#ff9914"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.biztalk.xlangs.btxengine.btxmessage(BTS.10).aspx"&gt;BTXMessage&lt;/a&gt;&lt;/font&gt; class. See the code below:&lt;/p&gt;

&lt;p align="justify"&gt;&lt;font color="#ff9914"&gt;CustomBTXMessage&lt;/font&gt;&amp;#160; &lt;font color="#ff9914"&gt;Class&lt;/font&gt;&lt;/p&gt;

&lt;table border="1" cellspacing="0" cellpadding="5" width="800" bgcolor="#ffffff"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="800"&gt;
        &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;namespace&lt;/span&gt; Microsoft.BizTalk.CAT.Samples.HandleXLANGMessages.Utilities
{
    [Serializable]
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;sealed&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; CustomBTXMessage : BTXMessage
    {
        &lt;span class="kwrd"&gt;public&lt;/span&gt; CustomBTXMessage(&lt;span class="kwrd"&gt;string&lt;/span&gt; messageName, Context context)
            : &lt;span class="kwrd"&gt;base&lt;/span&gt;(messageName, context)
        {
            context.RefMessage(&lt;span class="kwrd"&gt;this&lt;/span&gt;);
        }
    }
}&lt;/pre&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;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;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;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;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;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p align="justify"&gt;Said that, the code of the ProcessRequestReturnXLANGMessage looks as follows:&lt;/p&gt;

&lt;p align="justify"&gt;&lt;font color="#ff9914"&gt;ProcessRequestReturnXLANGMessage Method&lt;/font&gt;&lt;/p&gt;

&lt;p align="justify"&gt;
  &lt;table border="1" cellspacing="0" cellpadding="5" width="800" bgcolor="#ffffff"&gt;&lt;tbody&gt;
      &lt;tr&gt;
        &lt;td valign="top" width="800"&gt;
          &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; XLANGMessage ProcessRequestReturnXLANGMessage(XLANGMessage requestMessage)
{
    CustomBTXMessage customBTXMessage = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
    XLANGMessage responseMessage = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
    VirtualStream stream = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
    List&amp;lt;Response&amp;gt; responseList = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;Response&amp;gt;();
    &lt;span class="kwrd"&gt;string&lt;/span&gt; op = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
    &lt;span class="kwrd"&gt;string&lt;/span&gt; status = Ok;
    &lt;span class="kwrd"&gt;string&lt;/span&gt; error = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
    &lt;span class="kwrd"&gt;double&lt;/span&gt; operand1 = 0;
    &lt;span class="kwrd"&gt;double&lt;/span&gt; operand2 = 0;
    &lt;span class="kwrd"&gt;double&lt;/span&gt; &lt;span class="kwrd"&gt;value&lt;/span&gt; = 0;
    &lt;span class="kwrd"&gt;bool&lt;/span&gt; ok = &lt;span class="kwrd"&gt;true&lt;/span&gt;;
    &lt;span class="kwrd"&gt;bool&lt;/span&gt; succeeded = &lt;span class="kwrd"&gt;true&lt;/span&gt;;
    &lt;span class="kwrd"&gt;int&lt;/span&gt; i = 0;

    &lt;span class="kwrd"&gt;try&lt;/span&gt;
    {
        logHelper.WriteLine(&lt;span class="str"&gt;&amp;quot;[RequestManager][CustomBtxMessageOrchestration] Request message received.&amp;quot;&lt;/span&gt;);
        &lt;span class="kwrd"&gt;using&lt;/span&gt; (XmlReader reader = (XmlReader)requestMessage[0].RetrieveAs(&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(XmlReader)))
        {
            &lt;span class="kwrd"&gt;while&lt;/span&gt; (reader.Read() &amp;amp;&amp;amp; ok)
            {
                &lt;span class="kwrd"&gt;if&lt;/span&gt; (reader.LocalName == &lt;span class="str"&gt;&amp;quot;Operator&amp;quot;&lt;/span&gt; &amp;amp;&amp;amp;
                    reader.NodeType == XmlNodeType.Element)
                {
                    error = None;
                    &lt;span class="kwrd"&gt;value&lt;/span&gt; = 0;
                    succeeded = &lt;span class="kwrd"&gt;true&lt;/span&gt;;
                    op = reader.ReadElementContentAsString();
                    reader.MoveToContent();
                    operand1 = reader.ReadElementContentAsDouble();
                    reader.MoveToContent();
                    operand2 = reader.ReadElementContentAsDouble();
                    i++;
                    &lt;span class="kwrd"&gt;switch&lt;/span&gt; (op)
                    {
                        &lt;span class="kwrd"&gt;case&lt;/span&gt; &lt;span class="str"&gt;&amp;quot;+&amp;quot;&lt;/span&gt;:
                            &lt;span class="kwrd"&gt;value&lt;/span&gt; = operand1 + operand2;
                            &lt;span class="kwrd"&gt;break&lt;/span&gt;;
                        &lt;span class="kwrd"&gt;case&lt;/span&gt; &lt;span class="str"&gt;&amp;quot;-&amp;quot;&lt;/span&gt;:
                            &lt;span class="kwrd"&gt;value&lt;/span&gt; = operand1 - operand2;
                            &lt;span class="kwrd"&gt;break&lt;/span&gt;;
                        &lt;span class="kwrd"&gt;case&lt;/span&gt; &lt;span class="str"&gt;&amp;quot;*&amp;quot;&lt;/span&gt;:
                            &lt;span class="kwrd"&gt;value&lt;/span&gt; = operand1 * operand2;
                            &lt;span class="kwrd"&gt;break&lt;/span&gt;;
                        &lt;span class="kwrd"&gt;case&lt;/span&gt; &lt;span class="str"&gt;&amp;quot;/&amp;quot;&lt;/span&gt;:
                            &lt;span class="kwrd"&gt;value&lt;/span&gt; = operand1 / operand2;
                            &lt;span class="kwrd"&gt;break&lt;/span&gt;;
                        &lt;span class="kwrd"&gt;default&lt;/span&gt;:
                            error = &lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(OperationUnknownErrorMessageFormat, op);
                            status = OperationsFailed;
                            ok = &lt;span class="kwrd"&gt;false&lt;/span&gt;;
                            succeeded = &lt;span class="kwrd"&gt;false&lt;/span&gt;;
                            &lt;span class="kwrd"&gt;break&lt;/span&gt;;
                    }
                    &lt;span class="kwrd"&gt;if&lt;/span&gt; (succeeded)
                    {
                        logHelper.WriteLine(&lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(OperationFormat, &lt;span class="str"&gt;&amp;quot;CustomBtxMessageOrchestration&amp;quot;&lt;/span&gt;, operand1, op, operand2, &lt;span class="kwrd"&gt;value&lt;/span&gt;));
                    }
                    &lt;span class="kwrd"&gt;else&lt;/span&gt;
                    {
                        logHelper.WriteLine(error);
                    }
                    responseList.Add(&lt;span class="kwrd"&gt;new&lt;/span&gt; Response(error, &lt;span class="kwrd"&gt;value&lt;/span&gt;));
                }
            }
        }
        stream = &lt;span class="kwrd"&gt;new&lt;/span&gt; VirtualStream(bufferSize, thresholdSize);
        &lt;span class="kwrd"&gt;using&lt;/span&gt; (XmlWriter writer = XmlWriter.Create(stream))
        {
            writer.WriteStartDocument();
            writer.WriteStartElement(&lt;span class="str"&gt;&amp;quot;CalculatorResponse&amp;quot;&lt;/span&gt;, CalculatorResponseNamespace);
            writer.WriteStartElement(&lt;span class="str"&gt;&amp;quot;Status&amp;quot;&lt;/span&gt;, CalculatorResponseNamespace);
            writer.WriteString(status);
            writer.WriteEndElement();
            writer.WriteStartElement(&lt;span class="str"&gt;&amp;quot;Results&amp;quot;&lt;/span&gt;, CalculatorResponseNamespace);
            &lt;span class="kwrd"&gt;for&lt;/span&gt; (i = 0; i &amp;lt; responseList.Count; i++)
            {
                writer.WriteStartElement(&lt;span class="str"&gt;&amp;quot;Result&amp;quot;&lt;/span&gt;, CalculatorResponseNamespace);
                writer.WriteStartElement(&lt;span class="str"&gt;&amp;quot;Value&amp;quot;&lt;/span&gt;, CalculatorResponseNamespace);
                writer.WriteString(responseList[i].Value.ToString());
                writer.WriteEndElement();
                writer.WriteStartElement(&lt;span class="str"&gt;&amp;quot;Error&amp;quot;&lt;/span&gt;, CalculatorResponseNamespace);
                writer.WriteString(responseList[i].Error);
                writer.WriteEndElement();
                writer.WriteEndElement();
            }
            writer.WriteEndElement();
            writer.WriteEndElement();
        }
        stream.Seek(0, SeekOrigin.Begin);
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (ok)
        {
            logHelper.WriteLine(&lt;span class="str"&gt;&amp;quot;[RequestManager][CustomBtxMessageOrchestration] Response message successfully processed.&amp;quot;&lt;/span&gt;);
        }
        &lt;span class="kwrd"&gt;else&lt;/span&gt;
        {
            logHelper.WriteLine(&lt;span class="str"&gt;&amp;quot;[RequestManager][CustomBtxMessageOrchestration] Request failed.&amp;quot;&lt;/span&gt;);
        }

    }
    &lt;span class="kwrd"&gt;catch&lt;/span&gt; (Exception ex)
    {
        logHelper.WriteLine(&lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(&lt;span class="str"&gt;&amp;quot;[RequestManager][CustomBtxMessageOrchestration] {0}&amp;quot;&lt;/span&gt;, ex.Message));
        stream = &lt;span class="kwrd"&gt;new&lt;/span&gt; VirtualStream(bufferSize, thresholdSize);
        &lt;span class="kwrd"&gt;using&lt;/span&gt; (XmlWriter writer = XmlWriter.Create(stream))
        {
            writer.WriteStartDocument();
            writer.WriteStartElement(&lt;span class="str"&gt;&amp;quot;CalculatorResponse&amp;quot;&lt;/span&gt;, CalculatorResponseNamespace);
            writer.WriteStartElement(&lt;span class="str"&gt;&amp;quot;Status&amp;quot;&lt;/span&gt;, CalculatorResponseNamespace);
            writer.WriteString(ex.Message);
            writer.WriteEndElement();
            writer.WriteEndElement();
        }
        stream.Seek(0, SeekOrigin.Begin);
    }
    &lt;span class="kwrd"&gt;finally&lt;/span&gt;
    {
        customBTXMessage = &lt;span class="kwrd"&gt;new&lt;/span&gt; CustomBTXMessage(&lt;span class="str"&gt;&amp;quot;CalculatorResponse&amp;quot;&lt;/span&gt;, Service.RootService.XlangStore.OwningContext);
        customBTXMessage.AddPart(&lt;span class="kwrd"&gt;string&lt;/span&gt;.Empty, &lt;span class="str"&gt;&amp;quot;Body&amp;quot;&lt;/span&gt;);
        customBTXMessage[0].LoadFrom(stream);
        responseMessage = customBTXMessage.GetMessageWrapperForUserCode();
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (requestMessage != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
        {
            requestMessage.Dispose();
        }
    }
    &lt;span class="kwrd"&gt;return&lt;/span&gt; responseMessage; 
}&lt;/pre&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;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;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;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;/td&gt;
      &lt;/tr&gt;
    &lt;/tbody&gt;&lt;/table&gt;
&lt;/p&gt;

&lt;p&gt;&lt;font color="#ff9914"&gt;&lt;strong&gt;Comment&lt;/strong&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p align="justify"&gt;This technique is tricky and combines the performance of the streaming approach with the ability to directly return an XLANGMessage. In the &lt;a href="http://blogs.msdn.com/paolos/archive/2009/09/21/4-different-ways-to-process-an-xlangmessage-within-an-helper-component-invoked-by-an-orchestration-part-2.aspx"&gt;second part&lt;/a&gt; of the article, I will present the results of the performance tests I conducted to measure and compare the latency and throughput of the design patterns discussed in this post.&lt;/p&gt;

&lt;p&gt;&lt;font color="#ff9914"&gt;&lt;strong&gt;Code&lt;/strong&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;You can find the code for BizTalk Server 2009 &lt;a href="http://cid-09dba4a06b360a65.skydrive.live.com/self.aspx/Pubblica/HandleXLANGMessages.zip"&gt;here&lt;/a&gt;, while at the following &lt;a href="http://cid-09dba4a06b360a65.skydrive.live.com/self.aspx/Pubblica/HandleXLANGMessagesUseCases.zip"&gt;link&lt;/a&gt; you can download the Visio document I used to create my diagrams! Please, let me know your feedbacks! Enjoy! :-)&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9893750" width="1" height="1"&gt;</description></item><item><title>BizTalk Server 2009 Performance on Hyper-V and Physical Deployments</title><link>http://blogs.msdn.com/paolos/archive/2009/08/31/biztalk-server-2009-performance-on-hyper-v-and-physical-deployments.aspx</link><pubDate>Mon, 31 Aug 2009 16:37:15 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9889349</guid><dc:creator>leprino</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/paolos/comments/9889349.aspx</comments><wfw:commentRss>http://blogs.msdn.com/paolos/commentrss.aspx?PostID=9889349</wfw:commentRss><wfw:comment>http://blogs.msdn.com/paolos/rsscomments.aspx?PostID=9889349</wfw:comment><description>&lt;p&gt;My friend and colleague Ewan Fairweather will deliver a presentation during which he will cover all the performance testing results he/we obtained in the lab this year on physical and Hyper-V systems. If you would like to understand the performance differences of BizTalk Server 2009 on Microsoft SQL Server 2008, Windows Server 2008, and Hyper-V platforms, this webcast is for you.&lt;/p&gt;  &lt;p&gt;&lt;a href="https://emea.mail.microsoft.com/redir.aspx?C=54ae8d11442c499fbad4b09ff9ffb280&amp;amp;URL=http%3a%2f%2fservices.social.microsoft.com%2ffeeds%2fFeedItem%3ffeedId%3d1683b510-93c4-4ec4-9dc0-546cf91d1fd8%26itemId%3db86251bd-52ca-4582-8eb9-0f848ba533d9%26title%3dRegister%2bfor%2bthe%2bupcoming%2bTechNet%2bWebcast%253a%2bBizTalk%2bServer%2b2009%2bPerformance%2bon%2bHyper-V%2band%2bPhysical%2bDeployments%2b(Level%2b300)%26uri%3dhttp%253a%252f%252fmsevents.microsoft.com%252fCUI%252fWebCastEventDetails.aspx%253fEventID%253d1032416252%2526EventCategory%253d4%2526culture%253den-US%2526CountryCode%253dUS%26k%3dpTzkYfS1HcCRO14lQ0hsdhrMumhjKiWhwGHC65ME7HQ%253d"&gt;Register for the upcoming TechNet Webcast: BizTalk Server 2009 Performance on Hyper-V and Physical Deployments (Level 300)&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;   &lt;br /&gt;&lt;strong&gt;Language(s): &lt;/strong&gt;English.     &lt;br /&gt;&lt;strong&gt;Product(s): &lt;/strong&gt;Microsoft BizTalk Server.     &lt;br /&gt;&lt;strong&gt;Audience(s): &lt;/strong&gt;IT Generalist.     &lt;br /&gt;&lt;b&gt;Duration: &lt;/b&gt;60 Minutes     &lt;br /&gt;&lt;strong&gt;Start Date: &lt;/strong&gt;Tuesday, September 01, 2009 1:00 PM Pacific Time (US &amp;amp; Canada)&lt;/p&gt;  &lt;p&gt;   &lt;br /&gt;&lt;b&gt;&lt;font color="#ff9900"&gt;Event Overview&lt;/font&gt;&lt;/b&gt; &lt;/p&gt;  &lt;p&gt;As part of the Microsoft BizTalk Server 2009 launch wave, the BizTalk Rangers and Technology Adoption Program (TAP) teams are conducting a performance lab to compare Microsoft BizTalk Server 2006 R2, BizTalk Server 2009 (physical), and BizTalk Server 2009 on a Hyper-V platform. In this webcast, you hear from the product group about the performance characteristics of solutions deployed on different platforms. We outline the tests that we have performed and the results that we obtained, and we share common best practices for deployment. If you would like to understand the performance differences of BizTalk Server 2009 on Microsoft SQL Server 2008, Windows Server 2008, and Hyper-V platforms before the official guides are published, then this webcast is for you.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;font color="#ff9900"&gt;Presenter&lt;/font&gt;: &lt;/b&gt;Ewan Fairweather, Program Manager, Microsoft Corporation&lt;/p&gt;  &lt;p&gt;Ewan Fairweather has worked for Microsoft for four years. He currently works as a program manager in the Microsoft BizTalk Server product group on the Customer Advisory Team (CAT). Prior to this, Ewan spent over three years working for Microsoft U.K. on the Premier Field Engineering team where he worked with enterprise customers, helping them to maintain and optimize their BizTalk applications. This involved providing both proactive and reactive on-site assistance within the U.K. and the rest of Europe. Ewan has also worked in a dedicated capacity on some of the world's largest BizTalk deployments, predominantly within financial services. &lt;/p&gt;  &lt;p&gt;Ewan coauthored the successful Professional BizTalk Server 2006 (Wrox, 2007) and has written many white papers for Microsoft including the &amp;quot;Microsoft BizTalk Server Performance Optimization Guide,&amp;quot; which is available on the Microsoft Developers Network (MSDN) Web site. &lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9889349" width="1" height="1"&gt;</description></item><item><title>BizTalk Server 2009 – End to End Performance Testing</title><link>http://blogs.msdn.com/paolos/archive/2009/07/17/biztalk-server-2009-end-to-end-performance-testing.aspx</link><pubDate>Fri, 17 Jul 2009 16:06:21 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9837362</guid><dc:creator>leprino</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/paolos/comments/9837362.aspx</comments><wfw:commentRss>http://blogs.msdn.com/paolos/commentrss.aspx?PostID=9837362</wfw:commentRss><wfw:comment>http://blogs.msdn.com/paolos/rsscomments.aspx?PostID=9837362</wfw:comment><description>&lt;p align="justify"&gt;At the end of April 2009, I was invited by Microsoft Sweden for the Launch Event of BizTalk Server 2009. During this event I gave a speech about BizTalk Server 2009 End to End Performance Testing. In this session I introduced the methodology and process that the &lt;font color="#ff9900"&gt;BizTalk Customer Advisory Team&lt;/font&gt; follows to achieve consistent results during Performance Labs. The entire process along with the suggested optimizations will be soon delivered in the &lt;font color="#ff9900"&gt;BizTalk Server 2009 Optimization Guide&lt;/font&gt;. In the meantime, you can watch the presentation I took on Channel9:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://channel9.msdn.com/posts/johanlindfors/BizTalk-2009--End-to-end-performance-testing/"&gt;BizTalk Server 2009 – End To End Performance Testing (1/2)&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://channel9.msdn.com/posts/johanlindfors/BizTalk-2009--End-to-end-performance-testing/"&gt;BizTalk Server 2009 – End To End Performance Testing (2/2)&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9837362" width="1" height="1"&gt;</description></item><item><title>SOA Patterns with BizTalk Server 2009 by Richard Seroter</title><link>http://blogs.msdn.com/paolos/archive/2009/06/04/soa-patterns-with-biztalk-server-2009-by-richard-seroter.aspx</link><pubDate>Thu, 04 Jun 2009 10:37:53 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9698662</guid><dc:creator>leprino</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/paolos/comments/9698662.aspx</comments><wfw:commentRss>http://blogs.msdn.com/paolos/commentrss.aspx?PostID=9698662</wfw:commentRss><wfw:comment>http://blogs.msdn.com/paolos/rsscomments.aspx?PostID=9698662</wfw:comment><description>&lt;table border="0" cellspacing="0" cellpadding="5" width="100%"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top"&gt;         &lt;p align="justify"&gt;Recently I had the chance to review an excellent book called &lt;a href="http://www.packtpub.com/soa-patterns-with-biztalk-server-2009/book"&gt;SOA Patterns with BizTalk Server 2009&lt;/a&gt; by Richard Seroter who maintains a popular and appreciated &lt;a href="http://seroter.wordpress.com/"&gt;blog&lt;/a&gt; on BizTalk. The book discusses the core principles of SOA and shows how to effectively apply them in a BizTalk solution. Richard provides a good insight in WCF Adapters and explains with clear samples how to exploit their functionalities to implement synchronous and asynchronous communication patterns.&amp;#160; The author makes a superb introduction of technologies such as the new WCF SQL Adapter, UDDI&amp;#160; and the ESB Guidance 2.0. &lt;a href="http://www.packtpub.com/soa-patterns-with-biztalk-server-2009/book"&gt;SOA Patterns with BizTalk Server 2009&lt;/a&gt; is definitely a must have book for all BizTalk developers, especially for those who intend to design and implement a complex SOA platform using BizTalk Server 2009. You can download for free the &lt;a href="http://www.packtpub.com/files/soa-patterns-with-biztalk-server-2009-sample-chapter-9-new-soa-capabilities-in-biztalk-server-2009-wcf-sql-server-adapter.pdf"&gt;Chapter 9: New SOA Capabilities in BizTalk Server 2009: WCF SQL Server Adapter&lt;/a&gt; from the Packt website. This chapter covers the following topics:&lt;/p&gt;          &lt;ul&gt;           &lt;li&gt;Executing composite transactions &lt;/li&gt;            &lt;li&gt;Polling for data &lt;/li&gt;            &lt;li&gt;Using SQL Server Query notification &lt;/li&gt;            &lt;li&gt;Consuming the adapter from outside BizTalk Server &lt;/li&gt;         &lt;/ul&gt;          &lt;p&gt;I sincerely suggest this book to all BizTalkers. ;-)&lt;/p&gt;       &lt;/td&gt;        &lt;td style="align: right" valign="top" width="110" align="right"&gt;&lt;span style="align: right" align="right"&gt;&lt;a style="align: right" href="http://www.packtpub.com/soa-patterns-with-biztalk-server-2009/book" align="right"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; align: right" title="SOA Patterns" border="0" alt="SOA Patterns" align="right" src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/SOAPatternswithBizTalkServer2009byRichar_8156/SOA%20Patterns_7.png" width="104" height="127" /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9698662" width="1" height="1"&gt;</description></item><item><title>How to Throw Typed Fault Exceptions from Orchestrations Published as WCF Services</title><link>http://blogs.msdn.com/paolos/archive/2009/05/22/how-to-throw-typed-fault-exceptions-from-orchestrations-published-as-wcf-services.aspx</link><pubDate>Fri, 22 May 2009 19:29:22 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9635410</guid><dc:creator>leprino</dc:creator><slash:comments>7</slash:comments><comments>http://blogs.msdn.com/paolos/comments/9635410.aspx</comments><wfw:commentRss>http://blogs.msdn.com/paolos/commentrss.aspx?PostID=9635410</wfw:commentRss><wfw:comment>http://blogs.msdn.com/paolos/rsscomments.aspx?PostID=9635410</wfw:comment><description>&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 align="justify"&gt;In general, a WCF Web Service can return two types of SOAP faults: typed and untyped SOAP faults. &lt;/p&gt;  &lt;h1&gt;&lt;font color="#ff9900"&gt;Typed Faults&lt;/font&gt;&lt;/h1&gt;  &lt;p align="justify"&gt;In order to throw a typed fault, a service operation must be decorated with a &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.faultcontractattribute.aspx"&gt;System.ServiceModel.FaultContractAttribute&lt;/a&gt; that specifies a fault data contract defined earlier. The following code snippet shows a WCF web service called &lt;font color="#ff9900"&gt;HelloWorld&lt;/font&gt; which implements the &lt;font color="#ff9900"&gt;IHelloWorld&lt;/font&gt; service or contract interface. This interface exposes a single synchronous operation called &lt;font color="#ff9900"&gt;SayHello&lt;/font&gt; that is decorated with the &lt;font color="#ff9900"&gt;FaultContractAttribute&lt;/font&gt;. The attribute declares that the &lt;font color="#ff9900"&gt;SayHello&lt;/font&gt; method can throw a typed fault exception defined by the &lt;font color="#ff9900"&gt;CustomError&lt;/font&gt; data contract class. The implementation of the &lt;font color="#ff9900"&gt;SayHello&lt;/font&gt; method in the &lt;font color="#ff9900"&gt;HelloWorld&lt;/font&gt; class checks if the incoming request is null and in this case it throws an error of type &lt;font color="#ff9900"&gt;FaultException&amp;lt;CustomError&amp;gt;&lt;/font&gt;.&lt;/p&gt;  &lt;table border="1" cellspacing="0" cellpadding="5" width="800" bgcolor="#ffffff"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="800"&gt;         &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;namespace&lt;/span&gt; Microsoft.BizTalk.CAT.Samples.PublishTypedFaults.Services
{
    [Serializable]
    [DataContract(Name = &lt;span class="str"&gt;&amp;quot;HelloWorldRequest&amp;quot;&lt;/span&gt;, Namespace = &lt;span class="str"&gt;&amp;quot;http://microsoft.biztalk.cat/10/helloworld&amp;quot;&lt;/span&gt;)]
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; HelloWorldRequest
    {
       ...
    }

    [Serializable]
    [DataContract(Name = &lt;span class="str"&gt;&amp;quot;HelloWorldResponse&amp;quot;&lt;/span&gt;, Namespace = &lt;span class="str"&gt;&amp;quot;http://microsoft.biztalk.cat/10/helloworld&amp;quot;&lt;/span&gt;)]
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; HelloWorldResponse
    {
        ...
    }

    [Serializable]
    [DataContract(Name = &lt;span class="str"&gt;&amp;quot;CustomError&amp;quot;&lt;/span&gt;, Namespace = &lt;span class="str"&gt;&amp;quot;http://microsoft.biztalk.cat/10/customerror&amp;quot;&lt;/span&gt;)]
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; CustomError
    {
        ...
    }

    [ServiceContract(Name = &lt;span class="str"&gt;&amp;quot;HelloWorld&amp;quot;&lt;/span&gt;, Namespace = &lt;span class="str"&gt;&amp;quot;http://microsoft.biztalk.cat/10/helloworld&amp;quot;&lt;/span&gt;)]
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;interface&lt;/span&gt; IHelloWorld
    {
        [OperationContract(Action = &lt;span class="str"&gt;&amp;quot;SayHello&amp;quot;&lt;/span&gt;, ReplyAction = &lt;span class="str"&gt;&amp;quot;SayHello&amp;quot;&lt;/span&gt;, ProtectionLevel = ProtectionLevel.None)]
        [FaultContract(&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(CustomError), Action = &lt;span class="str"&gt;&amp;quot;CustomErrorFault&amp;quot;&lt;/span&gt;)]
        HelloWorldResponse SayHello(HelloWorldRequest request);
    }

    [ServiceBehavior(Name = &lt;span class="str"&gt;&amp;quot;HelloWorld&amp;quot;&lt;/span&gt;, Namespace = &lt;span class="str"&gt;&amp;quot;http://microsoft.biztalk.cat/10/helloworld&amp;quot;&lt;/span&gt;)]
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; HelloWorld : IHelloWorld
    {
        [OperationBehavior]
        &lt;span class="kwrd"&gt;public&lt;/span&gt; HelloWorldResponse SayHello(HelloWorldRequest request)
        {
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (request == &lt;span class="kwrd"&gt;null&lt;/span&gt; || &lt;span class="kwrd"&gt;string&lt;/span&gt;.IsNullOrEmpty(request.Name))
            {
                &lt;span class="kwrd"&gt;throw&lt;/span&gt; CreateFault(NameCannotBeNullOrEmpty);
            }
            &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; HelloWorldResponse(&lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(SayHelloFormat, request.Name));
        } 

         &lt;span class="kwrd"&gt;private&lt;/span&gt; FaultException&amp;lt;CustomError&amp;gt; CreateFault(&lt;span class="kwrd"&gt;string&lt;/span&gt; message)
        {
             ...
            &lt;span class="kwrd"&gt;return&lt;/span&gt; fault;
        }
    }
}&lt;/pre&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;h1&gt;&amp;#160;&lt;/h1&gt;

&lt;h1&gt;&lt;font color="#ff9900"&gt;Untyped Faults&lt;/font&gt;&lt;/h1&gt;

&lt;p&gt;Untyped SOAP faults are those that do not require a service operation to be decorated with a &lt;font color="#ff9900"&gt;FaultContractAttribute&lt;/font&gt; that specify a custom data contract class.&lt;/p&gt;

&lt;h1&gt;&lt;font color="#ff9900"&gt;BizTalk Orchestrations and Typed Faults&lt;/font&gt;&lt;/h1&gt;

&lt;p align="justify"&gt;BizTalk Server 2006 R2 and BizTalk Server 2009 allow handling typed fault contracts when consuming WCF services from within orchestrations. The steps necessary to implement this technique are clearly described in the&amp;#160; article “&lt;a href="http://msdn.microsoft.com/en-us/library/bb246117.aspx"&gt;How to Handle Typed Fault Contracts in Orchestrations&lt;/a&gt;” on MSDN. Instead, WCF adapters actually do not support processing typed fault contract exceptions within orchestrations published as WCF services. However, untyped SOAP faults can always be returned by orchestrations or pipelines. For more information on this topic review the article “&lt;a href="http://msdn.microsoft.com/en-us/library/bb226394.aspx"&gt;How to Throw Fault Exceptions from Orchestrations Published as WCF Services&lt;/a&gt;” on MSDN.&lt;/p&gt;

&lt;p align="justify"&gt;This constraint arises from how the Receive Handler of&lt;font color="#ff9900"&gt; WCF Adapters&lt;/font&gt; is actually implemented. The WCF Receive Adapter instantiates a singleton instance of the &lt;font color="#ff9900"&gt;BizTalkServiceInstance&lt;/font&gt; class for each WCF Receive Location. This class can be found in the &lt;font color="#ff9900"&gt;Microsoft.BizTalk.Adapter.Wcf.Runtime.dll&lt;/font&gt; assembly. In particular, as you can see in the picture below, the &lt;font color="#ff9900"&gt;BizTalkServiceInstance&lt;/font&gt; class is decorated with the attribute &lt;font color="#ff9900"&gt;ServiceBehavior(InstanceContextMode=InstanceContextMode.Single, ConcurrencyMode=ConcurrencyMode.Multiple)&lt;/font&gt;. &lt;/p&gt;

&lt;p align="justify"&gt;&lt;a href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/Reflector1_2.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Reflector1" border="0" alt="Reflector1" src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/Reflector1_thumb.jpg" width="1024" height="709" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p align="justify"&gt;Therefore, all the incoming requests towards a given WCF Receive Location are are managed by the same singleton object. When you enable a WCF Receive Location, the Adapter initializes and opens a dedicated instance of a &lt;font color="#ff9900"&gt;ServiceHost&lt;/font&gt;-derived class (&lt;font color="#ff9900"&gt;WebServiceHost&lt;/font&gt;), which dynamically builds the WCF runtime components within the in-process or isolated host process. This includes the channel stack, dispatcher, and generic service instance. Almost all of the WCF adapters can be hosted within the BizTalk service process itself – the only exception is &lt;font color="#ff9900"&gt;WCF-CustomIsolated&lt;/font&gt;, which must be used in a BizTalk isolated host by design. Even the HTTP adapters can be hosted in-process now. The WCF Adapters build the generic service contracts shown in the table below. Each service contract implemented by the &lt;font color="#ff9900"&gt;BizTalkServiceInstance&lt;/font&gt; covers a different scenario. &lt;/p&gt;

&lt;table border="1" cellspacing="0" cellpadding="5" width="800" bgcolor="#ffffff"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="800"&gt;
        &lt;pre class="csharpcode"&gt;[ServiceContract(Namespace = &lt;span class="str"&gt;&amp;quot;http://www.microsoft.com/biztalk/2006/r2/wcf-adapter&amp;quot;&lt;/span&gt;)]
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;interface&lt;/span&gt; IOneWayAsync
{
    &lt;span class="rem"&gt;// Methods&lt;/span&gt;
    [OperationContract(AsyncPattern = &lt;span class="kwrd"&gt;true&lt;/span&gt;, IsOneWay = &lt;span class="kwrd"&gt;true&lt;/span&gt;, Action = &lt;span class="str"&gt;&amp;quot;*&amp;quot;&lt;/span&gt;)]
    IAsyncResult BeginOneWayMethod(Message message, AsyncCallback callback, &lt;span class="kwrd"&gt;object&lt;/span&gt; state);
    [OperationContract(IsOneWay = &lt;span class="kwrd"&gt;true&lt;/span&gt;, Action = &lt;span class="str"&gt;&amp;quot;BizTalkSubmit&amp;quot;&lt;/span&gt;)]
    &lt;span class="kwrd"&gt;void&lt;/span&gt; BizTalkSubmit(Message message);
    &lt;span class="kwrd"&gt;void&lt;/span&gt; EndOneWayMethod(IAsyncResult result);
}

[ServiceContract(Namespace = &lt;span class="str"&gt;&amp;quot;http://www.microsoft.com/biztalk/2006/r2/wcf-adapter&amp;quot;&lt;/span&gt;)]
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;interface&lt;/span&gt; IOneWayAsyncTxn
{
    &lt;span class="rem"&gt;// Methods&lt;/span&gt;
    [OperationContract(AsyncPattern = &lt;span class="kwrd"&gt;true&lt;/span&gt;, IsOneWay = &lt;span class="kwrd"&gt;true&lt;/span&gt;, Action = &lt;span class="str"&gt;&amp;quot;*&amp;quot;&lt;/span&gt;)]
    IAsyncResult BeginOneWayMethod(Message message, AsyncCallback callback, &lt;span class="kwrd"&gt;object&lt;/span&gt; state);
    [OperationContract(IsOneWay = &lt;span class="kwrd"&gt;true&lt;/span&gt;, Action = &lt;span class="str"&gt;&amp;quot;BizTalkSubmit&amp;quot;&lt;/span&gt;)]
    &lt;span class="kwrd"&gt;void&lt;/span&gt; BizTalkSubmit(Message message);
    &lt;span class="kwrd"&gt;void&lt;/span&gt; EndOneWayMethod(IAsyncResult result);
}

[ServiceContract(Namespace = &lt;span class="str"&gt;&amp;quot;http://www.microsoft.com/biztalk/2006/r2/wcf-adapter&amp;quot;&lt;/span&gt;)]
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;interface&lt;/span&gt; ITwoWayAsync
{
    &lt;span class="rem"&gt;// Methods&lt;/span&gt;
    [OperationContract(AsyncPattern = &lt;span class="kwrd"&gt;true&lt;/span&gt;, IsOneWay = &lt;span class="kwrd"&gt;false&lt;/span&gt;, Action = &lt;span class="str"&gt;&amp;quot;*&amp;quot;&lt;/span&gt;, ReplyAction = &lt;span class="str"&gt;&amp;quot;*&amp;quot;&lt;/span&gt;)]
    IAsyncResult BeginTwoWayMethod(Message message, AsyncCallback callback, &lt;span class="kwrd"&gt;object&lt;/span&gt; state);
    [OperationContract(IsOneWay = &lt;span class="kwrd"&gt;false&lt;/span&gt;, Action = &lt;span class="str"&gt;&amp;quot;BizTalkSubmit&amp;quot;&lt;/span&gt;)]
    Message BizTalkSubmit(Message message);
    Message EndTwoWayMethod(IAsyncResult result);
}

[ServiceContract(Namespace = &lt;span class="str"&gt;&amp;quot;http://www.microsoft.com/biztalk/2006/r2/wcf-adapter&amp;quot;&lt;/span&gt;)]
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;interface&lt;/span&gt; ITwoWayAsyncVoid
{
    &lt;span class="rem"&gt;// Methods&lt;/span&gt;
    [OperationContract(AsyncPattern = &lt;span class="kwrd"&gt;true&lt;/span&gt;, IsOneWay = &lt;span class="kwrd"&gt;false&lt;/span&gt;, Action = &lt;span class="str"&gt;&amp;quot;*&amp;quot;&lt;/span&gt;, ReplyAction = &lt;span class="str"&gt;&amp;quot;*&amp;quot;&lt;/span&gt;)]
    IAsyncResult BeginTwoWayMethod(Message message, AsyncCallback callback, &lt;span class="kwrd"&gt;object&lt;/span&gt; state);
    [OperationContract(IsOneWay = &lt;span class="kwrd"&gt;false&lt;/span&gt;, Action = &lt;span class="str"&gt;&amp;quot;BizTalkSubmit&amp;quot;&lt;/span&gt;)]
    &lt;span class="kwrd"&gt;void&lt;/span&gt; BizTalkSubmit(Message message);
    &lt;span class="kwrd"&gt;void&lt;/span&gt; EndTwoWayMethod(IAsyncResult result);
}

[ServiceContract(Namespace = &lt;span class="str"&gt;&amp;quot;http://www.microsoft.com/biztalk/2006/r2/wcf-adapter&amp;quot;&lt;/span&gt;)]
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;interface&lt;/span&gt; ITwoWayAsyncVoidTxn
{
    &lt;span class="rem"&gt;// Methods&lt;/span&gt;
    [TransactionFlow(TransactionFlowOption.Mandatory), OperationContract(AsyncPattern = &lt;span class="kwrd"&gt;true&lt;/span&gt;, IsOneWay = &lt;span class="kwrd"&gt;false&lt;/span&gt;, Action = &lt;span class="str"&gt;&amp;quot;*&amp;quot;&lt;/span&gt;, ReplyAction = &lt;span class="str"&gt;&amp;quot;*&amp;quot;&lt;/span&gt;)]
    IAsyncResult BeginTwoWayMethod(Message message, AsyncCallback callback, &lt;span class="kwrd"&gt;object&lt;/span&gt; state);
    [TransactionFlow(TransactionFlowOption.Mandatory), OperationContract(IsOneWay = &lt;span class="kwrd"&gt;false&lt;/span&gt;, Action = &lt;span class="str"&gt;&amp;quot;BizTalkSubmit&amp;quot;&lt;/span&gt;)]
    &lt;span class="kwrd"&gt;void&lt;/span&gt; BizTalkSubmit(Message message);
    &lt;span class="kwrd"&gt;void&lt;/span&gt; EndTwoWayMethod(IAsyncResult result);
}&lt;/pre&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;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p align="justify"&gt;As you can easily see in the code above, all the service contracts implemented by the &lt;font color="#ff9900"&gt;BizTalkServiceInstance&lt;/font&gt; Class are generic and asynchronous. In fact, one-way service operations are decorated with &lt;font color="#ff9900"&gt;[OperationContract(AsyncPattern = true, IsOneWay = true, Action = &amp;quot;*&amp;quot;)] &lt;/font&gt;attribute, while request-response methods are decorated with the&lt;font color="#ff9900"&gt; [OperationContract(AsyncPattern = true, IsOneWay = false, Action = &amp;quot;*&amp;quot;, ReplyAction = &amp;quot;*&amp;quot;)] &lt;/font&gt;attribute. Besides, they receive a generic inbound message of type &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.channels.message.aspx"&gt;System.ServiceModel.Channels.Message&lt;/a&gt; and eventually return a message of the same type. As a consequence, these methods can accept any request message and eventually process any reply message. However, since these operations are generic and untyped, they are not decorated by any &lt;font color="#ff9900"&gt;FaultContractAttribute&lt;/font&gt;. As a consequence, WCF Receive Locations cannot return typed fault exceptions. Since every WCF Receive Location is implemented as an instance of the &lt;font color="#ff9900"&gt;BizTalkServiceInstance&lt;/font&gt; and this class cannot be customized or inherited to expose typed service contracts, BizTalk Server does not natively support throwing typed fault exceptions within orchestrations published as WCF services or more in general throwing typed fault exceptions within a WCF Receive Location.&lt;/p&gt;

&lt;p align="justify"&gt;At this point a question arises: is there any workaround to throw typed fault exceptions within orchestrations published as WCF services? The answer, fortunately, is yes.&lt;/p&gt;

&lt;h1&gt;&lt;font color="#ff9900"&gt;The Solution&lt;/font&gt;&lt;/h1&gt;

&lt;p align="justify"&gt;The &lt;font color="#ff9900"&gt;WCF-Custom&lt;/font&gt; and &lt;font color="#ff9900"&gt;WCF-CustomIsolated&lt;/font&gt; Adapters provided by BizTalk Server 2006 R2 and BizTalk Server 2009 allow to define a custom WCF binding configuration to meet your precise communication needs. These adapters can be used to define custom WCF configurations for Send Ports or Receive Locations and extend their standard functionality using custom components as endpoint and service behaviors, message inspectors, custom bindings, binding elements, channels, etc. Therefore, I decided to create the following custom components:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;div align="justify"&gt;&lt;font color="#ff9900"&gt;Microsoft.BizTalk.CAT.Samples.PublishTypedFaults.WsdlExportExtensions&lt;/font&gt; assembly: flattens and extends the WSDL generated by the &lt;font color="#ff9900"&gt;BizTalk WCF Service Publishing&lt;/font&gt; &lt;font color="#ff9900"&gt;Wizard&lt;/font&gt; to enable WCF Receive locations to expose typed soap faults.&lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;&lt;font color="#ff9900"&gt;Microsoft.BizTalk.CAT.Samples.PublishTypedFaults.MessageInspector&lt;/font&gt; assembly: intercepts a reply message and when this latter is a fault, it creates and returns a typed fault message.&lt;/div&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p align="justify"&gt;The following picture depicts the architecture of the proof of concept I implemented to test these components:&lt;/p&gt;

&lt;p align="justify"&gt;&lt;a href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/Architecture_6.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Architecture" border="0" alt="Architecture" src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/Architecture_thumb_2.jpg" width="1024" height="316" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;A &lt;font color="#ff9900"&gt;WCF-CustomIsolated Request-Response Receive Location&lt;/font&gt; receives a new xml document from a client application. &lt;/li&gt;

  &lt;li&gt;The XML disassembler component within the XMLTransmit pipeline promotes the MsgType context property. The Message Agent submits the incoming message to the MessageBox (BizTalkMsgBoxDb). &lt;/li&gt;

  &lt;li&gt;The inbound request starts a new instance of the &lt;font color="#ff9900"&gt;HelloWorld&lt;/font&gt; orchestration type. &lt;/li&gt;

  &lt;li&gt;The orchestration checks the incoming &lt;font color="#ff9900"&gt;HelloWorldRequest&lt;/font&gt; message, and if the Name element is null or empty, it creates and return a new fault message of type &lt;font color="#ff9900"&gt;CustomError&lt;/font&gt;. Otherwise, the orchestration returns a reply message of type &lt;font color="#ff9900"&gt;HelloWorldResponse&lt;/font&gt;. &lt;/li&gt;

  &lt;li&gt;The &lt;font color="#ff9900"&gt;HelloWorld&lt;/font&gt; orchestration publishes the reply message to the MessageBox (BizTalkMsgBoxDb). &lt;/li&gt;

  &lt;li&gt;The response message is retrieved by the &lt;font color="#ff9900"&gt;WCF-CustomIsolated Request-Response Receive Location&lt;/font&gt;. &lt;/li&gt;

  &lt;li&gt;The reply&amp;#160; message is processed by the &lt;font color="#ff9900"&gt;CustomErrorMessageInspector&lt;/font&gt; component. If the response is a fault message, it creates a new typed fault message using the configuration data set on the Receive Location. &lt;/li&gt;

  &lt;li&gt;The reply message is returned to the client application. &lt;/li&gt;
&lt;/ol&gt;

&lt;p align="justify"&gt;The following picture shows the XML Schema which defines the &lt;font color="#ff9900"&gt;CustomError&lt;/font&gt; typed fault.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/CustomErrorXsd_6.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="CustomErrorXsd" border="0" alt="CustomErrorXsd" src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/CustomErrorXsd_thumb_2.jpg" width="1026" height="663" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;The following figure shows the configuration of the WCF-CustomIsolated Request-Response Receive Location.&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;table border="0" cellspacing="0" cellpadding="5" width="980"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="489"&gt;&lt;a href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/GeneralTab_2.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="GeneralTab" border="0" alt="GeneralTab" src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/GeneralTab_thumb.jpg" width="422" height="581" /&gt;&lt;/a&gt; &lt;/td&gt;

      &lt;td valign="top" width="489"&gt;&lt;a href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/BindingTab_2.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="BindingTab" border="0" alt="BindingTab" src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/BindingTab_thumb.jpg" width="422" height="581" /&gt;&lt;/a&gt; &lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
      &lt;td valign="top" width="489"&gt;&lt;a href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/CustomErrorTab_2.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="CustomErrorTab" border="0" alt="CustomErrorTab" src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/CustomErrorTab_thumb.jpg" width="422" height="581" /&gt;&lt;/a&gt; &lt;/td&gt;

      &lt;td valign="top" width="489"&gt;&lt;a href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/MessagesTab_2.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="MessagesTab" border="0" alt="MessagesTab" src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/MessagesTab_thumb.jpg" width="422" height="581" /&gt;&lt;/a&gt; &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p align="justify"&gt;The Receive Location exposes an endpoint that uses the &lt;font color="#ff9900"&gt;WsHttpBinding&lt;/font&gt; and make use of the serviceThrottling service behavior (see &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.servicethrottlingbehavior.aspx"&gt;System.ServiceModel.Description.ServiceThrottlingBehavior&lt;/a&gt; for more information) and 2 custom endpoint behaviors:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;customError &lt;/li&gt;

  &lt;li&gt;wsdlExport &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These components must be configured in the machine.config as follows:&lt;/p&gt;

&lt;table border="1" cellspacing="0" cellpadding="5" width="800" bgcolor="#ffffff"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="800"&gt;
        &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;?&lt;/span&gt;&lt;span class="html"&gt;xml&lt;/span&gt; &lt;span class="attr"&gt;version&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;1.0&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;encoding&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;UTF-8&amp;quot;&lt;/span&gt;?&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;configuration&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    ...
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;system.serviceModel&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      ...
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;extensions&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;behaviorExtensions&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
          ...
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;add&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;customError&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Microsoft.BizTalk.CAT.Samples.PublishTypedFaults.MessageInspector.CustomErrorBehaviorExtensionElement,&lt;br /&gt;                                      Microsoft.BizTalk.CAT.Samples.PublishTypedFaults.MessageInspector, Version=1.0.0.0, Culture=neutral,&lt;br /&gt;                                      PublicKeyToken=d7f63d8d08d8f3a2&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;add&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;wsdlExport&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Microsoft.BizTalk.CAT.Samples.PublishTypedFaults.WsdlExportExtensions.WsdlExportBehaviorExtensionElement,&lt;br /&gt;                                     Microsoft.BizTalk.CAT.Samples.PublishTypedFaults.WsdlExportExtensions, Version=1.0.0.0, Culture=neutral,&lt;br /&gt;                                     PublicKeyToken=d7f63d8d08d8f3a2&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;behaviorExtensions&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;extensions&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;system.serviceModel&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;configuration&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&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;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p align="justify"&gt;The &lt;font color="#ff9900"&gt;Include exception detail in faults&lt;/font&gt; option must be set on the &lt;font color="#ff9900"&gt;Messages&lt;/font&gt; tab to enable the WCF Receive Location to return the error detail in fault messages. Below you can see the code of the &lt;font color="#ff9900"&gt;CustomErrorMessageInspector&lt;/font&gt; component. The constructor retrieves configuration data from the Receive Port configuration, while the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.idispatchmessageinspector.aspx"&gt;IDispatchMessageInspector::BeforeSendReply&lt;/a&gt; method intercepts the reply message and if this latter is a fault, it generates a typed fault exception using the configuration data.&lt;/p&gt;

&lt;table border="1" cellspacing="0" cellpadding="5" width="800" bgcolor="#ffffff"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="800"&gt;
        &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;namespace&lt;/span&gt; Microsoft.BizTalk.CAT.Samples.PublishTypedFaults.MessageInspector
{
    &lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
    &lt;span class="rem"&gt;/// This class can be customized to create a message inspector.&lt;/span&gt;
    &lt;span class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; CustomErrorMessageInspector : IDispatchMessageInspector, IClientMessageInspector
    {
        &lt;span class="preproc"&gt;#region&lt;/span&gt; Private Constants
        &lt;span class="kwrd"&gt;...&lt;/span&gt;        &lt;br /&gt;&lt;span class="preproc"&gt;        #endregion&lt;/span&gt;

        &lt;span class="preproc"&gt;#region&lt;/span&gt; Private Fields
        &lt;font color="#0000ff"&gt;...&lt;/font&gt;        &lt;br /&gt;        &lt;span class="preproc"&gt;#endregion&lt;/span&gt;

        &lt;span class="preproc"&gt;#region&lt;/span&gt; Public Constructors
        &lt;span class="kwrd"&gt;public&lt;/span&gt; CustomErrorMessageInspector(&lt;span class="kwrd"&gt;bool&lt;/span&gt; enabled,
                                           &lt;span class="kwrd"&gt;bool&lt;/span&gt; traceEnabled,
                                           &lt;span class="kwrd"&gt;int&lt;/span&gt; maxBufferSize,
                                           &lt;span class="kwrd"&gt;string&lt;/span&gt; typedFaults)
        {
            &lt;span class="kwrd"&gt;this&lt;/span&gt;.enabled = enabled;
            &lt;span class="kwrd"&gt;this&lt;/span&gt;.traceEnabled = traceEnabled;
            &lt;span class="kwrd"&gt;this&lt;/span&gt;.maxBufferSize = maxBufferSize;
            &lt;span class="kwrd"&gt;this&lt;/span&gt;.typedFaults = typedFaults;

            &lt;span class="kwrd"&gt;try&lt;/span&gt;
            {
                &lt;span class="kwrd"&gt;if&lt;/span&gt; (!&lt;span class="kwrd"&gt;string&lt;/span&gt;.IsNullOrEmpty(typedFaults))
                {
                    TypedFaults faultData = SerializationHelper.XmlDeserialize(typedFaults, &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(TypedFaults)) &lt;span class="kwrd"&gt;as&lt;/span&gt; TypedFaults;
                    &lt;span class="kwrd"&gt;if&lt;/span&gt; (faultData != &lt;span class="kwrd"&gt;null&lt;/span&gt; &amp;amp;&amp;amp;
                        faultData.FaultList != &lt;span class="kwrd"&gt;null&lt;/span&gt; &amp;amp;&amp;amp;
                        faultData.FaultList.Count &amp;gt; 0)
                    {
                        &lt;span class="kwrd"&gt;for&lt;/span&gt; (&lt;span class="kwrd"&gt;int&lt;/span&gt; i = 0; i &amp;lt; faultData.FaultList.Count; i++)
                        {
                            &lt;span class="kwrd"&gt;if&lt;/span&gt; (!&lt;span class="kwrd"&gt;string&lt;/span&gt;.IsNullOrEmpty(faultData.FaultList[i].Action) &amp;amp;&amp;amp;
                                !&lt;span class="kwrd"&gt;string&lt;/span&gt;.IsNullOrEmpty(faultData.FaultList[i].Name))
                            {
                                faults.Add(&lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(MessageTypeFormat, &lt;br /&gt;                                                         faultData.FaultList[i].Namespace, &lt;br /&gt;                                                         faultData.FaultList[i].Name ?? &lt;span class="kwrd"&gt;string&lt;/span&gt;.Empty), &lt;br /&gt;                                                         &lt;span class="kwrd"&gt;new&lt;/span&gt; CustomErrorFaultInfo(faultData.FaultList[i].Action, &lt;br /&gt;                                                                                  faultData.FaultList[i].Reason));
                            }
                        }
                    }
                }
            }
            &lt;span class="kwrd"&gt;catch&lt;/span&gt; (Exception ex)
            {
                EventLog.WriteEntry(Source, ex.Message, EventLogEntryType.Error);
            }
        }
        &lt;span class="preproc"&gt;#endregion&lt;/span&gt;

        &lt;span class="preproc"&gt;#region&lt;/span&gt; IDispatchMessageInspector Members
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;object&lt;/span&gt; AfterReceiveRequest(&lt;span class="kwrd"&gt;ref&lt;/span&gt; Message request, IClientChannel channel, InstanceContext instanceContext)
        {
            &lt;span class="kwrd"&gt;return&lt;/span&gt; request.Headers.Action;
        }

        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; BeforeSendReply(&lt;span class="kwrd"&gt;ref&lt;/span&gt; Message reply, &lt;span class="kwrd"&gt;object&lt;/span&gt; correlationState)
        {
            &lt;span class="kwrd"&gt;try&lt;/span&gt;
            {
                &lt;span class="kwrd"&gt;if&lt;/span&gt; (enabled &amp;amp;&amp;amp;
                    reply.IsFault &amp;amp;&amp;amp;
                    &lt;span class="kwrd"&gt;string&lt;/span&gt;.Compare(((&lt;span class="kwrd"&gt;string&lt;/span&gt;)correlationState), TransferGetNamespace, &lt;span class="kwrd"&gt;true&lt;/span&gt;) != 0)
                {
                    &lt;span class="kwrd"&gt;string&lt;/span&gt; action = correlationState &lt;span class="kwrd"&gt;as&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt;;
                    MessageFault fault = MessageFault.CreateFault(reply, maxBufferSize);
                    &lt;span class="kwrd"&gt;string&lt;/span&gt; detail = fault.Reason.ToString();
                    CustomErrorMessageFault faultMessage = &lt;span class="kwrd"&gt;new&lt;/span&gt; CustomErrorMessageFault(faults, &lt;br /&gt;                                                                                       &lt;span class="kwrd"&gt;new&lt;/span&gt; FaultCode(FaultCodeName), detail, traceEnabled);
                    Message message = Message.CreateMessage(reply.Version, faultMessage, &lt;span class="kwrd"&gt;null&lt;/span&gt;);
                    message.Headers.CopyHeadersFrom(reply.Headers);
                    message.Properties.CopyProperties(reply.Properties);
                    &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;string&lt;/span&gt;.IsNullOrEmpty(faultMessage.Action))
                    {
                        message.Headers.Action = action;
                    }
                    &lt;span class="kwrd"&gt;else&lt;/span&gt;
                    {
                        message.Headers.Action = faultMessage.Action;
                    }
                    reply = message;
                }
            }
            &lt;span class="kwrd"&gt;catch&lt;/span&gt; (Exception ex)
            {
                EventLog.WriteEntry(Source, ex.Message, EventLogEntryType.Error);
                &lt;span class="kwrd"&gt;throw&lt;/span&gt; ex;
            }
            &lt;span class="kwrd"&gt;return&lt;/span&gt;;
        }
        &lt;span class="preproc"&gt;#endregion&lt;/span&gt;

        &lt;span class="preproc"&gt;#region&lt;/span&gt; IClientMessageInspector Members
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; AfterReceiveReply(&lt;span class="kwrd"&gt;ref&lt;/span&gt; Message reply, &lt;span class="kwrd"&gt;object&lt;/span&gt; correlationState)
        {
            &lt;span class="kwrd"&gt;return&lt;/span&gt;;
        }

        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;object&lt;/span&gt; BeforeSendRequest(&lt;span class="kwrd"&gt;ref&lt;/span&gt; Message request, IClientChannel channel)
        {
            &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;null&lt;/span&gt;;
        }
        &lt;span class="preproc"&gt;#endregion&lt;/span&gt;
    }
}&lt;/pre&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;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
      &lt;td valign="top" width="800"&gt;&amp;#160;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p align="justify"&gt;The following table contains the XML snippet used as configuration data for the &lt;font color="#ff9900"&gt;CustomErrorMessageInspector&lt;/font&gt; component. As you can see, it allows defining multiple typed faults in a declarative way. At runtime it will use this data to recognize a fault reply message and accordingly set the &lt;font color="#ff9900"&gt;Action&lt;/font&gt; and &lt;font color="#ff9900"&gt;Reason&lt;/font&gt; properties of the fault message returned. &lt;/p&gt;

&lt;table border="1" cellspacing="0" cellpadding="5" width="800" bgcolor="#ffffff"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="800"&gt;
        &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;TypedFaults&lt;/span&gt; &lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;http://microsoft.biztalk.cat/10/typedfaults&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;TypedFault&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Action&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;SayHello&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Action&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;CustomError&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Namespace&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;http://microsoft.biztalk.cat/10/customerror&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Namespace&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Reason&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;Custom Error&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Reason&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;TypedFault&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;TypedFaults&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&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;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;If you set the &lt;font color="#ff9900"&gt;TraceEnabled&lt;/font&gt; property to true, at runtime the &lt;font color="#ff9900"&gt;CustomErrorMessageInspector&lt;/font&gt; component will produce a trace that you can intercept and review with a tool such as &lt;a href="http://technet.microsoft.com/en-us/sysinternals/bb896647.aspx"&gt;Debug&lt;/a&gt; as shown in the picture below.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/DebugViewCustomError_2.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="DebugViewCustomError" border="0" alt="DebugViewCustomError" src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/DebugViewCustomError_thumb.jpg" width="1024" height="384" /&gt;&lt;/a&gt;&amp;#160; &lt;/p&gt;

&lt;p&gt;The WCF-Receive Location can be created using the &lt;a href="http://msdn.microsoft.com/en-us/library/bb226547.aspx"&gt;BizTalk WCF Service Publishing Wizard&lt;/a&gt;&lt;font color="#ff9900"&gt;&lt;/font&gt;. In particular,&amp;#160; this allows to create a WCF Receive Location to expose the &lt;font color="#ff9900"&gt;HelloWorld&lt;/font&gt; orchestration as a WCF service. Moreover, setting the &lt;font color="#ff9900"&gt;Enable metadata endpoint&lt;/font&gt; option it’s possible to enable the&amp;#160; WCF Receive Location to expose a Metadata Endpoint. &lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/BizTalkWCFServicePublishingWizard_2.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="BizTalkWCFServicePublishingWizard" border="0" alt="BizTalkWCFServicePublishingWizard" src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/BizTalkWCFServicePublishingWizard_thumb.jpg" width="513" height="398" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p align="justify"&gt;This allows a developer to use Visual Studio or a tool such as &lt;a href="http://msdn.microsoft.com/en-us/library/aa347733.aspx"&gt;svcutil&lt;/a&gt; to generate a proxy class to invoke&amp;#160; the WCF Receive Location. Now, let’s say that you want to create a WCF client application to invoke the WCF Receive Location. Within Visual Studio you can create a new Windows Application, right-click the project inside the Solution Explorer and then select &lt;font color="#ff9900"&gt;Add Service Reference&lt;/font&gt;. If the WCF Receive Location exposes a Metadata Endpoint, this operation will create a proxy class to invoke the corresponding WCF web service. However, if you review the code and in particular the contract interface, you’ll realize that the &lt;font color="#ff9900"&gt;SayHello&lt;/font&gt; method is not decorated with a &lt;font color="#ff9900"&gt;FaultContractAttribute&lt;/font&gt;. This is due to the fact, that since BizTalk Server does not support throwing typed fault exceptions, the native wsdl returned by the Metadata Endpoint exposed by the WCF Receive location does not contain any soap fault message. In order to sort out this problem, you can adopt one of the following techniques:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;div align="justify"&gt;Create and expose a custom wsdl that contains the definition of your typed soap faults.&lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;Create a custom endpoint behavior to dynamically&amp;#160; modify the wsdl produced by BizTalk.&lt;/div&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p align="justify"&gt;The first technique is quite straightforward:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;div align="justify"&gt;You manually define a custom wsdl using a text or xml editor.&lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;You publish the resulting wsdl file to IIS (e.g. &lt;a href="http://localhost/samples/service.wsdl"&gt;http://localhost/samples/service.wsdl&lt;/a&gt;)&lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div align="justify"&gt;You configure your WCF-Custom or WCF-CustomIsolated Receive Location to expose metadata and in particular the newly created wsdl file.&lt;/div&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p align="justify"&gt;In order to accomplish the finale step, you can proceed as follows:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Start the BizTalk Server Administration Console.&lt;/li&gt;

  &lt;li&gt;Open your WCF-Custom/WCF-CustomIsolated Receive Location.&lt;/li&gt;

  &lt;li&gt;Click the Configure button in the Transport section.&lt;/li&gt;

  &lt;li&gt;Click the Behavior tab. &lt;/li&gt;

  &lt;li&gt;Right-click the Service Behavior node and choose to Add Extension. &lt;/li&gt;

  &lt;li&gt;In the Select Behavior Extension window, choose the &lt;font color="#ff9900"&gt;serviceMetadata&lt;/font&gt; component. &lt;/li&gt;

  &lt;li&gt;Set the value of the &lt;font color="#ff9900"&gt;httpGetEnabled&lt;/font&gt; property of the &lt;font color="#ff9900"&gt;serviceMetadata&lt;/font&gt; behavior to True (see the picture below).&lt;/li&gt;

  &lt;li&gt;Set the value of the &lt;font color="#ff9900"&gt;externalMetadataLocation&lt;/font&gt; property of the &lt;font color="#ff9900"&gt;serviceMetadata&lt;/font&gt; behavior to the url of your hand-built wsdl (see the picture below).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A1AB/serviceMetadata_2.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="serviceMetadata" border="0" alt="serviceMetadata" src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A1AB/serviceMetadata_thumb.jpg" width="542" height="581" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p align="justify"&gt;The second technique consists in creating a custom component called &lt;font color="#ff9900"&gt;WsdlExtensions&lt;/font&gt; to modify at run-time the wsdl returned by the the Metadata Endpoint exposed by a WCF-Custom/WCF-CustomIsolated Receive location. This component is implemented as an a custom endpoint behavior and it can be used along with any&lt;font color="#ff9900"&gt; WCF-Custom&lt;/font&gt; or &lt;font color="#ff9900"&gt;WCF-CustomIsolated&lt;/font&gt; Receive Location, as shown in the picture below.&lt;/p&gt;

&lt;p align="justify"&gt;&lt;a href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/WsdlExportTab_4.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="WsdlExportTab" border="0" alt="WsdlExportTab" src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/WsdlExportTab_thumb_1.jpg" width="420" height="579" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;The &lt;font color="#ff9900"&gt;WsdlExtensions&lt;/font&gt; property exposed by the component accepts an XML snippet that allows to specify how the wsdl has to be customized at runtime. &lt;/p&gt;

&lt;table border="1" cellspacing="0" cellpadding="5" width="800" bgcolor="#ffffff"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="800"&gt;
        &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;WsdlExtensions&lt;/span&gt; &lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;http://microsoft.biztalk.cat/10/wsdlextensions&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Prefix&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;bts&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Prefix&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;XmlSchemas&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;XmlSchema&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;CustomError&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Namespace&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;http://microsoft.biztalk.cat/10/customerror&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Namespace&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;XmlSchema&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;XmlSchemas&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Messages&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Message&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;HelloWorld_SayHello_CustomErrorFault_FaultMessage&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Namespace&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;http://microsoft.biztalk.cat/10/customerror&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Namespace&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Parts&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Part&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;detail&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Element&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;CustomError&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Element&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Part&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Parts&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Message&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Messages&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;PortTypes&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;PortType&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;HelloWorld&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Operations&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Operation&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;SayHello&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Faults&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Fault&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;CustomErrorFault&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Message&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;HelloWorld_SayHello_CustomErrorFault_FaultMessage&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Message&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Fault&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Faults&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Operation&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Operations&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;PortType&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;PortTypes&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;WsdlExtensions&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&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;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p align="justify"&gt;As shown in the picture above, the components allows to define the following information:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The prefix for the namespace of new messages created inside the wsdl. &lt;/li&gt;

  &lt;li&gt;One or multiple Xml Schemas each defining a different typed fault. These schemas must be deployed to BizTalk. At runtime, the component is able to retrieve the content of each schema from the BizTalkMgmtDb that&amp;#160; subsequently is inserted in the outbound wsdl. &lt;/li&gt;

  &lt;li&gt;One or multiple fault messages, each containing one or multiple parts. &lt;/li&gt;

  &lt;li&gt;One or multiple operation-fault associations. At runtime the component search through the original wsdl structure and creates faults accordingly. &lt;/li&gt;
&lt;/ul&gt;

&lt;p align="justify"&gt;At runtime the &lt;font color="#ff9900"&gt;WsdlExtensions&lt;/font&gt; component validates the XML configuration specified on the port and if the &lt;font color="#ff9900"&gt;TraceEnabled&lt;/font&gt; property is set to true, it produces a trace with a tool such as &lt;a href="http://technet.microsoft.com/en-us/sysinternals/bb896647.aspx"&gt;Debug&lt;/a&gt; as shown in the picture below. &lt;/p&gt;

&lt;p align="justify"&gt;&lt;a href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/DebugViewAddServiceReference_2.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="DebugViewAddServiceReference" border="0" alt="DebugViewAddServiceReference" src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/DebugViewAddServiceReference_thumb.jpg" width="1025" height="384" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p align="justify"&gt;The following picture shows the wsdl produced by the &lt;font color="#ff9900"&gt;WsdlExtensions&lt;/font&gt; component at runtime. In particular, the parts added by the component are highlighted by a red frame.&lt;/p&gt;

&lt;p align="justify"&gt;&lt;a href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/Wsdl_2.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Wsdl" border="0" alt="Wsdl" src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/Wsdl_thumb.jpg" width="903" height="2743" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p align="justify"&gt;&lt;font color="#ff9900"&gt;Note&lt;/font&gt;: Flattening the wsdl&amp;#160; to include the XML schemas used to define messages allows to make the wsdl document compatible with non-Microsoft development environments. In fact, Visual Studio supports import and include directives in a wsdl, but some non-Microsoft development environments are not able to consume the wsdl exposed by a WCF web service.&lt;/p&gt;

&lt;p align="justify"&gt;&lt;font color="#ff9900"&gt;Note&lt;/font&gt;: the XML Schemas defining the structure of the XML configuration data consumed at runtime respectively by the &lt;font color="#ff9900"&gt;CustomErrorMessageInspector&lt;/font&gt; and by the &lt;font color="#ff9900"&gt;WsdlExportEndpointBehavior&lt;/font&gt; can be found inside the &lt;font color="#ff9900"&gt;BehaviorSchemas&lt;/font&gt; project. The corresponding assembly doesn’t need to be deployed to BizTalk Server.&lt;/p&gt;

&lt;h1&gt;&lt;font color="#ff9900"&gt;Proof Of Concept in Action&lt;/font&gt;&lt;/h1&gt;

&lt;p align="justify"&gt;In order to test the WCF custom components, I created a WinForms application. In particular, when I leave the Name textbox blank and press the Call button, the &lt;font color="#ff9900"&gt;HelloWorld&lt;/font&gt; orchestration returns a fault message. The client application intercepts the error with a catch (FaultException&amp;lt;HelloWorldBizTalk.CustomError&amp;gt; ex) block and opens a MessageBox to show the detail of the exception.&lt;/p&gt;

&lt;p align="justify"&gt;&lt;a href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/DriverApplication_2.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="DriverApplication" border="0" alt="DriverApplication" src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/DriverApplication_thumb.jpg" width="856" height="447" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;&lt;font color="#ff9900"&gt;Show me the code!&lt;/font&gt;&lt;/h1&gt;

&lt;p&gt;At this point, you are probably saying: &lt;/p&gt;

&lt;p&gt;- ok, cool, where’s the code?&lt;/p&gt;

&lt;p&gt;Well, I packaged the code in 2 different flavors:&lt;/p&gt;

&lt;p&gt;- &lt;a href="http://cid-09dba4a06b360a65.skydrive.live.com/self.aspx/Pubblica/PublishTypedFaultsBTS2009.zip?ccr=7573"&gt;BizTalk Server 2009&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;- &lt;a href="http://cid-09dba4a06b360a65.skydrive.live.com/self.aspx/Pubblica/PublishTypedFaultsBTS2006R2.zip?ccr=657"&gt;BizTalk Server 2006 R2&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Obviously, everything there are many ways to implement the same functionalities, so I’d be glad if you could leave a message on my blog and let me know how you used/customized/improved my code. Enjoy! ;-)&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9635410" width="1" height="1"&gt;</description></item><item><title>BizTalk server and protocol transition</title><link>http://blogs.msdn.com/paolos/archive/2009/01/20/biztalk-server-and-protocol-transition.aspx</link><pubDate>Tue, 20 Jan 2009 20:26:45 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9349083</guid><dc:creator>leprino</dc:creator><slash:comments>4</slash:comments><comments>http://blogs.msdn.com/paolos/comments/9349083.aspx</comments><wfw:commentRss>http://blogs.msdn.com/paolos/commentrss.aspx?PostID=9349083</wfw:commentRss><wfw:comment>http://blogs.msdn.com/paolos/rsscomments.aspx?PostID=9349083</wfw:comment><description>&lt;p&gt;Consider the following scenario:&lt;/p&gt;  &lt;p&gt;&lt;em&gt;You have to implement a BizTalk Server application that has to interact with one or more downstream systems. Request messages are submitted by a front-end application which authenticates callers using the Windows Integrated Security. These messages are received by one or more SOAP or WCF Receive Locations which use the Windows Integrated Security to authenticate the original caller. The orchestration and/or the Send Ports (WCF, SOAP, SQL) responsible to process incoming requests need to impersonate the user account credentials of the original caller whilst invoking one or more downstream systems (e.g. Web Service, SQL Server database).&lt;/em&gt;&lt;i&gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;&lt;i&gt;     &lt;br /&gt;&lt;/i&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/aa558712.aspx"&gt;Enterprise Single Sign-On (SSO)&lt;/a&gt; that is part of BizTalk Server since the 2004 release provides services to enable credential mappings and single sign-on to end users for enterprise application integration (EAI) solutions. The SSO system maps Microsoft Windows accounts to back-end credentials. SSO simplifies the management of user IDs and passwords, both for users and administrators. It enables users to access back-end systems and applications by logging on only once to the Windows network. If the BizTalk Server application is able to properly authenticate the original caller, her/his credentials can be mapped to a username/password couple that can be used to access a downstream system (SAP, mainframe, etc.) on her/his behalf. What about if the target system in question is a web service which makes use of the Windows Integrated Security in order to authenticate and authorize incoming requests or SQL Server database configured to use the Windows Integrated Security? In this case, you should create a SSO Affiliate Application for each target system and map each domain account to its username/password credentials. The major drawback of this approach is that you should use the &lt;a href="http://msdn.microsoft.com/en-us/library/aa560691.aspx"&gt;Password Change Notification Service&lt;/a&gt; to receive password changes directly from domain controllers and keep password in sync with the Active Directory. But there&amp;#8217;s another issue with this approach: the SSO support for WCF and SOAP Send Ports include the Digest and Basic Authentication but not the Windows Integrated Security (see &lt;a href="http://msdn.microsoft.com/en-us/library/bb743477.aspx"&gt;Single Sign-On Support for the WCF Adapters&lt;/a&gt; for more information on this topic). As a consequence, even if you manage to successfully impersonate the original caller, the Send Handler of the WCF and SOAP Adapters won&amp;#8217;t be able to use these credentials when invoking the downstream service.&lt;/p&gt;  &lt;p&gt;The solution to this problem is to use the Kerberos protocol extensions provided by Windows Server 2003 and in particular the Kerberos Protocol Transition and Constrained Delegation. The objective of this article is not to provide full coverage of this topic. For more information on this subject, see the following articles:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://technet.microsoft.com/en-us/library/cc739587.aspx"&gt;Kerberos Protocol Transition and Constrained Delegation&lt;/a&gt;.&lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/it-it/magazine/cc188757(en-us).aspx"&gt;Exploring S4U Kerberos Extensions in Windows Server 2003&lt;/a&gt; by Keith Brown.&lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/magazine/cc163500.aspx"&gt;Using Protocol Transition&amp;#8212;Tips from the Trenches&lt;/a&gt; by Keith Brown.&lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/aa480585.aspx"&gt;Protocol Transition with Constrained Delegation Technical Supplement&lt;/a&gt;.&lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=99B0F94F-E28A-4726-BFFE-2F64AE2F59A2&amp;amp;displaylang=en"&gt;Troubleshooting Kerberos Delegation&lt;/a&gt;.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;font size="2"&gt;The following section provides an introduction to the Protocol Transition and Constraint Delegation.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;font color="#ff9900"&gt;&lt;font size="3"&gt;Protocol Transition and Constraint Delegation &lt;/font&gt;&lt;/font&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;The Protocol Transition and Constraint Delegation can be used in managed code to initialize a valid WindowsIdentity object to impersonate any domain account just using its user principal name in order to accomplish one of the following tasks:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Authorization checks.&lt;/li&gt;    &lt;li&gt;Impersonation.&lt;/li&gt;    &lt;li&gt;Access remote resources.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;The first two operations can be implemented independently of each other, but the third operation requires that you use Protocol Transition when you are not using Kerberos authentication. In other words, constrained delegation has two configurations; one that requires Kerberos authentication and another that works with any authentication protocol. When you use the configuration that supports any authentication protocol, you must first implement protocol transition with impersonation before you implement constrained delegation. &lt;/p&gt;  &lt;p&gt;The next section provides details on the extensions themselves. After you have an understanding of these extensions, see the &amp;#8220;Implementation&amp;#8221; section to learn how to implement the operations described earlier.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;font color="#ff9900"&gt;New Kerberos Extensions&lt;/font&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;As previously mentioned, Windows Server 2003 provides two new Service-for-User (S4U) Kerberos extensions that support protocol transition and constrained delegation. Protocol transition and constrained delegation can be used independently of each other, but they are often used together to implement the scenario described in the introduction.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;font color="#ff9900"&gt;Protocol Transition&lt;/font&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;The S4U2Self Kerberos extension can be used to initialize a WindowsIdentity object with the user principal name of a valid Windows account in Active Directory. The password associated with the user principal name is not required. This feature allows you to transition from any authentication protocol into the Kerberos authentication protocol. This operation is accomplished by using the ticket-granting ticket (TGT) of a service account to request a service ticket for itself. The service account in this case is the one associated with the Web service that performs the protocol transition. The service ticket that is returned from the ticket-granting service (TGS) contains identity and principal information for the user whose ID was sent with the request.&lt;/p&gt;  &lt;p&gt;The new WindowsIdentity that is initialized with this service ticket can then be used to perform role-based authorization checks. In addition, when used with constrained delegation, this new identity can be used to access downstream resources. There are limitations to what this new identity is allowed to do that are based on the privileges of the service account. These limitations are discussed in the &amp;#8220;Implementation&amp;#8221; section later in this technical supplement.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;font color="#ff9900"&gt;Constrained Delegation&lt;/font&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;The S4U2Proxy Kerberos extension provides an implementation of constrained delegation that allows you to use a Kerberos service ticket &amp;#8212; instead of a TGT &amp;#8212; to request another service ticket. Delegation is considered to be constrained because the identity (service account) that is used to request the service ticket must be configured to access a specific service. Constrained delegation works with or without protocol transition. The primary restriction is that the service account used to request a Kerberos service ticket must be configured to access the requested service. In addition, the service account must be able to impersonate the client prior to calling the service. For example, when you use Windows integrated authentication with impersonation, the default Web server&amp;#8217;s computer account can be configured for constrained delegation without making any changes to the Internet Information Services (IIS) process account. A restriction of protocol transition is that the Web server&amp;#8217;s computer account cannot be used for constrained delegation without modifying the IIS process account or better the service account used by the Application Pool. The reason for this is that the default IIS process account (which is the NT AUTHORITY\NETWORK SERVICE account on Windows 2003 Server) does not have necessary privileges to implement impersonation using the WindowsIdentity object that was created during protocol transition. Instead of modifying the default IIS process account, you can also use a different service account for the Application Pool.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;font color="#ff9900"&gt;Protocol Transition&lt;/font&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;.NET Framework applications can implement protocol transition by creating an instance of the &lt;b&gt;WindowsIdentity &lt;/b&gt;object with a &lt;b&gt;User Principal Name&lt;/b&gt; (UPN), which is similar to an e-mail address. For example, if the user ID is &lt;b&gt;john &lt;/b&gt;and the corresponding Active Directory domain is &lt;b&gt;contoso.com, &lt;/b&gt;the UPN is &lt;b&gt;john@contoso.com&lt;/b&gt;.&lt;/p&gt;  &lt;p&gt;It is also possible to use protocol transition to initialize a &lt;b&gt;WindowsIdentity &lt;/b&gt;object using a common Active Directory account for trusted subsystem implementations. This type of approach is normally used when you want to improve scalability with resources that use object or connection pooling based on the credentials that were used to access them. For example, connection pooling with SQL Server will work only if a common identity is used. As a result, the following two primary scenarios are associated with protocol transition in Windows:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Transitioning from a different authentication protocol, such as X.509 client certificates, into the Kerberos protocol.&lt;/li&gt;    &lt;li&gt;Transitioning from custom authentication by using a common identity for trusted subsystem implementations.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;For more information on these topics you can review &lt;a href="http://msdn.microsoft.com/en-us/library/aa480585.aspx"&gt;Protocol Transition with Constrained Delegation Technical Supplement&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;font color="#ff9900" size="3"&gt;&lt;/font&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;font color="#ff9900" size="3"&gt;Protocol Transition and BizTalk Server&lt;/font&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;In the following section I&amp;#8217;ll introduce the 3 scenarios implemented to demonstrate how exploiting the Protocol Transition technique in a BizTalk Server project.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;font color="#ff9900"&gt;&lt;font size="3"&gt;Scenario 1 &amp;#8211; Messaging Only Scenario with a SOAP Receive Location&lt;/font&gt; &lt;/font&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;The picture below depicts the architecture design and message flow of the first scenario. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/BizTalkserverandprotocoltransition_ECD8/ProtocolTransition_Scenario1_2.jpg"&gt;&lt;img height="357" alt="ProtocolTransition_Scenario1" src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/BizTalkserverandprotocoltransition_ECD8/ProtocolTransition_Scenario1_thumb.jpg" width="980" border="0" /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;b&gt;&lt;font color="#ff9900"&gt;Fig.1: Architecture Design of the first Scenario&lt;/font&gt;&lt;/b&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;&lt;font color="#ff9900"&gt;&lt;strong&gt;1.&lt;/strong&gt;&lt;/font&gt; A WinForm client application submits a Request to a Request-Response Soap Receive using the following code.&lt;/p&gt;  &lt;pre class="csharpcode"&gt;
    Private &lt;span class="kwrd"&gt;void&lt;/span&gt; btnSoap_Click(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, EventArgs e)
    {
        SoapReceiveLocation.HelloWorldService client = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
        &lt;span class="kwrd"&gt;try&lt;/span&gt;
        {
        client = &lt;span class="kwrd"&gt;new&lt;/span&gt; SoapReceiveLocation.HelloWorldService();
        client.Credentials = CredentialCache.DefaultCredentials;
        SoapReceiveLocation.RequestMessage request = &lt;span class="kwrd"&gt;new&lt;/span&gt; 
                SoapReceiveLocation.RequestMessage();
        request.Message = txtRequest.Text;
        SoapReceiveLocation.ResponseMessage response = 
                client.SayHello(request);
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (response != &lt;span class="kwrd"&gt;null&lt;/span&gt; &amp;amp;&amp;amp;
            !&lt;span class="kwrd"&gt;string&lt;/span&gt;.IsNullOrEmpty(response.Greeting))
        {
            WriteToLog(response.Greeting);
        }
        }
        &lt;span class="kwrd"&gt;catch&lt;/span&gt; (Exception ex)
        {
        MessageBox.Show(ex.Message, 
                ExceptionCaption, 
                MessageBoxButtons.OK, 
                MessageBoxIcon.Error);
        }
    }&lt;/pre&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;blockquote&gt;
  &lt;p&gt;&lt;b&gt;&lt;font color="#ff9900"&gt;Fig.2: Client code to invoke the Soap Receive Location&lt;/font&gt;&lt;/b&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;As you can see in the code above, the client invokes the Soap Receive Location through an instance of a Soap proxy class which inherits from SoapHttpClientProtocol and uses the Integrated Windows authentication with the credentials of the current user. The Soap Receive Location is hosted by a custom authentication trusted isolated host called &lt;b&gt;BizTalkServerTrustedIsolatedHost &lt;/b&gt;(see Fig.3). BizTalk Server trusts authentication trusted hosts to place the sender security ID (SSID) on messages that the trusted host is queuing that map to users other than to the host. For more information about authentication trusted hosts, see &lt;a href="http://msdn.microsoft.com/en-us/library/aa561080.aspx"&gt;Authenticating the Sender of a Message&lt;/a&gt; on MSDN.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/BizTalkserverandprotocoltransition_ECD8/SoapReceiveLocation1_2.jpg"&gt;&lt;img height="514" alt="SoapReceiveLocation1" src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/BizTalkserverandprotocoltransition_ECD8/SoapReceiveLocation1_thumb.jpg" width="644" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;b&gt;&lt;font color="#ff9900"&gt;Fig.3: The Soap Receive Location is hosted by an authentication trusted host.&lt;/font&gt;&lt;/b&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The virtual directory hosting the Soap Receive Location on IIS is configured to use the Integrated Windows authentication (see Fig.4).&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/BizTalkserverandprotocoltransition_ECD8/VirtualDirectory_2.jpg"&gt;&lt;img height="444" alt="VirtualDirectory" src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/BizTalkserverandprotocoltransition_ECD8/VirtualDirectory_thumb.jpg" width="371" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;b&gt;&lt;font color="#ff9900"&gt;Fig.4: Integrated Windows authentication configured on the RL virtual directory.&lt;/font&gt;&lt;/b&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In addition, the Soap Receive Location was configured to use the Enterprise Single Sign-On (see Fig.5).&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/BizTalkserverandprotocoltransition_ECD8/SoapReceiveLocation2_4.jpg"&gt;&lt;img height="448" alt="SoapReceiveLocation2" src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/BizTalkserverandprotocoltransition_ECD8/SoapReceiveLocation2_thumb_1.jpg" width="404" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;b&gt;&lt;font color="#ff9900"&gt;Fig.5: The SSO was enabled on the Soap Receive Location.&lt;/font&gt;&lt;/b&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In this way, when the Soap Receive Location is invoked by the client application, the Soap Adapter assigns the client credentials (DOMAIN\USER) to the &lt;b&gt;BTS.WindowsUser&lt;/b&gt; message context property. Note that this property is accessible within an orchestration via the &lt;b&gt;Microsoft.BizTalk.XLANGs.BTXEngine.OriginatorSID&lt;/b&gt; property.&lt;/p&gt;

&lt;p&gt;&lt;font color="#ff9900"&gt;&lt;strong&gt;2.&lt;/strong&gt;&lt;/font&gt; The Message Agent submits the incoming request message to the MessageBox (BizTalkMsgBoxDb).&lt;/p&gt;

&lt;p&gt;&lt;font color="#ff9900"&gt;&lt;strong&gt;3.&lt;/strong&gt;&lt;/font&gt; The inbound request is consumed by a Solicit Response WCF-Custom Send Port. This latter uses a Filter Expression to receive all the documents published by the Receive Port hosting the Soap Receive Location.&lt;/p&gt;

&lt;p&gt;&lt;font color="#ff9900"&gt;&lt;strong&gt;4.&lt;/strong&gt;&lt;/font&gt; The inbound message is mapped to the request format by the downstream &lt;b&gt;HelloWorldService&lt;/b&gt; web service. This latter is hosted by IIS and exposes a single &lt;b&gt;WsHttpBinding&lt;/b&gt; endpoint.&lt;/p&gt;

&lt;p&gt;&lt;font color="#ff9900"&gt;&lt;strong&gt;5.&lt;/strong&gt;&lt;/font&gt; The WCF-Custom Send Port invokes the underlying HelloWorldService WCF service that in the scenario is hosted by a separate Application Pool (w3wp.exe) on the same IIS instance. The WCF-Custom Send Port uses a &lt;b&gt;CustomBinding&lt;/b&gt; which contains the following binding elements (see Fig.9): &lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;ProtocolTransitionBindingElement. &lt;/li&gt;

  &lt;li&gt;TextMessageEncodingBindingElement, &lt;/li&gt;

  &lt;li&gt;HttpsTransportBindingElement. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This &lt;b&gt;ProtocolTransitionBindingElement&lt;/b&gt; binding element is a custom binding which injects a custom channel in the channel stack used by the WCF Send Handler to send out the request message. The binding element exposes multiple properties which allow controlling the channel behavior at run time. For example, the binding element can be configured to read the client credentials from a given message context property setting the value of the &lt;b&gt;WindowsUserPosition&lt;/b&gt; to Context. In this case, the name and namespace of the source context property must be specified respectively with the &lt;b&gt;ContextPropertyName&lt;/b&gt; and &lt;b&gt;ContextPropertyNamespace&lt;/b&gt; properties exposed by the custom binding element. By default, the context property used to read the client account is the &lt;b&gt;http://schemas.microsoft.com/BizTalk/2003/system-properties#WindowsUser&lt;/b&gt; promoted in this scenario by the Soap Adapter on the inbound Receive Location, but it could be read from a custom message context property. Instead, if the client account must be read from the Xml request message using an XPath Expression specified in the &lt;b&gt;WindowsUserXPath&lt;/b&gt; property of the binding element, the value of the &lt;b&gt;WindowsUserPosition&lt;/b&gt; property must be set to Message. At run time, the custom channel called &lt;b&gt;InspectingRequestChannel&lt;/b&gt; reads the client account name from the context property or from the message and impersonates the original caller before passing the call to the innerChannel. When reading the client account name from the message context, the custom channel exploits a feature provided by the WCF Send Handler: when creating the &lt;b&gt;System.ServiceModel.Channels.Message&lt;/b&gt; from the inbound &lt;b&gt;IBaseMessage&lt;/b&gt;, this latter writes all the message context properties in the &lt;b&gt;Properties &lt;/b&gt;of the newly WCF message. So to to read the name of the client user is sufficient to use the following lines of code within the custom channel. &lt;/p&gt;

&lt;pre class="csharpcode"&gt;
    &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;const&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; ContextPropertyKeyFormat = &lt;span class="str"&gt;&amp;quot;{0}#{1}&amp;quot;&lt;/span&gt;;
    ...
    &lt;span class="kwrd"&gt;string&lt;/span&gt; contextPropertyKey = &lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(ContextPropertyKeyFormat, 
                                              contextPropertyNamespace, 
                                              contextPropertyName);
    &lt;span class="kwrd"&gt;if&lt;/span&gt; (message.Properties.ContainsKey(contextPropertyKey))
    {
        windowsUser = message.Properties[contextPropertyKey] &lt;span class="kwrd"&gt;as&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt;;
    }&lt;/pre&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;blockquote&gt;
  &lt;p&gt;&lt;b&gt;&lt;font color="#ff9900"&gt;Fig.6: Code snippet from the helper class invoked by the custom channel.&lt;/font&gt;&lt;/b&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;A helper component invoked by the custom channel transforms the original account name (DOMAIN\USER) into the equivalent User Principal Name (USER@DOMAIN). Finally the custom channel impersonates the client user using the following code:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;
    &lt;span class="kwrd"&gt;public&lt;/span&gt; Message Request(Message message, TimeSpan timeout)
    {
        &lt;span class="kwrd"&gt;string&lt;/span&gt; upn = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
        ...
        &lt;span class="kwrd"&gt;try&lt;/span&gt;
        {
            ...
            upn = InspectingHelper.GetUserPrincipalName(...);
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (!&lt;span class="kwrd"&gt;string&lt;/span&gt;.IsNullOrEmpty(upn))
            {
                WindowsIdentity identity = &lt;span class="kwrd"&gt;new&lt;/span&gt; WindowsIdentity(upn);
                impersonationContext = identity.Impersonate();
            }
            reply = &lt;span class="kwrd"&gt;this&lt;/span&gt;.InnerChannel.Request(request);
        }
        &lt;span class="kwrd"&gt;catch&lt;/span&gt; (Exception ex)
        {
            Debug.WriteLineIf(traceEnabled, &lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(MessageFormat, ex.Message));
            &lt;span class="kwrd"&gt;throw&lt;/span&gt; ex;
        }
        &lt;span class="kwrd"&gt;finally&lt;/span&gt;
        {
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (impersonationContext != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
            {
                impersonationContext.Undo();
                Debug.WriteLineIf(traceEnabled, &lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(UndoneFormat, upn ?? Unknown));
            }
        }
        &lt;span class="kwrd"&gt;return&lt;/span&gt; reply;
    }&lt;/pre&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;blockquote&gt;
  &lt;p&gt;&lt;font color="#ff9900"&gt;&lt;b&gt;Fig.7: Request method of the InspectingRequestChannel&lt;/b&gt; &lt;b&gt;custom channel class.&lt;/b&gt;&lt;/font&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The custom binding element, along with other components (binding element extension, channel, channelfactory etc.) used to extend the default behavior of the WCF Send Port, is contained in a custom assembly. In order to let BizTalk to use the custom binding element inside a WCF-Custom Send Port, it&amp;#8217;s necessary to register the corresponding binding element extension inside the &lt;b&gt;machine.config&lt;/b&gt; configuration file with the following section.&lt;/p&gt;

&lt;pre class="csharpcode"&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;system.serviceModel&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;extensions&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;bindingElementExtensions&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;add&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;protocolTransition&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Microsoft.BizTalk.Rangers.ProtocolTransition.WCFCustomChannel.InspectingBindingExtensionElement,
                 Microsoft.BizTalk.Rangers.ProtocolTransition.WCFCustomChannel, Version=1.0.0.0, Culture=neutral, PublicKeyToken=874a60d7e5a4dd9b&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;bindingElementExtensions&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;extensions&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;system.serviceModel&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;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;blockquote&gt;
  &lt;p&gt;&lt;b&gt;&lt;font color="#ff9900"&gt;Fig.8: How to configure Binding Element Extension in the machine.config.&lt;/font&gt;&lt;/b&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;To configure the WCF-Custom Send Port to use &lt;b&gt;protocolTransition &lt;/b&gt;binding element, the custom binding element extension class needs to be configured in the&lt;b&gt; machine.config&lt;/b&gt;. This functionality is implemented by the &lt;b&gt;InspectingBindingExtensionElement&lt;/b&gt; class which returns the &lt;b&gt;InspectingBindingElement&lt;/b&gt; class to indirectly handle the message modification. &lt;b&gt;InspectingBindingElement&lt;/b&gt; is the only class that must be public. The factory, listener, and channels can all be internal implementations of the public run-time interfaces. The &lt;b&gt;protocolTransition &lt;/b&gt;custom binding element is associated with a BizTalk Server Send Port under the properties of the adapter in the &lt;b&gt;WCF-Custom Transport Properties&lt;/b&gt; dialog box (see Fig.9). On the &lt;b&gt;Binding&lt;/b&gt; tab, you can select a binding provided by the .NET Framework 3.0, in our scenario the &lt;b&gt;CustomBinding&lt;/b&gt;. Then in the &lt;b&gt;Binding&lt;/b&gt; panel it&amp;#8217;s possible to select any message encoding and transport element along with other custom or standard binding elements. In our case we selected the &lt;b&gt;InspectingBindingElement &lt;/b&gt;(protocolTransition), TextMessageEncodingBindingElement and HttpsTransportBindingElement. The assembly &lt;b&gt;Microsoft.BizTalk.Rangers.ProtocolTransition.WCFCustomChannel&lt;/b&gt; containing the custom binding element and channel needs to be installed into the GAC. &lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/BizTalkserverandprotocoltransition_ECD8/WCF-Custom_BindingTab_2.jpg"&gt;&lt;img height="580" alt="WCF-Custom_BindingTab" src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/BizTalkserverandprotocoltransition_ECD8/WCF-Custom_BindingTab_thumb.jpg" width="869" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;b&gt;&lt;font color="#ff9900"&gt;Fig.9: Binding configuration of the WCF-Custom Send Port.&lt;/font&gt;&lt;/b&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;&lt;font color="#ff9900"&gt;6.&lt;/font&gt;&lt;/strong&gt; The HelloWorldService WCF service returns a response message. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;font color="#ff9900"&gt;7.&lt;/font&gt;&lt;/strong&gt; The incoming response message is mapped to the format expected by the client application.&lt;/p&gt;

&lt;p&gt;&lt;font color="#ff9900"&gt;&lt;strong&gt;8.&lt;/strong&gt;&lt;/font&gt; The transformed response message is published to the MessageBox.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;font color="#ff9900"&gt;9.&lt;/font&gt;&lt;/strong&gt; The response message is retrieved by the Request-Response Soap Custom Receive Location which originally received the request call.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;font color="#ff9900"&gt;10.&lt;/font&gt;&lt;/strong&gt; The response message is returned to the client WinForm application.&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&lt;b&gt;&lt;font color="#ff9900"&gt;&lt;font size="3"&gt;Scenario 2 &amp;#8211; Messaging Only Scenario with a WCF-Custom Receive Location &lt;/font&gt;&lt;/font&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;The picture below depicts the architecture design and message flow of the second scenario. &lt;/p&gt;

&lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/BizTalkserverandprotocoltransition_ECD8/ProtocolTransition_Scenario2_2.jpg"&gt;&lt;img height="357" alt="ProtocolTransition_Scenario2" src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/BizTalkserverandprotocoltransition_ECD8/ProtocolTransition_Scenario2_thumb.jpg" width="980" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;b&gt;&lt;font color="#ff9900"&gt;Fig.10: Architecture Design of the second Scenario&lt;/font&gt;&lt;/b&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In this sample the Soap Receive Location was replaced by a WCF-Custom Receive Location.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;font color="#ff9900"&gt;1.&lt;/font&gt;&lt;/strong&gt; A WinForm client application submits a Request to a Request-Response Soap Receive using the following code.&lt;/p&gt;

&lt;pre class="csharpcode"&gt;
    &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; btnBizTalk_Click(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, EventArgs e)
    {
        WCFReceiveLocation.HelloWorldServiceClient client = &lt;span class="kwrd"&gt;null&lt;/span&gt;;

        &lt;span class="kwrd"&gt;try&lt;/span&gt;
        {
            client = &lt;span class="kwrd"&gt;new&lt;/span&gt; WCFReceiveLocation.HelloWorldServiceClient();
            client.ClientCredentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation;
            WCFReceiveLocation.RequestMessage request = &lt;span class="kwrd"&gt;new&lt;/span&gt; WCFReceiveLocation.RequestMessage();
            request.Message = txtRequest.Text;
            WCFReceiveLocation.ResponseMessage response = client.SayHello(request);
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (response != &lt;span class="kwrd"&gt;null&lt;/span&gt; &amp;amp;&amp;amp; !&lt;span class="kwrd"&gt;string&lt;/span&gt;.IsNullOrEmpty(response.Greeting))
            {
                WriteToLog(response.Greeting);
            }
        }
        &lt;span class="kwrd"&gt;catch&lt;/span&gt; (FaultException ex)
        {
            MessageBox.Show(ex.Message, 
                            ExceptionCaption, 
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Error);
        }
        &lt;span class="kwrd"&gt;catch&lt;/span&gt; (Exception ex)
        {
            MessageBox.Show(ex.Message,
                            ExceptionCaption,
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Error);
        }
        &lt;span class="kwrd"&gt;finally&lt;/span&gt;
        {
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (client != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
            {
                &lt;span class="kwrd"&gt;try&lt;/span&gt;
                {
                    client.Close();
                }
                &lt;span class="kwrd"&gt;catch&lt;/span&gt; (Exception)
               {
               }
            }
        }
    }&lt;/pre&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;blockquote&gt;
  &lt;p&gt;&lt;b&gt;&lt;font color="#ff9900"&gt;Fig.11: Client code to invoke the Soap Receive Location&lt;/font&gt;&lt;/b&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;As you can see in the code above, the client invokes the Soap Receive Location through an instance of a WCF proxy class and uses the Integrated Windows authentication with the credentials of the current user. The WCF-Custom Receive Location is hosted by an authentication trusted in-process host called &lt;b&gt;BizTalkServerTrustedHost&lt;/b&gt; (see Fig.12).&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/BizTalkserverandprotocoltransition_ECD8/WCF-Custom_ReceiveLocation1_2.jpg"&gt;&lt;img height="514" alt="WCF-Custom_ReceiveLocation1" src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/BizTalkserverandprotocoltransition_ECD8/WCF-Custom_ReceiveLocation1_thumb.jpg" width="644" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;b&gt;&lt;font color="#ff9900"&gt;Fig.12: WCF-Custom Receive Location Host configuration.&lt;/font&gt;&lt;/b&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This WCF-Custom Receive Location uses the &lt;b&gt;NetTcpBinding&lt;/b&gt; and is configured to use the Transport level security (see Fig.13).&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/BizTalkserverandprotocoltransition_ECD8/WCF-Custom_ReceiveLocation2_2.jpg"&gt;&lt;img height="580" alt="WCF-Custom_ReceiveLocation2" src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/BizTalkserverandprotocoltransition_ECD8/WCF-Custom_ReceiveLocation2_thumb.jpg" width="420" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;b&gt;&lt;font color="#ff9900"&gt;Fig.13: WCF-Custom Receive Location Binding configuration.&lt;/font&gt;&lt;/b&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In addition, the WCF-Custom Receive Location was configured to use the Enterprise Single Sign-On (see Fig.14).&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/BizTalkserverandprotocoltransition_ECD8/WCF-Custom_ReceiveLocation3_2.jpg"&gt;&lt;img height="580" alt="WCF-Custom_ReceiveLocation3" src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/BizTalkserverandprotocoltransition_ECD8/WCF-Custom_ReceiveLocation3_thumb.jpg" width="420" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;b&gt;&lt;font color="#ff9900"&gt;Fig.14: The SSO was enabled on the Soap Receive Location.&lt;/font&gt;&lt;/b&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In this way, when the WCF-Custom Receive Location is invoked by the client application, the WCF-Custom Adapter assigns the client credentials (DOMAIN\USER) to the &lt;b&gt;BTS.WindowsUser&lt;/b&gt; message context property. Note that this property is accessible within an orchestration via the &lt;b&gt;Microsoft.BizTalk.XLANGs.BTXEngine.OriginatorSID&lt;/b&gt; property. The original WCF Adapter contained in BizTalk Server 2006 R2 has a bug that is the Receive Handler doesn&amp;#8217;t assign the client credentials to the &lt;b&gt;BTS.WindowsUser &lt;/b&gt;context property. The product group made patch was done to fix this problem, but this package is not publicly available. By the way, even without the fix, it&amp;#8217;s possible to read and promote the client user account. To accomplish this task, you need to create a custom endpoint behavior which injects a message inspector in the execution chain of the WCF Receive Location. The endpoint behavior can be configured on the WCF-Custom Receive Location on the Behavior tab. The message inspector needs to implement the methods defined by the &lt;b&gt;IDispatchMessageInspector&lt;/b&gt; interface. In particular, the &lt;b&gt;AfterReceiveRequest&lt;/b&gt; method is executed after the WCF Receive Adapter has received a request message. This function can be used to read the client Windows identity name from the current service security context and to write this information in a custom header identified by a name and namespace that can be configured in the endpoint configuration.&lt;/p&gt;

&lt;pre class="csharpcode"&gt;
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;object&lt;/span&gt; AfterReceiveRequest(&lt;span class="kwrd"&gt;ref&lt;/span&gt; Message request, 
                                      IClientChannel channel,
                                      InstanceContext instanceContext)
    {
        ...
        &lt;span class="kwrd"&gt;string&lt;/span&gt; windowsUserName = ServiceSecurityContext.Current.WindowsIdentity.Name;
        request.Headers.Add(MessageHeader.CreateHeader(contextPropertyName,
                                                       contextPropertyNamespace,
                                                       windowsUserName));
        ...
        &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;null&lt;/span&gt;;
    }&lt;/pre&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;blockquote&gt;
  &lt;p&gt;&lt;b&gt;&lt;font color="#ff9900"&gt;Fig.15: The custom interceptor used to read the client user account.&lt;/font&gt;&lt;/b&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If you define a message context property in a custom PropertySchema with the same name and namespace as the header created by the message inspector component at the previous step, the WCF Adapter will transform the custom header in a written context property with the same name and namespace when transforming the inbound WCF message (&lt;b&gt;System.ServiceModel.Channels.Message&lt;/b&gt;) in an &lt;b&gt;IBaseMessage&lt;/b&gt; instance. Unofrtunately, the value of the header will be contained in a &lt;strong&gt;&amp;lt;name xmlns=&amp;#8221;&amp;#8230;&amp;#8221;&amp;gt;&amp;lt;/name&amp;gt;&lt;/strong&gt; Xml snippet, so it&amp;#8217;s necessary to create a custom pipeline component and a custom receive pipeline in order to extract the information from the custom context property and sets its value without the Xml start and end tags. The solution developed for to this article contains the code for the endpoint behavior, custom pipeline component and receive pipeline that you eventually need to set on the WCF-Custom Receive Location.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;font color="#ff9900"&gt;2.&lt;/font&gt;&lt;/strong&gt; The Message Agent submits the incoming request message to the MessageBox (BizTalkMsgBoxDb).&lt;/p&gt;

&lt;p&gt;&lt;font color="#ff9900"&gt;&lt;strong&gt;3.&lt;/strong&gt;&lt;/font&gt; The inbound request is consumed by a Solicit Response WCF-Custom Send Port. This latter uses a Filter Expression to receive all the documents published by the Receive Port hosting the Soap Receive Location.&lt;/p&gt;

&lt;p&gt;&lt;font color="#ff9900"&gt;&lt;strong&gt;4.&lt;/strong&gt;&lt;/font&gt; The inbound message is mapped to the request format by the downstream &lt;b&gt;HelloWorldService&lt;/b&gt; web service. This latter is hosted by IIS and exposes a single &lt;b&gt;WsHttpBinding&lt;/b&gt; endpoint.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;font color="#ff9900"&gt;5.&lt;/font&gt;&lt;/strong&gt; The WCF-Custom Send Port invokes the underlying HelloWorldService WCF service that in the scenario is hosted by a separate Application Pool (w3wp.exe) on the same IIS instance. For more details about this step, see the point number 5 of scenario 1.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;font color="#ff9900"&gt;6.&lt;/font&gt;&lt;/strong&gt; The HelloWorldService WCF service returns a response message. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;font color="#ff9900"&gt;7.&lt;/font&gt;&lt;/strong&gt; The incoming response message is mapped to the format expected by the client application.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;font color="#ff9900"&gt;8.&lt;/font&gt;&lt;/strong&gt; The transformed response message is published to the MessageBox.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;font color="#ff9900"&gt;9.&lt;/font&gt;&lt;/strong&gt; The response message is retrieved by the Request-Response Soap Custom Receive Location which originally received the request call.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;font color="#ff9900"&gt;10.&lt;/font&gt;&lt;/strong&gt; The response message is returned to the client WinForm application.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;&lt;font color="#ff9900"&gt;&lt;/font&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;&lt;b&gt;&lt;font color="#ff9900"&gt;Scenario 3 &amp;#8211; Orchestration with an Inline Send Port&lt;/font&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;The picture below depicts the architecture design and message flow of the third scenario. &lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/BizTalkserverandprotocoltransition_ECD8/ProtocolTransition_Scenario3_2.jpg"&gt;&lt;img height="357" alt="ProtocolTransition_Scenario3" src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/BizTalkserverandprotocoltransition_ECD8/ProtocolTransition_Scenario3_thumb.jpg" width="980" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;b&gt;&lt;font color="#ff9900"&gt;Fig.16: Architecture Design of the third Scenario.&lt;/font&gt;&lt;/b&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;This scenario uses a technique commonly known as &lt;b&gt;Inline Send Ports&lt;/b&gt; pattern: orchestrations do not use any logical ports bound to physical ports to invoke underlying services (e.g. WCF, Soap, Http services) or access data repositories (e.g. SQL Server, Oracle, Mainframe) but in their place they use custom .NET components (e.g. an instance of a SOAP or WCF proxy class to invoke a downstream web service or a ADO.NET component to invoke a SQL or an Oracle database) invoked inside an Expression Shape. Note that not using adapters and physical ports, the application will not benefit from their functional capabilities such as batching, retries, correlation sets initialization, declarative configuration and secondary transports. The advantage of this technique is that for each Solicit Response call made by the orchestration, it allows to eliminate 4 roundtrips to the MessageBox:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Orchestration Logical Port --&amp;gt; Request --&amp;gt; MessageBox&lt;/li&gt;

  &lt;li&gt;MessageBox --&amp;gt; Request --&amp;gt; Physical Send Port&lt;/li&gt;

  &lt;li&gt;Physical Send Port --&amp;gt; Response --&amp;gt; MessageBox&lt;/li&gt;

  &lt;li&gt;MessageBox --&amp;gt; Response --&amp;gt; Orchestration Logical Port&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the third scenario the request message is received by the same Soap Receive Location used by the first scenario, but in this case the incoming document is consumed and processed by an orchestration. This latter directly invokes the downstream &lt;b&gt;HelloWorldService&lt;/b&gt; WCF service using an instance of a WCF proxy.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;font color="#ff9900"&gt;1.&lt;/font&gt;&lt;/strong&gt; A WinForm client application submits a Request to a Request-Response Soap Receive using the following code. See point 1 of the first scenario for more information on the code used by the client application and the Soap Receive Location configuration.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;font color="#ff9900"&gt;2.&lt;/font&gt;&lt;/strong&gt; The Message Agent submits the incoming request message to the MessageBox (BizTalkMsgBoxDb).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;font color="#ff9900"&gt;3.&lt;/font&gt;&lt;/strong&gt; The inbound request is consumed by new instance of the &lt;b&gt;CallHelloWorld &lt;/b&gt;orchestration. &lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/BizTalkserverandprotocoltransition_ECD8/Orchestration_4.jpg"&gt;&lt;img height="580" alt="Orchestration" src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/BizTalkserverandprotocoltransition_ECD8/Orchestration_thumb_1.jpg" width="700" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;b&gt;&lt;font color="#ff9900"&gt;Fig.17: The structure of the orchestration used by the third scenario.&lt;/font&gt;&lt;/b&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;&lt;font color="#ff9900"&gt;4.&lt;/font&gt;&lt;/strong&gt; The orchestration instance invokes the &lt;b&gt;SayHello&lt;/b&gt; static method exposed by the &lt;b&gt;OrchestrationHelper&lt;/b&gt; class inside the WCF Call Expression Shape.&lt;/p&gt;

&lt;pre class="csharpcode"&gt;
 stream = Microsoft.BizTalk.Rangers.ProtocolTransition.Helpers.OrchestrationHelper.SayHello(
                                                               RequestMessage(Microsoft.BizTalk.XLANGs.BTXEngine.OriginatorSID), 
                                                               RequestMessage.BodyPart.Message);&lt;/pre&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;blockquote&gt;
  &lt;p&gt;&lt;b&gt;&lt;font color="#ff9900"&gt;Fig.18: Helper component call inside the CallHelloWorld orchestration.&lt;/font&gt;&lt;/b&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;&lt;font color="#ff9900"&gt;5.&lt;/font&gt;&lt;/strong&gt; The &lt;b&gt;SayHello&lt;/b&gt; method invoked by the orchestration impersonates the user account specified in the originatorSID parameter and then invokes the HelloWorld WCF service using the following code.&lt;/p&gt;

&lt;pre class="csharpcode"&gt;
    &lt;span class="kwrd"&gt;private const string &lt;/span&gt;UserPrincipalNameFormat = &amp;quot;&lt;a href="mailto:{0}@{1}"&gt;{0}@{1}&lt;/a&gt;&amp;quot;;&lt;br /&gt;&lt;span class="kwrd"&gt;    &lt;font color="#404040"&gt;...&lt;/font&gt;&lt;br /&gt;    public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; Stream SayHello(&lt;span class="kwrd"&gt;string&lt;/span&gt; originatorSID, &lt;span class="kwrd"&gt;string&lt;/span&gt; message)
    {
        WindowsImpersonationContext impersionationContext = &lt;span class="kwrd"&gt;null&lt;/span&gt;;

        &lt;span class="kwrd"&gt;try&lt;/span&gt;
        {
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (!&lt;span class="kwrd"&gt;string&lt;/span&gt;.IsNullOrEmpty(originatorSID))
            {
                &lt;span class="kwrd"&gt;string&lt;/span&gt;[] parts = originatorSID.Split(&lt;span class="kwrd"&gt;new&lt;/span&gt; &lt;span class="kwrd"&gt;char&lt;/span&gt;[] {Path.DirectorySeparatorChar});
                &lt;span class="kwrd"&gt;if&lt;/span&gt; (parts != &lt;span class="kwrd"&gt;null&lt;/span&gt; &amp;amp;&amp;amp; parts.Length &amp;gt; 1)
                {
                    &lt;span class="kwrd"&gt;string&lt;/span&gt; upn = &lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(UserPrincipalNameFormat, 
                                               parts[1], 
                                               domainFQDN);
                    WindowsIdentity identity = &lt;span class="kwrd"&gt;new&lt;/span&gt; WindowsIdentity(upn);
                    impersionationContext = identity.Impersonate();
                }
            }
            RequestMessage request = &lt;span class="kwrd"&gt;new&lt;/span&gt; RequestMessage();
            request.Message = message;
            HelloWorldClient client = &lt;span class="kwrd"&gt;new&lt;/span&gt; HelloWorldClient();
            ResponseMessage response = client.SayHello(request);
            &lt;span class="kwrd"&gt;string&lt;/span&gt; greeting;
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (response != &lt;span class="kwrd"&gt;null&lt;/span&gt; &amp;amp;&amp;amp; !&lt;span class="kwrd"&gt;string&lt;/span&gt;.IsNullOrEmpty(response.Greeting))
            {
                greeting = response.Greeting;
            }
            &lt;span class="kwrd"&gt;else&lt;/span&gt;
            {
                greeting = NoGreeting;
            }
            &lt;span class="kwrd"&gt;return&lt;/span&gt; WriteStream(greeting);
        }
        &lt;span class="kwrd"&gt;catch&lt;/span&gt; (FaultException&amp;lt;GreetingFault&amp;gt; ex)
        {
            &lt;span class="kwrd"&gt;return&lt;/span&gt; WriteStream(ex.Detail.Message);                
        }
        &lt;span class="kwrd"&gt;catch&lt;/span&gt; (Exception ex)
        {
            &lt;span class="kwrd"&gt;return&lt;/span&gt; WriteStream(ex.Message);
        }
        &lt;span class="kwrd"&gt;finally&lt;/span&gt;
        {
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (impersionationContext != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
            {
                impersionationContext.Undo();
            }
        }
    }&lt;/pre&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;&lt;b&gt;&lt;font color="#ff9900"&gt;Fig.19: The code of the SayHello method called by the CallHelloWorld orchestration.&lt;/font&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;The client endpoint used by the &lt;b&gt;HelloWorldClient&lt;/b&gt; WCF proxy class is defined in the BizTalk Server configuration file (BTSNTSvc.exe.config) as follows:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;system.serviceModel&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;bindings&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;wsHttpBinding&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;binding&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;HelloWorldBinding&amp;quot;&lt;/span&gt; 
                     &lt;span class="attr"&gt;closeTimeout&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;00:01:00&amp;quot;&lt;/span&gt;
                     &lt;span class="attr"&gt;openTimeout&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;00:01:00&amp;quot;&lt;/span&gt;
                     &lt;span class="attr"&gt;receiveTimeout&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;00:10:00&amp;quot;&lt;/span&gt;
                     &lt;span class="attr"&gt;sendTimeout&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;00:01:00&amp;quot;&lt;/span&gt;
                     &lt;span class="attr"&gt;bypassProxyOnLocal&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;false&amp;quot;&lt;/span&gt;
                     &lt;span class="attr"&gt;transactionFlow&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;false&amp;quot;&lt;/span&gt;
                     &lt;span class="attr"&gt;hostNameComparisonMode&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;StrongWildcard&amp;quot;&lt;/span&gt;
                     &lt;span class="attr"&gt;maxBufferPoolSize&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;524288&amp;quot;&lt;/span&gt;
                     &lt;span class="attr"&gt;maxReceivedMessageSize&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;65536&amp;quot;&lt;/span&gt;
                     &lt;span class="attr"&gt;messageEncoding&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Text&amp;quot;&lt;/span&gt;
                     &lt;span class="attr"&gt;textEncoding&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;utf-8&amp;quot;&lt;/span&gt;
                     &lt;span class="attr"&gt;useDefaultWebProxy&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt;
                     &lt;span class="attr"&gt;allowCookies&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;false&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;readerQuotas&lt;/span&gt; &lt;span class="attr"&gt;maxDepth&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;32&amp;quot;&lt;/span&gt; 
                          &lt;span class="attr"&gt;maxStringContentLength&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;8192&amp;quot;&lt;/span&gt;
                          &lt;span class="attr"&gt;maxArrayLength&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;16384&amp;quot;&lt;/span&gt;
                          &lt;span class="attr"&gt;maxBytesPerRead&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;4096&amp;quot;&lt;/span&gt; 
                          &lt;span class="attr"&gt;maxNameTableCharCount&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;16384&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;reliableSession&lt;/span&gt; &lt;span class="attr"&gt;ordered&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt;
                             &lt;span class="attr"&gt;inactivityTimeout&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;00:10:00&amp;quot;&lt;/span&gt;
                             &lt;span class="attr"&gt;enabled&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;false&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;security&lt;/span&gt; &lt;span class="attr"&gt;mode&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Transport&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;transport&lt;/span&gt; &lt;span class="attr"&gt;clientCredentialType&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Windows&amp;quot;&lt;/span&gt; 
                       &lt;span class="attr"&gt;proxyCredentialType&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;None&amp;quot;&lt;/span&gt;
                       &lt;span class="attr"&gt;realm&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;message&lt;/span&gt; &lt;span class="attr"&gt;clientCredentialType&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Windows&amp;quot;&lt;/span&gt;
                     &lt;span class="attr"&gt;negotiateServiceCredential&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt;
                     &lt;span class="attr"&gt;establishSecurityContext&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;security&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;binding&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;wsHttpBinding&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;bindings&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;client&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;endpoint&lt;/span&gt; &lt;span class="attr"&gt;address&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;https://domokun/HelloWorldService/HelloWorldService.svc&amp;quot;&lt;/span&gt;
                  &lt;span class="attr"&gt;binding&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;wsHttpBinding&amp;quot;&lt;/span&gt;
                  &lt;span class="attr"&gt;bindingConfiguration&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;HelloWorldBinding&amp;quot;&lt;/span&gt;
                  &lt;span class="attr"&gt;contract&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;IHelloWorld&amp;quot;&lt;/span&gt;
                  &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;HelloWorldBinding&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;endpoint&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;client&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;system.serviceModel&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;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;&lt;b&gt;&lt;font color="#ff9900"&gt;Fig.20: The system.serviceModel configuration in the BTSNTSvc.exe.config file.&lt;/font&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;font color="#ff9900"&gt;6.&lt;/font&gt;&lt;/strong&gt; The HelloWorldService WCF service returns a response message to the helper component. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;font color="#ff9900"&gt;7.&lt;/font&gt;&lt;/strong&gt; The orchestration creates a response message.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;font color="#ff9900"&gt;8.&lt;/font&gt;&lt;/strong&gt; The response message is published to the MessageBox.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;font color="#ff9900"&gt;9.&lt;/font&gt;&lt;/strong&gt; The response message is retrieved by the Request-Response Soap Custom Receive Location which originally received the request call.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;font color="#ff9900"&gt;10.&lt;/font&gt;&lt;/strong&gt; The response message is returned to the client WinForm application.&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&lt;b&gt;&lt;font color="#ff9900" size="3"&gt;Summary&lt;/font&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;This article described how using the Protocol Transition technique in a BizTalk Server project to impersonate the original caller authenticated with the Windows Integrated security at the transport level. At the same time the samples shown demonstrate the WCF extensibility points provided by the WCF Adapters and the use of the Inline Send Pattern. You can download the code &lt;a href="http://cid-09dba4a06b360a65.skydrive.live.com/self.aspx/Pubblica/ProtocolTransition.zip"&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9349083" width="1" height="1"&gt;</description></item><item><title>Microsoft BizTalk Server 2006 R2 Hyper-V Guide</title><link>http://blogs.msdn.com/paolos/archive/2008/07/23/microsoft-biztalk-server-2006-r2-hyper-v-guide.aspx</link><pubDate>Wed, 23 Jul 2008 19:30:40 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8767291</guid><dc:creator>leprino</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/paolos/comments/8767291.aspx</comments><wfw:commentRss>http://blogs.msdn.com/paolos/commentrss.aspx?PostID=8767291</wfw:commentRss><wfw:comment>http://blogs.msdn.com/paolos/rsscomments.aspx?PostID=8767291</wfw:comment><description>&lt;p&gt;The BizTalk Customer Advisory Team and BizTalk UE team released the first edition of the &amp;#8220;&lt;a href="http://msdn.microsoft.com/en-us/library/cc768518.aspx"&gt;Microsoft BizTalk Server 2006 R2 Hyper-V Guide&lt;/a&gt;&amp;#8221;. &lt;/p&gt;  &lt;p&gt;The Microsoft BizTalk Server 2006 R2 Hyper-V Guide is the third deliverable in a series of guides intended to provide easily accessible, hands-on guidance to our customer and partner community. This 145 page guide is available on &lt;a href="http://msdn.microsoft.com/en-us/library/cc768518.aspx"&gt;MSDN&lt;/a&gt;, &lt;a href="http://technet.microsoft.com/en-us/library/cc768518.aspx"&gt;TechNet&lt;/a&gt; and as a separate DOCX or PDF &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=5c5d86ad-5e17-4ff2-abc9-5a81177f4b30&amp;amp;displaylang=en"&gt;download&lt;/a&gt; alongside the already available &amp;#8220;&lt;a href="http://technet.microsoft.com/en-us/library/cc296643.aspx"&gt;Microsoft BizTalk Server Operations Guide&lt;/a&gt;&amp;#8221;&amp;#160; and &amp;#8220;&lt;a href="http://msdn.microsoft.com/en-us/library/cc558617.aspx"&gt;Microsoft BizTalk Server Performance Optimizations Guide&lt;/a&gt;&amp;#8221;&lt;/p&gt;  &lt;p&gt;The guide provides relevant information to IT professionals to enable them to make educated decisions about the advantages and tradeoffs of using Windows Server 2008 Hyper-V to virtualize BizTalk Server environments. This guidance was derived from a 6 week performance lab conducted by the BizTalk Customer Advisory Team and Premier Field Engineering.&amp;#160; It will be refreshed for future versions of Microsoft BizTalk Server. &lt;/p&gt;  &lt;p&gt;The key sections of the guide are: &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;b&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/cc768532.aspx"&gt;Getting Started&lt;/a&gt;&lt;/b&gt;: provides conceptual information about Hyper-V, the virtualization technology introduced with Windows Server 2008, and an introduction to the Hyper-V architecture.&lt;/li&gt;    &lt;li&gt;&lt;b&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/cc768525.aspx"&gt;Deploying BizTalk Server on Hyper-V&lt;/a&gt;&lt;/b&gt;: describes the steps that were followed to set up the lab environment, which was used to compare the performance of a BizTalk Server solution running on Hyper-V environment to the same BizTalk Server solution running on comparable physical hardware.&lt;/li&gt;    &lt;li&gt;&lt;b&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/cc768519.aspx"&gt;Evaluating BizTalk Server Performance on Hyper-V&lt;/a&gt;&lt;/b&gt;: details the important considerations when measuring the performance of a BizTalk Server solution running on a Hyper-V virtualized environment. &lt;/li&gt;    &lt;li&gt;&lt;b&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/cc768537.aspx"&gt;Testing BizTalk Server Performance on Hyper-V&lt;/a&gt;&lt;/b&gt;: provides detailed results of four distinct testing scenarios that compare the performance of a BizTalk Server solution running on Hyper-V environment to the same BizTalk Server solution running on comparable physical hardware. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;The target audience for this guide is Microsoft field, partner organizations, and customers who plan, deploy, and maintain BizTalk Server installations. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Full MSDN URL&lt;/strong&gt;: &lt;a href="http://msdn.microsoft.com/en-us/library/cc768518.aspx"&gt;http://msdn.microsoft.com/en-us/library/cc768518.aspx&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Full TechNet URL&lt;/strong&gt;: &lt;a href="http://technet.microsoft.com/en-us/library/cc768518.aspx"&gt;http://technet.microsoft.com/en-us/library/cc768518.aspx&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8767291" width="1" height="1"&gt;</description></item><item><title>Synchronous To Asynchronous Flows Without An Orchestration</title><link>http://blogs.msdn.com/paolos/archive/2008/07/21/msdn-blogs.aspx</link><pubDate>Mon, 21 Jul 2008 19:31:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8761951</guid><dc:creator>leprino</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/paolos/comments/8761951.aspx</comments><wfw:commentRss>http://blogs.msdn.com/paolos/commentrss.aspx?PostID=8761951</wfw:commentRss><wfw:comment>http://blogs.msdn.com/paolos/rsscomments.aspx?PostID=8761951</wfw:comment><description>&lt;P align=justify&gt;&lt;B&gt;The Issue&lt;/B&gt;&lt;/P&gt;
&lt;P align=justify&gt;Some months ago I had the chance to work with a customer who asked me a very nteresting and tricky question: does BizTalk Server 2006 R2 support synchronous-to-asynchronous messaging only flows, without the need of an orchestration to couple a Two Way Request Response Receive Location with a One-Way Send Port to send out the request and a One-Way Receive Location to get response back from the invoked system?&lt;/P&gt;
&lt;P align=justify&gt;The use case the customer wanted to reproduce was the following:&lt;/P&gt;
&lt;P align=justify&gt;· A Two-Way SOAP Receive Location receives a request message and publishes it to the BizTalkMsgBoxDb.&lt;/P&gt;
&lt;P align=justify&gt;· The message is consumed by a MQ Series One-Way Send Port which writes the document into an outgoing MQ queue.&lt;/P&gt;
&lt;P align=justify&gt;· The response message is received by a given MQ Series One-Way Receive Location which reads the document from an incoming MQ Queue and publishes the message to the BizTalkMsgBoxDb.&lt;/P&gt;
&lt;P align=justify&gt;· The response message is finally received by the Two-Way SOAP Receive Location which received the original request and then the document is returned to the caller.&lt;/P&gt;
&lt;P align=justify&gt;I started to create a POC of this scenario, using the FILE adapter in place of the MQ Series Adapter and folders in place of MQ queues. In the majority of BizTalk applications that use a Request-Response receive port, the request message is used to start a given Orchestration or it is directly relayed to a solicit-response Send Port. When the Orchestration or Send Port provides the response message, this message is routed back to the Two-Way Receive Location that submitted the original request message. These two design patterns are fully supported by the product group and the picture below depicts the case where a Two-Way Request Response Receive Location is directly coupled with a Two-Way Solicit Response Send Port which is responsible for invoking an external web service.&lt;/P&gt;
&lt;P align=justify&gt;&lt;A href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/MSDNBlogs_FA9C/SyncToAsync01_10.jpg" mce_href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/MSDNBlogs_FA9C/SyncToAsync01_10.jpg"&gt;&lt;IMG alt=SyncToAsync01 src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/MSDNBlogs_FA9C/SyncToAsync01_thumb_4.jpg" width=980 height=159 mce_src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/MSDNBlogs_FA9C/SyncToAsync01_thumb_4.jpg"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P align=justify&gt;But what about our case in which the request and response are respectively sent and received to/from an external target system not using a Two-Way Solicit-Response Send Port, but using a One-Way Send Port while and a One-Way Receive Location? The standard solution is using an Orchestration to correlate the request submitted to the external system with the response received from this latter. But as you can see from the picture below, this pattern requires 8 roundtrips to the BizTalkMsgBoxDb to complete, 4 message writes and 4 message reads. &lt;/P&gt;
&lt;P align=justify&gt;&lt;A href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/MSDNBlogs_FA9C/SyncToAsync02_6.jpg" mce_href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/MSDNBlogs_FA9C/SyncToAsync02_6.jpg"&gt;&lt;IMG alt=SyncToAsync02 src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/MSDNBlogs_FA9C/SyncToAsync02_thumb_2.jpg" width=980 height=224 mce_src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/MSDNBlogs_FA9C/SyncToAsync02_thumb_2.jpg"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P align=justify&gt;In other words, this approach requires multiple roundtrips to the MessageBox to publish and consume messages to/from the BizTalkMsgBoxDb and to hydrate and dehydrate the internal state of the orchestration and all these operations can dramatically increase the contention on SQL and reduce the overall throughput and speed of the application.&lt;/P&gt;
&lt;P align=justify&gt;So the following question spontaneously emerged: is there any technique to implement the same behavior getting rid of the orchestration? This pattern would allow to eliminate 2 messages publications and 2 message reads and this would allow to speed up the execution and to decrease the contention on the BizTalkMsgBox.&lt;/P&gt;
&lt;P align=justify&gt;The solution to this problem rests in understanding how BizTalk matches a response message to an initial request message. After you understood the internal subscription matching mechanism implemented by BizTalk, the second step is to individuate the context properties that need to be propagated along and promoted in the One-Way Receive Location in order to allow the Two-Way Receive Location to receive the response when this latter is published to the BizTalkMsgBox.&lt;/P&gt;
&lt;P align=justify&gt;When a message is received through a Request-Response Receive Location and published to the BizTalkMsgBoxDb, an instance subscription is created to allow the Receive Location to receive the response back when this latter is published to the MessageBox. This subscription expression is always composed of the pmRRCorrelationToken promoted property that is in the request message's context, and a RouteDirectToTP promoted property with a value of True. &lt;/P&gt;
&lt;P align=justify&gt;&lt;A href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/MSDNBlogs_FA9C/SyncToAsync03_2.jpg" mce_href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/MSDNBlogs_FA9C/SyncToAsync03_2.jpg"&gt;&lt;IMG alt=SyncToAsync03 src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/MSDNBlogs_FA9C/SyncToAsync03_thumb.jpg" width=600 height=610 mce_src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/MSDNBlogs_FA9C/SyncToAsync03_thumb.jpg"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P align=justify&gt;In particular the pmRRCorrelationToken is a string containing the name of the BizTalk node which received the request, the process id of the host instance which received the message and a GUID which represents a correlation id. For more info on these and other context properties you can review the following article on MSDN &lt;A href="http://msdn.microsoft.com/en-us/library/ms966048.aspx" mce_href="http://msdn.microsoft.com/en-us/library/ms966048.aspx"&gt;http://msdn.microsoft.com/en-us/library/ms966048.aspx&lt;/A&gt;.&lt;/P&gt;
&lt;P align=justify&gt;I made some tests and I quickly realized that those properties were not sufficient to correlate a response back to the original request. In other words, even if the subscription expression is composed of pmRRCorrelationToken and the RouteDirectToTP properties, promoting them with the expected value in the message context of the response document before publishing this latter is not sufficient to pass message back to the Receive Location. It was clear that it was necessary to propagate some additional context properties, even if they were not used by the subscription expression. After some attempts, I was able to identify the set of context properties that were necessary to correlate a response message back and I was able to create a sample were a synchronous WCF Request Response is couple to 2 asynchronous One-Way FILE Ports.&lt;/P&gt;
&lt;P align=justify&gt;&lt;B&gt;The Solution&lt;/B&gt;&lt;/P&gt;
&lt;P align=justify&gt;I created a sample BizTalk application called SyncToAsync containing a Two-Way Receive Port called SyncToAsync.Request.ReceivePort. Subsequently, I created a WCF-NetTcp Request Response Receive Location called SyncToAsync.Request.WCF-NetTcp.ReceiveLocation and a WinForm driver application to submit requests to it. Using the WCF Service Publishing Wizard I created a MetadataExchange Endpoint for the web service exposed by the WCF Receive Location and then I used the Add Service Reference command provided by Visual Studio 2005 to create a proxy class in order to submit messages to it. I selected the XmlReceive and PassThruTransmit pipelines on the SyncToAsync.Request.WCF-NetTcp.ReceiveLocation to process respectively the incoming request and the outgoing response messages. In particular, The XmlReceive pipeline contains the Xml Disassembler which is responsible to probe and individuate the message type and to promote this information along with other context properties. The second step was creating a One-Way FILE Send Port that subscribed all the messages published by the former Receive Location. In order to that I just used the BTS.ReceivePortName = SyncToAsync.Request.ReceivePort predicate as Filter expression. At this point I enabled the SyncToAsync.Request.WCF-NetTcp.ReceiveLocation WCF Receive Location and maintained disabled the SyncToAsync.Request.FILE.SendPort Send Port. Then, using the .NET driver application, I submitted some messages to the BizTalk application. Since no subscribers were active, those messages were suspended. Therefore, using the Administration Console I could review the promoted properties of the incoming request message. After some attempts, I realized that the properties highlighted below (CorrelationToken, EpmReqRespCorrelationToken, ReqRespTransmitPipelineID, IsRequestResponse) plus the RouteDirectToTP that is not promoted on the original request message, were the properties that had to be propagated and subsequently promoted on the One-Way FILE Receive Location used to publish the response to MessageBox.&lt;/P&gt;
&lt;P align=justify&gt;&lt;A href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/MSDNBlogs_FA9C/SyncToAsync04_2.jpg" mce_href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/MSDNBlogs_FA9C/SyncToAsync04_2.jpg"&gt;&lt;IMG alt=SyncToAsync04 src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/MSDNBlogs_FA9C/SyncToAsync04_thumb.jpg" width=980 height=612 mce_src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/MSDNBlogs_FA9C/SyncToAsync04_thumb.jpg"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P align=justify&gt;For the demo I created a very simple XML Schema to represent the basic attributes of a Book entity. I called the schema below InboundBook and this represents the format of the incoming message sent by the .NET Driver application and received by the WCF Receive Location.&lt;/P&gt;
&lt;P align=justify&gt;&lt;A href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/MSDNBlogs_FA9C/SyncToAsync05_4.jpg" mce_href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/MSDNBlogs_FA9C/SyncToAsync05_4.jpg"&gt;&lt;IMG alt=SyncToAsync05 src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/MSDNBlogs_FA9C/SyncToAsync05_thumb_1.jpg" width=800 height=497 mce_src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/MSDNBlogs_FA9C/SyncToAsync05_thumb_1.jpg"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P align=justify&gt;Then I created an extended version of the above XML schema in order to demote some of the aforementioned context properties inside the outgoing message. I called this schema OutboundBook. As you can see in the picture below, this schema is composed of a Header and a Body:&lt;/P&gt;
&lt;P align=justify&gt;· The Header contains the CorrelationToken, EpmRRCorrelationToken and ReqRespTransmitPipelineID elements. In particular, this latter will contain the GUID of the transmit pipeline used by the WCF Receive Location to process the outbound response message. I promoted these 3 elements respectively to the properties with the same name exposed by the BTS.bts_system_properties schema contained in the Microsoft.BizTalk.GlobalPropertySchemas assembly. In this way, if on the Send Port I use any send pipeline containing the XML Assembler component (e.g. the XmlTransmit standard pipeline), at run-time, when the pipeline is executed, the value of those message context properties are demoted to those elements.&lt;/P&gt;
&lt;P align=justify&gt;· The Body contains the payload of the message, that is the ISBN and Title elements.&lt;/P&gt;
&lt;P align=justify&gt;&lt;A href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/MSDNBlogs_FA9C/SyncToAsync06_2.jpg" mce_href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/MSDNBlogs_FA9C/SyncToAsync06_2.jpg"&gt;&lt;IMG alt=SyncToAsync06 src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/MSDNBlogs_FA9C/SyncToAsync06_thumb.jpg" width=800 height=497 mce_src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/MSDNBlogs_FA9C/SyncToAsync06_thumb.jpg"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P align=justify&gt;Then, I created a map to transform an InboundBook message into a OutboundBook document on the FILE Send Port.&lt;/P&gt;
&lt;P align=justify&gt;&lt;A href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/MSDNBlogs_FA9C/SyncToAsync07_2.jpg" mce_href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/MSDNBlogs_FA9C/SyncToAsync07_2.jpg"&gt;&lt;IMG alt=SyncToAsync07 src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/MSDNBlogs_FA9C/SyncToAsync07_thumb.jpg" width=800 height=497 mce_src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/MSDNBlogs_FA9C/SyncToAsync07_thumb.jpg"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P align=justify&gt;For the response message, I created an XML Schema to represent the author of a certain book. Even in this case, the schema is composed of a Header and Body elements. The Header contains the following elements:&lt;/P&gt;
&lt;P align=justify&gt;· CorrelationToken.&lt;/P&gt;
&lt;P align=justify&gt;· EpmRRCorrelationToken.&lt;/P&gt;
&lt;P align=justify&gt;· ReqRespTransmitPipelineID.&lt;/P&gt;
&lt;P align=justify&gt;· IsRequestResponse.&lt;/P&gt;
&lt;P align=justify&gt;· RouteDirectToTP.&lt;/P&gt;
&lt;P align=justify&gt;Each of those elements are promoted to the context properties having the same name and contained in the Microsoft.BizTalk.GlobalPropertySchemas assembly. In particular, the IsRequestResponse and RouteDirectToTP elements are defined as boolean and they have a Fixed value equal to 1.&lt;/P&gt;
&lt;P align=justify&gt;&lt;A href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/MSDNBlogs_FA9C/SyncToAsync08_2.jpg" mce_href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/MSDNBlogs_FA9C/SyncToAsync08_2.jpg"&gt;&lt;IMG alt=SyncToAsync08 src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/MSDNBlogs_FA9C/SyncToAsync08_thumb.jpg" width=800 height=497 mce_src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/MSDNBlogs_FA9C/SyncToAsync08_thumb.jpg"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P align=justify&gt;Finally, I created a One-Way Receive called SyncToAsync.Response.ReceivePort and a corresponding FILE Receive Location called SyncToAsync.Response.FILE.ReceiveLocation. I set the standard XmlReceive pipeline on this Receive Location which contains the XmlDisassembler component that is responsible for promoting contained in the Header section of an Author message.&lt;/P&gt;
&lt;P align=justify&gt;Inside the configuration file of the Driver application you can specify the location of the inbound and outbound folder used respectively by the FILE Receive and Send Ports. The client application used a FileSystemWatcher instance to trigger when a file is published by the Send Port on the outbound folder. When this event happens, a dialog opens where you can review the book information and enter the name and surname of the corresponding author. When you press the Submit button, an instance of the Author message is created for you by the Driver application, the value of the Header elements of the OutboundBook message are copied to the corresponding elements inside the Header of the Author message and the value of the IsRequestResponse and RouteDirectToTP elements is set to true. Then, the Author message is written in the inbound folder where it is received by the SyncToAsync.Response.FILE.ReceiveLocation which promotes the context properties and publishes the message to MessageBox. When the XML document is published, subscriptions are evaluated and the response message is passed to the WCF Receive Location which returns the message to the client application. The following picture depicts the overall architecture of the demo. &lt;/P&gt;
&lt;P align=justify&gt;&lt;A href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/MSDNBlogs_FA9C/SyncToAsync09_4.jpg" mce_href="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/MSDNBlogs_FA9C/SyncToAsync09_4.jpg"&gt;&lt;IMG alt=SyncToAsync09 src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/MSDNBlogs_FA9C/SyncToAsync09_thumb_1.jpg" width=980 height=539 mce_src="http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/MSDNBlogs_FA9C/SyncToAsync09_thumb_1.jpg"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P align=justify&gt;You can download the code &lt;A href="http://cid-09dba4a06b360a65.skydrive.live.com/self.aspx/Pubblica/SyncToAsync.zip" mce_href="http://cid-09dba4a06b360a65.skydrive.live.com/self.aspx/Pubblica/SyncToAsync.zip"&gt;here&lt;/A&gt;.&lt;/P&gt;
&lt;P align=justify&gt;&lt;B&gt;Conclusions&lt;/B&gt;&lt;/P&gt;
&lt;P align=justify&gt;This technique is a good way to couple a synchronous Request Response Port with 2 Asynchronous One-Way Ports without using an Orchestration. This approach, compared with the standard approach which makes use of an Orchestration to implement the same behavior, allows saving 4 roundtrips to the MessageBox. Therefore, this pattern allows to decrease the contention on the SQL Server instance running the master BizTalkMsgBoxDb and speed up the overall message processing. By the way, I don’t think that the Product Group would support this solution, even if it doesn’t require any custom component. In fact, it uses context properties that were not probably meant to be used by developers, even if the BizTalk programmers’ community knows and uses them. Remember in fact that Microsoft could in any moment release a fix or a service pack that could change the behavior of the subscriptions evaluation and of the request-response correlation, invalidating this technique. On the other hand, this eventuality is not likely for the following reasons:&lt;/P&gt;
&lt;P align=justify&gt;· The use of the request-response correlation mechanism is quite consolidated.&lt;/P&gt;
&lt;P align=justify&gt;· Microsoft is working on R3 and the Oslo, and I don’t think they would have time and will to re-engineer this mechanism.&lt;/P&gt;
&lt;P align=justify&gt;I have also some ideas on how to modify/customize the technique I described to obtain the same behavior in a slightly different way: for example, instead of including all the necessary context properties in the header of the response message and promote all of them, you could promote the EpmRRCorrelationToken, CorrelationToekn and RouteDirectToTP, since the IsRequestReponse and ReRespTransmitPipelineID are originally written properties. The solution I implemented is probably the fastest one, but it requires all the 5 properties to be propagated and promoted. Another approach could be to save the value of these properties on a DB with a custom pipeline component in the transmit pipeline run by the One-Way Send Port and retrieve them in the receive pipeline on the One-Way Receive Location. This mechanism would allow you to propagate just one unique identifier or correlation id that should be repeated in the response message. If you don’t want to use the EpmRRCorrelationToken or the CorrelationToken, you could even use an existing ID already present in the request and response documents as the OrderID or CustomerID.&amp;nbsp; This approach is less performant (since you need to access a custom DB on the send and receive pipelines) but more flexible and less intrusive, and it’s relatively easy to implement.&lt;/P&gt;
&lt;P align=justify&gt;&lt;A href="http://blogs.msdn.com/createblog.aspx" mce_href="http://blogs.msdn.com/createblog.aspx"&gt;MSDN Blogs&lt;/A&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8761951" width="1" height="1"&gt;</description></item></channel></rss>