Tenalinaga's Blog

I am frog in a well. Every time I jump out of the well; I relialize I am in bigger well and eventually get bored which motivates me to get to next level.

Create a Custom Itinerary Service for Calling BRE Rules (To get sensitive data from SSO for instance)

Custom Itinerary Class

I came accross a question at msdnWCF Custom Binding Credentials required BRE but have to be stored in SSO ? forums how to call Business Rules Engine (Microsoft offcourse!!) from Itineraries, which seemed straight.

It become intersting when questioner wanted to pass the object reference or database reference. Itineraries would let you use the Message (by setting useMsg, recoginze format to true) but not have option to pass parametrs.

Changing regsitry setting (including D-Word of StaticSupport = 1 or 2) and ESB extensions are the proposed solutions which might work. I tried the first and I am not sucessful.

So I came accross this Custom Itinerary feature some time back, and decided to use it. This class would help you solve similar problems or places where you need to write (C#) some code.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.BizTalk.Message.Interop;
using Microsoft.BizTalk.Component.Interop;

namespace CustomItineraryServicePipelineComponent
{
class CustomPipelineItineraryService:Microsoft.Practices.ESB.Itinerary.IMessagingService
{

public Microsoft.BizTalk.Message.Interop.IBaseMessage Execute(Microsoft.BizTalk.Component.Interop.IPipelineContext context, Microsoft.BizTalk.Message.Interop.IBaseMessage msg, string resolverString, Microsoft.Practices.ESB.Itinerary.IItineraryStep step)
{

System.Diagnostics.Debug.WriteLine(“\nInside Execute Method\n”);

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”);

System.Diagnostics.Debug.WriteLine(“Parametrs Received Corretly”);

// Try Starts here
Microsoft.Practices.ESB.Resolver.ResolverInfo _info = Microsoft.Practices.ESB.Resolver.ResolverMgr.GetResolverInfo(Microsoft.Practices.ESB.Resolver.ResolutionType.Endpoint, resolverString);
if (!_info.Success)
{
throw new ArgumentException(“Properties.Resources.Failed to aquire ResolverInfo”, “resolverString”);
}

// System.Diagnostics.Debug.WriteLine(“Got Resolver into and about to get Resolver Dicitinary”);

//Microsoft.Practices.ESB.Resolver.ResolverDictionary _Dictionary = new Microsoft.Practices.ESB.Resolver.ResolverDictionary _Dictionary();
Dictionary _Dictionary = Microsoft.Practices.ESB.Resolver.ResolverMgr.Resolve(_info, msg, context);

// System.Diagnostics.Debug.WriteLine(_Dictionary.Count().ToString());

// List _list = new List (_Dictionary.Keys);

// foreach (string _k in _list)
// {
// System.Diagnostics.Debug.WriteLine(_k, _Dictionary[_k]);
// }

Microsoft.Practices.ESB.Adapter.AdapterMgr.SetEndpoint(_Dictionary, msg.Context);
System.Diagnostics.Debug.WriteLine(“Endpoints Set”);

string _TransportLocation = “”;
string _UserName = “”;
string _Password = “”;

System.Diagnostics.Debug.WriteLine(“Get SSO Information”);
try
{

_TransportLocation = Microsoft.SSO.Utility.SSOConfigHelper.Read(“Naga”, “OracleTransportLocation”);
_UserName = Microsoft.SSO.Utility.SSOConfigHelper.Read(“Naga”, “OracleWCFUserName”);
_Password = Microsoft.SSO.Utility.SSOConfigHelper.Read(“Naga”, “OracleWCFPassword”);

System.Diagnostics.Debug.WriteLine(“itinerary TransportLocation” + _TransportLocation);
System.Diagnostics.Debug.WriteLine(“itinerary UserName” + _UserName);
System.Diagnostics.Debug.WriteLine(“itinerary Password” + _Password);
}
catch
{
System.Diagnostics.Debug.WriteLine(“Error fetching SSO information”);
throw new System.ApplicationException(“Error”);
}

//Microsoft.Practices.ESB.Adapter.AdapterMgr.SetContextProperties(msg.Context,c
System.Diagnostics.Debug.WriteLine(“Promote Properties”);
msg.Context.Promote(“OutboundTransportLocation”, “http://schemas.microsoft.com/BizTalk/2003/system-properties”, _TransportLocation);
msg.Context.Promote(“UserName”, “http://schemas.microsoft.com/BizTalk/2006/01/Adapters/WCF-properties”, _UserName);
msg.Context.Promote(“Password”, “http://schemas.microsoft.com/BizTalk/2006/01/Adapters/WCF-properties”, _Password);
return msg;
}

public string Name
{
get { return “CustomPipelineItineraryService”; }
}

public bool ShouldAdvanceStep(Microsoft.Practices.ESB.Itinerary.IItineraryStep step, IBaseMessage msg)
{
return true;
}

public bool SupportsDisassemble
{
get { return true; }
}
}
}

Resolver I used is BRE for getting endpoints. Which would look like.

Import things to notice are Transport Location, UserName & Password (these are part of set “Set End Point Config to” in BRE) are set to “GetFromSSO” which is a string, that gets overwritten by content obtained from SSO in the class.

BREPloicy

Check the link to development of Custom Itinerary Messaging Service for better documentation.

Set End Point Config to BindingType=oracleDBBinding&BindingConfiguration=&EndpointBehaviorConfiguration=

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: