AS2 Integration between SeeBurger BIS 6.0 and BizTalk server 2009

Recently I have been involved in an Integration activity between SeeBurger BIS 6.0 and BizTalk Server 2009 for AS2 communication. on QA everything was fine but in Production our partner started getting error "Illegal MDN Received" and ContentType and Charset was not as our partner accepted. partner wanted ContentType of the MDN message as "text/plain' while BizTalk Server 2009 was sending ContentType=text/plain and Charset=utf-8. We performed multiple round of test but still we were clueless as from where utf-8 as charset was getting populated.
      We continued testing for days but no encouraging results. We were using Request-Response port for receiving AS2 and sending Synchronous MDN. In case of Request-Response port and for Synch MDN we do not provide the url to send MDN. I thought if we can make the contentType as blank then it should be able to decide the ContentType required for MDN communication. As a solution we wrote a custom pipeline compoment and set the Message.ContentType="". This gave us the desired result and we were successfully able to receive AS2 message and send MDN to the partner. Below is the code for the help.
 
public IBaseMessage Execute(IPipelineContext context, IBaseMessage pInMsg)
        {
            try
            {
                IBaseMessagePart bodyPart = pInMsg.BodyPart;
                if ((bodyPart != null))
                {
                    // change the default content type to none.
                    pInMsg.BodyPart.ContentType = "";
                }
                return pInMsg;
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }
 
 
Second Issue which we faced was to preserve the name of the received AS2 file. As you know in BizTalk Server 2006 R2 you can not preserve the file name of the As2 message. In BizTalk Server 2009 edition you PreservedFileName as context property for the AS2 messages. Also AS2PayLoadContentType also contains the file name. By utilizing these two information we were able to preserve the file name. We read this context property from context and then we assigned or wrote this property to ReceivedFileName. Later at the file send port we gave the file name as %SourceFileName% and it all worked. Below is the code for help.
 
#region IComponent interface public methods
 
        public IBaseMessage Execute(IPipelineContext pc, IBaseMessage inmsg)
        {
           
            IBaseMessagePart bodyPart = inmsg.BodyPart;
            IBaseMessageContext context = inmsg.Context;
           
            string httpHeader = "";
            string filename = "";
           
            if (bodyPart != null)
            {
                try
                {   
                    if (Path.GetFileName(context.Read("PreservedFileName", "http://schemas.microsoft.com/BizTalk/2006/as2-properties").ToString()) != String.Empty)
                                {
                                   
                                    filename = Path.GetFileName(context.Read("PreservedFileName", "http://schemas.microsoft.com/BizTalk/2006/as2-properties").ToString());
                                    System.Diagnostics.EventLog.WriteEntry("BizTalk  Pipeline Component", filename);
                    }
                    else
                    {               
                                   
                                   
                                    httpHeader = context.Read("AS2PayloadContentType", "http://schemas.microsoft.com/BizTalk/2006/as2-properties").ToString();
                                    filename = Path.GetFileName(httpHeader.Substring(httpHeader.IndexOf("name=") + 5));
                                    System.Diagnostics.EventLog.WriteEntry("BizTalk Pipeline Component", filename);
                                    
                                   
                                   
                                    filename = Path.GetFileName(context.Read("ReceivedFileName", "http://schemas.microsoft.com/BizTalk/2003/file-properties").ToString());
                                   
                                   
                                }
                            context.Write("ReceivedFileName", "http://schemas.microsoft.com/BizTalk/2003/file-properties", filename);
 
                   }
            catch (Exception ex)
        {
        System.Diagnostics.EventLog.WriteEntry("BizTalk Pipeline Component Error", ex.ToString());
        throw ex;
        }
        }
        return inmsg;
                
        }
 
        #endregion