MTOM message optimization transmission mechanism is mainly used in the transmission of a large number of data, many articles also directly concluded that the use of MTOM file transfer efficiency. Why is mtom more efficient in data transmission than in other ways? is mtom really so perfect, what's the problem? When to use Mtom? These questions, this article WSE3.0 build the Web Services Security Series article 4th: Mtom message optimization transmission mechanism and file upload, download--will answer for you. The structure of this section is 1. MTOM Basic Concepts 2.wse3.0 Tool configuration MTOM3. Code implementation and Analysis 4. Finally attach the implementation code for your reference.
The introduction of the MTOM mechanism into the WSE3.0 brings significant benefits to our use of the WSE framework for large data interactions. In WSE 3.0, we can use Mtom for server-side and client delivery messages, and the other benefit is that WSE 3.0M allows us to use the WSE 3.0 message Layer Security mechanism when delivering large amounts of data, With the help of WSE3.0 security framework, we can not only verify the legality of the users, but also encrypt the message, not only to ensure the security of the data, but also to achieve the high efficiency of large data transmission.
1. "Mtom Basic Concept"
Referring to the MTOM message optimization transport mechanism, the usual experimental result is that using MTOM to transmit data can improve performance by about 33%. The message transfer optimization mechanism (MTOM) standard allows the large data elements contained in a message to be externalized and sent along with the message as binary data without any special encoding. MTOM messages are packaged as multipart/related MIME sequences and are sent together in a SOAP message.
We need to understand some of the relevant concepts. What is BASE64 encoding, MTOM message optimization transmission mechanism, MIME. These are very necessary for us to understand the MTOM message optimization transmission mechanism problem. Here's how to do the next introduction.
1.1 "BASE64 Code"
The principle of BASE64 coding is simple, and the method is take the input data stream 6 bit at a time (each bit represents a 1-bit binary), less than 6bit of 0, so that every 3 8 bytes will be encoded as 4 6-bit bytes (3x8→4x6), and 4 bytes are populated with "=". In fact, these 4 six-bit bytes are still 8 bits, but the high two bits are set to 0. When a byte is only 6 bits valid, its value space is 0 to 2 of 6 times minus 1 is 63, that is, the converted Base64 encoding each encoded value space is (0~63).
This allows you to convert 3 8-bit bytes to 4 bytes, which can be mapped to the character in 4 converted bytes. That is, the data can be replaced with a character encoding. Because the converted string is a byte longer than the original, 1/3. Thus the encoded data length increases to 4/3 times times. This is also why using SOAP messages is less efficient than mtom. Because SOAP uses the XML language for messaging, XML is a language based on BASE64 encoding.
1.2 "MIME"
MIME represents the Multipurpose Internet Mail Expansion protocol. MIME expands the basic text-oriented Internet mail system so that binary attachments can be included in the message. MIME (Multipurpose Internet Mail extentions), commonly translated as "Multipurpose Network Mail Extension Protocol". As the name suggests, it can transfer multimedia files. MIME (Multipurpose Internet Mail Extensions, multi-purpose Internet Message extensions) is a specification for creating file formats for e-mail exchanges, network documents, and corporate networks and other applications on the Internet.
1.3 "MTOM Message optimized transmission"
MTOM full name message transmission optimization mechanism, that is, messaging optimization mechanism. The model proposed is suitable for the interaction of a large number of data. Solution for the overhead of Base64 coding. When the amount of data is small, SOAP still uses XML for message delivery.
However, in a large number of data cases, if the data is still BASE64 encoding, it will bring 33% of the additional cost, such a situation for a large number of data exchange is intolerable. MTOM is an improved approach based on the transmission of SOAP messages. For the delivery of large amounts of data, the BASE64 encoding is not carried out, but is directly encapsulated in the MIME part of the SOAP message in the form of the binary raw data of the attachment, for transmission. The SOAP message refers to the binary content by pointing to the MIME part that it sends, and also includes SOAP basic XML data, or BASE64 encoding. Because this model is basically consistent with the Simple Mail protocol SMTP model.
MTOM improves data processing efficiency by simplifying the coding process for large amounts of data. Because of the necessary information, such as SOAP messages, MTOM also has some necessary overhead. Mtom can only show its advantages when the binary data element is larger than approximately 1 KB.
2. "WSE3.0 Tool configuration Mtom"
Using the Mtom messaging optimization mechanism in the WSE3.0 project is very handy, we can use the WSE 3.0 Configuration tool to enable MTOM for both Web services and client clients settings, generating the appropriate policy files. The WSE3.0 mechanism uses MTOM for message transmission based on policy (or it can be implemented through code).
The data is transmitted using the byte stream byte[] array on the client and server side, with a simple example of message interaction and file upload and download operations. This configuration of the basic introduction of the situation is also the use of WSE3.0 security mechanism to achieve secure transmission of files.
2.1 First Use the WSE 3.0 Configuration tool to set up the service-side message transfer policy. As shown in figure:
The client is set to ON, requiring the client to use the MTOM mechanism for data transfer. The service side is set to optional, which indicates an optional. In this case, the service side determines whether the MTOM mechanism is enabled for data delivery based on the size of the data. If set to always, the server will always use the MTOM mechanism for message delivery. This method is not recommended for general use. Off does not use the MTOM mechanism for message delivery. 64 is the maximum number of additional binary files. Finally, the SOAP message encapsulation needs to be used first.
The corresponding configuration file is:
<messaging>
<mtom serverMode="optional" clientMode="On" />
</messaging>