<?xml version="1.0" encoding="utf-8"?>
<feed xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xml:lang="en-us" xmlns="http://www.w3.org/2005/Atom">
  <title>Scott Klueppel's Blog</title>
  <link rel="alternate" type="text/html" href="http://offroadcoder.com/" />
  <link rel="self" href="http://offroadcoder.com/SyndicationService.asmx/GetAtom" />
  <icon>favicon.ico</icon>
  <updated>2009-04-14T20:02:57.639625-07:00</updated>
  <author>
    <name>Scott Klueppel</name>
  </author>
  <subtitle>making the hard line look easy</subtitle>
  <id>http://offroadcoder.com/</id>
  <generator uri="http://dasblog.info/" version="2.1.8102.813">DasBlog</generator>
  <entry>
    <title>I love a good manifesto</title>
    <link rel="alternate" type="text/html" href="http://offroadcoder.com/2009/04/14/ILoveAGoodManifesto.aspx" />
    <id>http://offroadcoder.com/PermaLink,guid,256d431c-d207-4226-8208-fd03303cb87f.aspx</id>
    <published>2009-04-14T16:03:48.889625-07:00</published>
    <updated>2009-04-14T20:02:57.639625-07:00</updated>
    <category term="Cloud" label="Cloud" scheme="http://offroadcoder.com/CategoryView,category,Cloud.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
I really like the manifesto’s web site! In the following post, MLB comments on the
Open Cloud Manifesto. 
</p>
        <p>
          <a href="http://www.dasblonde.net/2009/03/31/TheOpenCloudManifestoWhatIThink.aspx" target="_blank">http://www.dasblonde.net/2009/03/31/TheOpenCloudManifestoWhatIThink.aspx</a>
        </p>
        <img width="0" height="0" src="http://offroadcoder.com/aggbug.ashx?id=256d431c-d207-4226-8208-fd03303cb87f" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Developers - Get ready for the future!</title>
    <link rel="alternate" type="text/html" href="http://offroadcoder.com/2009/04/11/DevelopersGetReadyForTheFuture.aspx" />
    <id>http://offroadcoder.com/PermaLink,guid,9f705cfe-f476-48fb-9f4d-a938846d003d.aspx</id>
    <published>2009-04-11T05:51:30.451125-07:00</published>
    <updated>2009-04-11T05:51:30.451125-07:00</updated>
    <category term=".NET Framework" label=".NET Framework" scheme="http://offroadcoder.com/CategoryView,category,NETFramework.aspx" />
    <category term="Futures" label="Futures" scheme="http://offroadcoder.com/CategoryView,category,Futures.aspx" />
    <category term="Mobile" label="Mobile" scheme="http://offroadcoder.com/CategoryView,category,Mobile.aspx" />
    <category term="WCF" label="WCF" scheme="http://offroadcoder.com/CategoryView,category,WCF.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
Important, proven, and universally-useful technologies like WCF and Mobile are still
not well-known in the development community. Many believe there is another boom, similar
to the 1992 Internet boom, on the horizon that will require skilled and knowledgeable
developers to engineer the framework and associated connecting systems. Staying tech-current
and adapting to our new world is an absolute necessity. Don’t become the COBOL programmer
of the future. Knowing these great system-connecting technologies (WCF, Mobile, Cloud,
etc.) will quickly become a requirement to compete in the software industry.
</p>
        <p>
Check out the following interview with Richard Campbell (DotNetRocks, RunAs Radio)
and Juval Lowy (IDesign) talking about the EnergyNet at the DevConnections conference.
The growing hype about alternative energy and the EnergyNet is stunning. Technology
has progressed far enough where we can start to tie together disparate systems to
benefit producers and consumers alike. 
</p>
        <p>
          <a href="http://video.google.com/videoplay?docid=4831440850220717845" target="_blank">http://video.google.com/videoplay?docid=4831440850220717845</a>
        </p>
        <img width="0" height="0" src="http://offroadcoder.com/aggbug.ashx?id=9f705cfe-f476-48fb-9f4d-a938846d003d" />
      </div>
    </content>
  </entry>
  <entry>
    <title>The flowed transaction could not be unmarshaled.</title>
    <link rel="alternate" type="text/html" href="http://offroadcoder.com/2009/01/29/TheFlowedTransactionCouldNotBeUnmarshaled.aspx" />
    <id>http://offroadcoder.com/PermaLink,guid,08cef9e9-c8f3-49a5-bd38-dcb303bb9c52.aspx</id>
    <published>2009-01-28T18:39:52.1173488-08:00</published>
    <updated>2009-01-29T17:18:21.986-08:00</updated>
    <category term=".NET Framework" label=".NET Framework" scheme="http://offroadcoder.com/CategoryView,category,NETFramework.aspx" />
    <category term="MSDTC" label="MSDTC" scheme="http://offroadcoder.com/CategoryView,category,MSDTC.aspx" />
    <category term="Quotes" label="Quotes" scheme="http://offroadcoder.com/CategoryView,category,Quotes.aspx" />
    <category term="Transactions" label="Transactions" scheme="http://offroadcoder.com/CategoryView,category,Transactions.aspx" />
    <category term="WCF" label="WCF" scheme="http://offroadcoder.com/CategoryView,category,WCF.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <div style="width: 550px">
          <p>
“Do not anticipate trouble, or worry about what may never happen. Keep in the sunlight.” 
</p>
          <p>
  
</p>
          <p align="right">
- Benjamin Franklin
</p>
        </div>
        <p>
  
</p>
        <p>
It’s obvious that Mr. Franklin didn’t have to deal with bad data, bad code, or even
the occasional hiccup. In the real world, there is “trouble” and we need to not only
anticipate that trouble, but also worry about what may never happen. Simply “keeping
in the sunlight” won’t maintain data or application state integrity. In the real world
we need transactions! 
</p>
        <p>
  
</p>
        <p>
Since .NET 2.0, we’ve had the privilege of using <em>System.Transactions.TransactionScope</em> to
manage our transactions with very few headaches. One of the headaches that almost
everyone experiences is MSDTC. One of the oldest and most elusive topics on the web.
There are tons of blog and forum posts directing our fellow developers to check their
firewall settings for every MSDTC problem. The latest MSDTC hiccup I have seen comes
in the beautifully packaged error message: 
</p>
        <blockquote>
          <p>
            <strong>The flowed transaction could not be unmarshaled. The following exception occurred:
Communication with the underlying transaction manager has failed.</strong>
          </p>
        </blockquote>
        <p>
The what could not be what? You can read some <a href="http://msdn.microsoft.com/en-us/library/cc229833(PROT.10).aspx " target="_blank">MSDN
documentation on the topic</a> which will probably cause you more pain. If you are
seeing this error message, there’s only a few things that may be wrong. 
</p>
        <ol>
          <li>
MSDTC Settings 
<ul><li>
Check the MSDTC settings on the machine that is initiating the transaction. If “Allow
Outbound” is not checked, then it won’t allow the transaction in progress to be flowed
to the next machine in the transaction chain. Check the box and restart MSDTC… it
should work.</li></ul></li>
          <li>
Un-Trusted Domains 
<ul><li>
I have seen this error when you are trying to flow transactions between machines that
are in un-trusted domains. Machines in different domains that do not trust each other
block the antiquated, yet necessary, WINS resolution between the two machines. MSDTC
relies on WINS resolution. I have fixed this problem before by adding host file entries
on both machines pointing to the other machine. I can’t guarantee that this will work
in all cases. Both of those machines are no longer under my control.</li></ul></li>
          <li>
Imaged Servers 
<ul><li>
The most recent, and most blogged about problem is surprisingly caused by two machines
created from the same image. Cloning or imaging servers is quite common. Building
a server from scratch is not a fun activity, so we build one, create an image, and
put that image on every server we want to build after that. Once again, MSDTC is standing
in our way because of the way it detects the sending and receiving application’s unique
identifier. Each machine has a GUID in the registry that identifies it uniquely as
a participant in an MSDTC transaction. Imaged machines have the same GUID. I’ll talk
about the detection and resolution of this for the remainder of this post.</li></ul></li>
        </ol>
        <p>
Running DtcPing.exe between the two machines will actually tell you that the machines
are using the same GUID. Output window text from DtcPing shown below.
</p>
        <blockquote>
          <p>
            <font face="Consolas" size="2">DTCping log file: C:\DTC Ping\THRESHER4160.log<br />
Firewall Port Settings:<br />
Port:5150-5250<br />
RPC server is ready<br />
Please Start Partner DTCping before pinging<br /><font color="#ff0000"><strong>WARNING:the CID values for both test machines are the
same</strong><br /></font>Please send following LOG to Microsoft for analysis:<br />
Partner LOG: SCORPION6128.log<br />
My LOG: THRESHER4160.log</font>
          </p>
        </blockquote>
        <p>
Tucked away in the last step of a Microsoft Knowledge Base article titled <a href="http://support.microsoft.com/kb/306843" target="_blank">"How
to troubleshoot MS DTC firewall issues"</a> is a reference to this problem. Use regedit.exe
to look at the registry on both machines. Locate the HKEY_CLASSES_ROOT\CID key in
the registry. 
</p>
        <p>
          <a href="http://scott.klueppel.net/content/binary/Theflowedtransactioncouldnotbeunmarshal_124C3/CID.png">
            <img title="Find your MSDTC CID in the registry" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="371" alt="Find your MSDTC CID in the registry" src="http://scott.klueppel.net/content/binary/Theflowedtransactioncouldnotbeunmarshal_124C3/CID_thumb.png" width="771" border="0" />
          </a>
        </p>
        <p>
Find the CID key that has a description value of “MSDTC”. If they are the same, the
transaction cannot flow. 
</p>
        <p>
          <strong>WARNING:</strong> Back up your registry before making any changes!
</p>
        <p>
          <strong>Solution 1 - Replace the offending CID keys/values on one of the machines: </strong>In
this case, you will need to find all keys/values with GUID 28b81f1c-2afb-4ee2-ad85-5bc62dad1647
in your registry and replace it with a new GUID (using GuidGen). There is likely to
be 3 places this GUID appears. It is also important to note that the offending GUID
appears in the DtcPing log file generated during the ping test.
</p>
        <p>
          <strong>Solution 2 – Use msdtc command line tool to re-install MSDTC: </strong>The
commands are simply:
</p>
        <blockquote>
          <p>
            <font face="consol" size="2">msdtc -uninstall<br />
msdtc -install</font>
          </p>
        </blockquote>
        <p>
After making the registry changes or running the msdtc command line tool, you must
restart your server for the changes to take effect.
</p>
        <img width="0" height="0" src="http://offroadcoder.com/aggbug.ashx?id=08cef9e9-c8f3-49a5-bd38-dcb303bb9c52" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Crazy week at work leads me to find a great quote</title>
    <link rel="alternate" type="text/html" href="http://offroadcoder.com/2009/01/05/CrazyWeekAtWorkLeadsMeToFindAGreatQuote.aspx" />
    <id>http://offroadcoder.com/PermaLink,guid,3c86bd94-587a-40ee-8dad-2a8b90c74a1a.aspx</id>
    <published>2009-01-04T17:59:30.36225-08:00</published>
    <updated>2009-01-04T17:59:30.36225-08:00</updated>
    <category term="Quotes" label="Quotes" scheme="http://offroadcoder.com/CategoryView,category,Quotes.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <div style="width: 500px">
          <p>
"To achieve great things, two things are needed; a plan, and not quite enough time." 
</p>
          <p>
  
</p>
          <p align="right">
- Leonard Bernstein
</p>
        </div>
        <img width="0" height="0" src="http://offroadcoder.com/aggbug.ashx?id=3c86bd94-587a-40ee-8dad-2a8b90c74a1a" />
      </div>
    </content>
  </entry>
  <entry>
    <title>How to get started with Enterprise Library Data Application Block</title>
    <link rel="alternate" type="text/html" href="http://offroadcoder.com/2008/12/07/HowToGetStartedWithEnterpriseLibraryDataApplicationBlock.aspx" />
    <id>http://offroadcoder.com/PermaLink,guid,34796dd3-0878-431f-ba53-35e82627bce7.aspx</id>
    <published>2008-12-06T20:09:10.766375-08:00</published>
    <updated>2008-12-06T20:09:10.766375-08:00</updated>
    <category term="C#" label="C#" scheme="http://offroadcoder.com/CategoryView,category,C.aspx" />
    <category term="Enterprise Library" label="Enterprise Library" scheme="http://offroadcoder.com/CategoryView,category,EnterpriseLibrary.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
It's so easy! Start downloading <a href="http://www.microsoft.com/downloads/details.aspx?familyid=1643758B-2986-47F7-B529-3E41584B6CE5&amp;displaylang=en">Enterprise
Library 4.1</a> now while you read this. The data application block syntax has not
changed much since the first version. The most notable change was allowing us to use
System.Data.Common.DbCommand when version 3.0 was released. I understand the uneasy
feeling some developers have using Enterprise Library. My team at my previous employer
decided not to use it, thinking it would add increased complexity and would not give
us the flexibility we needed if we had to change something. This is typical of groups
that do not have an established Data Access Library. 
</p>
        <p>
Your Data Access Library should be one of the most highly tested libraries in your
application. If there is a problem there, you will have issues everywhere. Enterprise
Library not only comes with the source code, but also includes the full suite of unit
tests for each of the application blocks. You should feel at ease when you decide
to migrate to Enterprise Library. Run it through your full battery of tests before
you commit the team to it. If you find any problems, check the forums, request changes/enhancements
from the MS Patterns &amp; Practices team, or fix it yourself.
</p>
        <p>
The steps to achieve EntLib goodness:
</p>
        <ol>
          <li>
Download Enterprise Library 
</li>
          <li>
Add reference to "Enterprise Library Data Access Application Block" and "Enterprise
Library Shared Library" 
</li>
          <li>
Change your app.config or web.config 
</li>
          <li>
Write some much more readable data access code</li>
        </ol>
        <p>
I'll start at step 3 as steps 1 and 2 are self-explanatory. Your connection string
needs to be in you app's config file, the machine.config file, or in a connectionStrings.config
file referenced in those config files. You can start using it just by adding the &lt;configSections&gt;
clock and the &lt;dataConfiguration&gt; node. This will allow you to have one default
database for all commands you will execute.
</p>
        <p>
          <!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red239\green239\blue143;\red63\green63\blue63;\red227\green198\blue106;\red255\green255\blue255;\red204\green147\blue147;}??\fs18 \cf1\cb2\highlight2 &lt;?\cf3 xml\cf1  \cf4 version\cf1 ="\cf5 1.0\cf1 " \cf4 encoding\cf1 ="\cf5 utf-8\cf1 "?&gt;\par ??&lt;\cf3 configuration\cf1 &gt;\par ??    &lt;\cf3 configSections\cf1 &gt;\par ??        &lt;\cf3 section\cf1  \cf4 name\cf1 ="\cf5 dataConfiguration\cf1 " \cf4 type\cf1 ="\cf5 Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35\cf1 " /&gt;\par ??    &lt;/\cf3 configSections\cf1 &gt;\par ??    &lt;\cf3 dataConfiguration\cf1  \cf4 defaultDatabase\cf1 ="\cf5 Testing\cf1 " /&gt;\par ??    &lt;\cf3 connectionStrings\cf1 &gt;\par ??        &lt;\cf3 add\cf1  \cf4 name\cf1 ="\cf5 Testing\cf1 " \cf4 connectionString\cf1 ="\cf5 server=scorpion;database=ApplicationLog;Integrated Security=true;\cf1 "\par ??                  \cf4 providerName\cf1 ="\cf5 System.Data.SqlClient\cf1 " /&gt;\par ??        &lt;\cf3 add\cf1  \cf4 name\cf1 ="\cf5 Testing1\cf1 " \cf4 connectionString\cf1 ="\cf5 server=scorpion;database=ApplicationLog;Integrated Security=true;\cf1 "\par ??                  \cf4 providerName\cf1 ="\cf5 System.Data.SqlClient\cf1 " /&gt;\par ??    &lt;/\cf3 connectionStrings\cf1 &gt;\par ??&lt;/\cf3 configuration\cf1 &gt;}
-->
        </p>
        <p>
        </p>
        <p>
          <!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red239\green239\blue143;\red63\green63\blue63;\red227\green198\blue106;\red255\green255\blue255;\red204\green147\blue147;}??\fs18 \cf1\cb2\highlight2 &lt;?\cf3 xml\cf1  \cf4 version\cf1 ="\cf5 1.0\cf1 " \cf4 encoding\cf1 ="\cf5 utf-8\cf1 "?&gt;\par ??&lt;\cf3 configuration\cf1 &gt;\par ??    &lt;\cf3 configSections\cf1 &gt;\par ??        &lt;\cf3 section\cf1  \cf4 name\cf1 ="\cf5 dataConfiguration\cf1 " \cf4 type\cf1 ="\cf5 Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35\cf1 " /&gt;\par ??    &lt;/\cf3 configSections\cf1 &gt;\par ??    &lt;\cf3 dataConfiguration\cf1  \cf4 defaultDatabase\cf1 ="\cf5 Testing\cf1 " /&gt;\par ??    &lt;\cf3 connectionStrings\cf1 &gt;\par ??        &lt;\cf3 add\cf1  \cf4 name\cf1 ="\cf5 Testing\cf1 " \cf4 connectionString\cf1 ="\cf5 server=scorpion;database=ApplicationLog;Integrated Security=true;\cf1 "\par ??                  \cf4 providerName\cf1 ="\cf5 System.Data.SqlClient\cf1 " /&gt;\par ??        &lt;\cf3 add\cf1  \cf4 name\cf1 ="\cf5 Testing1\cf1 " \cf4 connectionString\cf1 ="\cf5 server=scorpion;database=ApplicationLog;Integrated Security=true;\cf1 "\par ??                  \cf4 providerName\cf1 ="\cf5 System.Data.SqlClient\cf1 " /&gt;\par ??    &lt;/\cf3 connectionStrings\cf1 &gt;\par ??&lt;/\cf3 configuration\cf1 &gt;}
-->
        </p>
        <div style="overflow-y: auto; font-size: 9pt; background: #3f3f3f; width: 865px; color: #dcdccc; font-family: consolas; height: 177px">
          <p style="margin: 0px">
            <span style="color: #efef8f">&lt;?</span>
            <span style="color: #e3c66a">xml</span>
            <span style="color: #efef8f">
            </span>
            <span style="color: white">version</span>
            <span style="color: #efef8f">="</span>
            <span style="color: #cc9393">1.0</span>
            <span style="color: #efef8f">" </span>
            <span style="color: white">encoding</span>
            <span style="color: #efef8f">="</span>
            <span style="color: #cc9393">utf-8</span>
            <span style="color: #efef8f">"?&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: #efef8f">&lt;</span>
            <span style="color: #e3c66a">configuration</span>
            <span style="color: #efef8f">&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: #efef8f">    &lt;</span>
            <span style="color: #e3c66a">configSections</span>
            <span style="color: #efef8f">&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: #efef8f">        &lt;</span>
            <span style="color: #e3c66a">section</span>
            <span style="color: #efef8f">
            </span>
            <span style="color: white">name</span>
            <span style="color: #efef8f">="</span>
            <span style="color: #cc9393">dataConfiguration</span>
            <span style="color: #efef8f">" </span>
            <span style="color: white">type</span>
            <span style="color: #efef8f">="</span>
            <span style="color: #cc9393">Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings,
Microsoft.Practices.EnterpriseLibrary.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35</span>
            <span style="color: #efef8f">"
/&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: #efef8f">    &lt;/</span>
            <span style="color: #e3c66a">configSections</span>
            <span style="color: #efef8f">&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: #efef8f">    &lt;</span>
            <span style="color: #e3c66a">dataConfiguration</span>
            <span style="color: #efef8f">
            </span>
            <span style="color: white">defaultDatabase</span>
            <span style="color: #efef8f">="</span>
            <span style="color: #cc9393">Testing</span>
            <span style="color: #efef8f">"
/&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: #efef8f">    &lt;</span>
            <span style="color: #e3c66a">connectionStrings</span>
            <span style="color: #efef8f">&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: #efef8f">        &lt;</span>
            <span style="color: #e3c66a">add</span>
            <span style="color: #efef8f">
            </span>
            <span style="color: white">name</span>
            <span style="color: #efef8f">="</span>
            <span style="color: #cc9393">Testing</span>
            <span style="color: #efef8f">" </span>
            <span style="color: white">connectionString</span>
            <span style="color: #efef8f">="</span>
            <span style="color: #cc9393">server=Server_Name;database=DB_Name;Integrated
Security=true;</span>
            <span style="color: #efef8f">"</span>
          </p>
          <p style="margin: 0px">
            <span style="color: #efef8f">                  </span>
            <span style="color: white">providerName</span>
            <span style="color: #efef8f">="</span>
            <span style="color: #cc9393">System.Data.SqlClient</span>
            <span style="color: #efef8f">"
/&gt;</span>
          </p>
          <p style="margin: 0px">
          </p>
          <p style="margin: 0px">
            <span style="color: #efef8f">
            </span>
          </p>
          <p>
            <span style="color: #efef8f">    &lt;/</span>
            <span style="color: #e3c66a">connectionStrings</span>
            <span style="color: #efef8f">&gt;</span>
            <br />
            <span style="color: #efef8f">&lt;/</span>
            <span style="color: #e3c66a">configuration</span>
            <span style="color: #efef8f">&gt;</span>
          </p>
        </div>
        <p>
 
</p>
        <p>
By the time you get to step 4, you have all of the infrastructure in place. Painless
so far, let's see how steep the learning curve is.
</p>
        <p>
