建立自訂路線傳訊服務
屬於 Microsoft BizTalk ESB 工具組一部分的路線架構支援使用實作執行路線傳訊服務的 IMessagingService 介面的類別來執行路線步驟。 當您想要讓服務負責下列作業時,可以實作自訂傳訊服務:
在路線中設定的自訂訊息驗證
在路線中設定的自訂訊息轉換
訊息的自訂處理
在這些情況下,您實作的自訂路線服務會作為攔截器,並由發送器管線元件呼叫。
自訂傳訊型路線服務或傳訊服務,全都會實作 IMessagingService 介面。 此介面會公開 Name 和 SupportsDisassemble 屬性和 Execute 和 ShouldAdvanceStep 方法。
Name屬性是服務的名稱,因為它會顯示在路線中。 它必須符合 Esb.config 檔案中路線服務組態中設定的名稱。
SupportsDisassemble屬性指出您要建立的自訂傳訊服務是否支援反組解碼和執行多個解析程式。
ShouldAdvanceStep方法會採用目前的路線步驟和目前的訊息,並傳回 Boolean 值,指出發送器是否應在服務執行之後前進路線。 幾乎所有情況下,這個方法都應該傳回 true。
Execute方法對於傳訊服務而言非常重要,而且包含將在執行時間執行的邏輯。 它會採用管線內容、訊息、解析程式字串和目前的路線步驟;並傳回更新的訊息。
Execute方法的參考實作可以在 ESB 的 RoutingService.cs 檔案中找到。Itinerary.Services 專案,如下列程式碼所示。
public IBaseMessage ExecuteRoute(IPipelineContext context, IBaseMessage msg, string resolverString)
{
if (context == null)
throw new ArgumentNullException("context");
if (msg == null)
throw new ArgumentNullException("msg");
if (string.IsNullOrEmpty(resolverString))
throw new ArgumentException(Properties.Resources.ArgumentStringRequired, "resolverString");
try
{
ResolverInfo info = ResolverMgr.GetResolverInfo(ResolutionType.Endpoint, resolverString);
if (!info.Success)
throw new RoutingException(Properties.Resources.ResolverStringInvalid, resolverString);
// Resolve configuration for routing.
Dictionary<string, string> resolverDictionary = ResolverMgr.Resolve(info, msg, context);
if (string.IsNullOrEmpty(resolverDictionary["Resolver.TransportLocation"]))
throw new RoutingException(Properties.Resources.TransportLocationNotResolved, resolverString);
AdapterMgr.SetEndpoint(resolverDictionary, msg.Context);
return msg;
}
catch (System.Exception ex)
{
EventLogger.Write(MethodInfo.GetCurrentMethod(), ex);
throw;
}
}
實作傳訊的自訂路線服務
使用衍生自 IMessagingService 的類別建立元件;在 Execute 方法中,包含修改訊息或訊息內容所需的所有邏輯,如果有任何) ,則 (。
新增具有 GUID 做為id屬性、服務名稱做為name屬性、類別的完整名稱做為類型屬性、傳訊作為範圍屬性,以及允許的階段 (,以新增服務之 Esb.config 檔案< 的 itineraryServices >區段中的專案。OnRampReceive、OnRampSend、OffRampSend、OffRampReceive、AllSend、AllReceive或All) 作為階段屬性。
在全域組件快取中註冊新的元件。