Freigeben über


Use custom pipeline component to set ContentType for outbound AS2 messages

In AS2 Party properties, we can set default content type for outbound messages. However, if ContentType is set in context of AS2 message's body part, the setting in party property will be overwritten. See the following introduction from BizTalk product document.

For Default content type, select the default content type that the home-organization BizTalk Server must use for an outgoing AS2 message. If the ContentType property is set in the context for a message body part, that setting is used to generate the outgoing message; otherwise, the value of this Default content type property is used.

Sometimes we may need to send multiple types of messages to remote partner. For instance, I had a customer has such requirement and their partner checks content type for AS2 messages based on the following pattern.

content tyep="text/plain"                          -> EDI
content tyep="application/octed-stream" -> Flat file

 

In this case, we can write a simple custom pipeline component to achieve it.

 

 

Code snippet:

======================================

 

publicIBaseMessage Execute(IPipelineContext pContext, IBaseMessage pInMsg)

        {

           

IPipelineContext pipelineContext;

           

IBaseMessage baseMessage;

           

//Validate parameters

 

if (pContext == null) thrownewArgumentNullException("pContext");

           

if (pInMsg == null) thrownewArgumentNullException("pInMsg");

            pipelineContext = pContext;

            baseMessage = pInMsg;                    

           

string partName;

           

for (int i = 0; i < baseMessage.PartCount; i++)

            {

                partName =

 

null;

               

 

IBaseMessagePart part = baseMessage.GetPartByIndex(i, out partName);

                part.ContentType = contentType;              

            }

            baseMessage.BodyPart.ContentType = contentType;

           

return baseMessage;

        }

        #endregion

 

Best regards,

WenJun Zhang