Geeks With Blogs
Pseudo Knowledge Base Useful stuff I've collected... Enjoy.

I recently built a recieve location that used used a File adaptor to test the recieve and Orchestration for a new multipart message.  It all went well until I converted the recieve port to a HTTP adaptor.  At that point my custom component in the recieve pipeline raised a 'method not implemented' error.

After several tests I was sure that the error was specific to HTTP adaptor and was not a problem with the installation of the custom component.  One theory that I had was that an aditional method(s) may be required when implementing a custom components in a HTTP recieve pipeline hence the error.  This was proven to be wrong.

In fact the issue was due to less methods being implemented in the HTTP adapter API.  In this case I was calling a property setter that was implemented in the File adaptor API but not in the HTTP adaptor API.  Specifically I was calling msg.BodyPart.Data getter.

To overcome this problem we used the get OriginalDataStream method to retieve the message stream as shown in the code below.

        public IBaseMessage Execute(IPipelineContext pc, IBaseMessage inmsg)
            //Convert Stream to a string
            Stream s = null;
            IBaseMessagePart bodyPart = inmsg.BodyPart;
            // NOTE inmsg.BodyPart.Data is implemented only as a setter in the http adapter API and a
            //getter and setter for the file adapter.  Use GetOriginalDataStream to get data instead.
            if (bodyPart != null)
                s = bodyPart.GetOriginalDataStream();

            byte[] bytes = new byte[s.Length];
            int n = s.Read(bytes, 0, (int)s.Length);
            string msg = new ASCIIEncoding().GetString(bytes).TrimEnd(null);
            //Get boundry value from first line of code
            string boundry = msg.Substring(2, msg.IndexOf("\r\n")-2);
            //Create new start to message with MIME requirements.
            msg = "MIME-Version: 1.0\r\nContent-Type: multipart/related; boundary=\"" + boundry + "\"\r\n" + msg;
            //Convert back to stram and set to Data property
            inmsg.BodyPart.Data = new MemoryStream(Encoding.UTF8.GetBytes(msg)); ;

            //reset the position of the stream to zero
            inmsg.BodyPart.Data.Position = 0;
            return inmsg;

(Note: to debug the custom code in the HTTP recieve pipeline attach to the w3wp.exe process)

Posted on Tuesday, January 13, 2009 1:06 PM BizTalk | Back to top

Comments on this post: Problems receiving a Multi Part Message via a HTTP vs File Adaptor

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Geordie | Powered by: