SOAP Message with Binary Attachments


SOAP (Simple Object Access Protocol) is message based protocol. SOAP messages are nothing but XML document. SOAP messages consist of Envelop Header and Body .XML document data elements are self describing. In this article I am going to show how to attach binary data into SOAP message.


eXtensible Markup Language, XML is text based data storage, XML data are self describing and this data easily move to any platforms (because XML document is ASCII text). XML is not a replacement for HTML. XML and HTML were designed with different goals, XML was designed to describe data and HTML was designed to display data and to focus on how data looks. HTML is about displaying information, XML is about describing information.

Nowadays email clients uses MIME format for attachments, MIME means Multipurpose Internet Mail Extensions. SOAP messages also uses same MIME format for Binary data attachments.


Recently Microsoft announced new format called DIME: Sending Binary Data with Your SOAP Messages. Direct Internet Message Encapsulation (DIME) specification defines a mechanism for packaging binary data with SOAP messages, so that when sending data not in XML format, applications need not be constrained by the SOAP specification

When we attach binary data into XML document we will be using base64 encoding format. This base64 encoding uses A-Z, a-z, 0-9 and / characters for encoding.

COM Interoperability:

I developed this application in VB 6.0, using COM Interoperability I imported this application to .NET. Here MSXML and ADO are called using RCW (Runtime COM callable wrapper). RCW helps .NET client can able to call unmanaged codes.

Here I am creating a record set with image filed and then Creating XML document based on the record set fields.

Dim objCon As New ADODB.Connection
Dim sql As String = "SELECT * from pub_info where pub_id='0736'"
Dim rst As New ADODB.Recordset
Dim http As New MSXML2.DOMDocument
Dim onode As MSXML.IXMLDOMNode
Dim oroot, oele As MSXML2.IXMLDOMElement
Dim sCon1 As String = "Provider=SQLOLEDB;User ID=sa; password=sa;Initial"
Catalog=pubs;Data Source=(local)"
rst = objCon.Execute(sql)
Console.Write("{0}", rst(1))
http.loadXML("<?xml version=""1.0""?>"")")
oroot = http.createElement("FamilyImages")
http.documentElement = oroot
oele = http.createElement("Ragavan")
'These following Two lines are very important
'Here we are setting Record set Image fields to base64 data type
oele.dataType = "bin.base64"
oele.nodeTypedValue = rst.Fields(1).Value

Once you create the XML document you post this XML to Server as a SOAP