With ADO.NET, you would write:
</p>
        <p>
          <!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red225\green225\blue138;\red63\green63\blue63;\red220\green220\blue204;\red223\green223\blue191;\red43\green145\blue175;\red200\green145\blue145;\red138\green204\blue207;}??\fs18 \cf1\cb2\highlight2 {\b string}\cf3  \cf4 connectionString\cf3  = \cf5 ConfigurationManager\cf3 .\cf4 ConnectionStrings\cf3 [\cf6 "Testing"\cf3 ].\cf4 ConnectionString\cf3 ;\par ??\cf1 {\b using}\cf3  (\cf5 SqlConnection\cf3  \cf4 con\cf3  = \cf1 {\b new}\cf3  \cf5 SqlConnection\cf3 (\cf4 connectionString\cf3 ))\par ??\cf1 {\b using}\cf3  (\cf5 SqlCommand\cf3  \cf4 cmd\cf3  = \cf1 {\b new}\cf3  \cf5 SqlCommand\cf3 (\cf6 "usp_ErrorLog_Insert"\cf3 , \cf4 con\cf3 ))\par ??\{\par ??    \cf4 cmd\cf3 .\cf4 CommandType\cf3  = \cf4 System\cf3 .\cf4 Data\cf3 .\cf5 CommandType\cf3 .\cf4 StoredProcedure\cf3 ;\par ??    \cf4 cmd\cf3 .\cf4 Parameters\cf3 .\cf4 AddWithValue\cf3 (\cf6 "Message"\cf3 , \cf6 "Testing 1"\cf3 );\par ??    \cf4 cmd\cf3 .\cf4 Parameters\cf3 .\cf4 AddWithValue\cf3 (\cf6 "UserID"\cf3 , \cf7 5150\cf3 );\par ??    \cf1 {\b try}\par ??\cf3     \{\par ??        \cf4 con\cf3 .\cf4 Open\cf3 ();\par ??        \cf4 cmd\cf3 .\cf4 ExecuteNonQuery\cf3 ();\par ??    \}\par ??    \cf1 {\b finally}\par ??\cf3     \{\par ??        \cf4 con\cf3 .\cf4 Close\cf3 ();\par ??    \}\par ??\}}
-->
        </p>
        <div style="overflow-y: auto; font-size: 9pt; background: #3f3f3f; width: 700px; color: #dcdccc; font-family: consolas; height: 248px">
          <p style="margin: 0px">
            <span style="color: #85ac8d">  116</span> <span style="font-weight: bold; color: #e1e18a">string</span><span style="color: #dfdfbf">connectionString</span> = <span style="color: #2b91af">ConfigurationManager</span>.<span style="color: #dfdfbf">ConnectionStrings</span>[<span style="color: #c89191">"Testing"</span>].<span style="color: #dfdfbf">ConnectionString</span>;
</p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">  117</span> <span style="font-weight: bold; color: #e1e18a">using</span> (<span style="color: #2b91af">SqlConnection</span><span style="color: #dfdfbf">con</span> = <span style="font-weight: bold; color: #e1e18a">new</span><span style="color: #2b91af">SqlConnection</span>(<span style="color: #dfdfbf">connectionString</span>))
</p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">  118</span> <span style="font-weight: bold; color: #e1e18a">using</span> (<span style="color: #2b91af">SqlCommand</span><span style="color: #dfdfbf">cmd</span> = <span style="font-weight: bold; color: #e1e18a">new</span><span style="color: #2b91af">SqlCommand</span>(<span style="color: #c89191">"usp_ErrorLog_Insert"</span>, <span style="color: #dfdfbf">con</span>))
</p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">  119</span> {
</p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">  120</span>     <span style="color: #dfdfbf">cmd</span>.<span style="color: #dfdfbf">CommandType</span> = <span style="color: #dfdfbf">System</span>.<span style="color: #dfdfbf">Data</span>.<span style="color: #2b91af">CommandType</span>.<span style="color: #dfdfbf">StoredProcedure</span>;
</p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">  121</span>     <span style="color: #dfdfbf">cmd</span>.<span style="color: #dfdfbf">Parameters</span>.<span style="color: #dfdfbf">AddWithValue</span>(<span style="color: #c89191">"Message"</span>, <span style="color: #c89191">"Testing
1"</span>);
</p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">  122</span>     <span style="color: #dfdfbf">cmd</span>.<span style="color: #dfdfbf">Parameters</span>.<span style="color: #dfdfbf">AddWithValue</span>(<span style="color: #c89191">"UserID"</span>, <span style="color: #8acccf">5150</span>);
</p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">  123</span>     <span style="font-weight: bold; color: #e1e18a">try</span></p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">  124</span>     {
</p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">  125</span>         <span style="color: #dfdfbf">con</span>.<span style="color: #dfdfbf">Open</span>();
</p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">  126</span>         <span style="color: #dfdfbf">cmd</span>.<span style="color: #dfdfbf">ExecuteNonQuery</span>();
</p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">  127</span>     }
</p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">  128</span>     <span style="font-weight: bold; color: #e1e18a">finally</span></p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">  129</span>     {
</p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">  130</span>         <span style="color: #dfdfbf">con</span>.<span style="color: #dfdfbf">Close</span>();
</p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">  131</span>     }
</p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">  132</span> }
</p>
        </div>
        <p>
        </p>
        <p>
With Enterprise Library, you write:
</p>
        <p>
          <!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red43\green145\blue175;\red63\green63\blue63;\red220\green220\blue204;\red223\green223\blue191;\red200\green145\blue145;\red138\green204\blue207;}??\fs18 \cf1\cb2\highlight2 Database\cf3  \cf4 db\cf3  = \cf1 DatabaseFactory\cf3 .\cf4 CreateDatabase\cf3 (\cf5 "Testing"\cf3 );\par ??\cf1 DbCommand\cf3  \cf4 cmd\cf3  = \cf4 db\cf3 .\cf4 GetStoredProcCommand\cf3 (\cf5 "usp_ErrorLog_Insert"\cf3 );\par ??\cf4 db\cf3 .\cf4 AddInParameter\cf3 (\cf4 cmd\cf3 , \cf5 "Message"\cf3 , \cf4 System\cf3 .\cf4 Data\cf3 .\cf1 DbType\cf3 .\cf4 String\cf3 , \cf5 "Testing 1"\cf3 );\par ??\cf4 db\cf3 .\cf4 AddInParameter\cf3 (\cf4 cmd\cf3 , \cf5 "UserID"\cf3 , \cf4 System\cf3 .\cf4 Data\cf3 .\cf1 DbType\cf3 .\cf4 Int32\cf3 , \cf6 5150\cf3 );\par ??\cf4 db\cf3 .\cf4 ExecuteNonQuery\cf3 (\cf4 cmd\cf3 );}
-->
        </p>
        <div style="overflow-y: auto; font-size: 9pt; background: #3f3f3f; width: 699px; color: #dcdccc; font-family: consolas; height: 82px">
          <p style="margin: 0px">
            <span style="color: #85ac8d">  170</span> <span style="color: #2b91af">Database</span><span style="color: #dfdfbf">db</span> = <span style="color: #2b91af">DatabaseFactory</span>.<span style="color: #dfdfbf">CreateDatabase</span>();
</p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">  171</span> <span style="color: #2b91af">DbCommand</span><span style="color: #dfdfbf">cmd</span> = <span style="color: #dfdfbf">db</span>.<span style="color: #dfdfbf">GetStoredProcCommand</span>(<span style="color: #c89191">"usp_ErrorLog_Insert"</span>);
</p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">  172</span> <span style="color: #dfdfbf">db</span>.<span style="color: #dfdfbf">AddInParameter</span>(<span style="color: #dfdfbf">cmd</span>, <span style="color: #c89191">"Message"</span>, <span style="color: #dfdfbf">System</span>.<span style="color: #dfdfbf">Data</span>.<span style="color: #2b91af">DbType</span>.<span style="color: #dfdfbf">String</span>, <span style="color: #c89191">"Testing
1"</span>);
</p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">  173</span> <span style="color: #dfdfbf">db</span>.<span style="color: #dfdfbf">AddInParameter</span>(<span style="color: #dfdfbf">cmd</span>, <span style="color: #c89191">"UserID"</span>, <span style="color: #dfdfbf">System</span>.<span style="color: #dfdfbf">Data</span>.<span style="color: #2b91af">DbType</span>.<span style="color: #dfdfbf">Int32</span>, <span style="color: #8acccf">5150</span>);
</p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">  174</span> <span style="color: #dfdfbf">db</span>.<span style="color: #dfdfbf">ExecuteNonQuery</span>(<span style="color: #dfdfbf">cmd</span>);
</p>
        </div>
        <p>
 
</p>
        <p>
Line 170 creates the database object. This is the hardest thing to get used to. You
call everything related to the Database object. In ADO.NET, we are used to creating
a connection, adding the connection to a command, using the command in an adapter.
Here you'll always be using the Database object to create a command, add parameters
to the command, execute the command, fill a DataSet, etc. It is definitely less code
to write, but it is also more readable and elegant.
</p>
        <p>
If you have a database to execute commands against other than the defaultDatabase
specified in the config file, then the first line changes to:
</p>
        <p>
          <!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red43\green145\blue175;\red63\green63\blue63;\red220\green220\blue204;\red223\green223\blue191;\red200\green145\blue145;}??\fs18 \cf1\cb2\highlight2 Database\cf3  \cf4 db\cf3  = \cf1 DatabaseFactory\cf3 .\cf4 CreateDatabase\cf3 (\cf5 "Testing"\cf3 );}
-->
        </p>
        <div style="overflow-y: auto; font-size: 9pt; background: #3f3f3f; width: 698px; color: #dcdccc; font-family: consolas; height: 24px">
          <p style="margin: 0px">
            <span style="color: #85ac8d">  170</span> <span style="color: #2b91af">Database</span><span style="color: #dfdfbf">db</span> = <span style="color: #2b91af">DatabaseFactory</span>.<span style="color: #dfdfbf">CreateDatabase</span>(<span style="color: #c89191">"OtherConnectionStringKey"</span>);
</p>
        </div>
        <p>
 
</p>
        <p>
That's it. The patterns &amp; practices team has really done a nice job making it
painless to use Enterprise Library. Take the time to try it out again if you reviewed
a previous version. I reviewed 2.0, and chose not to use it. When 3.0 came out, I
was hooked.
</p>
        <img width="0" height="0" src="http://offroadcoder.com/aggbug.ashx?id=34796dd3-0878-431f-ba53-35e82627bce7" />
      </div>
    </content>
  </entry>
  <entry>
    <title>What happens to your transaction with different data access methods</title>
    <link rel="alternate" type="text/html" href="http://offroadcoder.com/2008/12/05/WhatHappensToYourTransactionWithDifferentDataAccessMethods.aspx" />
    <id>http://offroadcoder.com/PermaLink,guid,5aef3f0a-3e66-4e87-8469-0411651d2aba.aspx</id>
    <published>2008-12-04T18:50:25.703-08:00</published>
    <updated>2008-12-06T20:10:03.56325-08:00</updated>
    <category term="C#" label="C#" scheme="http://offroadcoder.com/CategoryView,category,C.aspx" />
    <category term="MSDTC" label="MSDTC" scheme="http://offroadcoder.com/CategoryView,category,MSDTC.aspx" />
    <category term="SQL" label="SQL" scheme="http://offroadcoder.com/CategoryView,category,SQL.aspx" />
    <category term="Transactions" label="Transactions" scheme="http://offroadcoder.com/CategoryView,category,Transactions.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
Unless you are working on a extremely simple or read-only application, transactions
are a must. Using the System.Transactions namespace is the easiest and most efficient
way to maintain system consistency when dealing with multiple calls or multiple resources.
Although System.Transactions arrived in .NET in the 2005 product, it is still a relatively
unknown part of the framework. System.Transactions was designed by the Indigo team
in preparation for WCF. It is not compatible with Win98 or WinME, but most people
are incompatible with Win98 and WinME so it works out just fine.
</p>
        <p>
Before System.Transactions, we only had access to System.Data.SqlClient.SqlTransaction
or a true SQL transaction using BEGIN/ROLLBACK/COMMIT TRAN. Using SQL transactions,
you are stuck with only being able to update DB records as part of your transaction.
If you wanted to change a cached value in your app in addition to the SQL updates
in the same transaction then you would be out of luck. This also required a lot of
transaction code in your stored procedures, writing stored procedures that can be
called independently or part of transaction made for very messy stored procedures
and often led to multiple stored procedures that served the same purpose.
</p>
        <p>
Using the SqlTransaction class was also messy. The most important restriction is that
you need to have all database calls inside the same SqlConnection. This does not work
well for a well-designed N-tier application. The other problem is that you need to
handle your own non-DB transaction logic inside the same SqlTransaction and conditionally
commit/rollback as necessary. This all tends to lead to several try-catch statements
within one SqlTransaction. Handling the plumbing to manually add each SqlCommand to
the transaction gets old quickly too.
</p>
        <p>
          <strong>Using SqlTransaction</strong>
        </p>
        <p>
          <!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red225\green225\blue138;\red63\green63\blue63;\red220\green220\blue204;\red223\green223\blue191;\red43\green145\blue175;\red200\green145\blue145;\red138\green204\blue207;}??\fs18 \cf1\cb2\highlight2 {\b string}\cf3  \cf4 connectionString\cf3  = \cf5 ConfigurationManager\cf3 .\cf4 ConnectionStrings\cf3 [\cf6 "Testing"\cf3 ].\cf4 ConnectionString\cf3 ;\par ??\cf1 {\b using}\cf3  (\cf5 SqlConnection\cf3  \cf4 con\cf3  = \cf1 {\b new}\cf3  \cf5 SqlConnection\cf3 (\cf4 connectionString\cf3 ))\par ??\{\par ??    \cf5 SqlTransaction\cf3  \cf4 tran\cf3  = \cf1 {\b null}\cf3 ;\par ??    \cf1 {\b try}\par ??\cf3     \{\par ??        \cf4 con\cf3 .\cf4 Open\cf3 ();\par ??        \cf4 tran\cf3  = \cf4 con\cf3 .\cf4 BeginTransaction\cf3 ();\par ??        \cf1 {\b using}\cf3  (\cf5 SqlCommand\cf3  \cf4 cmd\cf3  = \cf1 {\b new}\cf3  \cf5 SqlCommand\cf3 (\cf6 "usp_ErrorLog_Insert"\cf3 , \cf4 con\cf3 ))\par ??        \{\par ??            \cf4 cmd\cf3 .\cf4 Transaction\cf3  = \cf4 tran\cf3 ;\par ??            \cf4 cmd\cf3 .\cf4 CommandType\cf3  = \cf4 System\cf3 .\cf4 Data\cf3 .\cf5 CommandType\cf3 .\cf4 StoredProcedure\cf3 ;\par ??            \cf4 cmd\cf3 .\cf4 Parameters\cf3 .\cf4 AddWithValue\cf3 (\cf6 "Message"\cf3 , \cf6 "Testing 1"\cf3 );\par ??            \cf4 cmd\cf3 .\cf4 Parameters\cf3 .\cf4 AddWithValue\cf3 (\cf6 "UserID"\cf3 , \cf7 5150\cf3 );\par ??            \cf4 cmd\cf3 .\cf4 ExecuteNonQuery\cf3 ();\par ??        \}\par ??\par ??        \cf1 {\b using}\cf3  (\cf5 SqlCommand\cf3  \cf4 cmd\cf3  = \cf1 {\b new}\cf3  \cf5 SqlCommand\cf3 (\cf6 "usp_ErrorLog_Insert"\cf3 , \cf4 con\cf3 ))\par ??        \{\par ??            \cf4 cmd\cf3 .\cf4 Transaction\cf3  = \cf4 tran\cf3 ;\par ??            \cf4 cmd\cf3 .\cf4 CommandType\cf3  = \cf4 System\cf3 .\cf4 Data\cf3 .\cf5 CommandType\cf3 .\cf4 StoredProcedure\cf3 ;\par ??            \cf4 cmd\cf3 .\cf4 Parameters\cf3 .\cf4 AddWithValue\cf3 (\cf6 "Message"\cf3 , \cf6 "Testing 2"\cf3 );\par ??            \cf4 cmd\cf3 .\cf4 Parameters\cf3 .\cf4 AddWithValue\cf3 (\cf6 "UserID"\cf3 , \cf7 5150\cf3 );\par ??            \cf4 cmd\cf3 .\cf4 ExecuteNonQuery\cf3 ();\par ??        \}\par ??\par ??        \cf4 tran\cf3 .\cf4 Commit\cf3 ();\par ??    \}\par ??    \cf1 {\b catch}\par ??\cf3     \{\par ??        \cf1 {\b if}\cf3  (\cf4 tran\cf3  != \cf1 {\b null}\cf3 ) \cf4 tran\cf3 .\cf4 Rollback\cf3 ();\par ??    \}\par ??    \cf1 {\b finally}\par ??\cf3     \{\par ??        \cf4 con\cf3 .\cf4 Close\cf3 ();\par ??    \}\par ??\}\par ??}
-->
        </p>
        <div style="OVERFLOW-Y: auto; FONT-SIZE: 9pt; BACKGROUND: #3f3f3f; WIDTH: 761px; COLOR: #dcdccc; FONT-FAMILY: consolas; HEIGHT: 250px">
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   27</span> <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">string</span><span style="COLOR: #dfdfbf">connectionString</span> = <span style="COLOR: #2b91af">ConfigurationManager</span>.<span style="COLOR: #dfdfbf">ConnectionStrings</span>[<span style="COLOR: #c89191">"Testing"</span>].<span style="COLOR: #dfdfbf">ConnectionString</span>;
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   28</span> <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">using</span> (<span style="COLOR: #2b91af">SqlConnection</span><span style="COLOR: #dfdfbf">con</span> = <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">new</span><span style="COLOR: #2b91af">SqlConnection</span>(<span style="COLOR: #dfdfbf">connectionString</span>))
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   29</span> {
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   30</span>     <span style="COLOR: #2b91af">SqlTransaction</span><span style="COLOR: #dfdfbf">tran</span> = <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">null</span>;
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   31</span>     <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">try</span></p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   32</span>     {
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   33</span>         <span style="COLOR: #dfdfbf">con</span>.<span style="COLOR: #dfdfbf">Open</span>();
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   34</span>         <span style="COLOR: #dfdfbf">tran</span> = <span style="COLOR: #dfdfbf">con</span>.<span style="COLOR: #dfdfbf">BeginTransaction</span>();
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   35</span>         <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">using</span> (<span style="COLOR: #2b91af">SqlCommand</span><span style="COLOR: #dfdfbf">cmd</span> = <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">new</span><span style="COLOR: #2b91af">SqlCommand</span>(<span style="COLOR: #c89191">"usp_ErrorLog_Insert"</span>, <span style="COLOR: #dfdfbf">con</span>))
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   36</span>        
{
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   37</span>             <span style="COLOR: #dfdfbf">cmd</span>.<span style="COLOR: #dfdfbf">Transaction</span> = <span style="COLOR: #dfdfbf">tran</span>;
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   38</span>             <span style="COLOR: #dfdfbf">cmd</span>.<span style="COLOR: #dfdfbf">CommandType</span> = <span style="COLOR: #dfdfbf">System</span>.<span style="COLOR: #dfdfbf">Data</span>.<span style="COLOR: #2b91af">CommandType</span>.<span style="COLOR: #dfdfbf">StoredProcedure</span>;
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   39</span>             <span style="COLOR: #dfdfbf">cmd</span>.<span style="COLOR: #dfdfbf">Parameters</span>.<span style="COLOR: #dfdfbf">AddWithValue</span>(<span style="COLOR: #c89191">"Message"</span>, <span style="COLOR: #c89191">"Testing
1"</span>);
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   40</span>             <span style="COLOR: #dfdfbf">cmd</span>.<span style="COLOR: #dfdfbf">Parameters</span>.<span style="COLOR: #dfdfbf">AddWithValue</span>(<span style="COLOR: #c89191">"UserID"</span>, <span style="COLOR: #8acccf">5150</span>);
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   41</span>             <span style="COLOR: #dfdfbf">cmd</span>.<span style="COLOR: #dfdfbf">ExecuteNonQuery</span>();
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   42</span>        
}
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   43</span> 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   44</span>         <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">using</span> (<span style="COLOR: #2b91af">SqlCommand</span><span style="COLOR: #dfdfbf">cmd</span> = <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">new</span><span style="COLOR: #2b91af">SqlCommand</span>(<span style="COLOR: #c89191">"usp_ErrorLog_Insert"</span>, <span style="COLOR: #dfdfbf">con</span>))
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   45</span>        
{
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   46</span>             <span style="COLOR: #dfdfbf">cmd</span>.<span style="COLOR: #dfdfbf">Transaction</span> = <span style="COLOR: #dfdfbf">tran</span>;
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   47</span>             <span style="COLOR: #dfdfbf">cmd</span>.<span style="COLOR: #dfdfbf">CommandType</span> = <span style="COLOR: #dfdfbf">System</span>.<span style="COLOR: #dfdfbf">Data</span>.<span style="COLOR: #2b91af">CommandType</span>.<span style="COLOR: #dfdfbf">StoredProcedure</span>;
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   48</span>             <span style="COLOR: #dfdfbf">cmd</span>.<span style="COLOR: #dfdfbf">Parameters</span>.<span style="COLOR: #dfdfbf">AddWithValue</span>(<span style="COLOR: #c89191">"Message"</span>, <span style="COLOR: #c89191">"Testing
2"</span>);
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   49</span>             <span style="COLOR: #dfdfbf">cmd</span>.<span style="COLOR: #dfdfbf">Parameters</span>.<span style="COLOR: #dfdfbf">AddWithValue</span>(<span style="COLOR: #c89191">"UserID"</span>, <span style="COLOR: #8acccf">5150</span>);
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   50</span>             <span style="COLOR: #dfdfbf">cmd</span>.<span style="COLOR: #dfdfbf">ExecuteNonQuery</span>();
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   51</span>        
}
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   52</span> 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   53</span>         <span style="COLOR: #dfdfbf">tran</span>.<span style="COLOR: #dfdfbf">Commit</span>();
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   54</span>     }
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   55</span>     <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">catch</span></p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   56</span>     {
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   57</span>         <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">if</span> (<span style="COLOR: #dfdfbf">tran</span> != <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">null</span>) <span style="COLOR: #dfdfbf">tran</span>.<span style="COLOR: #dfdfbf">Rollback</span>();
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   58</span>     }
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   59</span>     <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">finally</span></p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   60</span>     {
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   61</span>         <span style="COLOR: #dfdfbf">con</span>.<span style="COLOR: #dfdfbf">Close</span>();
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   62</span>     }
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   63</span> }
</p>
        </div>
        <p>
 
</p>
        <p>
System.Transactions liberated us from the mundane SqlClient code and repetitive try-catches.
simply wrapping your old ADO.NET with a using (TransactionScope) { } is all you need
to do. You will typically add a transactionScope.Complete() statement as the last
line in the TransactionScope using block is really all you need. Any exception thrown
before this point will break out of scope, implicitly aborting the transation. Much
better.
</p>
        <p>
System.Transactions uses the LTM (Lightweight Transaction Manager) when dealing with
single resources or machines. The transaction is automatically promoted to MSDTC (Microsoft
Distributed Transaction Coordinator) when another resource is enlisted in a transaction.
A lot of people struggle with MSDTC because it is difficult to setup, requires special
firewall considerations, and doesn't really work well for smart client applications
since you have to install MSDTC on every client machine.
</p>
        <p>
