Going binary with BizTalk

When you want to create new message programmatically within an orchestration, you'd normally assign an XmlDocument object to your message.  However: did you ever wonder how you could create non-XML messages within BizTalk Server orchestrations?  (Assigning an XmlDocument would clearly not work here :-) )

For all of you "bitheads", here it is :

Option Explicit On
Option Strict On
Imports System
Imports System.Runtime.InteropServices
Imports Microsoft.XLANGs.BaseTypes

     <Serializable()> _
    Public Class MyStreamFactory
        Implements Microsoft.XLANGs.BaseTypes.IStreamFactory
        Private m_mystringdata As String = ""
        Public Sub New(ByVal stringdata As String)
                m_mystringdata = stringdata 
        End Sub
        Public Overridable Function CreateStream() As System.IO.Stream _
            Implements Microsoft.XLANGs.BaseTypes.IStreamFactory.CreateStream
            return New IO.MemoryStream( _
               System.Text.ASCIIEncoding.ASCII.GetBytes(m_mystringdata ))

        End Function
    End Class
     <Serializable()> _
    Public Class MyMessageCreator

            Public Sub CreateMyMessage(ByVal mydestmsg As XLANGMessage)
                           mydestmsg(0).LoadFrom(New MyStreamFactory("this is my data to create message from"))
            End Sub
     End Class
End Namespace
The trick here is in the IStreamFactory.  BizTalk Server is able to create messages from such a factory class.  In this example, I've just created a 'binary' message from a string, using ASCII encoding.  However: you could just as well assign something like a .PDF file or image to your message if you want.
No limits! BizTalk Server rocks!


Comments have been disabled for this content.