6
11/28/10 1:00 PM Introduction to MTOM: Hands-on Page 1 of 6 http://www.crosschecknet.com/intro_to_mtom.php Introduction to MTOM A hands-on Approach MTOM OVERVIEW With web services-based SOA now being deployed across Global 2000 enterprises, transmitting attachments such as MRI Scans, X-Rays, Design Documents and Business Contracts using SOAP messages has become a common practice. SOAP Message Transmission Optimization Mechanism (MTOM), is a W3C Recommendation designed for optimizing the electronic transmission of attachments. Through electronic transmission of documents, corporations can realize significant cost savings and better service levels by eliminating the use of postal mail. Paper-based manual tasks can be replaced with simple and efficient electronic processes where binary data can be transmitted between organizations through standards such as MTOM. MTOM provides an elegant mechanism of efficiently transmitting binary data, such as images, PDF files, MS Word documents, between systems. The Figure below shows the steps involved in transmitting data between a Consumer and Producer using MTOM. The Consumer application begins by sending a SOAP Message that contains complex data in Base64Binary encoded format. Base64Binary data type represents arbitrary data (e.g., Images, PDF files, Word Docs) in 65 textual characters that can be displayed as part of a SOAP Message element. For the Send SOAP Message Step 1 in the Figure above, a sample SOAP Body with Base64Binary encoded element <tns:data> is as follows: <soap:Body> <tns:ByteEcho> <tns:data>JVBERi0xLjYNJeLjz9MNCjE+DQpzdGFyNCjEx0YNCg==</tns:data> </tns:ByteEcho> </soap:Body> An MTOM-aware web services engine detects the presence of Base64Binary encoded data types, <tns:data> in our example, and makes a decision – typically based on data size – to convert the Base64Binary data to MIME data with an XML-binary Optimization Package (xop) content type. The data conversion, shown in Step 2 of the Figure above, results in replacing the Base64Binary data with an <xop:Include> element that references the original raw bytes of the document being transmitted. The raw bytes are appended to the SOAP Message and are separated by a MIME boundary as shown below: <soap:Envelope> <soap:Body> <tns:ByteEcho> <tns:data><xop:Include href="cid:[email protected]"/></tns:data> </tns:ByteEcho> </soap:Body> </soap:Envelope> --MIMEBoundary000000 content-id: <[email protected]> content-type: application/octet-stream content-transfer-encoding: binary The raw binary data along with the SOAP Message and the MIME Boundary is transmitted over the wire to the Producer. The Producer then changes the raw binary data back to Base64Binary encoding for further processing. With this conversion between Base64Binary and raw binary MIME types, MTOM provides two significant advantages: 1. Efficient Transmission: Base64Binary encoded data is ~33% larger than raw byte transmission using MIME. MTOM therefore reduces data bloat by converting Base64Binary encoding to raw bytes for transmission. 2. Processing Simplicity: Base64Binary encoded data is composed of 65 textual characters. The data is represented within an element of a SOAP message. Security standards such as WS-Signatures and WS-Encryption can directly be applied to the SOAP Message. Once such operations are performed, the Base64Binary data can be converted to raw bytes for efficient transmission. Securing document transmission via SOAP, therefore, does not require additional standards for securing MIME-based attachments. In this paper, we will deploy a web service for processing binary data ByteEcho(byte[] data) and examine using this service without MTOM and with MTOM enabled. SETUP AND INSTALLATION OVERVIEW Home About Us Products Solutions Cloud Resources Downloads Press Support Contact Us

Introduction to MTOM: A Hands-On Approach

Embed Size (px)

DESCRIPTION

With web services-based SOA now being deployed across Global 2000 enterprises, transmitting attachments such as MRI Scans, X-Rays, Design Documents and Business Contracts using SOAP messages has become a common practice. SOAP Message Transmission Optimization Mechanism (MTOM), is a W3C Recommendation designed for optimizing the electronic transmission of attachments. Through electronic transmission of documents, corporations can realize significant cost savings and better service levels by eliminating the use of postal mail. Paper-based manual tasks can be replaced with simple and efficient electronic processes where binary data can be transmitted between organizations through standards such as MTOM.MTOM provides an elegant mechanism of efficiently transmitting binary data, such as images, PDF files, MS Word documents, between systems. This paper describes MTOM and provides readers with a hands-on understanding on how MTOM actually works.