I'll show one transaction performed three different ways and show what happens with
the LTM and MSDTC for each of them. I will also demonstrate an excellent reason to
migrate to Enterprise Library.
</p>
        <p>
          <strong>1) Executing two ADO.NET SqlCommands in different SqlConnections</strong>
        </p>
        <p>
          <!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red225\green225\blue138;\red63\green63\blue63;\red220\green220\blue204;\red43\green145\blue175;\red223\green223\blue191;\red200\green145\blue145;\red138\green204\blue207;}??\fs18 \cf1\cb2\highlight2 {\b using}\cf3  (\cf4 TransactionScope\cf3  \cf5 scope\cf3  = \cf1 {\b new}\cf3  \cf4 TransactionScope\cf3 ())\par ??\{\par ??    \cf1 {\b string}\cf3  \cf5 connectionString\cf3  = \cf4 ConfigurationManager\cf3 .\cf5 ConnectionStrings\cf3 [\cf6 "Testing"\cf3 ].\cf5 ConnectionString\cf3 ;\par ??    \cf1 {\b using}\cf3  (\cf4 SqlConnection\cf3  \cf5 con\cf3  = \cf1 {\b new}\cf3  \cf4 SqlConnection\cf3 (\cf5 connectionString\cf3 ))\par ??    \cf1 {\b using}\cf3  (\cf4 SqlCommand\cf3  \cf5 cmd\cf3  = \cf1 {\b new}\cf3  \cf4 SqlCommand\cf3 (\cf6 "usp_ErrorLog_Insert"\cf3 , \cf5 con\cf3 ))\par ??    \{\par ??        \cf5 cmd\cf3 .\cf5 CommandType\cf3  = \cf5 System\cf3 .\cf5 Data\cf3 .\cf4 CommandType\cf3 .\cf5 StoredProcedure\cf3 ;\par ??        \cf5 cmd\cf3 .\cf5 Parameters\cf3 .\cf5 AddWithValue\cf3 (\cf6 "Message"\cf3 , \cf6 "Testing 1"\cf3 );\par ??        \cf5 cmd\cf3 .\cf5 Parameters\cf3 .\cf5 AddWithValue\cf3 (\cf6 "UserID"\cf3 , \cf7 5150\cf3 );\par ??        \cf1 {\b try}\par ??\cf3         \{\par ??            \cf5 con\cf3 .\cf5 Open\cf3 ();\par ??            \cf5 cmd\cf3 .\cf5 ExecuteNonQuery\cf3 ();\par ??        \}\par ??        \cf1 {\b finally}\par ??\cf3         \{\par ??            \cf5 con\cf3 .\cf5 Close\cf3 ();\par ??        \}\par ??    \}\par ??\par ??    \cf4 Console\cf3 .\cf5 WriteLine\cf3 (\cf6 "Local Transaction ID: \{0\}"\cf3 , \par ??        \cf4 Transaction\cf3 .\cf5 Current\cf3 .\cf5 TransactionInformation\cf3 .\cf5 LocalIdentifier\cf3 );\par ??    \cf4 Console\cf3 .\cf5 WriteLine\cf3 (\cf6 "Distributed Transaction ID: \{0\}"\cf3 , \par ??        \cf4 Transaction\cf3 .\cf5 Current\cf3 .\cf5 TransactionInformation\cf3 .\cf5 DistributedIdentifier\cf3 .\cf5 ToString\cf3 ());\par ??\par ??    \cf1 {\b using}\cf3  (\cf4 SqlConnection\cf3  \cf5 con\cf3  = \cf1 {\b new}\cf3  \cf4 SqlConnection\cf3 (\cf4 ConfigurationManager\cf3 .\cf5 ConnectionStrings\cf3 [\cf6 "Testing"\cf3 ].\cf5 ConnectionString\cf3 ))\par ??    \cf1 {\b using}\cf3  (\cf4 SqlCommand\cf3  \cf5 cmd\cf3  = \cf1 {\b new}\cf3  \cf4 SqlCommand\cf3 (\cf6 "usp_ErrorLog_Insert"\cf3 , \cf5 con\cf3 ))\par ??    \{\par ??        \cf5 cmd\cf3 .\cf5 CommandType\cf3  = \cf5 System\cf3 .\cf5 Data\cf3 .\cf4 CommandType\cf3 .\cf5 StoredProcedure\cf3 ;\par ??        \cf5 cmd\cf3 .\cf5 Parameters\cf3 .\cf5 AddWithValue\cf3 (\cf6 "Message"\cf3 , \cf6 "Testing 2"\cf3 );\par ??        \cf5 cmd\cf3 .\cf5 Parameters\cf3 .\cf5 AddWithValue\cf3 (\cf6 "UserID"\cf3 , \cf7 5150\cf3 );\par ??        \cf1 {\b try}\par ??\cf3         \{\par ??            \cf5 con\cf3 .\cf5 Open\cf3 ();\par ??            \cf5 cmd\cf3 .\cf5 ExecuteNonQuery\cf3 ();\par ??        \}\par ??        \cf1 {\b finally}\par ??\cf3         \{\par ??            \cf5 con\cf3 .\cf5 Close\cf3 ();\par ??        \}\par ??    \}\par ??\par ??    \cf4 Console\cf3 .\cf5 WriteLine\cf3 (\cf6 "Local Transaction ID: \{0\}"\cf3 , \par ??        \cf4 Transaction\cf3 .\cf5 Current\cf3 .\cf5 TransactionInformation\cf3 .\cf5 LocalIdentifier\cf3 );\par ??    \cf4 Console\cf3 .\cf5 WriteLine\cf3 (\cf6 "Distributed Transaction ID: \{0\}"\cf3 , \par ??        \cf4 Transaction\cf3 .\cf5 Current\cf3 .\cf5 TransactionInformation\cf3 .\cf5 DistributedIdentifier\cf3 .\cf5 ToString\cf3 ());\par ??\par ??    \cf5 scope\cf3 .\cf5 Complete\cf3 ();\par ??\}}
-->
        </p>
        <p>
        </p>
        <p>
        </p>
        <p>
          <!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red225\green225\blue138;\red63\green63\blue63;\red220\green220\blue204;\red43\green145\blue175;\red223\green223\blue191;\red200\green145\blue145;\red138\green204\blue207;}??\fs18 \cf1\cb2\highlight2 {\b using}\cf3  (\cf4 TransactionScope\cf3  \cf5 scope\cf3  = \cf1 {\b new}\cf3  \cf4 TransactionScope\cf3 ())\par ??\{\par ??    \cf1 {\b string}\cf3  \cf5 connectionString\cf3  = \cf4 ConfigurationManager\cf3 .\cf5 ConnectionStrings\cf3 [\cf6 "Testing"\cf3 ].\cf5 ConnectionString\cf3 ;\par ??    \cf1 {\b using}\cf3  (\cf4 SqlConnection\cf3  \cf5 con\cf3  = \cf1 {\b new}\cf3  \cf4 SqlConnection\cf3 (\cf5 connectionString\cf3 ))\par ??    \cf1 {\b using}\cf3  (\cf4 SqlCommand\cf3  \cf5 cmd\cf3  = \cf1 {\b new}\cf3  \cf4 SqlCommand\cf3 (\cf6 "usp_ErrorLog_Insert"\cf3 , \cf5 con\cf3 ))\par ??    \{\par ??        \cf5 cmd\cf3 .\cf5 CommandType\cf3  = \cf5 System\cf3 .\cf5 Data\cf3 .\cf4 CommandType\cf3 .\cf5 StoredProcedure\cf3 ;\par ??        \cf5 cmd\cf3 .\cf5 Parameters\cf3 .\cf5 AddWithValue\cf3 (\cf6 "Message"\cf3 , \cf6 "Testing 1"\cf3 );\par ??        \cf5 cmd\cf3 .\cf5 Parameters\cf3 .\cf5 AddWithValue\cf3 (\cf6 "UserID"\cf3 , \cf7 5150\cf3 );\par ??        \cf1 {\b try}\par ??\cf3         \{\par ??            \cf5 con\cf3 .\cf5 Open\cf3 ();\par ??            \cf5 cmd\cf3 .\cf5 ExecuteNonQuery\cf3 ();\par ??        \}\par ??        \cf1 {\b finally}\par ??\cf3         \{\par ??            \cf5 con\cf3 .\cf5 Close\cf3 ();\par ??        \}\par ??    \}\par ??\par ??    \cf4 Console\cf3 .\cf5 WriteLine\cf3 (\cf6 "Local Transaction ID: \{0\}"\cf3 , \par ??        \cf4 Transaction\cf3 .\cf5 Current\cf3 .\cf5 TransactionInformation\cf3 .\cf5 LocalIdentifier\cf3 );\par ??    \cf4 Console\cf3 .\cf5 WriteLine\cf3 (\cf6 "Distributed Transaction ID: \{0\}"\cf3 , \par ??        \cf4 Transaction\cf3 .\cf5 Current\cf3 .\cf5 TransactionInformation\cf3 .\cf5 DistributedIdentifier\cf3 .\cf5 ToString\cf3 ());\par ??\par ??    \cf1 {\b using}\cf3  (\cf4 SqlConnection\cf3  \cf5 con\cf3  = \cf1 {\b new}\cf3  \cf4 SqlConnection\cf3 (\cf5 connectionString\cf3 ))\par ??    \cf1 {\b using}\cf3  (\cf4 SqlCommand\cf3  \cf5 cmd\cf3  = \cf1 {\b new}\cf3  \cf4 SqlCommand\cf3 (\cf6 "usp_ErrorLog_Insert"\cf3 , \cf5 con\cf3 ))\par ??    \{\par ??        \cf5 cmd\cf3 .\cf5 CommandType\cf3  = \cf5 System\cf3 .\cf5 Data\cf3 .\cf4 CommandType\cf3 .\cf5 StoredProcedure\cf3 ;\par ??        \cf5 cmd\cf3 .\cf5 Parameters\cf3 .\cf5 AddWithValue\cf3 (\cf6 "Message"\cf3 , \cf6 "Testing 2"\cf3 );\par ??        \cf5 cmd\cf3 .\cf5 Parameters\cf3 .\cf5 AddWithValue\cf3 (\cf6 "UserID"\cf3 , \cf7 5150\cf3 );\par ??        \cf1 {\b try}\par ??\cf3         \{\par ??            \cf5 con\cf3 .\cf5 Open\cf3 ();\par ??            \cf5 cmd\cf3 .\cf5 ExecuteNonQuery\cf3 ();\par ??        \}\par ??        \cf1 {\b finally}\par ??\cf3         \{\par ??            \cf5 con\cf3 .\cf5 Close\cf3 ();\par ??        \}\par ??    \}\par ??\par ??    \cf4 Console\cf3 .\cf5 WriteLine\cf3 (\cf6 "Local Transaction ID: \{0\}"\cf3 , \par ??        \cf4 Transaction\cf3 .\cf5 Current\cf3 .\cf5 TransactionInformation\cf3 .\cf5 LocalIdentifier\cf3 );\par ??    \cf4 Console\cf3 .\cf5 WriteLine\cf3 (\cf6 "Distributed Transaction ID: \{0\}"\cf3 , \par ??        \cf4 Transaction\cf3 .\cf5 Current\cf3 .\cf5 TransactionInformation\cf3 .\cf5 DistributedIdentifier\cf3 .\cf5 ToString\cf3 ());\par ??\par ??    \cf5 scope\cf3 .\cf5 Complete\cf3 ();\par ??\}}
-->
        </p>
        <div style="OVERFLOW-Y: auto; FONT-SIZE: 9pt; BACKGROUND: #3f3f3f; WIDTH: 764px; COLOR: #dcdccc; FONT-FAMILY: consolas; HEIGHT: 250px">
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  122</span> <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">using</span> (<span style="COLOR: #2b91af">TransactionScope</span><span style="COLOR: #dfdfbf">scope</span> = <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">new</span><span style="COLOR: #2b91af">TransactionScope</span>())
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  123</span> {
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  124</span>     <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">string</span><span style="COLOR: #dfdfbf">connectionString</span> = <span style="COLOR: #2b91af">ConfigurationManager</span>.<span style="COLOR: #dfdfbf">ConnectionStrings</span>[<span style="COLOR: #c89191">"Testing"</span>].<span style="COLOR: #dfdfbf">ConnectionString</span>;
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  125</span>     <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">using</span> (<span style="COLOR: #2b91af">SqlConnection</span><span style="COLOR: #dfdfbf">con</span> = <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">new</span><span style="COLOR: #2b91af">SqlConnection</span>(<span style="COLOR: #dfdfbf">connectionString</span>))
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  126</span>     <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">using</span> (<span style="COLOR: #2b91af">SqlCommand</span><span style="COLOR: #dfdfbf">cmd</span> = <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">new</span><span style="COLOR: #2b91af">SqlCommand</span>(<span style="COLOR: #c89191">"usp_ErrorLog_Insert"</span>, <span style="COLOR: #dfdfbf">con</span>))
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  127</span>     {
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  128</span>         <span style="COLOR: #dfdfbf">cmd</span>.<span style="COLOR: #dfdfbf">CommandType</span> = <span style="COLOR: #dfdfbf">System</span>.<span style="COLOR: #dfdfbf">Data</span>.<span style="COLOR: #2b91af">CommandType</span>.<span style="COLOR: #dfdfbf">StoredProcedure</span>;
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  129</span>         <span style="COLOR: #dfdfbf">cmd</span>.<span style="COLOR: #dfdfbf">Parameters</span>.<span style="COLOR: #dfdfbf">AddWithValue</span>(<span style="COLOR: #c89191">"Message"</span>, <span style="COLOR: #c89191">"Testing
1"</span>);
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  130</span>         <span style="COLOR: #dfdfbf">cmd</span>.<span style="COLOR: #dfdfbf">Parameters</span>.<span style="COLOR: #dfdfbf">AddWithValue</span>(<span style="COLOR: #c89191">"UserID"</span>, <span style="COLOR: #8acccf">5150</span>);
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  131</span>         <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">try</span></p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  132</span>        
{
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  133</span>             <span style="COLOR: #dfdfbf">con</span>.<span style="COLOR: #dfdfbf">Open</span>();
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  134</span>             <span style="COLOR: #dfdfbf">cmd</span>.<span style="COLOR: #dfdfbf">ExecuteNonQuery</span>();
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  135</span>        
}
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  136</span>         <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">finally</span></p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  137</span>        
{
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  138</span>             <span style="COLOR: #dfdfbf">con</span>.<span style="COLOR: #dfdfbf">Close</span>();
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  139</span>        
}
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  140</span>     }
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  141</span> 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  142</span>     <span style="COLOR: #2b91af">Console</span>.<span style="COLOR: #dfdfbf">WriteLine</span>(<span style="COLOR: #c89191">"Local
Transaction ID: {0}"</span>, 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  143</span>         <span style="COLOR: #2b91af">Transaction</span>.<span style="COLOR: #dfdfbf">Current</span>.<span style="COLOR: #dfdfbf">TransactionInformation</span>.<span style="COLOR: #dfdfbf">LocalIdentifier</span>);
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  144</span>     <span style="COLOR: #2b91af">Console</span>.<span style="COLOR: #dfdfbf">WriteLine</span>(<span style="COLOR: #c89191">"Distributed
Transaction ID: {0}"</span>, 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  145</span>         <span style="COLOR: #2b91af">Transaction</span>.<span style="COLOR: #dfdfbf">Current</span>.<span style="COLOR: #dfdfbf">TransactionInformation</span>.<span style="COLOR: #dfdfbf">DistributedIdentifier</span>.<span style="COLOR: #dfdfbf">ToString</span>());
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  146</span> 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  147</span>     <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">using</span> (<span style="COLOR: #2b91af">SqlConnection</span><span style="COLOR: #dfdfbf">con</span> = <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">new</span><span style="COLOR: #2b91af">SqlConnection</span>(<span style="COLOR: #dfdfbf">connectionString</span>))
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  148</span>     <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">using</span> (<span style="COLOR: #2b91af">SqlCommand</span><span style="COLOR: #dfdfbf">cmd</span> = <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">new</span><span style="COLOR: #2b91af">SqlCommand</span>(<span style="COLOR: #c89191">"usp_ErrorLog_Insert"</span>, <span style="COLOR: #dfdfbf">con</span>))
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  149</span>     {
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  150</span>         <span style="COLOR: #dfdfbf">cmd</span>.<span style="COLOR: #dfdfbf">CommandType</span> = <span style="COLOR: #dfdfbf">System</span>.<span style="COLOR: #dfdfbf">Data</span>.<span style="COLOR: #2b91af">CommandType</span>.<span style="COLOR: #dfdfbf">StoredProcedure</span>;
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  151</span>         <span style="COLOR: #dfdfbf">cmd</span>.<span style="COLOR: #dfdfbf">Parameters</span>.<span style="COLOR: #dfdfbf">AddWithValue</span>(<span style="COLOR: #c89191">"Message"</span>, <span style="COLOR: #c89191">"Testing
2"</span>);
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  152</span>         <span style="COLOR: #dfdfbf">cmd</span>.<span style="COLOR: #dfdfbf">Parameters</span>.<span style="COLOR: #dfdfbf">AddWithValue</span>(<span style="COLOR: #c89191">"UserID"</span>, <span style="COLOR: #8acccf">5150</span>);
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  153</span>         <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">try</span></p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  154</span>        
{
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  155</span>             <span style="COLOR: #dfdfbf">con</span>.<span style="COLOR: #dfdfbf">Open</span>();
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  156</span>             <span style="COLOR: #dfdfbf">cmd</span>.<span style="COLOR: #dfdfbf">ExecuteNonQuery</span>();
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  157</span>        
}
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  158</span>         <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">finally</span></p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  159</span>        
{
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  160</span>             <span style="COLOR: #dfdfbf">con</span>.<span style="COLOR: #dfdfbf">Close</span>();
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  161</span>        
}
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  162</span>     }
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  163</span> 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  164</span>     <span style="COLOR: #2b91af">Console</span>.<span style="COLOR: #dfdfbf">WriteLine</span>(<span style="COLOR: #c89191">"Local
Transaction ID: {0}"</span>, 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  165</span>         <span style="COLOR: #2b91af">Transaction</span>.<span style="COLOR: #dfdfbf">Current</span>.<span style="COLOR: #dfdfbf">TransactionInformation</span>.<span style="COLOR: #dfdfbf">LocalIdentifier</span>);
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  166</span>     <span style="COLOR: #2b91af">Console</span>.<span style="COLOR: #dfdfbf">WriteLine</span>(<span style="COLOR: #c89191">"Distributed
Transaction ID: {0}"</span>, 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  167</span>         <span style="COLOR: #2b91af">Transaction</span>.<span style="COLOR: #dfdfbf">Current</span>.<span style="COLOR: #dfdfbf">TransactionInformation</span>.<span style="COLOR: #dfdfbf">DistributedIdentifier</span>.<span style="COLOR: #dfdfbf">ToString</span>());
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  168</span> 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  169</span>     <span style="COLOR: #dfdfbf">scope</span>.<span style="COLOR: #dfdfbf">Complete</span>();
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  170</span> }
</p>
        </div>
        <p>
 
</p>
        <p>
This writes the following to the command line:
</p>
        <blockquote>
          <p>
            <font face="Courier New" size="2">
              <strong>Local Transaction ID: e90f47f4-df80-496b-a9c0-0c45b2f452c4:2<br />
Distributed Transaction ID: 00000000-0000-0000-0000-000000000000<br />
Local Transaction ID: e90f47f4-df80-496b-a9c0-0c45b2f452c4:2<br />
Distributed Transaction ID: 1fad8108-ddae-496a-a7da-ce92df175e40</strong>
            </font>
          </p>
        </blockquote>
        <p>
You'll notice that the first command creates a transaction using LTM as indicated
by the <em>Local Transaction ID</em>. After the second command is executed, the transaction
is promoted to DTC as indicated by the <em>Distributed Transaction ID</em>. This is
expected because there are two distinct SqlConnections. Even though the connection
string is the same, TransactionScope treats these ADO.NET objects as unique resources.
</p>
        <p>
This has additional implications when connection pooling comes into play. After I
close the first connection, it is returned to the pool and is available for use. If
this connection is requested for use, it will no longer be available to commit or
abort this transaction, and you will see the dreaded MSDTC error "Communication with
the underlying transaction manager has failed."
</p>
        <p>
        </p>
        <p>
          <strong>2) Executing two ADO.NET SqlCommands in the same SqlConnection</strong>
        </p>
        <p>
          <!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red220\green220\blue204;\red63\green63\blue63;\red225\green225\blue138;\red43\green145\blue175;\red223\green223\blue191;\red200\green145\blue145;\red138\green204\blue207;}??\fs18 \cf1\cb2\highlight2             \cf3 {\b using}\cf1  (\cf4 SqlConnection\cf1  \cf5 con\cf1  = \cf3 {\b new}\cf1  \cf4 SqlConnection\cf1 (\cf4 ConfigurationManager\cf1 .\cf5 ConnectionStrings\cf1 [\cf6 "Testing"\cf1 ].\cf5 ConnectionString\cf1 ))\par ??            \{\par ??                \cf4 SqlTransaction\cf1  \cf5 tran\cf1  = \cf3 {\b null}\cf1 ;\par ??                \cf3 {\b try}\par ??\cf1                 \{\par ??                    \cf5 con\cf1 .\cf5 Open\cf1 ();\par ??                    \cf5 tran\cf1  = \cf5 con\cf1 .\cf5 BeginTransaction\cf1 ();\par ??                    \cf3 {\b using}\cf1  (\cf4 SqlCommand\cf1  \cf5 cmd\cf1  = \cf3 {\b new}\cf1  \cf4 SqlCommand\cf1 (\cf6 "usp_ErrorLog_Insert"\cf1 , \cf5 con\cf1 ))\par ??                    \{\par ??                        \cf5 cmd\cf1 .\cf5 Transaction\cf1  = \cf5 tran\cf1 ;\par ??                        \cf5 cmd\cf1 .\cf5 CommandType\cf1  = \cf5 System\cf1 .\cf5 Data\cf1 .\cf4 CommandType\cf1 .\cf5 StoredProcedure\cf1 ;\par ??                        \cf5 cmd\cf1 .\cf5 Parameters\cf1 .\cf5 AddWithValue\cf1 (\cf6 "Message"\cf1 , \cf6 "Testing 1"\cf1 );\par ??                        \cf5 cmd\cf1 .\cf5 Parameters\cf1 .\cf5 AddWithValue\cf1 (\cf6 "UserID"\cf1 , \cf7 5150\cf1 );\par ??                        \cf5 cmd\cf1 .\cf5 ExecuteNonQuery\cf1 ();\par ??                    \}\par ??\par ??                    \cf3 {\b using}\cf1  (\cf4 SqlCommand\cf1  \cf5 cmd\cf1  = \cf3 {\b new}\cf1  \cf4 SqlCommand\cf1 (\cf6 "usp_ErrorLog_Insert"\cf1 , \cf5 con\cf1 ))\par ??                    \{\par ??                        \cf5 cmd\cf1 .\cf5 Transaction\cf1  = \cf5 tran\cf1 ;\par ??                        \cf5 cmd\cf1 .\cf5 CommandType\cf1  = \cf5 System\cf1 .\cf5 Data\cf1 .\cf4 CommandType\cf1 .\cf5 StoredProcedure\cf1 ;\par ??                        \cf5 cmd\cf1 .\cf5 Parameters\cf1 .\cf5 AddWithValue\cf1 (\cf6 "Message"\cf1 , \cf6 "Testing 2"\cf1 );\par ??                        \cf5 cmd\cf1 .\cf5 Parameters\cf1 .\cf5 AddWithValue\cf1 (\cf6 "UserID"\cf1 , \cf7 5150\cf1 );\par ??                        \cf5 cmd\cf1 .\cf5 ExecuteNonQuery\cf1 ();\par ??                    \}\par ??\par ??                    \cf5 tran\cf1 .\cf5 Commit\cf1 ();\par ??                \}\par ??                \cf3 {\b catch}\par ??\cf1                 \{\par ??                    \cf3 {\b if}\cf1  (\cf5 tran\cf1  != \cf3 {\b null}\cf1 ) \cf5 tran\cf1 .\cf5 Rollback\cf1 ();\par ??                \}\par ??                \cf3 {\b finally}\par ??\cf1                 \{\par ??                    \cf5 con\cf1 .\cf5 Close\cf1 ();\par ??                \}\par ??            \}}
-->
        </p>
        <p>
        </p>
        <p>
          <!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red220\green220\blue204;\red63\green63\blue63;\red225\green225\blue138;\red223\green223\blue191;\red43\green145\blue175;\red200\green145\blue145;\red138\green204\blue207;}??\fs18 \cf1\cb2\highlight2             \cf3 {\b string}\cf1  \cf4 connectionString\cf1  = \cf5 ConfigurationManager\cf1 .\cf4 ConnectionStrings\cf1 [\cf6 "Testing"\cf1 ].\cf4 ConnectionString\cf1 ;\par ??            \cf3 {\b using}\cf1  (\cf5 SqlConnection\cf1  \cf4 con\cf1  = \cf3 {\b new}\cf1  \cf5 SqlConnection\cf1 (\cf4 connectionString\cf1 ))\par ??            \{\par ??                \cf5 SqlTransaction\cf1  \cf4 tran\cf1  = \cf3 {\b null}\cf1 ;\par ??                \cf3 {\b try}\par ??\cf1                 \{\par ??                    \cf4 con\cf1 .\cf4 Open\cf1 ();\par ??                    \cf4 tran\cf1  = \cf4 con\cf1 .\cf4 BeginTransaction\cf1 ();\par ??                    \cf3 {\b using}\cf1  (\cf5 SqlCommand\cf1  \cf4 cmd\cf1  = \cf3 {\b new}\cf1  \cf5 SqlCommand\cf1 (\cf6 "usp_ErrorLog_Insert"\cf1 , \cf4 con\cf1 ))\par ??                    \{\par ??                        \cf4 cmd\cf1 .\cf4 Transaction\cf1  = \cf4 tran\cf1 ;\par ??                        \cf4 cmd\cf1 .\cf4 CommandType\cf1  = \cf4 System\cf1 .\cf4 Data\cf1 .\cf5 CommandType\cf1 .\cf4 StoredProcedure\cf1 ;\par ??                        \cf4 cmd\cf1 .\cf4 Parameters\cf1 .\cf4 AddWithValue\cf1 (\cf6 "Message"\cf1 , \cf6 "Testing 1"\cf1 );\par ??                        \cf4 cmd\cf1 .\cf4 Parameters\cf1 .\cf4 AddWithValue\cf1 (\cf6 "UserID"\cf1 , \cf7 5150\cf1 );\par ??                        \cf4 cmd\cf1 .\cf4 ExecuteNonQuery\cf1 ();\par ??                    \}\par ??\par ??                    \cf3 {\b using}\cf1  (\cf5 SqlCommand\cf1  \cf4 cmd\cf1  = \cf3 {\b new}\cf1  \cf5 SqlCommand\cf1 (\cf6 "usp_ErrorLog_Insert"\cf1 , \cf4 con\cf1 ))\par ??                    \{\par ??                        \cf4 cmd\cf1 .\cf4 Transaction\cf1  = \cf4 tran\cf1 ;\par ??                        \cf4 cmd\cf1 .\cf4 CommandType\cf1  = \cf4 System\cf1 .\cf4 Data\cf1 .\cf5 CommandType\cf1 .\cf4 StoredProcedure\cf1 ;\par ??                        \cf4 cmd\cf1 .\cf4 Parameters\cf1 .\cf4 AddWithValue\cf1 (\cf6 "Message"\cf1 , \cf6 "Testing 2"\cf1 );\par ??                        \cf4 cmd\cf1 .\cf4 Parameters\cf1 .\cf4 AddWithValue\cf1 (\cf6 "UserID"\cf1 , \cf7 5150\cf1 );\par ??                        \cf4 cmd\cf1 .\cf4 ExecuteNonQuery\cf1 ();\par ??                    \}\par ??\par ??                    \cf4 tran\cf1 .\cf4 Commit\cf1 ();\par ??                \}\par ??                \cf3 {\b catch}\par ??\cf1                 \{\par ??                    \cf3 {\b if}\cf1  (\cf4 tran\cf1  != \cf3 {\b null}\cf1 ) \cf4 tran\cf1 .\cf4 Rollback\cf1 ();\par ??                \}\par ??                \cf3 {\b finally}\par ??\cf1                 \{\par ??                    \cf4 con\cf1 .\cf4 Close\cf1 ();\par ??                \}\par ??            \}}
-->
        </p>
        <p>
        </p>
        <p>
          <!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red220\green220\blue204;\red63\green63\blue63;\red225\green225\blue138;\red223\green223\blue191;\red43\green145\blue175;\red200\green145\blue145;\red138\green204\blue207;}??\fs18 \cf1\cb2\highlight2             \cf3 {\b string}\cf1  \cf4 connectionString\cf1  = \cf5 ConfigurationManager\cf1 .\cf4 ConnectionStrings\cf1 [\cf6 "Testing"\cf1 ].\cf4 ConnectionString\cf1 ;\par ??            \cf3 {\b using}\cf1  (\cf5 TransactionScope\cf1  \cf4 scope\cf1  = \cf3 {\b new}\cf1  \cf5 TransactionScope\cf1 ())\par ??            \cf3 {\b using}\cf1  (\cf5 SqlConnection\cf1  \cf4 con\cf1  = \cf3 {\b new}\cf1  \cf5 SqlConnection\cf1 (\cf4 connectionString\cf1 ))\par ??            \{\par ??                \cf3 {\b using}\cf1  (\cf5 SqlCommand\cf1  \cf4 cmd\cf1  = \cf3 {\b new}\cf1  \cf5 SqlCommand\cf1 (\cf6 "usp_ErrorLog_Insert"\cf1 , \cf4 con\cf1 ))\par ??                \{\par ??                    \cf4 cmd\cf1 .\cf4 CommandType\cf1  = \cf4 System\cf1 .\cf4 Data\cf1 .\cf5 CommandType\cf1 .\cf4 StoredProcedure\cf1 ;\par ??                    \cf4 cmd\cf1 .\cf4 Parameters\cf1 .\cf4 AddWithValue\cf1 (\cf6 "Message"\cf1 , \cf6 "Testing 1"\cf1 );\par ??                    \cf4 cmd\cf1 .\cf4 Parameters\cf1 .\cf4 AddWithValue\cf1 (\cf6 "UserID"\cf1 , \cf7 5150\cf1 );\par ??                    \cf3 {\b try}\par ??\cf1                     \{\par ??                        \cf4 con\cf1 .\cf4 Open\cf1 ();\par ??                        \cf4 cmd\cf1 .\cf4 ExecuteNonQuery\cf1 ();\par ??                    \}\par ??                    \cf3 {\b finally}\par ??\cf1                     \{\par ??                        \cf4 con\cf1 .\cf4 Close\cf1 ();\par ??                    \}\par ??                \}\par ??\par ??                \cf5 Console\cf1 .\cf4 WriteLine\cf1 (\cf6 "Local Transaction ID: \{0\}"\cf1 , \cf5 Transaction\cf1 .\cf4 Current\cf1 .\cf4 TransactionInformation\cf1 .\cf4 LocalIdentifier\cf1 );\par ??                \cf5 Console\cf1 .\cf4 WriteLine\cf1 (\cf6 "Distributed Transaction ID: \{0\}"\cf1 , \cf5 Transaction\cf1 .\cf4 Current\cf1 .\cf4 TransactionInformation\cf1 .\cf4 DistributedIdentifier\cf1 .\cf4 ToString\cf1 ());\par ??\par ??                \cf3 {\b using}\cf1  (\cf5 SqlCommand\cf1  \cf4 cmd\cf1  = \cf3 {\b new}\cf1  \cf5 SqlCommand\cf1 (\cf6 "usp_ErrorLog_Insert"\cf1 , \cf4 con\cf1 ))\par ??                \{\par ??                    \cf4 cmd\cf1 .\cf4 CommandType\cf1  = \cf4 System\cf1 .\cf4 Data\cf1 .\cf5 CommandType\cf1 .\cf4 StoredProcedure\cf1 ;\par ??                    \cf4 cmd\cf1 .\cf4 Parameters\cf1 .\cf4 AddWithValue\cf1 (\cf6 "Message"\cf1 , \cf6 "Testing 2"\cf1 );\par ??                    \cf4 cmd\cf1 .\cf4 Parameters\cf1 .\cf4 AddWithValue\cf1 (\cf6 "UserID"\cf1 , \cf7 5150\cf1 );\par ??                    \cf3 {\b try}\par ??\cf1                     \{\par ??                        \cf4 con\cf1 .\cf4 Open\cf1 ();\par ??                        \cf4 cmd\cf1 .\cf4 ExecuteNonQuery\cf1 ();\par ??                    \}\par ??                    \cf3 {\b finally}\par ??\cf1                     \{\par ??                        \cf4 con\cf1 .\cf4 Close\cf1 ();\par ??                    \}\par ??                \}\par ??\par ??                \cf5 Console\cf1 .\cf4 WriteLine\cf1 (\cf6 "Local Transaction ID: \{0\}"\cf1 , \cf5 Transaction\cf1 .\cf4 Current\cf1 .\cf4 TransactionInformation\cf1 .\cf4 LocalIdentifier\cf1 );\par ??                \cf5 Console\cf1 .\cf4 WriteLine\cf1 (\cf6 "Distributed Transaction ID: \{0\}"\cf1 , \cf5 Transaction\cf1 .\cf4 Current\cf1 .\cf4 TransactionInformation\cf1 .\cf4 DistributedIdentifier\cf1 .\cf4 ToString\cf1 ());\par ??\par ??                \cf4 scope\cf1 .\cf4 Complete\cf1 ();\par ??            \}}
