Microsoft BizTalk ESB 工具包中的解析程序和适配器提供程序框架实现使用名为 Dispatcher 的管道组件和名为 ItineraryReceive 和 ItinerarySend 的管道。
Dispatcher 管道组件具有四个属性: Validate、Enabled、EndPoint 和 MapName。 EndPoint 属性可以包含具有以下值的解析程序连接字符串,其中 UDDI:\\ 表示要使用的解析类型(根名字对象)。
UDDI:\\serverUrl=http://localhost/uddi;serviceName=OrderPurchaseToOrderPost;serviceProvider=Microsoft.Practices.ESB
其他受支持的标识符包括 XPATH:\\、STATIC:\\和BRE:\\。 每种标识符类型使用实现 IResolveProvider 接口的特定类。 可以为其他名字对象类型创建自己的自定义解析程序,并注册它们以供动态解析系统使用。
别名等同于解析器连接字符串。 各个模式定义参数及其根名称。 解析程序采用解析程序连接字符串,验证连接字符串,并利用验证结果来查询和填充 Dictionary 对象,该对象可用于路由、转换、行程选择或其他特定于您的服务的用途。
解析程序配置
必须在 Esb.config 配置文件中注册所有解析程序。 以下 XML 显示了配置文件内容的示例。
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="esb" type="Microsoft.Practices.ESB.Configuration.ESBConfigurationSection, Microsoft.Practices.ESB.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=c62dd63c784d6e22"/>
<!-- Other Section Definitions Here -->
</configSections>
<esb>
<resolvers cacheManager= "Resolver Providers Cache Manager" absoluteExpiration="3600">
<resolver name="UDDI" type="Microsoft.Practices.ESB.Resolver.UDDI.ResolveProvider, Microsoft.Practices.ESB.Resolver.UDDI, Version=2.0.0.0, Culture=neutral, PublicKeyToken=c62dd63c784d6e22">
<resolverConfig>
<add name="cacheTimeoutValue" value="120" />
<add name="cacheName" value="UDDI Cache Manager" />
</resolverConfig>
</resolver>
<resolver name="XPATH" type="Microsoft.Practices.ESB.Resolver.XPATH.ResolveProvider, Microsoft.Practices.ESB.Resolver.XPATH, Version=2.0.0.0, Culture=neutral, PublicKeyToken=c62dd63c784d6e22"/>
<!-- Other Resolver Definitions Here -->
</resolvers>
<!-- Other ESB Configuration Settings Here -->
</esb>
<!-- Other Configuration Sections Here -->
</configuration>
每个解析程序节点下的 resolverConfig 部分允许你配置解析程序在特定环境中运行所需的额外属性。 若要访问配置,解析程序必须公开采用 类型为 Microsoft.Practices.ESB.Configuration.Resolver 的参数的构造函数。 在解析程序实现中,可以使用 ResolverConfigHelper 类的 ReadResolverConfigByKey 方法访问配置属性;为此,请传入最初传递给构造函数的参数,然后传入有问题的值的名称。 如果在 resolverConfig 节点中未指定名称/值对,将使用默认无参数构造函数来实例化解析程序。
配置中定义了两个通用说明、发现和集成(UDDI)3 解析程序:UDDI 3 和 UDDI 3-SOASOFTWARE。 这两个解析程序使用相同的基础程序集,但它们提供了不同的配置,以支持不同的符合 UDDI 3.0 的注册表,这些注册表具有不同的统一资源标识符(URI)格式和安全要求。 如果需要为兼容 UDDI 3.0 的注册表配置一个额外的名称标识符,除了已受支持的标识符之外,可以使用以下配置属性:
cacheTimeoutValue
cacheName
publisherKey
useUddiAuth
baseUri
inquireUriSuffix
securityUriSuffix
securityMode。 有关有效值,请参阅枚举 System.ServiceModel.BasicHttpSecurityMode (https://go.microsoft.com/fwlink/?LinkID=188284&clcid=0x409)。 默认值为 TransportCredentialOnly。
credentialType。 有关有效值,请参阅枚举 System.ServiceModel.HttpClientCredentialType (https://go.microsoft.com/fwlink/?LinkId=188285)。 默认值为 Windows。
username
password
如果要创建依赖于 Unity 应用程序块依赖项注入功能的解析程序,则需要其他配置。 有关详细信息,请参阅 使用 Unity 容器创建自定义冲突解决程序。
IResolveProvider 接口
所有解析程序都必须实现 IResolveProvider 接口。 位于 Microsoft.Practices.ESB.Resolver 项目中的 IResolveProvider 接口由 Resolve 方法的三个重载组成,这些重载返回 Dictionary 类的实例,其中包含具体解析程序类实例提供的解析事实。 下面的代码示例显示了这些方法重载的签名。
// <summary>
// This is the main interface that is called from the
// ResolverMgr class.
// This interface supports being called from a Microsoft BizTalk
// Server pipeline component.
// </summary>
// <param name="config">Configuration string entered into
// pipeline component as argument</param>
// <param name="resolver">Moniker representing the resolver
// to load</param>.
// <param name="message">IBaseMessage passed from pipeline</param>.
// <param name="pipelineContext">IPipelineContext passed from
// pipeline</param>.
// <returns>Dictionary object fully populated</returns>.
Dictionary<string, string> Resolve(string config, string resolver,
IBaseMessage message, IPipelineContext pipelineContext);
// <summary>
// This is the main interface that is called from the ResolverMgr
// class.
// This interface supports being called from a Web service interface.
// </summary>
// <param name="config">Configuration string entered into Web
// service as argument</param>.
// <param name="resolver">Moniker representing the resolver
// to load</param>.
// <param name="message">XML document passed from Web
// service</param>.
// <returns>Dictionary object fully populated</returns>.
Dictionary<string,string> Resolve(string config, string resolver, System.Xml.XmlDocument message);
// <summary>
// This is the main interface that is called from the
// ResolverMgr class.
// This interface supports being called from an orchestration.
// </summary>
// <param name="resolverInfo">Configuration string containing
// configuration and resolver</param>.
// <param name="message">XLANGMessage passed from
// orchestration</param>.
// <returns>Dictionary object fully populated</returns>.
Dictionary<string, string> Resolve(ResolverInfo resolverInfo, XLANGs.BaseTypes.XLANGMessage message);
解析结构位于 Microsoft.Practices.ESB.Resolver 项目中,还定义存储在 Dictionary 实例中的名称/值对。 解析结构公开多个属性;下表列出了其中最相关的内容。 ResolutionHelper 类的 CreateResolverDictionary 方法可用于生成包含最常用的键的解析程序字典,其中包含空字符串值。 Dictionary 实例支持通过 Resolver 类的具体实现添加自定义解析程序名称/值对。
资产 | 数据类型 | 数据类型 | 数据类型 |
---|---|---|---|
TransformType | 字符串 | ActionField | 字符串 |
成功 | 布尔型 | EpmRRCorrelationTokenField | 字符串 |
TransportNamespace | 字符串 | InboundTransportLocationField | 字符串 |
运输类型 | 字符串 | InterchangeIDField | 字符串 |
TransportLocation | 字符串 | ReceiveLocationNameField | 字符串 |
行动 | 字符串 | ReceivePortNameField | 字符串 |
MessageExchangePattern | 字符串 | InboundTransportTypeField | 字符串 |
EndpointConfig | 字符串 | IsRequestResponseField | 字符串 |
TargetNamespace | 字符串 | DocumentSpecStrongNameField | 字符串 |
FixJaxRPC | 布尔型 | DocumentSpecNameField | 字符串 |
WindowUserField | 字符串 | 消息类型 | 字符串 |
CacheTimeout | 字符串 | OutboundTransportCLSID | 字符串 |
MethodNameField | 字符串 |
创建自定义解析程序
在运行时,管道检索解析程序连接字符串并调用解析程序管理器( ResolverMgr 类的实例)。 解析程序管理器分析、填充和验证解析程序连接字符串。 为此,请执行以下步骤:
它会分析连接字符串以确定要加载的 解析程序 类型。
它将此类型与配置文件中定义的名字对象匹配(密钥是根名字对象,如 UDDI)。
它读取此标识符解析器的程序集名称。
它加载指定的程序集。
动态解析机制缓存 IResolveProvider 接口的所有已加载实现,以避免在多个传入消息使用相同的解析程序时重复读取配置信息和程序集加载。
最后,解析程序管理器执行具体 IResolveProvider 实现的 Resolve 方法,并返回填充的 Dictionary 实例。
创建自定义解析程序
创建包含实现 IResolveProvider 接口的类的程序集,并包含一个 Resolve 方法,该方法将解析程序事实作为 Dictionary 类的实例返回。
使用一个包含根名字对象作为name属性和完全限定程序集名称作为type属性的<解析程序>元素,将解析程序添加到Esb.config配置文件中以注册解析程序。
(可选)创建定义根名字对象和查询参数的架构,然后将其保存在 ESB 中。Schemas.Resolvers 文件夹。 该名称应遵循现有的 ESB 命名约定;这意味着它应使用追加有“_Resolution.xsd”的根名字对象的名称。
(可选)从新架构生成一个类,并将其保存在自定义解析程序程序集中。 这会在自定义解析程序中公开类型化参数。
在全局程序集缓存中注册新程序集。