订阅消息和提取消息
业务流程可以包含用于订阅和从 ESB 错误消息中提取消息的代码。 例如,以下代码使用 GetMessage 和 GetException 方法从 ESB 错误消息中提取两条强类型消息和 System.Exception 对象。
// Retrieve two messages from the fault message.
requestMsg = Microsoft.Practices.ESB.ExceptionHandling.ExceptionMgmt.GetMessage(
faultMsg, "ApprovedRequest");
deniedMsg = Microsoft.Practices.ESB.ExceptionHandling.ExceptionMgmt.GetMessage(
faultMsg, "DeniedRequest");
// Retrieve the System.Exception object.
newExc = Microsoft.Practices.ESB.ExceptionHandling.ExceptionMgmt.GetException(
faultMsg);
为了提取无类型消息,以下代码使用 GetMessages 方法提取所有消息,然后循环访问它们。
Microsoft.Practices.ESB.ExceptionHandling.MessageCollection msgs;
msgs = Microsoft.Practices.ESB.ExceptionHandling.ExceptionMgmt.GetMessages(faultMsg);
System.Xml.XmlDocument tmpMsg;
while (msgs.MoveNext())
{
tmpMsg = msgs.Current;
}