FW: IComponent.Execute Consider...

The Execute method returns the IBaseMessage object,which represents all parts of the processed message (such as the message content and context). You may perform any type of message or context processing if you return the IBaseMessage object  at the end of the function. When BizTalk processes messages through pipelines, it streams the messages, rather than passing the whole messages. Additionally, the message passed through the pipeline is a read-only data object. You must perform the following steps if you plan to alter the message content:

1. Create a memory stream object to hold the contents on the updated message or a copy of the inbound message. Remember that an inbound message is read-only, and you need a new container to perform updates to the inbound message. The new memory stream object is a container for the updated message.

2. Process the inbound message stream. The easiest way of processing the inbound message is to copy the stream to a string and load the message into an XMLDocument. However, using an XMLDocument object does not perform well and is not recommended for a production-type solution. A better method involved using a stream reader to manipulate the inbound stream. Consider the following approaches for manipulating the inbound memory stream:

  • Use Stream.Read() as the primary mechanism for dealing with message content.
  • Use XMLReader.Read() as the secondary mechanism for dealing with message content.
  • Use the XML message in the DOM as a last resort option due to the performance hit. Specifically, if you're dealing with large messages, do not load the entire message into the DOM for processing.

3. Set the message body part. After processing the message, you must return the updated message. If you used a memory stream object , you can set the return IBaseMessage.Data object to the memory stream object. Remember to rewind the updated memory stream object so you are passing the whole message and not the end of the memory stream. The pipeline processor will not attempt to rewind the stream, and you will receive a pipeline if the stream is not rewound. 

4. Add the memory stream to the resource tracker. If you used a new memory stream object, make sure to add the memory stream object to the IPipelineContext.Resourcetracker for cleanup. 

Pipelines are the first line of processing before a message is received by the BizTalk MessageBox or before the message is received by a target system. Out-of-the-box functionally supports the ability to perform straightforward processing of messages. There may be situations that require more complex processing, data validation, or interaction with .NET objects. In those situations, implementing a custom pipeline component offers the flexibility of adding processing logic within the BizTalk framework. 

The main function required for implementing a custom pipeline component is the Execute function in the IComponent interface. The other interfaces serve for design-time and component interactions with the runtime engine. 

Manipulation of the inbound message requires making a copy of the inbound message stream, as the inbound message stream is read-only. Before a memory stream can be returned to the IBaseMessage.Data object, it must be rewound, as the BizTalk pipeline engine does not perform this function. You should also clean up memory stream objects by adding the object to the pipeline resource tracker.

你可能感兴趣的:(component)