Remember, during the course we went over App Domain configuration for BizTalk. The key to creating App Domains with BizTalk, and hence being able to use configuration files with your project is to edit the BTSNTSvc.exe.config file located in the BizTalk program directory. The next key is to make sure you put the right sections in the right spot within the config file, else the BizTalk service will never start again (I ran into this myself once).
Why would you use them? Well, here’s a couple of reasons:
1) It gives you the ability to configure them separately. This is useful for orchestrations that use 3rd party component that read their configuration for the config file and you have different requirements for these 3rd party components when they are used from different orchestrations. You can also specify an assembly search-path on a per-app-domain basis.
2) The unit of code-unloading in .Net is app-domain. If you put separate orchestrations into app-domains there is an opportunity to unload some of them while the rest are still in use. For example, you can put you frequently used orchestrations into a “hot” app-domain and the less-used orchestrations into a “cold” app-domain. The hot app-domain will be continually used. The cold app-domain will get recycled after 25 minutes of idle time. You can control the unloading times with app-domain configuration (see MSDN).
3) It gives you some level of isolation. For example, if you have a singleton object—you’ll actually get one per app-domain—so one orchestration cannot mess the other orchestration’s singleton.
4) Internally, XLANG can use app-domains to host different versions of the XLANG runtime (e.g., Voyager vs. Pathfinder)
Here’s a sample of the edits to the BizTalk config file. Remember, the configSections comes first, and the sections it defines comes last….all the new additions are in RED.
<?xml version=”1.0″ ?>
<configuration>
<configSections>
<section
name=”xlangs”
type=”Microsoft.XLANGs.BizTalk.CrossProcess.XmlSerializationConfigurationSectionHandler, Microsoft.XLANGs.BizTalk.CrossProcess” />
</configSections>
<runtime>
<assemblyBinding xmlns=”urn:schemas-microsoft-com:asm.v1″>
<probing privatePath=”BizTalk Assemblies;Developer Tools;Tracking;Tracking\interop” />
</assemblyBinding>
</runtime>
<system.runtime.remoting>
<channelSinkProviders>
<serverProviders>
<provider id=”sspi” type=”Microsoft.BizTalk.XLANGs.BTXEngine.SecurityServerChannelSinkProvider,Microsoft.XLANGs.BizTalk.Engine” securityPackage=”ntlm” authenticationLevel=”packetPrivacy” />
</serverProviders>
</channelSinkProviders>
<application>
<channels>
<channel ref=”tcp” port=”0″ name=””>
<serverProviders>
<provider ref=”sspi” />
<formatter ref=”binary” typeFilterLevel=”Full”/>
</serverProviders>
</channel>
</channels>
</application>
</system.runtime.remoting>
<xlangs>
<Configuration>
<AppDomains AssembliesPerDomain=”10″>
<DefaultSpec SecondsIdleBeforeShutdown=”5″ SecondsEmptyBeforeShutdown=”5″>
</DefaultSpec>
<AppDomainSpecs>
<AppDomainSpec Name=”MyAppDomain”>
<BaseSetup>
<ConfigurationFile>C:\Projects\Projects\AppDomainConfig\MyAppDomainConfiguration.config</ConfigurationFile>
</BaseSetup>
</AppDomainSpec>
</AppDomainSpecs>
<PatternAssignmentRules>
<PatternAssignmentRule AssemblyNamePattern=”AppDomainConfig.*” AppDomainName=”MyAppDomain” />
</PatternAssignmentRules>
</AppDomains>
</Configuration>
</xlangs>
</configuration>
Lastly, here’s the sample we walked through in class. Yossi Levanoni put this together back in September of 03′.
The sample demonstrates how to instruct the orchestration engine to execute top-level (i.e., not-called) orchestrations from a particular assembly in a particular app domain; then how to specify configuration for this domain. In this sample, a configuration file is associated with the domain. The config file contains a custom configuration section. The test orchestration calls into user code and consumes this custom configuration section. The data is inserted into a flat-file-like XLANG message which is sent to an output folder.
To test it:
1) Compile.
2) Gac/deploy/modify binding.
3) Copy the BTSNTSvc.exe.config to your program files dir. You might want to edit this file so that it points to the correct location for MyAppDomainConfiguration.Config on your machine.
4) Drop any file (it’s just used to start the orchestration) with .xml extension into DataFolders\in.
5) You should see a file with a name like ConfigOut_<guid>.txt generated in DataFolders\out.
6) The contents of the file are:
key=”setting1″ val=”Value1″
key=”setting2″ val=”value two”
key=”setting3″ val=”third value”
Which corresponds to the contents of MyAppDomainConfiguration.config:
<?xml version=”1.0″?>
<configuration>
<configSections>
<section name=”sampleSection”
type=”System.Configuration.SingleTagSectionHandler” />
</configSections>
<sampleSection setting1=”Value1″ setting2=”value two”
setting3=”third value” /> </configuration>