Citation preview

11/28/10 1:00 PMIntroduction to MTOM: Hands-on

Page 1 of 6http://www.crosschecknet.com/intro_to_mtom.php

Introduction to MTOMA hands-on Approach

MTOM OVERVIEW

With web services-based SOA now being deployed across Global 2000 enterprises, transmitting attachments such as MRI Scans, X-Rays, Design Documents and Business Contracts using SOAP

messages has become a common practice. SOAP Message Transmission Optimization Mechanism (MTOM), is a W3C Recommendation designed for optimizing the electronic transmission of

attachments. Through electronic transmission of documents, corporations can realize significant cost savings and better service levels by eliminating the use of postal mail. Paper-based manual

tasks can be replaced with simple and efficient electronic processes where binary data can be transmitted between organizations through standards such as MTOM.

MTOM provides an elegant mechanism of efficiently transmitting binary data, such as images, PDF files, MS Word documents, between systems. The Figure below shows the steps involved in

transmitting data between a Consumer and Producer using MTOM.

The Consumer application begins by sending a SOAP Message that contains complex data in Base64Binary encoded format. Base64Binary data type represents arbitrary data (e.g., Images, PDF

files, Word Docs) in 65 textual characters that can be displayed as part of a SOAP Message element. For the Send SOAP Message Step 1 in the Figure above, a sample SOAP Body with

Base64Binary encoded element <tns:data> is as follows:

<soap:Body> <tns:ByteEcho> <tns:data>JVBERi0xLjYNJeLjz9MNCjE+DQpzdGFyNCjEx0YNCg==</tns:data></tns:ByteEcho></soap:Body>

An MTOM-aware web services engine detects the presence of Base64Binary encoded data types, <tns:data> in our example, and makes a decision – typically based on data size – to convert the

Base64Binary data to MIME data with an XML-binary Optimization Package (xop) content type. The data conversion, shown in Step 2 of the Figure above, results in replacing the Base64Binary

data with an <xop:Include> element that references the original raw bytes of the document being transmitted. The raw bytes are appended to the SOAP Message and are separated by a MIME

boundary as shown below:

<soap:Envelope> <soap:Body> <tns:ByteEcho> <tns:data><xop:Include href="cid:[email protected]"/></tns:data> </tns:ByteEcho> </soap:Body></soap:Envelope>--MIMEBoundary000000content-id: <[email protected]>content-type: application/octet-streamcontent-transfer-encoding: binary

The raw binary data along with the SOAP Message and the MIME Boundary is transmitted over the wire to the Producer. The Producer then changes the raw binary data back to Base64Binary

encoding for further processing. With this conversion between Base64Binary and raw binary MIME types, MTOM provides two significant advantages:

1. Efficient Transmission: Base64Binary encoded data is ~33% larger than raw byte transmission using MIME. MTOM therefore reduces data bloatby converting Base64Binary encoding to raw bytes for transmission.

2. Processing Simplicity: Base64Binary encoded data is composed of 65 textual characters. The data is represented within an element of a SOAPmessage. Security standards such as WS-Signatures and WS-Encryption can directly be applied to the SOAP Message. Once such operations areperformed, the Base64Binary data can be converted to raw bytes for efficient transmission. Securing document transmission via SOAP,therefore, does not require additional standards for securing MIME-based attachments.

In this paper, we will deploy a web service for processing binary data ByteEcho(byte[] data) and examine using this service without MTOM and with MTOM enabled.

SETUP AND INSTALLATION OVERVIEW

Home About Us Products Solutions Cloud Resources Downloads Press Support Contact Us

11/28/10 1:00 PMIntroduction to MTOM: Hands-on

Page 2 of 6http://www.crosschecknet.com/intro_to_mtom.php

For a hands-on understanding of MTOM, we will build web services with simple operation that will echo a byte stream. In this section, we will focus on setting up the SOA Testing framework for

