Going binary with BizTalk

Published 08 July 04 08:36 PM | christof claessens

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
 

Namespace CLAESSENS.BTS2004.SAMPLES
     <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!
 
Filed under:

Comments

# Patrick Wellink said on July 12, 2004 02:14 AM:

Hi Christof,

I am currently having problems sending binary attachments with the SMTP adapter.

Do you think I could use this to send Binary messages via FTP ? (and if I could could you hint a littlebit)




# Christof Claessens said on July 14, 2004 05:29 PM:

Hi Patrick,

yes you may use this with the SMTP adapter. We are addressing your question in the public newsgroup :-)

You might need to do some BASE64 encoding as well.

Best regards,
Christof

# TrackBack said on October 21, 2004 02:49 AM:
# TrackBack said on October 21, 2004 02:51 AM:

Leave a Comment

(required) 
(required) 
(optional)
(required)