-->
        </p>
        <p>
          <!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red225\green225\blue138;\red63\green63\blue63;\red220\green220\blue204;\red223\green223\blue191;\red43\green145\blue175;\red200\green145\blue145;\red138\green204\blue207;}??\fs18 \cf1\cb2\highlight2 {\b string}\cf3  \cf4 connectionString\cf3  = \cf5 ConfigurationManager\cf3 .\cf4 ConnectionStrings\cf3 [\cf6 "Testing"\cf3 ].\cf4 ConnectionString\cf3 ;\par ??\cf1 {\b using}\cf3  (\cf5 TransactionScope\cf3  \cf4 scope\cf3  = \cf1 {\b new}\cf3  \cf5 TransactionScope\cf3 ())\par ??\cf1 {\b using}\cf3  (\cf5 SqlConnection\cf3  \cf4 con\cf3  = \cf1 {\b new}\cf3  \cf5 SqlConnection\cf3 (\cf4 connectionString\cf3 ))\par ??\{\par ??    \cf1 {\b using}\cf3  (\cf5 SqlCommand\cf3  \cf4 cmd\cf3  = \cf1 {\b new}\cf3  \cf5 SqlCommand\cf3 (\cf6 "usp_ErrorLog_Insert"\cf3 , \cf4 con\cf3 ))\par ??    \{\par ??        \cf4 cmd\cf3 .\cf4 CommandType\cf3  = \cf4 System\cf3 .\cf4 Data\cf3 .\cf5 CommandType\cf3 .\cf4 StoredProcedure\cf3 ;\par ??        \cf4 cmd\cf3 .\cf4 Parameters\cf3 .\cf4 AddWithValue\cf3 (\cf6 "Message"\cf3 , \cf6 "Testing 1"\cf3 );\par ??        \cf4 cmd\cf3 .\cf4 Parameters\cf3 .\cf4 AddWithValue\cf3 (\cf6 "UserID"\cf3 , \cf7 5150\cf3 );\par ??        \cf1 {\b try}\par ??\cf3         \{\par ??            \cf4 con\cf3 .\cf4 Open\cf3 ();\par ??            \cf4 cmd\cf3 .\cf4 ExecuteNonQuery\cf3 ();\par ??        \}\par ??        \cf1 {\b finally}\par ??\cf3         \{\par ??            \cf4 con\cf3 .\cf4 Close\cf3 ();\par ??        \}\par ??    \}\par ??\par ??    \cf5 Console\cf3 .\cf4 WriteLine\cf3 (\cf6 "Local Transaction ID: \{0\}"\cf3 , \cf5 Transaction\cf3 .\cf4 Current\cf3 .\cf4 TransactionInformation\cf3 .\cf4 LocalIdentifier\cf3 );\par ??    \cf5 Console\cf3 .\cf4 WriteLine\cf3 (\cf6 "Distributed Transaction ID: \{0\}"\cf3 , \cf5 Transaction\cf3 .\cf4 Current\cf3 .\cf4 TransactionInformation\cf3 .\cf4 DistributedIdentifier\cf3 .\cf4 ToString\cf3 ());\par ??\par ??    \cf1 {\b using}\cf3  (\cf5 SqlCommand\cf3  \cf4 cmd\cf3  = \cf1 {\b new}\cf3  \cf5 SqlCommand\cf3 (\cf6 "usp_ErrorLog_Insert"\cf3 , \cf4 con\cf3 ))\par ??    \{\par ??        \cf4 cmd\cf3 .\cf4 CommandType\cf3  = \cf4 System\cf3 .\cf4 Data\cf3 .\cf5 CommandType\cf3 .\cf4 StoredProcedure\cf3 ;\par ??        \cf4 cmd\cf3 .\cf4 Parameters\cf3 .\cf4 AddWithValue\cf3 (\cf6 "Message"\cf3 , \cf6 "Testing 2"\cf3 );\par ??        \cf4 cmd\cf3 .\cf4 Parameters\cf3 .\cf4 AddWithValue\cf3 (\cf6 "UserID"\cf3 , \cf7 5150\cf3 );\par ??        \cf1 {\b try}\par ??\cf3         \{\par ??            \cf4 con\cf3 .\cf4 Open\cf3 ();\par ??            \cf4 cmd\cf3 .\cf4 ExecuteNonQuery\cf3 ();\par ??        \}\par ??        \cf1 {\b finally}\par ??\cf3         \{\par ??            \cf4 con\cf3 .\cf4 Close\cf3 ();\par ??        \}\par ??    \}\par ??\par ??    \cf5 Console\cf3 .\cf4 WriteLine\cf3 (\cf6 "Local Transaction ID: \{0\}"\cf3 , \cf5 Transaction\cf3 .\cf4 Current\cf3 .\cf4 TransactionInformation\cf3 .\cf4 LocalIdentifier\cf3 );\par ??    \cf5 Console\cf3 .\cf4 WriteLine\cf3 (\cf6 "Distributed Transaction ID: \{0\}"\cf3 , \cf5 Transaction\cf3 .\cf4 Current\cf3 .\cf4 TransactionInformation\cf3 .\cf4 DistributedIdentifier\cf3 .\cf4 ToString\cf3 ());\par ??\par ??    \cf4 scope\cf3 .\cf4 Complete\cf3 ();\par ??\}}
-->
        </p>
        <p>
        </p>
        <p>
          <!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red225\green225\blue138;\red63\green63\blue63;\red220\green220\blue204;\red223\green223\blue191;\red43\green145\blue175;\red200\green145\blue145;\red138\green204\blue207;}??\fs18 \cf1\cb2\highlight2 {\b string}\cf3  \cf4 connectionString\cf3  = \cf5 ConfigurationManager\cf3 .\cf4 ConnectionStrings\cf3 [\cf6 "Testing"\cf3 ].\cf4 ConnectionString\cf3 ;\par ??\cf1 {\b using}\cf3  (\cf5 TransactionScope\cf3  \cf4 scope\cf3  = \cf1 {\b new}\cf3  \cf5 TransactionScope\cf3 ())\par ??\cf1 {\b using}\cf3  (\cf5 SqlConnection\cf3  \cf4 con\cf3  = \cf1 {\b new}\cf3  \cf5 SqlConnection\cf3 (\cf4 connectionString\cf3 ))\par ??\{\par ??    \cf1 {\b using}\cf3  (\cf5 SqlCommand\cf3  \cf4 cmd\cf3  = \cf1 {\b new}\cf3  \cf5 SqlCommand\cf3 (\cf6 "usp_ErrorLog_Insert"\cf3 , \cf4 con\cf3 ))\par ??    \{\par ??        \cf4 cmd\cf3 .\cf4 CommandType\cf3  = \cf4 System\cf3 .\cf4 Data\cf3 .\cf5 CommandType\cf3 .\cf4 StoredProcedure\cf3 ;\par ??        \cf4 cmd\cf3 .\cf4 Parameters\cf3 .\cf4 AddWithValue\cf3 (\cf6 "Message"\cf3 , \cf6 "Testing 1"\cf3 );\par ??        \cf4 cmd\cf3 .\cf4 Parameters\cf3 .\cf4 AddWithValue\cf3 (\cf6 "UserID"\cf3 , \cf7 5150\cf3 );\par ??        \cf1 {\b try}\par ??\cf3         \{\par ??            \cf4 con\cf3 .\cf4 Open\cf3 ();\par ??            \cf4 cmd\cf3 .\cf4 ExecuteNonQuery\cf3 ();\par ??        \}\par ??        \cf1 {\b finally}\par ??\cf3         \{\par ??            \cf4 con\cf3 .\cf4 Close\cf3 ();\par ??        \}\par ??    \}\par ??\par ??    \cf5 Console\cf3 .\cf4 WriteLine\cf3 (\cf6 "Local Transaction ID: \{0\}"\cf3 , \par ??        \cf5 Transaction\cf3 .\cf4 Current\cf3 .\cf4 TransactionInformation\cf3 .\cf4 LocalIdentifier\cf3 );\par ??    \cf5 Console\cf3 .\cf4 WriteLine\cf3 (\cf6 "Distributed Transaction ID: \{0\}"\cf3 , \par ??        \cf5 Transaction\cf3 .\cf4 Current\cf3 .\cf4 TransactionInformation\cf3 .\cf4 DistributedIdentifier\cf3 .\cf4 ToString\cf3 ());\par ??\par ??    \cf1 {\b using}\cf3  (\cf5 SqlCommand\cf3  \cf4 cmd\cf3  = \cf1 {\b new}\cf3  \cf5 SqlCommand\cf3 (\cf6 "usp_ErrorLog_Insert"\cf3 , \cf4 con\cf3 ))\par ??    \{\par ??        \cf4 cmd\cf3 .\cf4 CommandType\cf3  = \cf4 System\cf3 .\cf4 Data\cf3 .\cf5 CommandType\cf3 .\cf4 StoredProcedure\cf3 ;\par ??        \cf4 cmd\cf3 .\cf4 Parameters\cf3 .\cf4 AddWithValue\cf3 (\cf6 "Message"\cf3 , \cf6 "Testing 2"\cf3 );\par ??        \cf4 cmd\cf3 .\cf4 Parameters\cf3 .\cf4 AddWithValue\cf3 (\cf6 "UserID"\cf3 , \cf7 5150\cf3 );\par ??        \cf1 {\b try}\par ??\cf3         \{\par ??            \cf4 con\cf3 .\cf4 Open\cf3 ();\par ??            \cf4 cmd\cf3 .\cf4 ExecuteNonQuery\cf3 ();\par ??        \}\par ??        \cf1 {\b finally}\par ??\cf3         \{\par ??            \cf4 con\cf3 .\cf4 Close\cf3 ();\par ??        \}\par ??    \}\par ??\par ??    \cf5 Console\cf3 .\cf4 WriteLine\cf3 (\cf6 "Local Transaction ID: \{0\}"\cf3 , \par ??        \cf5 Transaction\cf3 .\cf4 Current\cf3 .\cf4 TransactionInformation\cf3 .\cf4 LocalIdentifier\cf3 );\par ??    \cf5 Console\cf3 .\cf4 WriteLine\cf3 (\cf6 "Distributed Transaction ID: \{0\}"\cf3 , \par ??        \cf5 Transaction\cf3 .\cf4 Current\cf3 .\cf4 TransactionInformation\cf3 .\cf4 DistributedIdentifier\cf3 .\cf4 ToString\cf3 ());\par ??\par ??    \cf4 scope\cf3 .\cf4 Complete\cf3 ();\par ??\}}
