March 12, 2009, 6:40 a.m.
posted by angryuser
DIMEAt times you will need to send binary data with a SOAP message. For example, you may want to send an image from a Web server to an image server in order to customize the image for the Web surfer. For scenarios such as this, you have a couple of options: You can encode the binary data as a string (either as hexBinary or base64), or package the SOAP message into a format that is friendly to both XML and binary data, such as MIME (Multipurpose Internet Mail Extension) or DIME (Direct Internet Message Encapsulation). Multipart MIME has existed for many years and has been used quite successfully for sending e-mail with attachments. DIME is a new specification that has been specially designed for this scenario of SOAP messages with binary attachments (although it also works well for non-SOAP scenarios). Anatomy of a DIME MessageDIME makes a distinction between messages and records. A message is a series of records. Each DIME record contains a fixed-length header that determines the length and type of the record. The first and last records in the message also indicate this about themselves. Figure shows the format of a typical DIME message consisting of multiple records. 6. A Typical DIME Message
The data section of each record can be of any length up to 4GB in size. The header has a fixed length of 128 bits. The data itself is padded so that it is an exact multiple of 32 bits. This allows for DIME records to be packed into 32-bit memory registers nicely. Figure shows this layout. 7. DIME Record Layout
Using DIME with SOAPDIME was designed mostly for use with SOAP—not only for sending SOAP messages with attachments over HTTP, but also for sending SOAP messages (with or without attachments) over TCP. This is a particularly good reason for using DIME over multipart MIME. When using SOAP with DIME, there are only a couple of really important rules to remember: The first record in the DIME message must be the SOAP message, and the rest of the records in the message are the attachments. Each attachment is assigned an ID; therefore, to refer to any particular attachment within a SOAP message, use an href attribute. Figure shows how this ID can be used. 8. Using IDs
With the WSE, you can easily add attachments to any request or response message by merely creating a new DimeAttachment object, and then adding that attachment to the Attachments collection of the Soap-Context. If there are any attachments in this collection, then the WSE auto-matically switches from doing plain SOAP to SOAP with DIME, as defined in the WS-Attachments specification. Here is a small example of how you could do this from a client application that uses a proxy class:
Using Microsoft.Web.Services.Dime;
Using Microsoft.Web.Services;
Using System.IO;
DimeAttachment att = new DimeAttachment("image/gif",
TypeFormatEnum.MediaType,
File.OpenRead("..\\..\\some.gif "));
proxy.RequestSoapContext.Attachments.Add(att);
|
- Comment


