MTOM Support to Web Service

Overview of MTOM

Using MTOM an application can send or receive a large amount of data. MTOM allows message-level security to be applied to the message including binary data. MTOM encodes the SOAP message and transmits the message as XML.

Following is the procedure to send large amount of data using MTOM

  1. Open the web service project in Visual studio 2005

  2.   Enable the project to use WSE by

        a. In solution explorer right click the project and then click WSE Settings

        b. Select the general tab

        c. Select Enable this project for Web Services Enhancements and 

           Enable Microsoft Web Services Enhancements SOAP Protocol 


3. Specify that web service can accept SOAP messages encoded using MTOM.

        a. In solution explorer right click the project and then click  WSE Settings.

        b. Select the Messaging tab.

        c. Choose optional or always for the Server Mode.

           always MTOM mode specifies that all incoming and outgoing SOAP  

           messages must be MTOM encoded.

           optional MTOM mode specifies that whether or not all incoming and  

           outgoing messages can be encoded.

Define a Web service method that returns a byte array.

public byte[] GetFile(string fileName)


    byte[] response;
    String filePath = AppDomain.CurrentDomain.BaseDirectory 
+ @"App_Data\" + fileName;
    response = File.ReadAllBytes(filePath);
    return response;


4. Configure the Web server to handle the larger amount of data.

  <httpRuntime maxMessageLength="409600"

Leave a reply

Why ask?