MTOM by installing the following components. Install the three products below in the listed sequence:

1. Crosscheck Networks SOAPSonar Enterprise Edition: A .NET-based SOAP client used for comprehensive web services testing. Install pre-requisites thatthe SOAPSonar installer will ask you for such as .NET Framework 2.0 if it is not already installed on your machine.

2. Web Service Enhancements (WSE) 3.0 for Microsoft .NET Framework: This is an add-on to Microsoft .NET Framework 2.0 that enables developers to buildsecure Web services based on the latest Web services protocol specifications such as MTOM. Note: During installion, please select theDeveloper Version option.

3. Microsoft .NET WebMatrix: This installer includes an IDE for building web services and a lightweight web server.

All three components can be installed on a Windows 2000/XP/2003/Vista machine with moderate resources. The web services Producer is the .NET WebMatrix server that supplies a web service

with the ByteEcho(byte[] data) operation that applications can invoke, over HTTP. In addition, it produces the WSDL file that defines the web service interface. This file provides all the necessary

information for the consumer, SOAPSonar, to send SOAP requests to the target web service. SOAPSonar consumes and interprets the WSDL-based API published by the producer and invokes

the web service.

BUILDING A WEB SERVICE FOR BINARY DATA

To build a simple web service that illustrates handling binary data, follow these steps:

1. Goto: Start > All Programs > Microsoft ASP .NET Web Matrix > ASP .NET Web Matrix.2. You will be prompted for with a screen shown below. Fill in the information as shown. Select "Web Services" in the left panel and the "Simple"

template in the right panel. Create a C:\WebServices folder to store the .asmx file and picked C#.

Note: The OK button will be grayed until all the information on this panel is filled out.

3. This will auto-generate a web service for you with an Add(int a, int b) operation as shown below. We will keep this auto-generated operationand include a new byte processing operation in the next step.

4. Cut and paste the following code in the Web Matrix IDE right under the Add(int a, int b) operation:

[WebMethod]

public byte [] ByteEcho(byte[] data) {

return data;

}

5. The IDE will look as follows:

11/28/10 1:00 PMIntroduction to MTOM: Hands-on

Page 3 of 6http://www.crosschecknet.com/intro_to_mtom.php

6. Hit the play button in the IDE and it will prompt you for the start the web application on port 8080. Your local firewall may prevent you fromstarting a listener on port 8080. Add the port to your firewall's list of allowable ports.

7. A web browser with operation Add and ByteEcho will appear. You can click this and start playing with the Add operation. The ByteEchooperation does not accept input from the browser.

SOAPSonar SETUP

To setup the SOAPSonar test client, perform the following steps:

1. Goto: Start > All Programs > Crosscheck Networks > SOAPSonar Enterprise Edition 3 > SOAPSonar Enterprise to launch SOAPSonar.2. Load the WSDL published at the .NET WebMatrix Endpoint http://localhost:8080/BinaryProcess.asmx?WSDL into SOAPSonar as shown in the

figure below. Select the ByteEcho_1 test case in the left Project Tree Panel. Right click on the data field and select Content Function >Base64Encode. File Dialog will pop up to enable you to select a file from your system such as a PDF or JPEG file. The filename will beembedded in the data field with a $b64:file prefix. Click to commit changes and to execute the test. You will see the SOAP response inthe Response Panel.

11/28/10 1:00 PMIntroduction to MTOM: Hands-on

Page 4 of 6http://www.crosschecknet.com/intro_to_mtom.php

3. Save the project by going to File > Save Project As.4. Click on in the Request Panel to review the Header information for the request. Select the (Sent Request) Tab as show in the Figure below.

The SOAP request and the Header information are also shown below. Make a note of the following information:

a. Header Content-Length is 324771 bytes. This will vary based on the file you select.b. Content-type is text/xml. This will change when MTOM is enabled.c. The data field contains base64Encoded value of the selected binary file.

So far, you have successfully loaded a WSDL into the test client, SOAPSonar and setup a simple consumer (SOAPSonar) to producer (webMatrix) Framework to send base64Encoded bytes to the

