ESB Toolkit Management Portal Resubmit with Itinerary

Edit the MessageViewer.ascx.cs BindGrid method grabbing the itinerary from context and store in an invisible label for later use.

private void BindGrid()
        {
            IExceptionService client = null;
            try
            {
                client = PortalHelper.GetExceptionService();

                List<usp_select_ContextPropertiesResult> contextProperties = client.GetContextProperties(new Guid(Request.QueryString["esb:MessageID"]));
                
                contextPropertiesView.DataSource = contextProperties;
                contextPropertiesView.DataBind();

                // Get Itienrary from context properties and write to visible=false label
                if (contextProperties.Exists(delegate(usp_select_ContextPropertiesResult prop) { return prop.Name == "ItineraryHeader"; }))
                {
                    usp_select_ContextPropertiesResult itineraryContextProperty = contextProperties.Find(delegate(usp_select_ContextPropertiesResult prop) { return prop.Name == "ItineraryHeader"; });
                    this.lblItineraryHeader.Text = itineraryContextProperty.Value;
                }

Edit the ResubmitMessage method of MessageViewer.ascx.cs. Things to note is reading the itinerary from the label and then just deserializing it to the Itinerary Object. Note in the below POC code the MessageResubmitter.ResubmitWCF method has been modified to return the exception.Message to display on the UI and also take an extra parameter, of type Itinerary.

private bool ResubmitMessage(string resubmitUrl, out string responseCode, out string responseMessage)
        {
            bool result = false;    // returned.
            if (resubmitUrl.ToUpper().Equals("WCF ONRAMP"))
            {
                // resubmit message and capture the result
                System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
                doc.LoadXml(((TextBox)this.MessageView.FindControl("messageBodyBox")).Text);

                // Derserialize ItineraryHeader
                System.Xml.Serialization.XmlSerializer reader = new System.Xml.Serialization.XmlSerializer(typeof(Itinerary));
                StringReader sr = new StringReader(this.lblItineraryHeader.Text);
                Itinerary itinerary = (Itinerary)reader.Deserialize(sr);

                string response = MessageResubmitter.ResubmitWCF(itinerary, doc);
                if (response == string.Empty)
                {
                    result = true;
                    responseCode = "202";
                    responseMessage = "Successfully sumbitted to WCF OnRamp";
                }
                else
                {
                    result = false;
                    responseCode = "500";
                    responseMessage = "Failure re-submitting to WCF OnRamp : " + response;
                }
            }

For the deserialization code above to work I had to edit the Itinerary Type to include the XmlRootAttribute as below. You don’t need to do this for SOAP as the ProcessItinerary.Itinerary type already has this.

[System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "3.0.4506.30")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "http://schemas.microsoft.biztalk.practices.esb.com/itinerary")]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "http://schemas.microsoft.biztalk.practices.esb.com/itinerary", IsNullable = false)]
public partial class Itinerary

Edited MessageResubmitter.ResubmitWCF below.

public static string ResubmitWCF(Itinerary itinerary, XmlDocument doc)
      {
         try
         {

            ProcessRequestClient onRamp = new ProcessRequestClient();
            onRamp.SubmitRequest(itinerary, doc.OuterXml);
            return string.Empty;
         }
         catch (Exception ex)

That is pretty much it for the portal enhancements. Create a WCF-WSHTTP receive location with config as per the below security tab, which should match up with the config in the ESB Portal web.config.

Screen Shot 2015-11-04 at 9.41.08 pm

Your receive pipeline will look something like the following.  Ignore the Reset Itinerary State component.  It’s some POC code I wrote that generically resets an itinerary state for a specific project.  If you want to resume the itinerary at the point where it failed all you need do is drop an ESB Itinerary component as the first component followed by an ESB Dispatcher to start executing your itinerary.  The ESB Itinerary component basically takes the itinerary from the inbound message and places it in the ItineraryHeader context property ready for the ESB Dispatcher.

Screen Shot 2015-11-04 at 9.43.10 pm 1

That it!  Too easy…

Advertisements
This entry was posted in BizTalk Server. Bookmark the permalink.

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