Skip to the content.

Host Resolution Policy

Downloads The code samples used in this user guide have been made available in the Be.Stateless.BizTalk.Factory.Samples GitHub repository.

There usually are conventions when defining Microsoft BizTalk Server® hosts and host instances. It is a standard practice to at least create different hosts for processing, receiving, or sending purposes. But one could also chose to create a host by available adapters and directions. Host conventions could also be influenced by network zones, or DMZ, where some adapters could only be available in only one zone, while some others might be available in multiple zones. Some adapters further require to be hosted in an isolated process. Moreover, hosts might not be configured the same way in all target deployment environments, for instance; it usually is the case that the DEVELOPMENT and BUILD environments have different host configurations than the ACCEPTANCE and PRODUCTION environments —though one should strive to have identical host configurations for the ACCEPTANCE and PRODUCTION environments.

The Microsoft BizTalk Server® host conventions can consequently be quite elaborated and binding a port artifact to its right host can become error-prone. Instead of leaving the responsibility entirely to the developer to pick the right host —usually a string literal name— when configuring an artifact, one could write a policy that would automatically resolve the right host to bind the artifact to, as in the following code

Transport.Host = Host.Default

instead of the traditional explicit host name assignment

Transport.Host = "BizTalkServerApplication"

Remark Both expressions above are supported by BizTalk.Factory’s Binding DSL out of the box, i.e. assigning either a string literal or a policy object.

The corner stone of the host resolution policy mechanism is the ISupportHostResolution interface together combined with the HostResolutionPolicy base class policy, which is the policy that accepts any string literal as the host name to be resolved when the bindings will be generated for whatever target deployment environment.

BizTalk.Factory also comes with an additional HostResolutionPolicy that matches the default Microsoft BizTalk Server® host setup —BizTalkServerApplication and BizTalkServerIsolatedHost hosts— and automatically picks the right host among the isolated or in-process ones for a receive location. This is the policy that a developer would typically use for the DEVELOPMENT or BUILD target deployment environments.

If the developer needs to provide a richer host resolution policy, he can write a custom class that derives from the HostResolutionPolicy base policy, override the members according to his needs, and finally bind —assign— an instance of this custom policy to any orchestration or transport host.

Sample

For the sake of illustration, let us imagine that the developer needs to write a policy that will resolve the right host according to the following rules:

The following pattern integrates and summarizes all the above constraints:

<L|P|R|T>xHost[_B2B][_<Adapter>][_32][_Single]

where

The sample Org.Anization.BizTalk.Environment.Settings project provides a host resolution policy —AnyNetworkZoneHostResolutionPolicy accessible via its factory Host singleton— that satisfies all these requirements and allows the developer to bind a Microsoft BizTalk Server® artifact to a host as follows:

using Org.Anization.BizTalk.Environment.Settings;

Transport.Host = Host.Default;

Transport.Host = Host.Intranet;

Transport.Host = Host.B2B;

In order to implement the AnyNetworkZoneHostResolutionPolicy host resolution policy, some amount of scaffolding code has been written; this code is provided with unit tests that also shed some light on its purpose and how to use it. At the basis of it all, there are the NetworkZones enumeration and the AdapterExtensions class. The former defines the network zones that will be supported by the policy, the latter provides some extension methods to IAdapter-derived classes that allows to determine some of its characteristics, as for instance its name or whether it is a WCF-based adapter, etc.

Built on top of these, then come the InboundAdapterExtensions and OutboundAdapterExtensions classes, whose role is to determine whether an adapter is supported in any given network zone —the classes contain decision tables with an entry for each of the adapter configuration classes provided by BizTalk.Factory’s Binding DSL. Notice that WCF-based adapters can be equivalently configured in two different ways, either through their explicit configuration classes, e.g. WcfBasicHttpAdapter.Outbound, or through the generic WcfCustomAdapter.Outbound<> configuration class, e.g. WcfCustomAdapter.Outbound<BasicHttpBindingElement>. It would be a resource waste to host equivalent WCF-based adapters in two different processes just because they have been configured through their explicit or generic configuration classes. In order to avoid multiple similar entries in the decision tables concerning WCF adapters, it is therefore not the actual adapter configuration class but its binding element that is used.

The following table summarizes the hosts that will be available in each network zone to support the adapters, as implemented by the previously mentioned decision tables:

Adapter Isolated Inbound Outbound
File - Intranet Intranet
FTP - None None
HTTP - Intranet All
Office365Email - B2B -
POP3 - B2B -
SBMessaging - B2B B2B
SFTP - B2B B2B
WcfBasicHttp All None All
WcfBasicHttpRelay None None None
WcfNetMsmq None Intranet Intranet
WcfNetNamedPipe None None All
WcfNetTcp Intranet Intranet Intranet
WcfNetTcpRelay None None None
WcfOracle None Intranet Intranet
WcfSap None Intranet Intranet
WcfSql None Intranet Intranet
WcfWebHttp All None All
WcfWSHttp B2B None B2B

With this knowledge in place, NetworkZoneBoundHostResolutionPolicy is the last scaffolding class that we need in order to compute the name of the host that will actually run a Microsoft BizTalk Server® artifact. This latter class has to be instantiated for each network zone that we care to support. And that is precisely what AnyNetworkZoneHostResolutionPolicy does, combined with the fact that the latter will throw when a host is available in multiple network zones so as to require the developer to remove the ambiguity —instead of assigning Host.Default, the developer will have to either pick Host.Intranet or Host.B2B.