-->
        </p>
        <div style="OVERFLOW-Y: auto; FONT-SIZE: 9pt; BACKGROUND: #3f3f3f; WIDTH: 765px; COLOR: #dcdccc; FONT-FAMILY: consolas; HEIGHT: 250px">
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   69</span> <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">string</span><span style="COLOR: #dfdfbf">connectionString</span> = <span style="COLOR: #2b91af">ConfigurationManager</span>.<span style="COLOR: #dfdfbf">ConnectionStrings</span>[<span style="COLOR: #c89191">"Testing"</span>].<span style="COLOR: #dfdfbf">ConnectionString</span>;
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   70</span> <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">using</span> (<span style="COLOR: #2b91af">TransactionScope</span><span style="COLOR: #dfdfbf">scope</span> = <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">new</span><span style="COLOR: #2b91af">TransactionScope</span>())
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   71</span> <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">using</span> (<span style="COLOR: #2b91af">SqlConnection</span><span style="COLOR: #dfdfbf">con</span> = <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">new</span><span style="COLOR: #2b91af">SqlConnection</span>(<span style="COLOR: #dfdfbf">connectionString</span>))
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   72</span> {
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   73</span>     <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">using</span> (<span style="COLOR: #2b91af">SqlCommand</span><span style="COLOR: #dfdfbf">cmd</span> = <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">new</span><span style="COLOR: #2b91af">SqlCommand</span>(<span style="COLOR: #c89191">"usp_ErrorLog_Insert"</span>, <span style="COLOR: #dfdfbf">con</span>))
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   74</span>     {
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   75</span>         <span style="COLOR: #dfdfbf">cmd</span>.<span style="COLOR: #dfdfbf">CommandType</span> = <span style="COLOR: #dfdfbf">System</span>.<span style="COLOR: #dfdfbf">Data</span>.<span style="COLOR: #2b91af">CommandType</span>.<span style="COLOR: #dfdfbf">StoredProcedure</span>;
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   76</span>         <span style="COLOR: #dfdfbf">cmd</span>.<span style="COLOR: #dfdfbf">Parameters</span>.<span style="COLOR: #dfdfbf">AddWithValue</span>(<span style="COLOR: #c89191">"Message"</span>, <span style="COLOR: #c89191">"Testing
1"</span>);
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   77</span>         <span style="COLOR: #dfdfbf">cmd</span>.<span style="COLOR: #dfdfbf">Parameters</span>.<span style="COLOR: #dfdfbf">AddWithValue</span>(<span style="COLOR: #c89191">"UserID"</span>, <span style="COLOR: #8acccf">5150</span>);
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   78</span>         <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">try</span></p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   79</span>        
{
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   80</span>             <span style="COLOR: #dfdfbf">con</span>.<span style="COLOR: #dfdfbf">Open</span>();
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   81</span>             <span style="COLOR: #dfdfbf">cmd</span>.<span style="COLOR: #dfdfbf">ExecuteNonQuery</span>();
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   82</span>        
}
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   83</span>         <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">finally</span></p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   84</span>        
{
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   85</span>             <span style="COLOR: #dfdfbf">con</span>.<span style="COLOR: #dfdfbf">Close</span>();
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   86</span>        
}
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   87</span>     }
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   88</span> 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   89</span>     <span style="COLOR: #2b91af">Console</span>.<span style="COLOR: #dfdfbf">WriteLine</span>(<span style="COLOR: #c89191">"Local
Transaction ID: {0}"</span>, 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   90</span>         <span style="COLOR: #2b91af">Transaction</span>.<span style="COLOR: #dfdfbf">Current</span>.<span style="COLOR: #dfdfbf">TransactionInformation</span>.<span style="COLOR: #dfdfbf">LocalIdentifier</span>);
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   91</span>     <span style="COLOR: #2b91af">Console</span>.<span style="COLOR: #dfdfbf">WriteLine</span>(<span style="COLOR: #c89191">"Distributed
Transaction ID: {0}"</span>, 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   92</span>         <span style="COLOR: #2b91af">Transaction</span>.<span style="COLOR: #dfdfbf">Current</span>.<span style="COLOR: #dfdfbf">TransactionInformation</span>.<span style="COLOR: #dfdfbf">DistributedIdentifier</span>.<span style="COLOR: #dfdfbf">ToString</span>());
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   93</span> 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   94</span>     <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">using</span> (<span style="COLOR: #2b91af">SqlCommand</span><span style="COLOR: #dfdfbf">cmd</span> = <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">new</span><span style="COLOR: #2b91af">SqlCommand</span>(<span style="COLOR: #c89191">"usp_ErrorLog_Insert"</span>, <span style="COLOR: #dfdfbf">con</span>))
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   95</span>     {
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   96</span>         <span style="COLOR: #dfdfbf">cmd</span>.<span style="COLOR: #dfdfbf">CommandType</span> = <span style="COLOR: #dfdfbf">System</span>.<span style="COLOR: #dfdfbf">Data</span>.<span style="COLOR: #2b91af">CommandType</span>.<span style="COLOR: #dfdfbf">StoredProcedure</span>;
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   97</span>         <span style="COLOR: #dfdfbf">cmd</span>.<span style="COLOR: #dfdfbf">Parameters</span>.<span style="COLOR: #dfdfbf">AddWithValue</span>(<span style="COLOR: #c89191">"Message"</span>, <span style="COLOR: #c89191">"Testing
2"</span>);
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   98</span>         <span style="COLOR: #dfdfbf">cmd</span>.<span style="COLOR: #dfdfbf">Parameters</span>.<span style="COLOR: #dfdfbf">AddWithValue</span>(<span style="COLOR: #c89191">"UserID"</span>, <span style="COLOR: #8acccf">5150</span>);
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   99</span>         <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">try</span></p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  100</span>        
{
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  101</span>             <span style="COLOR: #dfdfbf">con</span>.<span style="COLOR: #dfdfbf">Open</span>();
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  102</span>             <span style="COLOR: #dfdfbf">cmd</span>.<span style="COLOR: #dfdfbf">ExecuteNonQuery</span>();
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  103</span>        
}
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  104</span>         <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">finally</span></p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  105</span>        
{
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  106</span>             <span style="COLOR: #dfdfbf">con</span>.<span style="COLOR: #dfdfbf">Close</span>();
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  107</span>        
}
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  108</span>     }
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  109</span> 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  110</span>     <span style="COLOR: #2b91af">Console</span>.<span style="COLOR: #dfdfbf">WriteLine</span>(<span style="COLOR: #c89191">"Local
Transaction ID: {0}"</span>, 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  111</span>         <span style="COLOR: #2b91af">Transaction</span>.<span style="COLOR: #dfdfbf">Current</span>.<span style="COLOR: #dfdfbf">TransactionInformation</span>.<span style="COLOR: #dfdfbf">LocalIdentifier</span>);
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  112</span>     <span style="COLOR: #2b91af">Console</span>.<span style="COLOR: #dfdfbf">WriteLine</span>(<span style="COLOR: #c89191">"Distributed
Transaction ID: {0}"</span>, 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  113</span>         <span style="COLOR: #2b91af">Transaction</span>.<span style="COLOR: #dfdfbf">Current</span>.<span style="COLOR: #dfdfbf">TransactionInformation</span>.<span style="COLOR: #dfdfbf">DistributedIdentifier</span>.<span style="COLOR: #dfdfbf">ToString</span>());
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  114</span> 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  115</span>     <span style="COLOR: #dfdfbf">scope</span>.<span style="COLOR: #dfdfbf">Complete</span>();
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  116</span> }
</p>
        </div>
        <p>
 
</p>
        <p>
This writes the following to the command line:
</p>
        <blockquote>
          <p>
            <font face="Courier New" size="2">
              <strong>Local Transaction ID: e90f47f4-df80-496b-a9c0-0c45b2f452c4:1<br />
Distributed Transaction ID: 00000000-0000-0000-0000-000000000000<br />
Local Transaction ID: e90f47f4-df80-496b-a9c0-0c45b2f452c4:1<br />
Distributed Transaction ID: becac9c9-e15f-4370-9f73-7f369665bed7</strong>
            </font>
          </p>
        </blockquote>
        <p>
        </p>
        <p>
        </p>
        <p>
This is not expected because both commands are part of the same connection. Of course
I am closing the connection to simulate an N-tier app where the data access layer
is maintaining it's own SQL access, opening and closing its connection as it should.
If I did not close the connection, you would not see a <em>Distributed Transaction
ID</em> after the second command.
</p>
        <p>
        </p>
        <p>
          <strong>3) Executing two Enterprise Library commands</strong>
        </p>
        <p>
          <!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red225\green225\blue138;\red63\green63\blue63;\red220\green220\blue204;\red43\green145\blue175;\red223\green223\blue191;\red200\green145\blue145;\red138\green204\blue207;}??\fs18 \cf1\cb2\highlight2 {\b using}\cf3  (\cf4 TransactionScope\cf3  \cf5 scope\cf3  = \cf1 {\b new}\cf3  \cf4 TransactionScope\cf3 ())\par ??\{\par ??    \cf4 Database\cf3  \cf5 db\cf3  = \cf4 DatabaseFactory\cf3 .\cf5 CreateDatabase\cf3 (\cf6 "Testing"\cf3 );\par ??    \cf4 DbCommand\cf3  \cf5 cmd\cf3  = \cf5 db\cf3 .\cf5 GetStoredProcCommand\cf3 (\cf6 "usp_ErrorLog_Insert"\cf3 );\par ??    \cf5 db\cf3 .\cf5 AddInParameter\cf3 (\cf5 cmd\cf3 , \cf6 "Message"\cf3 , \cf5 System\cf3 .\cf5 Data\cf3 .\cf4 DbType\cf3 .\cf5 String\cf3 , \cf6 "Testing 1"\cf3 );\par ??    \cf5 db\cf3 .\cf5 AddInParameter\cf3 (\cf5 cmd\cf3 , \cf6 "UserID"\cf3 , \cf5 System\cf3 .\cf5 Data\cf3 .\cf4 DbType\cf3 .\cf5 Int32\cf3 , \cf7 5150\cf3 );\par ??    \cf5 db\cf3 .\cf5 ExecuteNonQuery\cf3 (\cf5 cmd\cf3 );\par ??\par ??    \cf4 Console\cf3 .\cf5 WriteLine\cf3 (\cf6 "Local Transaction ID: \{0\}"\cf3 , \par ??        \cf4 Transaction\cf3 .\cf5 Current\cf3 .\cf5 TransactionInformation\cf3 .\cf5 LocalIdentifier\cf3 );\par ??    \cf4 Console\cf3 .\cf5 WriteLine\cf3 (\cf6 "Distributed Transaction ID: \{0\}"\cf3 , \par ??        \cf4 Transaction\cf3 .\cf5 Current\cf3 .\cf5 TransactionInformation\cf3 .\cf5 DistributedIdentifier\cf3 .\cf5 ToString\cf3 ());\par ??\par ??    \cf4 Database\cf3  \cf5 db1\cf3  = \cf4 DatabaseFactory\cf3 .\cf5 CreateDatabase\cf3 (\cf6 "Testing1"\cf3 );\par ??    \cf4 DbCommand\cf3  \cf5 cmd1\cf3  = \cf5 db\cf3 .\cf5 GetStoredProcCommand\cf3 (\cf6 "usp_ErrorLog_Insert"\cf3 );\par ??    \cf5 db1\cf3 .\cf5 AddInParameter\cf3 (\cf5 cmd1\cf3 , \cf6 "Message"\cf3 , \cf5 System\cf3 .\cf5 Data\cf3 .\cf4 DbType\cf3 .\cf5 String\cf3 , \cf6 "Testing 2"\cf3 );\par ??    \cf5 db1\cf3 .\cf5 AddInParameter\cf3 (\cf5 cmd1\cf3 , \cf6 "UserID"\cf3 , \cf5 System\cf3 .\cf5 Data\cf3 .\cf4 DbType\cf3 .\cf5 Int32\cf3 , \cf7 5150\cf3 );\par ??    \cf5 db1\cf3 .\cf5 ExecuteNonQuery\cf3 (\cf5 cmd1\cf3 );\par ??\par ??    \cf4 Console\cf3 .\cf5 WriteLine\cf3 (\cf6 "Local Transaction ID: \{0\}"\cf3 , \par ??        \cf4 Transaction\cf3 .\cf5 Current\cf3 .\cf5 TransactionInformation\cf3 .\cf5 LocalIdentifier\cf3 );\par ??    \cf4 Console\cf3 .\cf5 WriteLine\cf3 (\cf6 "Distributed Transaction ID: \{0\}"\cf3 , \par ??        \cf4 Transaction\cf3 .\cf5 Current\cf3 .\cf5 TransactionInformation\cf3 .\cf5 DistributedIdentifier\cf3 .\cf5 ToString\cf3 ());\par ??\par ??    \cf5 scope\cf3 .\cf5 Complete\cf3 ();\par ??\}}
-->
        </p>
        <div style="OVERFLOW-Y: auto; FONT-SIZE: 9pt; BACKGROUND: #3f3f3f; WIDTH: 761px; COLOR: #dcdccc; FONT-FAMILY: consolas; HEIGHT: 250px">
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  176</span> <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">using</span> (<span style="COLOR: #2b91af">TransactionScope</span><span style="COLOR: #dfdfbf">scope</span> = <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">new</span><span style="COLOR: #2b91af">TransactionScope</span>())
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  177</span> {
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  178</span>     <span style="COLOR: #2b91af">Database</span><span style="COLOR: #dfdfbf">db</span> = <span style="COLOR: #2b91af">DatabaseFactory</span>.<span style="COLOR: #dfdfbf">CreateDatabase</span>(<span style="COLOR: #c89191">"Testing"</span>);
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  179</span>     <span style="COLOR: #2b91af">DbCommand</span><span style="COLOR: #dfdfbf">cmd</span> = <span style="COLOR: #dfdfbf">db</span>.<span style="COLOR: #dfdfbf">GetStoredProcCommand</span>(<span style="COLOR: #c89191">"usp_ErrorLog_Insert"</span>);
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  180</span>     <span style="COLOR: #dfdfbf">db</span>.<span style="COLOR: #dfdfbf">AddInParameter</span>(<span style="COLOR: #dfdfbf">cmd</span>, <span style="COLOR: #c89191">"Message"</span>, <span style="COLOR: #dfdfbf">System</span>.<span style="COLOR: #dfdfbf">Data</span>.<span style="COLOR: #2b91af">DbType</span>.<span style="COLOR: #dfdfbf">String</span>, <span style="COLOR: #c89191">"Testing
1"</span>);
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  181</span>     <span style="COLOR: #dfdfbf">db</span>.<span style="COLOR: #dfdfbf">AddInParameter</span>(<span style="COLOR: #dfdfbf">cmd</span>, <span style="COLOR: #c89191">"UserID"</span>, <span style="COLOR: #dfdfbf">System</span>.<span style="COLOR: #dfdfbf">Data</span>.<span style="COLOR: #2b91af">DbType</span>.<span style="COLOR: #dfdfbf">Int32</span>, <span style="COLOR: #8acccf">5150</span>);
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  182</span>     <span style="COLOR: #dfdfbf">db</span>.<span style="COLOR: #dfdfbf">ExecuteNonQuery</span>(<span style="COLOR: #dfdfbf">cmd</span>);
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  183</span> 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  184</span>     <span style="COLOR: #2b91af">Console</span>.<span style="COLOR: #dfdfbf">WriteLine</span>(<span style="COLOR: #c89191">"Local
Transaction ID: {0}"</span>, 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  185</span>         <span style="COLOR: #2b91af">Transaction</span>.<span style="COLOR: #dfdfbf">Current</span>.<span style="COLOR: #dfdfbf">TransactionInformation</span>.<span style="COLOR: #dfdfbf">LocalIdentifier</span>);
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  186</span>     <span style="COLOR: #2b91af">Console</span>.<span style="COLOR: #dfdfbf">WriteLine</span>(<span style="COLOR: #c89191">"Distributed
Transaction ID: {0}"</span>, 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  187</span>         <span style="COLOR: #2b91af">Transaction</span>.<span style="COLOR: #dfdfbf">Current</span>.<span style="COLOR: #dfdfbf">TransactionInformation</span>.<span style="COLOR: #dfdfbf">DistributedIdentifier</span>.<span style="COLOR: #dfdfbf">ToString</span>());
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  188</span> 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  189</span>     <span style="COLOR: #2b91af">Database</span><span style="COLOR: #dfdfbf">db1</span> = <span style="COLOR: #2b91af">DatabaseFactory</span>.<span style="COLOR: #dfdfbf">CreateDatabase</span>(<span style="COLOR: #c89191">"Testing1"</span>);
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  190</span>     <span style="COLOR: #2b91af">DbCommand</span><span style="COLOR: #dfdfbf">cmd1</span> = <span style="COLOR: #dfdfbf">db</span>.<span style="COLOR: #dfdfbf">GetStoredProcCommand</span>(<span style="COLOR: #c89191">"usp_ErrorLog_Insert"</span>);
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  191</span>     <span style="COLOR: #dfdfbf">db1</span>.<span style="COLOR: #dfdfbf">AddInParameter</span>(<span style="COLOR: #dfdfbf">cmd1</span>, <span style="COLOR: #c89191">"Message"</span>, <span style="COLOR: #dfdfbf">System</span>.<span style="COLOR: #dfdfbf">Data</span>.<span style="COLOR: #2b91af">DbType</span>.<span style="COLOR: #dfdfbf">String</span>, <span style="COLOR: #c89191">"Testing
2"</span>);
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  192</span>     <span style="COLOR: #dfdfbf">db1</span>.<span style="COLOR: #dfdfbf">AddInParameter</span>(<span style="COLOR: #dfdfbf">cmd1</span>, <span style="COLOR: #c89191">"UserID"</span>, <span style="COLOR: #dfdfbf">System</span>.<span style="COLOR: #dfdfbf">Data</span>.<span style="COLOR: #2b91af">DbType</span>.<span style="COLOR: #dfdfbf">Int32</span>, <span style="COLOR: #8acccf">5150</span>);
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  193</span>     <span style="COLOR: #dfdfbf">db1</span>.<span style="COLOR: #dfdfbf">ExecuteNonQuery</span>(<span style="COLOR: #dfdfbf">cmd1</span>);
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  194</span> 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  195</span>     <span style="COLOR: #2b91af">Console</span>.<span style="COLOR: #dfdfbf">WriteLine</span>(<span style="COLOR: #c89191">"Local
Transaction ID: {0}"</span>, 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  196</span>         <span style="COLOR: #2b91af">Transaction</span>.<span style="COLOR: #dfdfbf">Current</span>.<span style="COLOR: #dfdfbf">TransactionInformation</span>.<span style="COLOR: #dfdfbf">LocalIdentifier</span>);
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  197</span>     <span style="COLOR: #2b91af">Console</span>.<span style="COLOR: #dfdfbf">WriteLine</span>(<span style="COLOR: #c89191">"Distributed
Transaction ID: {0}"</span>, 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  198</span>         <span style="COLOR: #2b91af">Transaction</span>.<span style="COLOR: #dfdfbf">Current</span>.<span style="COLOR: #dfdfbf">TransactionInformation</span>.<span style="COLOR: #dfdfbf">DistributedIdentifier</span>.<span style="COLOR: #dfdfbf">ToString</span>());
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  199</span> 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  200</span>     <span style="COLOR: #dfdfbf">scope</span>.<span style="COLOR: #dfdfbf">Complete</span>();
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  201</span> }
</p>
        </div>
        <p>
 
</p>
        <p>
This writes the following to the command line:
</p>
        <blockquote>
          <p>
            <font face="Courier New" size="2">
              <strong>Local Transaction ID: 6737b756-2d5b-4eff-902d-15f9ccd5c26f:3<br />
Distributed Transaction ID: 00000000-0000-0000-0000-000000000000<br />
Local Transaction ID: 6737b756-2d5b-4eff-902d-15f9ccd5c26f:3<br />
Distributed Transaction ID: 00000000-0000-0000-0000-000000000000</strong>
            </font>
          </p>
        </blockquote>
        <p>
Whoa! How cool is that? No DTC promotion. Enterprise Library is intelligently deciding
to keep the connection open when it is part of the transaction. This will save a lot
of wasted time as the promotion to DTC adds a noticeable delay. If I wasn't using
Enterprise Library already, I'd switch now.
</p>
        <p>
        </p>
        <p>
Useful links:
</p>
        <ul>
          <li>
            <a href="http://msdn.microsoft.com/en-us/library/ms172152.aspx">Implementing an Implicit
Transaction using Transaction Scope</a>
          </li>
          <li>
            <a href="http://msdn.microsoft.com/en-us/library/ms730266.aspx">WCF Transactions</a>
          </li>
          <li>
            <a href="http://msdn.microsoft.com/en-us/library/ms973865.aspx">Introducing System.Transactions
in the .NET Framework 2.0</a>
          </li>
        </ul>
        <img width="0" height="0" src="http://offroadcoder.com/aggbug.ashx?id=5aef3f0a-3e66-4e87-8469-0411651d2aba" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Communication with the underlying transaction manager has failed.</title>
    <link rel="alternate" type="text/html" href="http://offroadcoder.com/2008/10/30/CommunicationWithTheUnderlyingTransactionManagerHasFailed.aspx" />
    <id>http://offroadcoder.com/PermaLink,guid,bc3f77a3-9d3a-44cf-ba92-d71125cdc5bd.aspx</id>
    <published>2008-10-29T19:54:29.90625-07:00</published>
    <updated>2008-10-29T19:54:29.90625-07:00</updated>
    <category term=".NET Framework" label=".NET Framework" scheme="http://offroadcoder.com/CategoryView,category,NETFramework.aspx" />
    <category term="C#" label="C#" scheme="http://offroadcoder.com/CategoryView,category,C.aspx" />
    <category term="MSDTC" label="MSDTC" scheme="http://offroadcoder.com/CategoryView,category,MSDTC.aspx" />
    <category term="WCF" label="WCF" scheme="http://offroadcoder.com/CategoryView,category,WCF.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
Don't be so quick to blame the service or MSDTC when you see the error "Communication
with the underlying transaction manager has failed."
</p>
        <p>
          <strong>Symptom:</strong>
        </p>
        <p>
An error message that reads something like: 
</p>
        <blockquote>
          <p>
System.Transactions.TransactionManagerCommunicationException: Communication with the
underlying transaction manager has failed. ---&gt; System.Runtime.InteropServices.COMException
(0x80004005): Error HRESULT E_FAIL has been returned from a call to a COM component.
</p>
        </blockquote>
        <p>
          <strong>Solutions:</strong>
        </p>
        <p>
  
</p>
        <p>
"Check your firewall settings" is what you will find in almost all forum posts and
on MSDN. You need port 135 open bi-directionally for RPC's end point mapper (EPM).
You also need ports 1024-5000 open bi-directionally if you have not specified your
own port settings for RPC in the registry. If you have your own ports specified in
the registry, then those need to be open bi-directionally. 
</p>
        <p>
  
</p>
        <p>
          <strong>
            <em>WHAT ?!? </em>
          </strong>It may also be your code causing the issue. If
you are using TransactionScope, you have to be mindful of every method called within
the using braces. Looking at the code below, you will see two service calls and a
seemingly innocuous <em>ShouldContinue()</em> method checking to see if the second
operation should be called. 
</p>
        <blockquote>
          <p>
            <font color="#0000ff">using</font> (TransactionScope scope = new TransactionScope()) 
</p>
          <p>
            <font color="#0000ff">using</font> (MyServiceClient proxy = new MyServiceClient()) 
</p>
          <p>
{ 
</p>
          <p>
       proxy.DoOperationOne(someID); 
</p>
          <p>
       
</p>
          <p>
       <font color="#0000ff">if</font> (ShouldContinue()) <font color="#008000">//
uh, oh! What if this has an ADO.NET connection that is opened and closed inside it?</font></p>
          <p>
       { 
</p>
          <p>
              
proxy.DoOperationTwo(someOtherID); 
</p>
          <p>
       } 
</p>
          <p>
}
</p>
        </blockquote>
        <p>
If <em>ShouldContinue()</em> opens and closes an SqlConnection, the TransactionScope
object has no means by which to commit or rollback this part of the transaction. This
will cause the error "Communication with the underlying transaction manager has failed." 
</p>
        <p>
  
</p>
        <p>
1. If you do not need to results of <em>DoOperationOne()</em> to feed <em>ShouldContinue()</em>,
then do that logic before the TransactionScope using block. 
</p>
        <p>
2. If you do need the result of <em>DoOperationOne()</em> to feed <em>ShouldContinue()</em>,
then you can wrap the internals of <em>ShouldContinue()</em> with a TransactionScope
using block specifying TransactionScopeOption.Suppress. This will not add the resource
access contained within the block to the ambient transaction. 
</p>
        <p>
3. Use an intelligent data access library like Enterprise Library that manages your
connections for you. It won't close the connection if enlisted in a transaction. 
</p>
        <p>
  
</p>
        <p>
Look at your code before you involve your network dudes. This is more common when
integrating legacy code with new service calls. 
</p>
        <img width="0" height="0" src="http://offroadcoder.com/aggbug.ashx?id=bc3f77a3-9d3a-44cf-ba92-d71125cdc5bd" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Exposing existing WCF services to ASP.NET AJAX clients</title>
    <link rel="alternate" type="text/html" href="http://offroadcoder.com/2008/09/21/ExposingExistingWCFServicesToASPNETAJAXClients.aspx" />
    <id>http://offroadcoder.com/PermaLink,guid,cfeeb9f7-2a9e-40a5-99ce-dea714e3284d.aspx</id>
    <published>2008-09-21T09:21:24.0155066-07:00</published>
    <updated>2008-09-21T09:21:24.0155066-07:00</updated>
    <category term=".NET Framework" label=".NET Framework" scheme="http://offroadcoder.com/CategoryView,category,NETFramework.aspx" />
    <category term="AJAX" label="AJAX" scheme="http://offroadcoder.com/CategoryView,category,AJAX.aspx" />
    <category term="ASP.NET" label="ASP.NET" scheme="http://offroadcoder.com/CategoryView,category,ASPNET.aspx" />
    <category term="C#" label="C#" scheme="http://offroadcoder.com/CategoryView,category,C.aspx" />
    <category term="Javascript" label="Javascript" scheme="http://offroadcoder.com/CategoryView,category,Javascript.aspx" />
    <category term="WCF" label="WCF" scheme="http://offroadcoder.com/CategoryView,category,WCF.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
WCF never ceases to amaze me. Around every corner is another fascinating use for WCF,
and much forethought on Microsoft's part to make it look and behave great. I wanted
to expose my services to my AJAX functions on my web site. I did not want to change
my class library because it is used by other clients. I could just add the service
classes to this web site, but why re-do when you can re-use.
</p>
        <p>
If you have an existing WCF Service Library, you will need to expose it with the <font color="#0000ff">AspNetCompatibilityRequirementsMode</font>.Allowed
attribute on the service class to make it visible to ASP.NET clients. To avoid changing
your service library in any way, the easiest thing to do is to add a new class to
your web site that inherits from your service class. In this example, my existing
service library uses the <em>JeepServices</em> namespace. Notice there is no implementation
in this class. It is simply a placeholder for the real service implementation with
the compatibility attribute attached.
</p>
        <p>
          <!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red225\green225\blue138;\red63\green63\blue63;\red220\green220\blue204;\red223\green223\blue191;\red43\green145\blue175;}??\fs18 \cf1\cb2\highlight2 {\b using}\cf3  \cf4 System\cf3 ;\par ??\cf1 {\b using}\cf3  \cf4 System\cf3 .\cf4 Linq\cf3 ;\par ??\cf1 {\b using}\cf3  \cf4 System\cf3 .\cf4 Runtime\cf3 .\cf4 Serialization\cf3 ;\par ??\cf1 {\b using}\cf3  \cf4 System\cf3 .\cf4 ServiceModel\cf3 ;\par ??\cf1 {\b using}\cf3  \cf4 System\cf3 .\cf4 ServiceModel\cf3 .\cf4 Activation\cf3 ;\par ??\cf1 {\b using}\cf3  \cf4 System\cf3 .\cf4 ServiceModel\cf3 .\cf4 Web\cf3 ;\par ??\par ??[\cf5 ServiceBehavior\cf3 (\cf4 IncludeExceptionDetailInFaults\cf3  = \cf1 {\b true}\cf3 )]\par ??[\cf5 AspNetCompatibilityRequirements\cf3 (\cf4 RequirementsMode\cf3  = \cf5 AspNetCompatibilityRequirementsMode\cf3 .\cf4 Allowed\cf3 )]\par ??\cf1 {\b public}\cf3  \cf1 {\b class}\cf3  \cf5 WebHttpService\cf3  : \cf4 JeepServices\cf3 .\cf5 Service\par ??\cf3 \{\par ??\}}
-->
        </p>
        <p>
          <!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red225\green225\blue138;\red63\green63\blue63;\red220\green220\blue204;\red223\green223\blue191;\red43\green145\blue175;}??\fs18 \cf1\cb2\highlight2 {\b using}\cf3  \cf4 System\cf3 .\cf4 ServiceModel\cf3 ;\par ??\cf1 {\b using}\cf3  \cf4 System\cf3 .\cf4 ServiceModel\cf3 .\cf4 Activation\cf3 ;\par ??\par ??[\cf5 ServiceBehavior\cf3 (\cf4 IncludeExceptionDetailInFaults\cf3  = \cf1 {\b true}\cf3 )]\par ??[\cf5 AspNetCompatibilityRequirements\cf3 (\cf4 RequirementsMode\cf3  = \cf5 AspNetCompatibilityRequirementsMode\cf3 .\cf4 Allowed\cf3 )]\par ??\cf1 {\b public}\cf3  \cf1 {\b class}\cf3  \cf5 WebHttpService\cf3  : \cf4 JeepServices\cf3 .\cf5 Service\par ??\cf3 \{\par ??\}}
-->
        </p>
        <div style="font-size: 9pt; background: #3f3f3f; width: 817px; color: #dcdccc; font-family: consolas; height: 126px">
          <p style="margin: 0px">
            <span style="color: #85ac8d">    1</span> <span style="font-weight: bold; color: #e1e18a">using</span><span style="color: #dfdfbf">System</span>.<span style="color: #dfdfbf">ServiceModel</span>;
</p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">    2</span> <span style="font-weight: bold; color: #e1e18a">using</span><span style="color: #dfdfbf">System</span>.<span style="color: #dfdfbf">ServiceModel</span>.<span style="color: #dfdfbf">Activation</span>;
</p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">    3</span> 
</p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">    4</span> [<span style="color: #2b91af">ServiceBehavior</span>]
</p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">    5</span> [<span style="color: #2b91af">AspNetCompatibilityRequirements</span>(<span style="color: #dfdfbf">RequirementsMode</span> = <span style="color: #2b91af">AspNetCompatibilityRequirementsMode</span>.<span style="color: #dfdfbf">Allowed</span>)]
</p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">    6</span> <span style="font-weight: bold; color: #e1e18a">public</span><span style="font-weight: bold; color: #e1e18a">class</span><span style="color: #2b91af">WebHttpService</span> : <span style="color: #dfdfbf">JeepServices</span>.<span style="color: #2b91af">Service</span></p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">    7</span> {
</p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">    8</span> }
</p>
        </div>
        <p>
        </p>
        <p>
Now that I have a ASP.NET compatible service, I need to expose it to the web site
clients. Create a service file (.svc), and change the <em>Service</em> and <em>CodeBehind</em> attributes
to point to the .svc file. The last thing you need is the <em>Factory</em> attribute.
This notifies WCF of this service, eliminating the need for a configuration file entry
for the service endpoint. In fact, you don't even need the &lt;system.servicemodel&gt;
in your configuration file at all. This is because it is only hosted as a web script,
and cannot be called outside of the web site.
</p>
        <p>
          <!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red0\green0\blue0;\red255\green238\blue98;\red239\green239\blue143;\red63\green63\blue63;\red220\green220\blue204;\red227\green206\blue171;\red223\green223\blue191;\red204\green147\blue147;}??\fs18 \cb2\highlight2 &lt;%\cf3\cb4\highlight4 @\cf5  \cf6 ServiceHost\cf5  \cf7 Language\cf3 =\cf8 "C#"\cf5  \cf7 Debug\cf3 =\cf8 "true"\cf5  \cf7 Service\cf3 =\cf8 "WebHttpService"\cf5  \cf7 CodeBehind\cf3 =\cf8 "~/App_Code/WebHttpService.cs"\par ??\cf5 \tab \cf7 Factory\cf3 =\cf8 "System.ServiceModel.Activation.WebScriptServiceHostFactory"\cf5  \cf0\cb2\highlight2 %&gt;}
-->
        </p>
        <div style="font-size: 9pt; background: #3f3f3f; width: 816px; color: #dcdccc; font-family: consolas; height: 43px">
          <p style="margin: 0px">
            <span style="color: #85ac8d">    1</span> <span style="background: #ffee62">&lt;%</span><span style="color: #efef8f">@</span><span style="color: #e3ceab">ServiceHost</span><span style="color: #dfdfbf">Language</span><span style="color: #efef8f">=</span><span style="color: #cc9393">"C#"</span><span style="color: #dfdfbf">Debug</span><span style="color: #efef8f">=</span><span style="color: #cc9393">"true"</span><span style="color: #dfdfbf">Service</span><span style="color: #efef8f">=</span><span style="color: #cc9393">"WebHttpService"</span><span style="color: #dfdfbf">CodeBehind</span><span style="color: #efef8f">=</span><span style="color: #cc9393">"~/App_Code/WebHttpService.cs"</span></p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">    2</span>     <span style="color: #dfdfbf">Factory</span><span style="color: #efef8f">=</span><span style="color: #cc9393">"System.ServiceModel.Activation.WebScriptServiceHostFactory"</span><span style="background: #ffee62">%&gt;</span></p>
        </div>
        <p>
 
</p>
        <p>
In your web page you will need a few things. First your will need a <em>ScriptManager</em> with
a <em>ServiceReference</em> to the .svc file. You will then need the Javascript functions
to make the call (<em>DoJeepWork</em>), handle the success message (<em>OnJeepWorkSucceeded</em>),
and handle the failure message (<em>OnJeepWorkFailed</em>). Notice in <em>DoJeepWork</em> that
you don't call the service by it's service name <em>WebHttpService</em>, you call
it by the ServiceContract namespace and name. For this example, my interface has ServiceContract
attributes Namespace = "JeepServices", and Name = "JeepServiceContract". Now you just
wire up a ASP.NET control's OnClientClick or an input or anchor tag's onclick to <em>DoJeepWork()</em> and
you are good to go.
</p>
        <p>
          <!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red0\green0\blue0;\red255\green238\blue98;\red239\green239\blue143;\red63\green63\blue63;\red220\green220\blue204;\red227\green206\blue171;\red223\green223\blue191;\red204\green147\blue147;\red225\green225\blue138;\red200\green145\blue145;\red127\green159\blue127;}??\fs18 \cb2\highlight2 &lt;%\cf3\cb4\highlight4 @\cf5  \cf6 Page\cf5  \cf7 Language\cf3 =\cf8 "C#"\cf5  \cf7 AutoEventWireup\cf3 =\cf8 "true"\cf5  \cf7 CodeFile\cf3 =\cf8 "Default.aspx.cs"\cf5  \cf7 Inherits\cf3 =\cf8 "_Default"\cf5  \cf0\cb2\highlight2 %&gt;\par ??\par ??\cf3\cb4\highlight4 &lt;!\cf6 DOCTYPE\cf5  \cf7 html\cf5  \cf7 PUBLIC\cf5  \cf8 "-//W3C//DTD XHTML 1.0 Transitional//EN"\cf5  \cf8 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"\cf3 &gt;\par ??&lt;\cf6 html\cf5  \cf7 xmlns\cf3 =\cf8 "http://www.w3.org/1999/xhtml"\cf3 &gt;\par ??&lt;\cf6 head\cf5  \cf7 runat\cf3 =\cf8 "server"\cf3 &gt;\par ??\cf5 \tab \cf3 &lt;\cf6 title\cf3 &gt;\cf5 Test page\cf3 &lt;/\cf6 title\cf3 &gt;\par ??\par ??\cf5 \tab \cf3 &lt;\cf6 script\cf5  \cf7 type\cf3 =\cf8 "text/javascript"\cf3 &gt;\par ??\cf5 \tab \tab \cf9 {\b function}\cf5  \cf7 DoJeepWork\cf5 ()\par ??\tab \tab \{    \par ??\tab \tab \tab \cf7 JeepServices\cf5 .\cf7 JeepServiceContract\cf5 .\cf7 DoWork\cf5 (\cf7 OnJeepWorkSuccedeed\cf5 , \cf7 OnJeepWorkFailed\cf5 );\par ??\tab \tab \}\par ??\tab \tab \cf9 {\b function}\cf5  \cf7 OnJeepWorkSuccedeed\cf5 (\cf7 res\cf5 )\par ??\tab \tab \{\par ??\tab \tab \tab \cf7 document\cf5 .\cf7 getElementById\cf5 (\cf10 "&lt;%= this.lblMessage.ClientID %&gt;"\cf5 ).\cf7 innerText\cf5  = \cf7 res\cf5 ;\par ??\tab \tab \}\par ??\tab \tab \cf9 {\b function}\cf5  \cf7 OnJeepWorkFailed\cf5 (\cf7 error\cf5 )\par ??\tab \tab \{\par ??\tab \tab     \cf11 // Alert user to the error.    \par ??\cf5 \tab \tab     \cf7 alert\cf5 (\cf7 error\cf5 .\cf7 get_message\cf5 ());\par ??\tab \tab \}\par ??\tab \cf3 &lt;/\cf6 script\cf3 &gt;\par ??\par ??&lt;/\cf6 head\cf3 &gt;\par ??&lt;\cf6 body\cf3 &gt;\par ??\cf5 \tab \cf3 &lt;\cf6 form\cf5  \cf7 id\cf3 =\cf8 "form1"\cf5  \cf7 runat\cf3 =\cf8 "server"\cf3 &gt;\par ??\cf5 \tab \cf3 &lt;\cf6 div\cf3 &gt;\par ??\cf5 \tab \tab \cf3 &lt;\cf6 asp\cf3 :\cf6 ScriptManager\cf5  \cf7 runat\cf3 =\cf8 "server"\cf3 &gt;\par ??\cf5 \tab \tab \tab \cf3 &lt;\cf6 Services\cf3 &gt;\par ??\cf5 \tab \tab \tab \tab \cf3 &lt;\cf6 asp\cf3 :\cf6 ServiceReference\cf5  \cf7 Path\cf3 =\cf8 "~/Services/WebHttpService.svc"\cf5  \cf7 InlineScript\cf3 =\cf8 "false"\cf5  \cf3 /&gt;\par ??\cf5 \tab \tab \tab \cf3 &lt;/\cf6 Services\cf3 &gt;\par ??\cf5 \tab \tab \cf3 &lt;/\cf6 asp\cf3 :\cf6 ScriptManager\cf3 &gt;\par ??\cf5 \tab \tab \cf3 &lt;\cf6 asp\cf3 :\cf6 Label\cf5  \cf7 ID\cf3 =\cf8 "lblMessage"\cf5  \cf7 runat\cf3 =\cf8 "server"\cf5  \cf7 Text\cf3 =\cf8 "No work has been done"\cf5  \cf3 /&gt;\cf5  \cf3 &lt;\cf6 a\cf5  \cf7 href\cf3 =\cf8 "javascript:void(0); DoJeepWork()"\cf3 &gt;\cf5 Do Work\cf3 &lt;/\cf6 a\cf3 &gt;\par ??\cf5 \tab \cf3 &lt;/\cf6 div\cf3 &gt;\par ??\cf5 \tab \cf3 &lt;/\cf6 form\cf3 &gt;\par ??&lt;/\cf6 body\cf3 &gt;\par ??&lt;/\cf6 html\cf3 &gt;}
-->
        </p>
        <p>
        </p>
        <p>
          <!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red0\green0\blue0;\red255\green238\blue98;\red239\green239\blue143;\red63\green63\blue63;\red220\green220\blue204;\red227\green206\blue171;\red223\green223\blue191;\red204\green147\blue147;\red225\green225\blue138;\red200\green145\blue145;\red127\green159\blue127;}??\fs18 \cb2\highlight2 &lt;%\cf3\cb4\highlight4 @\cf5  \cf6 Page\cf5  \cf7 Language\cf3 =\cf8 "C#"\cf5  \cf7 AutoEventWireup\cf3 =\cf8 "true"\cf5  \cf7 CodeFile\cf3 =\cf8 "Default.aspx.cs"\cf5  \cf7 Inherits\cf3 =\cf8 "_Default"\cf5  \cf0\cb2\highlight2 %&gt;\par ??\par ??\cf3\cb4\highlight4 &lt;!\cf6 DOCTYPE\cf5  \cf7 html\cf5  \cf7 PUBLIC\cf5  \cf8 "-//W3C//DTD XHTML 1.0 Transitional//EN"\par ??"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"\cf3 &gt;\par ??&lt;\cf6 html\cf5  \cf7 xmlns\cf3 =\cf8 "http://www.w3.org/1999/xhtml"\cf3 &gt;\par ??&lt;\cf6 head\cf5  \cf7 runat\cf3 =\cf8 "server"\cf3 &gt;\par ??\cf5 \tab \cf3 &lt;\cf6 title\cf3 &gt;\cf5 Test page\cf3 &lt;/\cf6 title\cf3 &gt;\par ??\par ??\cf5 \tab \cf3 &lt;\cf6 script\cf5  \cf7 type\cf3 =\cf8 "text/javascript"\cf3 &gt;\par ??\cf5 \tab \tab \cf9 {\b function}\cf5  \cf7 DoJeepWork\cf5 () \{\par ??\tab \tab \tab \cf7 JeepServices\cf5 .\cf7 JeepServiceContract\cf5 .\cf7 DoWork\cf5 (\cf7 OnJeepWorkSuccedeed\cf5 , \cf7 OnJeepWorkFailed\cf5 );\par ??\tab \tab \}\par ??\tab \tab \cf9 {\b function}\cf5  \cf7 OnJeepWorkSuccedeed\cf5 (\cf7 res\cf5 ) \{\par ??\tab \tab \tab \cf7 document\cf5 .\cf7 getElementById\cf5 (\cf10 "&lt;%= this.lblMessage.ClientID %&gt;"\cf5 ).\cf7 innerText\cf5  = \cf7 res\cf5 ;\par ??\tab \tab \}\par ??\tab \tab \cf9 {\b function}\cf5  \cf7 OnJeepWorkFailed\cf5 (\cf7 error\cf5 ) \{\par ??\tab \tab \tab \cf11 // Alert user to the error.    \par ??\cf5 \tab \tab \tab \cf7 alert\cf5 (\cf7 error\cf5 .\cf7 get_message\cf5 ());\par ??\tab \tab \}\par ??\tab \cf3 &lt;/\cf6 script\cf3 &gt;\par ??\par ??&lt;/\cf6 head\cf3 &gt;\par ??&lt;\cf6 body\cf3 &gt;\par ??\cf5 \tab \cf3 &lt;\cf6 form\cf5  \cf7 id\cf3 =\cf8 "form1"\cf5  \cf7 runat\cf3 =\cf8 "server"\cf3 &gt;\par ??\cf5 \tab \cf3 &lt;\cf6 div\cf3 &gt;\par ??\cf5 \tab \tab \cf3 &lt;\cf6 asp\cf3 :\cf6 ScriptManager\cf5  \cf7 runat\cf3 =\cf8 "server"\cf3 &gt;\par ??\cf5 \tab \tab \tab \cf3 &lt;\cf6 Services\cf3 &gt;\par ??\cf5 \tab \tab \tab \tab \cf3 &lt;\cf6 asp\cf3 :\cf6 ServiceReference\cf5  \cf7 Path\cf3 =\cf8 "~/Services/WebHttpService.svc"\cf5  \cf7 InlineScript\cf3 =\cf8 "false"\cf5  \cf3 /&gt;\par ??\cf5 \tab \tab \tab \cf3 &lt;/\cf6 Services\cf3 &gt;\par ??\cf5 \tab \tab \cf3 &lt;/\cf6 asp\cf3 :\cf6 ScriptManager\cf3 &gt;\par ??\cf5 \tab \tab \cf3 &lt;\cf6 asp\cf3 :\cf6 Label\cf5  \cf7 ID\cf3 =\cf8 "lblMessage"\cf5  \cf7 runat\cf3 =\cf8 "server"\cf5  \cf7 Text\cf3 =\cf8 "No work has been done"\cf5  \cf3 /&gt;\par ??\cf5 \tab \tab \cf3 &lt;\cf6 a\cf5  \cf7 href\cf3 =\cf8 "javascript:void(0); DoJeepWork()"\cf3 &gt;\cf5 Do Work\cf3 &lt;/\cf6 a\cf3 &gt;\par ??\cf5 \tab \cf3 &lt;/\cf6 div\cf3 &gt;\par ??\cf5 \tab \cf3 &lt;/\cf6 form\cf3 &gt;\par ??&lt;/\cf6 body\cf3 &gt;\par ??&lt;/\cf6 html\cf3 &gt;\par ??}
-->
        </p>
        <div style="font-size: 9pt; background: #3f3f3f; width: 819px; color: #dcdccc; font-family: consolas; height: 519px">
          <p style="margin: 0px">
            <span style="color: #85ac8d">    1</span> <span style="background: #ffee62">&lt;%</span><span style="color: #efef8f">@</span><span style="color: #e3ceab">Page</span><span style="color: #dfdfbf">Language</span><span style="color: #efef8f">=</span><span style="color: #cc9393">"C#"</span><span style="color: #dfdfbf">AutoEventWireup</span><span style="color: #efef8f">=</span><span style="color: #cc9393">"true"</span><span style="color: #dfdfbf">CodeFile</span><span style="color: #efef8f">=</span><span style="color: #cc9393">"Default.aspx.cs"</span><span style="color: #dfdfbf">Inherits</span><span style="color: #efef8f">=</span><span style="color: #cc9393">"_Default"</span><span style="background: #ffee62">%&gt;</span></p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">    2</span> 
</p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">    3</span> <span style="color: #efef8f">&lt;!</span><span style="color: #e3ceab">DOCTYPE</span><span style="color: #dfdfbf">html</span><span style="color: #dfdfbf">PUBLIC</span><span style="color: #cc9393">"-//W3C//DTD
XHTML 1.0 Transitional//EN"</span></p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">    4</span> <span style="color: #cc9393">"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"</span><span style="color: #efef8f">&gt;</span></p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">    5</span> <span style="color: #efef8f">&lt;</span><span style="color: #e3ceab">html</span><span style="color: #dfdfbf">xmlns</span><span style="color: #efef8f">=</span><span style="color: #cc9393">"http://www.w3.org/1999/xhtml"</span><span style="color: #efef8f">&gt;</span></p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">    6</span> <span style="color: #efef8f">&lt;</span><span style="color: #e3ceab">head</span><span style="color: #dfdfbf">runat</span><span style="color: #efef8f">=</span><span style="color: #cc9393">"server"</span><span style="color: #efef8f">&gt;</span></p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">    7</span>     <span style="color: #efef8f">&lt;</span><span style="color: #e3ceab">title</span><span style="color: #efef8f">&gt;</span>Test
page<span style="color: #efef8f">&lt;/</span><span style="color: #e3ceab">title</span><span style="color: #efef8f">&gt;</span></p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">    8</span> 
</p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">    9</span>     <span style="color: #efef8f">&lt;</span><span style="color: #e3ceab">script</span><span style="color: #dfdfbf">type</span><span style="color: #efef8f">=</span><span style="color: #cc9393">"text/javascript"</span><span style="color: #efef8f">&gt;</span></p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">   10</span>         <span style="font-weight: bold; color: #e1e18a">function</span><span style="color: #dfdfbf">DoJeepWork</span>()
{
</p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">   11</span>             <span style="color: #dfdfbf">JeepServices</span>.<span style="color: #dfdfbf">JeepServiceContract</span>.<span style="color: #dfdfbf">DoWork</span>(<span style="color: #dfdfbf">OnJeepWorkSuccedeed</span>, <span style="color: #dfdfbf">OnJeepWorkFailed</span>);
</p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">   12</span>        
}
</p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">   13</span>         <span style="font-weight: bold; color: #e1e18a">function</span><span style="color: #dfdfbf">OnJeepWorkSuccedeed</span>(<span style="color: #dfdfbf">res</span>)
{
</p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">   14</span>             <span style="color: #dfdfbf">document</span>.<span style="color: #dfdfbf">getElementById</span>(<span style="color: #c89191">"&lt;%=
this.lblMessage.ClientID %&gt;"</span>).<span style="color: #dfdfbf">innerText</span> = <span style="color: #dfdfbf">res</span>;
</p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">   15</span>        
}
</p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">   16</span>         <span style="font-weight: bold; color: #e1e18a">function</span><span style="color: #dfdfbf">OnJeepWorkFailed</span>(<span style="color: #dfdfbf">error</span>)
{
</p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">   17</span>             <span style="color: #7f9f7f">//
Alert user to the error.    </span></p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">   18</span>             <span style="color: #dfdfbf">alert</span>(<span style="color: #dfdfbf">error</span>.<span style="color: #dfdfbf">get_message</span>());
</p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">   19</span>        
}
</p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">   20</span>     <span style="color: #efef8f">&lt;/</span><span style="color: #e3ceab">script</span><span style="color: #efef8f">&gt;</span></p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">   21</span> 
</p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">   22</span> <span style="color: #efef8f">&lt;/</span><span style="color: #e3ceab">head</span><span style="color: #efef8f">&gt;</span></p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">   23</span> <span style="color: #efef8f">&lt;</span><span style="color: #e3ceab">body</span><span style="color: #efef8f">&gt;</span></p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">   24</span>     <span style="color: #efef8f">&lt;</span><span style="color: #e3ceab">form</span><span style="color: #dfdfbf">id</span><span style="color: #efef8f">=</span><span style="color: #cc9393">"form1"</span><span style="color: #dfdfbf">runat</span><span style="color: #efef8f">=</span><span style="color: #cc9393">"server"</span><span style="color: #efef8f">&gt;</span></p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">   25</span>     <span style="color: #efef8f">&lt;</span><span style="color: #e3ceab">div</span><span style="color: #efef8f">&gt;</span></p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">   26</span>         <span style="color: #efef8f">&lt;</span><span style="color: #e3ceab">asp</span><span style="color: #efef8f">:</span><span style="color: #e3ceab">ScriptManager</span><span style="color: #dfdfbf">runat</span><span style="color: #efef8f">=</span><span style="color: #cc9393">"server"</span><span style="color: #efef8f">&gt;</span></p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">   27</span>             <span style="color: #efef8f">&lt;</span><span style="color: #e3ceab">Services</span><span style="color: #efef8f">&gt;</span></p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">   28</span>                 <span style="color: #efef8f">&lt;</span><span style="color: #e3ceab">asp</span><span style="color: #efef8f">:</span><span style="color: #e3ceab">ServiceReference</span><span style="color: #dfdfbf">Path</span><span style="color: #efef8f">=</span><span style="color: #cc9393">"~/Services/WebHttpService.svc"</span><span style="color: #dfdfbf">InlineScript</span><span style="color: #efef8f">=</span><span style="color: #cc9393">"false"</span><span style="color: #efef8f">/&gt;</span></p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">   29</span>             <span style="color: #efef8f">&lt;/</span><span style="color: #e3ceab">Services</span><span style="color: #efef8f">&gt;</span></p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">   30</span>         <span style="color: #efef8f">&lt;/</span><span style="color: #e3ceab">asp</span><span style="color: #efef8f">:</span><span style="color: #e3ceab">ScriptManager</span><span style="color: #efef8f">&gt;</span></p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">   31</span>         <span style="color: #efef8f">&lt;</span><span style="color: #e3ceab">asp</span><span style="color: #efef8f">:</span><span style="color: #e3ceab">Label</span><span style="color: #dfdfbf">ID</span><span style="color: #efef8f">=</span><span style="color: #cc9393">"lblMessage"</span><span style="color: #dfdfbf">runat</span><span style="color: #efef8f">=</span><span style="color: #cc9393">"server"</span><span style="color: #dfdfbf">Text</span><span style="color: #efef8f">=</span><span style="color: #cc9393">"No
work has been done"</span><span style="color: #efef8f">/&gt;</span></p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">   32</span>         <span style="color: #efef8f">&lt;</span><span style="color: #e3ceab">a</span><span style="color: #dfdfbf">href</span><span style="color: #efef8f">=</span><span style="color: #cc9393">"javascript:void(0);
DoJeepWork()"</span><span style="color: #efef8f">&gt;</span>Do Work<span style="color: #efef8f">&lt;/</span><span style="color: #e3ceab">a</span><span style="color: #efef8f">&gt;</span></p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">   33</span>     <span style="color: #efef8f">&lt;/</span><span style="color: #e3ceab">div</span><span style="color: #efef8f">&gt;</span></p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">   34</span>     <span style="color: #efef8f">&lt;/</span><span style="color: #e3ceab">form</span><span style="color: #efef8f">&gt;</span></p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">   35</span> <span style="color: #efef8f">&lt;/</span><span style="color: #e3ceab">body</span><span style="color: #efef8f">&gt;</span></p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">   36</span> <span style="color: #efef8f">&lt;/</span><span style="color: #e3ceab">html</span><span style="color: #efef8f">&gt;</span></p>
        </div>
        <p>
 
</p>
        <p>
Mission accomplished! Here you've seen how to expose an existing WCF service library
without changing any code in the library itself. Adding two files allowed the service
to be exposed to your AJAX clients. Best of all, there is no configuration file changes
to make.
</p>
        <p>
        </p>
        <p>
Useful Links:
</p>
        <ul>
          <li>
            <a href="http://msdn.microsoft.com/en-us/library/bb514961.aspx">Exposing WCF Services
to Client Script</a>
          </li>
        </ul>
        <img width="0" height="0" src="http://offroadcoder.com/aggbug.ashx?id=cfeeb9f7-2a9e-40a5-99ce-dea714e3284d" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Hosting an MSMQ WCF Service in WAS</title>
    <link rel="alternate" type="text/html" href="http://offroadcoder.com/2008/09/17/HostingAnMSMQWCFServiceInWAS.aspx" />
    <id>http://offroadcoder.com/PermaLink,guid,49e557e3-d9dd-4705-865f-71c4f468ed1b.aspx</id>
    <published>2008-09-16T18:48:22.605375-07:00</published>
    <updated>2008-09-16T18:52:10.21475-07:00</updated>
    <category term=".NET Framework" label=".NET Framework" scheme="http://offroadcoder.com/CategoryView,category,NETFramework.aspx" />
    <category term="C#" label="C#" scheme="http://offroadcoder.com/CategoryView,category,C.aspx" />
    <category term="WAS" label="WAS" scheme="http://offroadcoder.com/CategoryView,category,WAS.aspx" />
    <category term="WCF" label="WCF" scheme="http://offroadcoder.com/CategoryView,category,WCF.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
Hosting an MSMQ service is a little bit different than the other bindings. Since WCF
is using MSMQ as a transport mechanism, you must setup the queues, permissions, and
bindingConfigurations to allow this to happen. Surprisingly, MSDN has a <a href="http://msdn.microsoft.com/en-us/library/ms752246.aspx">good
sample article</a> that goes into sufficient detail on how to set this up for the
3.5 WF-WCF-CardSpace samples. 
</p>
        <p>
I have read in other articles that the AppPool must have an interactive identity and
that the queue names needed to match the name of the .svc file. I did not find this
to be the case. I was able to use the <em>NetworkService</em> account for my AppPool
after adding receive and peek permissions for <em>NetworkService</em> on my queue.
Communication between client and WAS worked fine with my service file named WasServices.svc
and my queue address as <a title="net.msmq://localhost/private/QueuedService1" href="net.msmq://localhost/private/QueuedService1">net.msmq://localhost/private/QueuedService1</a>.
</p>
        <p>
You can download my solution with the following link: <a href="http://scott.klueppel.net/content/binary/WasServices.zip">WasServices.zip</a> (78K)
</p>
        <p>
Additional Info:
</p>
        <ul>
          <li>
            <a href="http://msdn.microsoft.com/en-us/library/ms752246.aspx">MSMQ Activation (MSDN)</a>
          </li>
          <li>
            <a href="http://idesign.net/idesign/DesktopDefault.aspx?tabindex=5&amp;tabid=11#WCFEssentials">IDesign
Code Library - Look for the WAS Hosting download</a>
          </li>
        </ul>
        <img width="0" height="0" src="http://offroadcoder.com/aggbug.ashx?id=49e557e3-d9dd-4705-865f-71c4f468ed1b" />
      </div>
    </content>
  </entry>
  <entry>
    <title>WASed up and ready to go</title>
    <link rel="alternate" type="text/html" href="http://offroadcoder.com/2008/09/13/WASedUpAndReadyToGo.aspx" />
    <id>http://offroadcoder.com/PermaLink,guid,a3e76678-c8fe-4440-898d-7739c8c99efb.aspx</id>
    <published>2008-09-12T21:58:31.276-07:00</published>
    <updated>2008-09-13T08:33:18.3385-07:00</updated>
    <category term=".NET Framework" label=".NET Framework" scheme="http://offroadcoder.com/CategoryView,category,NETFramework.aspx" />
    <category term="C#" label="C#" scheme="http://offroadcoder.com/CategoryView,category,C.aspx" />
    <category term="WAS" label="WAS" scheme="http://offroadcoder.com/CategoryView,category,WAS.aspx" />
    <category term="WCF" label="WCF" scheme="http://offroadcoder.com/CategoryView,category,WCF.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
It has taken me weeks to get WAS (Windows Activation Service) working. Finally, tonight,
my long hours of research has paid off. After everything I tried, it turned out to
be a general IIS7 issue caused by a stray http reservation that I probably entered
months ago during some testing. As I primarily use the built-in development server
for web development, I rarely crank up an IIS site on my development machine. 
</p>
        <p>
This post by Phil Haack helped me fix my IIS install:
</p>
        <p>
          <a href="http://haacked.com/archive/2007/05/21/the-iis-7-team-rocks.aspx">http://haacked.com/archive/2007/05/21/the-iis-7-team-rocks.aspx</a>
        </p>
        <p>
I have been cursing IIS7, Vista, and WAS for weeks. I should have been cursing my
own lack of IIS7 knowledge all along. Now that it's working, I am a big fan of WAS.
From the tone of recent forum responses and blog posts, very few people are using
WAS. Maybe it is due to Windows Server 2008 being so new. Not many people have Vista
workstations for development and <u>all</u> Windows Server 2008 servers to deploy
to. Knowing how many problems I had, I can only assume others are experiencing the
same thing. The only real info available right now is pre-release articles and MVP
posts about the new features with a sneak peak example on how to get it to work. Even
MSDN doesn't show how to use an existing WCF Service Library with WAS. They just walk
through a WsHttpBinding example as a new WCF web site served up by WAS.
</p>
        <p>
I'm posting the details so others will maybe see that it's really not that hard.
For this example I want to expose this service with the NetTcpBinding to prove that
it is not IIS hosting the service. I used the WCF Service Library project template
for my WCF service, and named the project <em>WasServices</em>. So the lame Service1
service is all I have in the library. I made no changes to the project and built it
in release mode to get the DLL. Some posts and articles out there say that the only
way to get WAS to work is to have an HTTP-based WCF web site. This is simply not true.
You just need to have an application set up in IIS.
</p>
        <p>
Here is the steps to success:
</p>
        <p>
1. Enable the required Windows Features to wake up IIS7 and WAS. You will find these
in the helpful links below.
</p>
        <p>
2. Configuration file <em>C:\Windows\System32\inetsrv\config\applicationHost.config</em> must
be modified to enable the required protocols on your web site and application. You
can modify the file yourself, or use command-line utilities.
</p>
        <blockquote>
          <p>
To enable net.tcp on the web site, if it is not already:
</p>
          <p>
            <font face="Courier New">%windir%\system32\inetsrv\appcmd.exe set site "Default Web
Site" -+bindings.[protocol='net.tcp',bindingInformation='808:*']</font>
          </p>
          <p>
To enable net.tcp on your application (my app is named <em>WasServices</em>) within
that web site, if it is not already:
</p>
          <p>
            <font face="Courier New">%windir%\system32\inetsrv\appcmd.exe set app "Default Web
Site/WasServices" /enabledProtocols:http,net.tcp</font>
          </p>
          <p>
          </p>
          <p>
Here is an exerpt from the applicationHost.config file showing the site and application
settings:
</p>
          <p>
          </p>
          <div style="OVERFLOW-Y: auto; FONT-SIZE: 9pt; BACKGROUND: #3f3f3f; OVERFLOW-X: auto; WIDTH: 848px; COLOR: #dcdccc; FONT-FAMILY: consolas; HEIGHT: 218px">
            <p style="MARGIN: 0px">
              <span style="COLOR: #85ac8d">  151</span> <span style="COLOR: #efef8f">           
&lt;</span><span style="COLOR: #e3c66a">site</span><span style="COLOR: #efef8f"></span><span style="COLOR: white">name</span><span style="COLOR: #efef8f">="</span><span style="COLOR: #cc9393">Default
Web Site</span><span style="COLOR: #efef8f">" </span><span style="COLOR: white">id</span><span style="COLOR: #efef8f">="</span><span style="COLOR: #cc9393">1</span><span style="COLOR: #efef8f">" </span><span style="COLOR: white">serverAutoStart</span><span style="COLOR: #efef8f">="</span><span style="COLOR: #cc9393">true</span><span style="COLOR: #efef8f">"&gt;</span></p>
            <p style="MARGIN: 0px">
              <span style="COLOR: #85ac8d">  152</span> <span style="COLOR: #efef8f">               
&lt;</span><span style="COLOR: #e3c66a">application</span><span style="COLOR: #efef8f"></span><span style="COLOR: white">path</span><span style="COLOR: #efef8f">="</span><span style="COLOR: #cc9393">/</span><span style="COLOR: #efef8f">"&gt;</span></p>
            <p style="MARGIN: 0px">
              <span style="COLOR: #85ac8d">  153</span> <span style="COLOR: #efef8f">                   
&lt;</span><span style="COLOR: #e3c66a">virtualDirectory</span><span style="COLOR: #efef8f"></span><span style="COLOR: white">path</span><span style="COLOR: #efef8f">="</span><span style="COLOR: #cc9393">/</span><span style="COLOR: #efef8f">" </span><span style="COLOR: white">physicalPath</span><span style="COLOR: #efef8f">="</span><span style="COLOR: #cc9393">%SystemDrive%\inetpub\wwwroot</span><span style="COLOR: #efef8f">"
/&gt;</span></p>
            <p style="MARGIN: 0px">
              <span style="COLOR: #85ac8d">  154</span> <span style="COLOR: #efef8f">               
&lt;/</span><span style="COLOR: #e3c66a">application</span><span style="COLOR: #efef8f">&gt;</span></p>
            <p style="MARGIN: 0px">
              <span style="COLOR: #85ac8d">  155</span> <span style="COLOR: #efef8f">               
&lt;</span><span style="COLOR: #e3c66a">application</span><span style="COLOR: #efef8f"></span><span style="COLOR: white">path</span><span style="COLOR: #efef8f">="</span><span style="COLOR: #cc9393">/WasServices</span><span style="COLOR: #efef8f">" </span><span style="COLOR: white">applicationPool</span><span style="COLOR: #efef8f">="</span><span style="COLOR: #cc9393">WasHosting</span><span style="COLOR: #efef8f">" </span><span style="COLOR: white">enabledProtocols</span><span style="COLOR: #efef8f">="</span><span style="COLOR: #cc9393">http,net.tcp</span><span style="COLOR: #efef8f">"&gt;</span></p>
            <p style="MARGIN: 0px">
              <span style="COLOR: #85ac8d">  156</span> <span style="COLOR: #efef8f">                   
&lt;</span><span style="COLOR: #e3c66a">virtualDirectory</span><span style="COLOR: #efef8f"></span><span style="COLOR: white">path</span><span style="COLOR: #efef8f">="</span><span style="COLOR: #cc9393">/</span><span style="COLOR: #efef8f">" </span><span style="COLOR: white">physicalPath</span><span style="COLOR: #efef8f">="</span><span style="COLOR: #cc9393">C:\inetpub\wwwroot\WasServices</span><span style="COLOR: #efef8f">"
/&gt;</span></p>
            <p style="MARGIN: 0px">
              <span style="COLOR: #85ac8d">  157</span> <span style="COLOR: #efef8f">               
&lt;/</span><span style="COLOR: #e3c66a">application</span><span style="COLOR: #efef8f">&gt;</span></p>
            <p style="MARGIN: 0px">
              <span style="COLOR: #85ac8d">  158</span> <span style="COLOR: #efef8f">               
&lt;</span><span style="COLOR: #e3c66a">bindings</span><span style="COLOR: #efef8f">&gt;</span></p>
            <p style="MARGIN: 0px">
              <span style="COLOR: #85ac8d">  159</span> <span style="COLOR: #efef8f">                   
&lt;</span><span style="COLOR: #e3c66a">binding</span><span style="COLOR: #efef8f"></span><span style="COLOR: white">protocol</span><span style="COLOR: #efef8f">="</span><span style="COLOR: #cc9393">net.tcp</span><span style="COLOR: #efef8f">" </span><span style="COLOR: white">bindingInformation</span><span style="COLOR: #efef8f">="</span><span style="COLOR: #cc9393">808:*</span><span style="COLOR: #efef8f">"
/&gt;</span></p>
            <p style="MARGIN: 0px">
              <span style="COLOR: #85ac8d">  160</span> <span style="COLOR: #efef8f">                   
&lt;</span><span style="COLOR: #e3c66a">binding</span><span style="COLOR: #efef8f"></span><span style="COLOR: white">protocol</span><span style="COLOR: #efef8f">="</span><span style="COLOR: #cc9393">net.pipe</span><span style="COLOR: #efef8f">" </span><span style="COLOR: white">bindingInformation</span><span style="COLOR: #efef8f">="</span><span style="COLOR: #cc9393">*</span><span style="COLOR: #efef8f">"
/&gt;</span></p>
            <p style="MARGIN: 0px">
              <span style="COLOR: #85ac8d">  161</span> <span style="COLOR: #efef8f">                   
&lt;</span><span style="COLOR: #e3c66a">binding</span><span style="COLOR: #efef8f"></span><span style="COLOR: white">protocol</span><span style="COLOR: #efef8f">="</span><span style="COLOR: #cc9393">net.msmq</span><span style="COLOR: #efef8f">" </span><span style="COLOR: white">bindingInformation</span><span style="COLOR: #efef8f">="</span><span style="COLOR: #cc9393">localhost</span><span style="COLOR: #efef8f">"
/&gt;</span></p>
            <p style="MARGIN: 0px">
              <span style="COLOR: #85ac8d">  162</span> <span style="COLOR: #efef8f">                   
&lt;</span><span style="COLOR: #e3c66a">binding</span><span style="COLOR: #efef8f"></span><span style="COLOR: white">protocol</span><span style="COLOR: #efef8f">="</span><span style="COLOR: #cc9393">msmq.formatname</span><span style="COLOR: #efef8f">" </span><span style="COLOR: white">bindingInformation</span><span style="COLOR: #efef8f">="</span><span style="COLOR: #cc9393">localhost</span><span style="COLOR: #efef8f">"
/&gt;</span></p>
            <p style="MARGIN: 0px">
              <span style="COLOR: #85ac8d">  163</span> <span style="COLOR: #efef8f">                   
&lt;</span><span style="COLOR: #e3c66a">binding</span><span style="COLOR: #efef8f"></span><span style="COLOR: white">protocol</span><span style="COLOR: #efef8f">="</span><span style="COLOR: #cc9393">http</span><span style="COLOR: #efef8f">" </span><span style="COLOR: white">bindingInformation</span><span style="COLOR: #efef8f">="</span><span style="COLOR: #cc9393">*:80:</span><span style="COLOR: #efef8f">"
/&gt;</span></p>
            <p style="MARGIN: 0px">
              <span style="COLOR: #85ac8d">  164</span> <span style="COLOR: #efef8f">               
&lt;/</span><span style="COLOR: #e3c66a">bindings</span><span style="COLOR: #efef8f">&gt;</span></p>
            <p style="MARGIN: 0px">
              <span style="COLOR: #85ac8d">  165</span> <span style="COLOR: #efef8f">           
&lt;/</span><span style="COLOR: #e3c66a">site</span><span style="COLOR: #efef8f">&gt;</span></p>
          </div>
        </blockquote>
        <p>
3. Prepare the application in your application folder (C:\inetpub\wwwroot\WasServices)
</p>
        <blockquote>
          <p>
Create a service file (WasServices.svc) that points to your existing WCF service library:
</p>
          <p>
          </p>
          <div style="OVERFLOW-Y: auto; FONT-SIZE: 9pt; BACKGROUND: #3f3f3f; OVERFLOW-X: auto; WIDTH: 600px; COLOR: #dcdccc; FONT-FAMILY: consolas; HEIGHT: 34px">
            <p style="MARGIN: 0px">
              <span style="COLOR: #85ac8d">    1</span> <span style="BACKGROUND: #ffee62">&lt;%</span><span style="COLOR: #efef8f">@</span><span style="COLOR: #e3ceab">ServiceHost</span><span style="COLOR: #dfdfbf">Service</span><span style="COLOR: #efef8f">=</span><span style="COLOR: #cc9393">"WasServices.Service1"</span><span style="BACKGROUND: #ffee62">%&gt;</span></p>
          </div>
          <p>
 
</p>
          <p>
Create a web.config file that specifies the service's endpoints:
</p>
          <p>
          </p>
          <p>
          </p>
          <div style="OVERFLOW-Y: auto; FONT-SIZE: 9pt; BACKGROUND: #3f3f3f; OVERFLOW-X: auto; WIDTH: 600px; COLOR: #dcdccc; FONT-FAMILY: consolas; HEIGHT: 200px">
            <p style="MARGIN: 0px">
              <span style="COLOR: #85ac8d">    1</span> <span style="COLOR: #efef8f">&lt;?</span><span style="COLOR: #e3c66a">xml</span><span style="COLOR: #efef8f"></span><span style="COLOR: white">version</span><span style="COLOR: #efef8f">="</span><span style="COLOR: #cc9393">1.0</span><span style="COLOR: #efef8f">" </span><span style="COLOR: white">encoding</span><span style="COLOR: #efef8f">="</span><span style="COLOR: #cc9393">utf-8</span><span style="COLOR: #efef8f">"?&gt;</span></p>
            <p style="MARGIN: 0px">
              <span style="COLOR: #85ac8d">    2</span> <span style="COLOR: #efef8f">&lt;</span><span style="COLOR: #e3c66a">configuration</span><span style="COLOR: #efef8f">&gt;</span></p>
            <p style="MARGIN: 0px">
              <span style="COLOR: #85ac8d">    3</span> <span style="COLOR: #efef8f">   
&lt;</span><span style="COLOR: #e3c66a">system.serviceModel</span><span style="COLOR: #efef8f">&gt;</span></p>
            <p style="MARGIN: 0px">
              <span style="COLOR: #85ac8d">    4</span> <span style="COLOR: #efef8f">       
&lt;</span><span style="COLOR: #e3c66a">services</span><span style="COLOR: #efef8f">&gt;</span></p>
            <p style="MARGIN: 0px">
              <span style="COLOR: #85ac8d">    5</span> <span style="COLOR: #efef8f">           
&lt;</span><span style="COLOR: #e3c66a">service</span><span style="COLOR: #efef8f"></span><span style="COLOR: white">name</span><span style="COLOR: #efef8f">="</span><span style="COLOR: #cc9393">WasServices.Service1</span><span style="COLOR: #efef8f">"</span></p>
            <p style="MARGIN: 0px">
              <span style="COLOR: #85ac8d">    6</span> <span style="COLOR: #efef8f">                    </span><span style="COLOR: white">behaviorConfiguration</span><span style="COLOR: #efef8f">="</span><span style="COLOR: #cc9393">MEX</span><span style="COLOR: #efef8f">"&gt;</span></p>
            <p style="MARGIN: 0px">
              <span style="COLOR: #85ac8d">    7</span> <span style="COLOR: #efef8f">               
&lt;</span><span style="COLOR: #e3c66a">endpoint</span><span style="COLOR: #efef8f"></span><span style="COLOR: white">address</span><span style="COLOR: #efef8f">="</span><span style="COLOR: #cc9393">wsHttp</span><span style="COLOR: #efef8f">"</span></p>
            <p style="MARGIN: 0px">
              <span style="COLOR: #85ac8d">    8</span> <span style="COLOR: #efef8f">                          </span><span style="COLOR: white">binding</span><span style="COLOR: #efef8f">="</span><span style="COLOR: #cc9393">wsHttpBinding</span><span style="COLOR: #efef8f">"</span></p>
            <p style="MARGIN: 0px">
              <span style="COLOR: #85ac8d">    9</span> <span style="COLOR: #efef8f">                          </span><span style="COLOR: white">contract</span><span style="COLOR: #efef8f">="</span><span style="COLOR: #cc9393">WasServices.IService1</span><span style="COLOR: #efef8f">"/&gt;</span></p>
            <p style="MARGIN: 0px">
              <span style="COLOR: #85ac8d">   10</span> <span style="COLOR: #efef8f">               
&lt;</span><span style="COLOR: #e3c66a">endpoint</span><span style="COLOR: #efef8f"></span><span style="COLOR: white">address</span><span style="COLOR: #efef8f">="</span><span style="COLOR: #cc9393">netTcp</span><span style="COLOR: #efef8f">"</span></p>
            <p style="MARGIN: 0px">
              <span style="COLOR: #85ac8d">   11</span> <span style="COLOR: #efef8f">                          </span><span style="COLOR: white">binding</span><span style="COLOR: #efef8f">="</span><span style="COLOR: #cc9393">netTcpBinding</span><span style="COLOR: #efef8f">"</span></p>
            <p style="MARGIN: 0px">
              <span style="COLOR: #85ac8d">   12</span> <span style="COLOR: #efef8f">                          </span><span style="COLOR: white">bindingConfiguration</span><span style="COLOR: #efef8f">="</span><span style="COLOR: #cc9393">NetTcpBinding_Common</span><span style="COLOR: #efef8f">"</span></p>
            <p style="MARGIN: 0px">
              <span style="COLOR: #85ac8d">   13</span> <span style="COLOR: #efef8f">                          </span><span style="COLOR: white">contract</span><span style="COLOR: #efef8f">="</span><span style="COLOR: #cc9393">WasServices.IService1</span><span style="COLOR: #efef8f">"/&gt;</span></p>
            <p style="MARGIN: 0px">
              <span style="COLOR: #85ac8d">   14</span> <span style="COLOR: #efef8f">               
&lt;</span><span style="COLOR: #e3c66a">endpoint</span><span style="COLOR: #efef8f"></span><span style="COLOR: white">address</span><span style="COLOR: #efef8f">="</span><span style="COLOR: #cc9393">mex</span><span style="COLOR: #efef8f">"</span></p>
            <p style="MARGIN: 0px">
              <span style="COLOR: #85ac8d">   15</span> <span style="COLOR: #efef8f">                          </span><span style="COLOR: white">binding</span><span style="COLOR: #efef8f">="</span><span style="COLOR: #cc9393">mexHttpBinding</span><span style="COLOR: #efef8f">"</span></p>
            <p style="MARGIN: 0px">
              <span style="COLOR: #85ac8d">   16</span> <span style="COLOR: #efef8f">                          </span><span style="COLOR: white">contract</span><span style="COLOR: #efef8f">="</span><span style="COLOR: #cc9393">IMetadataExchange</span><span style="COLOR: #efef8f">"
/&gt;</span></p>
            <p style="MARGIN: 0px">
              <span style="COLOR: #85ac8d">   17</span> <span style="COLOR: #efef8f">           
&lt;/</span><span style="COLOR: #e3c66a">service</span><span style="COLOR: #efef8f">&gt;</span></p>
            <p style="MARGIN: 0px">
              <span style="COLOR: #85ac8d">   18</span> <span style="COLOR: #efef8f">       
&lt;/</span><span style="COLOR: #e3c66a">services</span><span style="COLOR: #efef8f">&gt;</span></p>
            <p style="MARGIN: 0px">
              <span style="COLOR: #85ac8d">   19</span> <span style="COLOR: #efef8f">       
&lt;</span><span style="COLOR: #e3c66a">behaviors</span><span style="COLOR: #efef8f">&gt;</span></p>
            <p style="MARGIN: 0px">
              <span style="COLOR: #85ac8d">   20</span> <span style="COLOR: #efef8f">           
&lt;</span><span style="COLOR: #e3c66a">serviceBehaviors</span><span style="COLOR: #efef8f">&gt;</span></p>
            <p style="MARGIN: 0px">
              <span style="COLOR: #85ac8d">   21</span> <span style="COLOR: #efef8f">               
&lt;</span><span style="COLOR: #e3c66a">behavior</span><span style="COLOR: #efef8f"></span><span style="COLOR: white">name</span><span style="COLOR: #efef8f">="</span><span style="COLOR: #cc9393">MEX</span><span style="COLOR: #efef8f">"&gt;</span></p>
            <p style="MARGIN: 0px">
              <span style="COLOR: #85ac8d">   22</span> <span style="COLOR: #efef8f">                   
&lt;</span><span style="COLOR: #e3c66a">serviceMetadata</span><span style="COLOR: #efef8f"></span><span style="COLOR: white">httpGetEnabled</span><span style="COLOR: #efef8f">="</span><span style="COLOR: #cc9393">true</span><span style="COLOR: #efef8f">"/&gt;</span></p>
            <p style="MARGIN: 0px">
              <span style="COLOR: #85ac8d">   23</span> <span style="COLOR: #efef8f">               
&lt;/</span><span style="COLOR: #e3c66a">behavior</span><span style="COLOR: #efef8f">&gt;</span></p>
            <p style="MARGIN: 0px">
              <span style="COLOR: #85ac8d">   24</span> <span style="COLOR: #efef8f">           
&lt;/</span><span style="COLOR: #e3c66a">serviceBehaviors</span><span style="COLOR: #efef8f">&gt;</span></p>
            <p style="MARGIN: 0px">
              <span style="COLOR: #85ac8d">   25</span> <span style="COLOR: #efef8f">       
&lt;/</span><span style="COLOR: #e3c66a">behaviors</span><span style="COLOR: #efef8f">&gt;</span></p>
            <p style="MARGIN: 0px">
              <span style="COLOR: #85ac8d">   26</span> <span style="COLOR: #efef8f">       
&lt;</span><span style="COLOR: #e3c66a">bindings</span><span style="COLOR: #efef8f">&gt;</span></p>
            <p style="MARGIN: 0px">
              <span style="COLOR: #85ac8d">   27</span> <span style="COLOR: #efef8f">           
&lt;</span><span style="COLOR: #e3c66a">netTcpBinding</span><span style="COLOR: #efef8f">&gt;</span></p>
            <p style="MARGIN: 0px">
              <span style="COLOR: #85ac8d">   28</span> <span style="COLOR: #efef8f">               
&lt;</span><span style="COLOR: #e3c66a">binding</span><span style="COLOR: #efef8f"></span><span style="COLOR: white">name</span><span style="COLOR: #efef8f">="</span><span style="COLOR: #cc9393">NetTcpBinding_Common</span><span style="COLOR: #efef8f">"&gt;</span></p>
            <p style="MARGIN: 0px">
              <span style="COLOR: #85ac8d">   29</span> <span style="COLOR: #efef8f">                   
&lt;</span><span style="COLOR: #e3c66a">reliableSession</span><span style="COLOR: #efef8f"></span><span style="COLOR: white">enabled</span><span style="COLOR: #efef8f">="</span><span style="COLOR: #cc9393">true</span><span style="COLOR: #efef8f">"/&gt;</span></p>
            <p style="MARGIN: 0px">
              <span style="COLOR: #85ac8d">   30</span> <span style="COLOR: #efef8f">                   
&lt;</span><span style="COLOR: #e3c66a">security</span><span style="COLOR: #efef8f"></span><span style="COLOR: white">mode</span><span style="COLOR: #efef8f">="</span><span style="COLOR: #cc9393">None</span><span style="COLOR: #efef8f">"/&gt;</span></p>
            <p style="MARGIN: 0px">
              <span style="COLOR: #85ac8d">   31</span> <span style="COLOR: #efef8f">               
&lt;/</span><span style="COLOR: #e3c66a">binding</span><span style="COLOR: #efef8f">&gt;</span></p>
            <p style="MARGIN: 0px">
              <span style="COLOR: #85ac8d">   32</span> <span style="COLOR: #efef8f">           
&lt;/</span><span style="COLOR: #e3c66a">netTcpBinding</span><span style="COLOR: #efef8f">&gt;</span></p>
            <p style="MARGIN: 0px">
              <span style="COLOR: #85ac8d">   33</span> <span style="COLOR: #efef8f">       
&lt;/</span><span style="COLOR: #e3c66a">bindings</span><span style="COLOR: #efef8f">&gt;</span></p>
            <p style="MARGIN: 0px">
              <span style="COLOR: #85ac8d">   34</span> <span style="COLOR: #efef8f">   
&lt;/</span><span style="COLOR: #e3c66a">system.serviceModel</span><span style="COLOR: #efef8f">&gt;</span></p>
            <p style="MARGIN: 0px">
              <span style="COLOR: #85ac8d">   35</span> <span style="COLOR: #efef8f">&lt;/</span><span style="COLOR: #e3c66a">configuration</span><span style="COLOR: #efef8f">&gt;</span></p>
          </div>
          <p>
 
</p>
          <p>
Place the release-compiled DLL created from the WCF Service Library in a new folder
named <em>Bin</em>.
</p>
        </blockquote>
        <p>
4. At this point, you can browse and see the familiar "You have created a service."
page for Service1.
</p>
        <p>
5. Write your proxy file and config file.
</p>
        <blockquote>
          <p>
WAS and IIS7 decide the address for your service, and it is not intuitive. 
</p>
          <p>
          </p>
          <div style="OVERFLOW-Y: auto; FONT-SIZE: 9pt; BACKGROUND: #3f3f3f; OVERFLOW-X: auto; WIDTH: 691px; COLOR: #dcdccc; FONT-FAMILY: consolas; HEIGHT: 200px">
            <p style="MARGIN: 0px">
              <span style="COLOR: #85ac8d">    1</span> <span style="COLOR: #efef8f">&lt;?</span><span style="COLOR: #e3c66a">xml</span><span style="COLOR: #efef8f"></span><span style="COLOR: white">version</span><span style="COLOR: #efef8f">="</span><span style="COLOR: #cc9393">1.0</span><span style="COLOR: #efef8f">" </span><span style="COLOR: white">encoding</span><span style="COLOR: #efef8f">="</span><span style="COLOR: #cc9393">utf-8</span><span style="COLOR: #efef8f">"
?&gt;</span></p>
            <p style="MARGIN: 0px">
              <span style="COLOR: #85ac8d">    2</span> <span style="COLOR: #efef8f">&lt;</span><span style="COLOR: #e3c66a">configuration</span><span style="COLOR: #efef8f">&gt;</span></p>
            <p style="MARGIN: 0px">
              <span style="COLOR: #85ac8d">    3</span> <span style="COLOR: #efef8f">   
&lt;</span><span style="COLOR: #e3c66a">system.serviceModel</span><span style="COLOR: #efef8f">&gt;</span></p>
            <p style="MARGIN: 0px">
              <span style="COLOR: #85ac8d">    4</span> <span style="COLOR: #efef8f">       
&lt;</span><span style="COLOR: #e3c66a">client</span><span style="COLOR: #efef8f">&gt;</span></p>
            <p style="MARGIN: 0px">
              <span style="COLOR: #85ac8d">    5</span> <span style="COLOR: #efef8f">           
&lt;</span><span style="COLOR: #e3c66a">endpoint</span><span style="COLOR: #efef8f"></span><span style="COLOR: white">address</span><span style="COLOR: #efef8f">="</span><span style="COLOR: #cc9393">net.tcp://localhost/WasServices/WasServices.svc/netTcp</span><span style="COLOR: #efef8f">"</span></p>
            <p style="MARGIN: 0px">
              <span style="COLOR: #85ac8d">    6</span> <span style="COLOR: #efef8f">                      </span><span style="COLOR: white">binding</span><span style="COLOR: #efef8f">="</span><span style="COLOR: #cc9393">netTcpBinding</span><span style="COLOR: #efef8f">"</span></p>
            <p style="MARGIN: 0px">
              <span style="COLOR: #85ac8d">    7</span> <span style="COLOR: #efef8f">                      </span><span style="COLOR: white">bindingConfiguration</span><span style="COLOR: #efef8f">="</span><span style="COLOR: #cc9393">NetTcpBinding_IService1</span><span style="COLOR: #efef8f">"</span></p>
            <p style="MARGIN: 0px">
              <span style="COLOR: #85ac8d">    8</span> <span style="COLOR: #efef8f">                      </span><span style="COLOR: white">contract</span><span style="COLOR: #efef8f">="</span><span style="COLOR: #cc9393">WasServices.IService1</span><span style="COLOR: #efef8f">"</span></p>
            <p style="MARGIN: 0px">
              <span style="COLOR: #85ac8d">    9</span> <span style="COLOR: #efef8f">                      </span><span style="COLOR: white">name</span><span style="COLOR: #efef8f">="</span><span style="COLOR: #cc9393">NetTcpBinding_Common</span><span style="COLOR: #efef8f">"
/&gt;</span></p>
            <p style="MARGIN: 0px">
              <span style="COLOR: #85ac8d">   10</span> <span style="COLOR: #efef8f">       
&lt;/</span><span style="COLOR: #e3c66a">client</span><span style="COLOR: #efef8f">&gt;</span></p>
            <p style="MARGIN: 0px">
              <span style="COLOR: #85ac8d">   11</span> <span style="COLOR: #efef8f">       
&lt;</span><span style="COLOR: #e3c66a">bindings</span><span style="COLOR: #efef8f">&gt;</span></p>
            <p style="MARGIN: 0px">
              <span style="COLOR: #85ac8d">   12</span> <span style="COLOR: #efef8f">           
&lt;</span><span style="COLOR: #e3c66a">netTcpBinding</span><span style="COLOR: #efef8f">&gt;</span></p>
            <p style="MARGIN: 0px">
              <span style="COLOR: #85ac8d">   13</span> <span style="COLOR: #efef8f">               
&lt;</span><span style="COLOR: #e3c66a">binding</span><span style="COLOR: #efef8f"></span><span style="COLOR: white">name</span><span style="COLOR: #efef8f">="</span><span style="COLOR: #cc9393">NetTcpBinding_Common</span><span style="COLOR: #efef8f">"&gt;</span></p>
            <p style="MARGIN: 0px">
              <span style="COLOR: #85ac8d">   14</span> <span style="COLOR: #efef8f">                   
&lt;</span><span style="COLOR: #e3c66a">reliableSession</span><span style="COLOR: #efef8f"></span><span style="COLOR: white">enabled</span><span style="COLOR: #efef8f">="</span><span style="COLOR: #cc9393">true</span><span style="COLOR: #efef8f">"
/&gt;</span></p>
            <p style="MARGIN: 0px">
              <span style="COLOR: #85ac8d">   15</span> <span style="COLOR: #efef8f">                   
&lt;</span><span style="COLOR: #e3c66a">security</span><span style="COLOR: #efef8f"></span><span style="COLOR: white">mode</span><span style="COLOR: #efef8f">="</span><span style="COLOR: #cc9393">None</span><span style="COLOR: #efef8f">"
/&gt;</span></p>
            <p style="MARGIN: 0px">
              <span style="COLOR: #85ac8d">   16</span> <span style="COLOR: #efef8f">               
&lt;/</span><span style="COLOR: #e3c66a">binding</span><span style="COLOR: #efef8f">&gt;</span></p>
            <p style="MARGIN: 0px">
              <span style="COLOR: #85ac8d">   17</span> <span style="COLOR: #efef8f">           
&lt;/</span><span style="COLOR: #e3c66a">netTcpBinding</span><span style="COLOR: #efef8f">&gt;</span></p>
            <p style="MARGIN: 0px">
              <span style="COLOR: #85ac8d">   18</span> <span style="COLOR: #efef8f">       
&lt;/</span><span style="COLOR: #e3c66a">bindings</span><span style="COLOR: #efef8f">&gt;</span></p>
            <p style="MARGIN: 0px">
              <span style="COLOR: #85ac8d">   19</span> <span style="COLOR: #efef8f">   
&lt;/</span><span style="COLOR: #e3c66a">system.serviceModel</span><span style="COLOR: #efef8f">&gt;</span></p>
            <p style="MARGIN: 0px">
              <span style="COLOR: #85ac8d">   20</span> <span style="COLOR: #efef8f">&lt;/</span><span style="COLOR: #e3c66a">configuration</span><span style="COLOR: #efef8f">&gt;</span></p>
          </div>
          <p>
 
</p>
          <p>
The <em>/netTcp</em> at the end of the address is due to the address specified in
the service's web.config file. The address was given there as simply <em>netTcp</em>.
This is because IIS7 and WAS decide your address based on the available bindings and
ports you specified in the applicationHost.config file using appcmd.exe. Since my
enabled protocols are http and net.tcp and the only open tcp port is 808, you will
not see a port number in the address. The same would go for my wsHttpBinding since
the only allowable port is 80.
</p>
        </blockquote>
        <p>
I'm proud to be the fourth, and maybe final, member of the "Got WAS to work" club.
If anyone wants to join, and needs help to get in... please let me know.
</p>
        <blockquote>
          <p>
          </p>
        </blockquote>
        <p>
Here are some helpful links for those of you having problems:
</p>
        <ul>
          <li>
            <a href="http://yourbit.com/2008/03/09/hosting-a-windows-communication-foundation-service-in-iis7-on-windows-vista/">Hosting
a WCF Service using IIS7 and Windows Vista</a>
          </li>
          <li>
            <a href="http://blah.winsmarts.com/2008-4-Host_a_WCF_Service_in_IIS_7_-and-amp;_Windows_2008_-_The_right_way.aspx">Host
a WCF Service in IIS 7 &amp; Windows 2008 - The right way</a>
          </li>
          <li>
            <a href="http://www.devx.com/VistaSpecialReport/Article/33831">Hosting WCF Services
in Windows Activation Service</a>
          </li>
        </ul>
        <img width="0" height="0" src="http://offroadcoder.com/aggbug.ashx?id=a3e76678-c8fe-4440-898d-7739c8c99efb" />
      </div>
    </content>
  </entry>
</feed>