webMatrix server that reflects the bytes to SOAPSonar in the SOAP Response. Next, we will enable MTOM and review its impact on the SOAP Request and Response.

ENABLING MTOM

In the section, we will enable MTOM for WebMatrix and the SOAPSonar test client. To enable MTOM for webMatrix as follows:

1. Goto C:\Program Files\Microsoft WSE\v3.0\Tools and launch WseConfigEditor3.exe.2. With the WSE 3.0 Configuration tool, select the File Menu to open the web.config file located in

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG.3. Under the General Tab, check both boxes to enable WSE 3.0 for the WebMatrix sever as shown in the Figure below:

11/28/10 1:00 PMIntroduction to MTOM: Hands-on

Page 5 of 6http://www.crosschecknet.com/intro_to_mtom.php

4. Next, select the Messaging Tab and select “always” for the Server Mode MTOM Settings.

5. Goto File > Save to the new configuration and Exit from the WSE 3.0 configuration tool.6. Review the web.config file using a text editor and ensure that the following elements appear in the web.config file. As expected, the serverMode

value for MTOM is set to “always.” The server will now only accept MTOM encoded messages. If a SOAP request is received by WebMatrixthat is not MTOM, an HTTP error 415: "Media unsupported" is returned to the sender.

<messaging> <mtom clientMode="Off" serverMode="always"/></messaging>

7. Re-send the base64Encoded SOAP request. Since WebMatrix receives a message that is not MTOM, an HTTP error 415: "Media unsupported"is returned to the SOAPSonar as displayed in the Response Panel.

8. In the Project Tree, click on the Policy Settings node. Change the MTOM Setting – Client Mode to On as shown in the Figure below. Thisenables SOAPSonar to send MTOM encoded messages. Click to commit changes.

9. Goto the ByteEcho_1 test case and click to execute the test. Review the request sent to the server by clicking on the (Send Request) Tab inthe Request Panel. The SOAP request and the Header information are also shown below. Make a note of the following information:

a. Header Content-Length is 244093 bytes. This will vary based on the file you select.b. Content-type is application/xop+xml. This indicates that an MTOM message is being generated by SOAPSonar.c. The data field contains MIMEBoundary content-transfer-encoding.

11/28/10 1:00 PMIntroduction to MTOM: Hands-on

Page 6 of 6http://www.crosschecknet.com/intro_to_mtom.php

home products about privacy terms of use contact Copyright © 2010 Crosscheck Networks. All Rights Reserved.

Note: The Header Content Length for the Message Request with MTOM turned-on is 244K compared to 325K with the Message Request without MTOM. This corresponds to a ~25%

reduction in message size even for a moderately sized message.

10. Goto the panel shown in Step 8 above and check Show Raw Response for the MTOM settings. This turns-off the binary to text-encoding andenables you to view the raw binary content in the response panel.

You should be now be comfortable with sending base64Binary encoded and MTOM encoded messages to a test server and viewing the responses in wire format and base64Binary encoded

formats.

CONCLUSIONS

MTOM provides an efficient mechanism for transmitting binary data. MTOM’s approach of reducing the number of standards required for transmission while reducing the data bloat caused by

Base64Binary encoding the entire attachment makes it an ideal standard for transmission of large binary content. Obviously, nothing comes for free. The gain in network transmission efficiency by

reducing “wire footprint” is at the expense of CPU resources. The client has to expend processing resources to convert Base64Binary encoded type to MIME type before transmitting it over the

wire. The receiver then performs another data type transformation from MIME to Base64Binary data. MTOM is ideal for use cases where a large number of external organizations want to transmit

sizeable documents to an enterprise over the internet with low bandwidth availability.

REFERENCES

1. Faster Data Transport Means Faster Web Services with MTOM/XOP.2. XML, SOAP and Binary Data.3. Getting Started: Creating a WSE 3.0 Enabled Web Service to Transfer Large Amount of Data using WSE 3.0 MTOM.

CONTACT INFORMATION

Website: www.crosschecknet.com

Email: [email protected]

US Phone: 1-888-CROSSCK (276-7725)

International Phone: 1-617-938-3956