|
How to handle binary data with SOAP
Tech Forum - Dr. Nitin Paranjpe
Everyone
knows that MIME (Multipurpose Internet Mail Extensions) is the method
used to send attachments along with mail messages. MIME was designed
for Internet mail and it was designed before SOAP (Simple Object
Access Protocol) and XML (Extensible Markup Language) came into
the picture.
Now, users of SOAP also need to bundle binary
data within the messages. Generally this is done based upon some
type of encoding. However, an encoding-based approach has the following
problems:
- The problem with encoding is that
it requires decoding at the other end, thus making the process
slow.
- MIME based data attachments are stored
in a linear fashion. To search for a given attachment, you have
to traverse through the entire set of messages. Boundaries between
different binary attachments are not defined in the header.
SOAP uses XML as the core standard for data
transfer. Binary data is encoded and sent. However, digitally signed
data cannot be tampered with. Furthermore, many binary data formats
like images are already highly structured and optimised. To convert
these to XML and back into native format would be a very slow process.
In short, there is a need for a method that
can allow binary files to be attached to a SOAP message without
any modification, while allowing fast processing at the sending
as well as the receiving end. This is exactly why a new specification
called Direct Internet Message Encapsulation (DIME) was created.
It does not replace MIME. In fact, the scenarios wherein DIME (SOAP
messages) is used do not overlap with MIME at all (Internet mail
messaging).
Understanding DIME
DIME is a specification that allows inclusion
of one or more binary files in a single package. The contents could
be of any type and any size. This standard is simpler and more convenient
to program and utilise. A typical DIME package contains a Message
Begin flag, multiple binary records and a Message End flag. The
record contains a header, which includes information like the size
of the record. While creating and sending the record, the processing
application does not need to know the overall size of the package.
When the records are transmitted, it simply adds the end-record
flag. This results in much faster and more flexible processing.
If the data is so large that available memory
itself can become a constraint, you can even break it up into pieces
and send it as a set of multiple records. If you have data that
is being created and sent online, it is not even possible to know
the exact size of the data till it actually stops generating. Even
in these cases you can use DIME. This would be a typical scenario
where a database query result is being sent out live as a DIME message.
How DIME works with SOAP
When you want to attach binary files along
with a SOAP message, you attach the DIME package to it. To refer
to an attached binary record, the SOAP message must contain a reference
to the record ID. The record ID must be defined for each DIME record.
The primary SOAP message may cross-reference any subsequent attachments
by a Universal Unique Identifier (UUID) or any form of URI (Uniform
Resource Identifier). This UUID is indicated by the ‘href’ attribute
and is used to match the ID field of the corresponding DIME record.
Ws-attachments
Ws-attachments is a specification which
specifies how DIME is to be incorporated into SOAP messages. The
detailed specification can be found at:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnglobspec/html/wsattachmentsindex.asp
The actual specification is available at:
http://www.ietf.org/mail-archive/ietf-announce/Current/msg19323.html
WSDL Extension for SOAP
The WSDL Extension for SOAP in the DIME
specification defines XML elements and attributes for use in Web
Service Description Language (WSDL) documents to describe the encapsulation
of a Simple Object Access Protocol (SOAP) message with base64Binary
and/or hexBinary content in a Direct Internet Message Exchange (DIME)
message. There is a new dime::message element and many related attributes.
The details can be found at:
http://www.gotdotnet.com/team/xml_wsspecs/dime/WSDL-Extension-for-DIME.htm#_Toc8625757
DIME references
Details of the DIME specifications can be
found at:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnglobspec/html/dimeindex.asp
 |
About the Author:Dr
Nitin Paranjape is the Chairman and MD of Maestros (Mediline).
He is a consultant with many organisations, covering appropriate
technology utilisation, business application of relevant technology,
application architecture and audit as well as knowledge transfer.
He has authored more than 650 articles on various technology-related
subjects. He can be contacted at nitin@mediline.co.in |
|