1

Is it possible to convert Microsoft.BizTalk.Operations.BizTalkMessage instance to Microsoft.XLANGs.BaseTypes.XLANGMessage instance (without losing context from BizTalkMessage)?

The reason is that I want to retrieve all constructed orchestration message instances and then add these messages to ESB Toolkit method:

private List<BizTalkMessage> GetOrchestrationMessages()
{
    List<BizTalkMessage> messages = new List<BizTalkMessage>();

    MessageBoxServiceInstance serviceInstance = GetServiceInstance();

    foreach (object item in serviceInstance.Messages)
    {
        BizTalkMessage bizTalkMessage = (BizTalkMessage)item;

        messages.Add(bizTalkMessage);
    }

    return messages;
}


public void HelperMethod(XLANGMessage faultMessage)
{
     foreach(BizTalkMessage biztalkMessage in GetOrchestrationMessages)
     {
        XLANGMessage xlangMessage = ConvertToXLANGMessage(biztalkMessage);

          Microsoft.Practices.ESB.ExceptionHandling.ExceptionMgmt.AddMessage(faultMessage, xlangMessage);
     }
}

So, the main question is how to implement ConvertToXLANGMessage method?

Thank you!

valsador
  • 83
  • 3

1 Answers1

0

There are no direct casts among any of the BizTalk Message Types, XLANGMessage, IBaseMessage, WMI, etc.

Can you do it? Sure, but you'd essentially be recreating the message manually.

Also, I'm pretty sure your code will only get the Messages routed to an Orchestration, not any of the internal/persisted instances.

I have to ask, why are you doing this? It would be better to just handle you Fault message inside the Orchestration using regular exception handling techniques.

Johns-305
  • 10,908
  • 12
  • 21
  • Method mentioned above retrieves all message instances from last persistence point. I am not using regular exception handling techniques because in that case I will need to place try/catch blocks practically for all orchestration shapes where new messages are constructed, because in each of that places different message instances are available. So I will need to hardcode different set of messages in each catch block to avoid error "use of unconstructed message". – valsador Aug 07 '14 at 14:46
  • But I want to avoid hardcoding. – valsador Aug 07 '14 at 14:58