建立自訂解析程式
Microsoft BizTalk ESB 工具組中的 Resolver 和 Adapter Provider Framework 實作會使用名為 Dispatcher 的管線元件,以及名為 RoutingyReceive 和 RoutingySend 的管線元件。
發送器管線元件有四個屬性: Validate、Enabled、EndPoint 和 MapName。 EndPoint 屬性可以包含具有下列值的解析程式連接字串,其中 UDDI:\\ 代表要用來 (根 Moniker) 的解析類型。
UDDI:\\serverUrl=http://localhost/uddi;serviceName=OrderPurchaseToOrderPost;serviceProvider=Microsoft.Practices.ESB
其他支援的Monikers包括 XPATH:\\、STATIC:\\和BRE:\\。 每個Moniker類型都會使用實作 IResolveProvider 介面的特定類別。 您可以為其他Moniker類型建立自己的自定義解析程式,並註冊它們以供動態解析系統使用。
Moniker 相當於解析程式 連接字串。 個別架構會定義參數及其根Moniker。 解析程式會取得解析程式 連接字串、驗證解析程式,並使用結果來查詢及填入字典物件,該物件可用於路由、轉換、路線選取,或服務特定的其他用途。
解析程式組態
您必須在 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 相容的登錄設定額外的 Moniker,但已支援這些登錄,可以使用下列組態屬性:
cacheTimeoutValue
cacheName
publisherKey
useUddiAuth
baseUri
查詢UriSuffix
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 介面包含三個可傳回 Dictionary 類別實例的 Resolve 方法多載,其中包含具象解析程式類別實例所提供的解析事實。 下列程式代碼範例顯示這些方法多載的簽章。
// <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 | 字串 |
「成功」 | Boolean | EpmRRCorrelationTokenField | 字串 |
TransportNamespace | 字串 | InboundTransportLocationField | 字串 |
TransportType | 字串 | 交換標識符欄位 | 字串 |
TransportLocation | 字串 | ReceiveLocationNameField | 字串 |
動作 | 字串 | ReceivePortNameField | 字串 |
MessageExchangePattern | 字串 | InboundTransportTypeField | 字串 |
EndpointConfig | 字串 | IsRequestResponseField | 字串 |
TargetNamespace | 字串 | DocumentSpecStrongNameField | 字串 |
FixJaxRPC | Boolean | DocumentSpecNameField | 字串 |
WindowUserField | 字串 | MessageType | 字串 |
CacheTimeout | 字串 | OutboundTransportCLSID | 字串 |
MethodNameField | 字串 |
建立自訂解析程式
在運行時間,管線會擷取解析程式 連接字串,並呼叫解析程式管理員, (ResolverMgr 類別的實例) 。 解析程式管理員會剖析、填入和驗證解析程式 連接字串。 它會執行下列動作來執行此動作:
它會剖析 連接字串,以判斷要載入的解析程序類型。
它會將此類型與組態檔中定義的Moniker比對, (索引鍵是根Moniker,例如UDDI) 。
它會讀取這個Moniker之解析程式的元件名稱。
它會載入指定的元件。
動態解析機制會快取 IResolveProvider 介面的所有載入實作,以避免在數個傳入訊息使用相同的解析程式時重複讀取組態資訊和元件載入。
最後,解析程式管理員會執行具象 IResolveProvider 實作的 Resolve 方法,並傳回填入的 Dictionary 實例。
建立自定義解析程式
使用實作 IResolveProvider 介面的類別建立元件,並包含 Resolve 方法,這個方法會傳回解析程式事實做為 Dictionary 類別的實例。
使用<包含根 Moniker 做為名稱屬性的解析>程式,並將完整元件名稱新增至 Esb.config 組態檔,以註冊解析程式。
(選擇性) 建立定義根 Moniker 和查詢參數的架構,然後將它儲存在 ESB 中。Schemas.Resolvers 資料夾。 名稱應遵循現有的 ESB 命名慣例;這表示它應該使用附加 「_Resolution.xsd」 的根 Moniker 名稱。
(選擇性) 從新的架構產生類別,並將它儲存在自定義解析程式元件中。 這會公開自定義解析程式中的具型別參數。
在全域程式集緩存中註冊新的元件。