Click here to Skip to main content
13,398,090 members (39,919 online)
Click here to Skip to main content
Add your own
alternative version


29 bookmarked
Posted 27 Oct 2004

Configure DIME with WSE 2.0

, 25 Apr 2005
Rate this:
Please Sign up or sign in to vote.
This article focuses on demonstrating the usage of DIME (Direct Internet Message Encapsulation) with Web Services. Here, you will have two applications, one is a Web Serivice that uses DIME technology to send an attachment (of different types) to a client side, other is a Windows Forms application.


SOAP messages are not the best way to send large binary files. As the Web Services emerge, people look for Web services to have more and more functionality. Result was the introduction of Web Services Enhancement (WSE) 2.0. The Web Services Enhancements for Microsoft .NET (WSE) supports attaching files to SOAP messages outside the SOAP envelope; these files are not serialized as XML. This can be beneficial when sending large text or binary files because XML serialization is a very costly process and can result in files much larger than the originals. Direct Internet Message Encapsulation (DIME) is a lightweight, binary message format that WSE uses to encapsulate SOAP messages and their attachments in a DIME message.


  • First, we create a Web service that can read an image file, and return a DIME message that contains a SOAP message and the image file attached.
  • Second, we create a Windows Forms client that can consume the DIME message created by the Web service and display the image.


The users who read this article need a basic understanding of Web services and how to create and use them with .NET Framework. Additionally, they need to have the Microsoft Visual Studio .NET 2003 and Web Service Enhancement 2.0 installed.

Web service that generates a DIME message containing image attachments

Note: Because DIME attachments are contained outside of the SOAP envelope, they cannot be signed or encrypted using WSE. It is strongly recommended that all SOAP messages that contain DIME attachments be sent over a secure transport protocol such as HTTPS.

Note: If you send a file as a DIME attachment, you cannot close or delete the file from within the Web method that sent the file. This is because WSE holds a reference to the file until the message is serialized and delivered to the client. To overcome this, override a file stream and delete the file when all references to the file stream are released.

Let's create the Visual Studio ASP/.NET Web service project:

  1. Go to File menu and create a New Project.
  2. In the Project Types pane, select Visual C# Projects.
  3. In the Templates pane, select ASP.NET Web Service.
  4. Fill the Location box with the project name: http://localhost/MyDimeTest.
  5. Click OK button to add the MyDimeTest project to the solution.
  6. Go to Solution Explorer and change the name of Service1.asmx to DimeService.asmx by selecting the Properties of the file.
  7. To be smarter, view the DimeService.asmx and change the class name as well as the constructor name to have the same name, i.e., "DimeService".

    Now the project is done, and now you got to configure the project for WSE 2.0. It is very easy.

  8. In the Solution Explorer, right click on the project name, you will see "WSE 2.0 Settings ..." just below the "Property" menu item.
  9. Select "WSE 2.0 Settings ...".
  10. To configure a Web service project to use WSE 2.0, you got to check both check boxes in the "General" tab.

    • The first check box enables the use of the current project with WSE. This means that the Microsoft.Web.Services2.dll will be added to the project references, and that changes will be made to the Web.config file to add support for the WSE configuration handler. In addition, any Web references that are created from this point on will include WSE 2.0 support in the proxy classes generated.
    • The second check box is only enabled if this is an ASP.NET Web Service project. By selecting it, the WSE Soap Extension is added to the project, which will enable the additional protocol support to work within the ASP.NET Web service HTTP handler (for .ASMX files). This is accomplished by modifying the Web.config file and adding the WSE SOAP Extension to the list of .asmx SOAP Extensions for the virtual directory.
  11. Add using statement to the DimeService.asmx.cs file:
    using Microsoft.Web.Services2.Dime;
    using Microsoft.Web.Services2;
    using System.Net;
  12. Place an image file to be read by the DimeService. In my case, I placed a "test.gif" file in my "c:" drive. So the path of the image file is described as "c:\test.gif".
  13. Write a Web Method that can read the image file and attach it with the SOAP message using DIME technology and transfer it to the client end. Please follow the code below:
    // The CreateDimedImage Web service returns an image in a DIME
    // attachment.
    public void CreateDimedImage()
        SoapContext respContext = ResponseSoapContext.Current;
        DimeAttachment dimeAttach = new DimeAttachment(
            "image/gif", TypeFormat.MediaType,

    Compile the project. Now you are done with the Web service end.

Windows Forms client that can consume a DIME message containing an image

Let's create the Windows Forms Project:

  1. Go to File menu and create a New Project.
  2. In the Project Types pane, select Visual C# Projects.
  3. In the Templates pane, select Windows Application.
  4. Fill the Name box with the project name: DimeClient.
  5. Click OK button to add the DimeClient project to the solution.
  6. In Solution Explorer, select View Designer for DimeClient Windows Form.
  7. Add a PictureBox control to the form from the Tool Bar.
  8. Double click on the DimeClient Form to add the Form_Load event.

    Now the client project is done, and now you got to configure the project for WSE 2.0. It is very easy.

  9. In the Solution Explorer, right click on the project name, you will see "WSE 2.0 Settings ..." just below the "Property" menu item.
  10. Select "WSE 2.0 Settings ...".
  11. To configure a Web service project to use WSE 2.0, you got to check the first check box in the "General" tab. (I.e., enable this project for Web Service enhancements.) This will add all necessary references as well as it will edit the Web.Config for you.
  12. In Solution Explorer, right-click References, and then select Add Web Reference.
  13. In the address window, enter http://localhost/MyDimeTest/DimeService.asmx, and then click the arrow icon.
  14. Name your proxy class as "pxy" and click Add Reference.
  15. Insert the code below in the "Form_Load" method of the "DimeClient.cs".
    private void Form1_Load(object sender, System.EventArgs e)
        pxy.DimeServiceWse lobjProxy = new pxy.DimeServiceWse();
        if (lobjProxy.ResponseSoapContext.Attachments.Count == 1)
            this.pictureBox1.Image = new Bitmap(
            MessageBox.Show("No Attachment Found");

DIME Defaults

By default, DIME/ WSE 2.0 doesn't allow adding/sending attachments larger than 4096 KB of size. If you intend to send larger files, which are over the 4 MB limit (including the SOAP message), you need to add some tags to the web.config file of the service as well as, remember, of the receiver (client) end. You need to add values to override the values of the maxRequestLengths.

<httpRuntime> Settings

This configures the ASP.NET HTTP runtime settings. This section can be declared at the machine, site, application, and subdirectory levels:

<httpRuntime useFullyQualifiedRedirectUrl="true|false"

  maxRequestLength="size in kbytes"

  executionTimeout="seconds" />


This example demonstrates a instant of sending an attachment of size 8 MB and the timeout is set to 45 seconds:

      <httpRuntime maxRequestLength="8000"


                   executionTimeout="45" />

<microsoft.web.services2> Settings

      <maxRequestLength>"size in kbytes"</maxRequestLength>
    <diagnostics />


    <diagnostics />

Last Updated

The article was updated on 19th of April 2005.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Architect Virtusa Pvt. Ltd.
Sri Lanka Sri Lanka
In-depth coverage of Microsoft .Net, Cloud and many other cutting-edge Technologies.

- The Mandelbrot set – someone has called it the thumb-print of God – is one of the most beautiful and remarkable discoveries in the entire history of mathematics. My profile picture is generated with that equation.

You may contact Nirosh for Consultations, Code Reviews and Architecture Guide Workshops via c_nir*o* (Remove * to use)

View Nirosh L.W.C.'s profile on LinkedIn

You may also be interested in...

Comments and Discussions

GeneralRe: email with Attachment Pin
Nirosh30-Jan-07 17:26
memberNirosh30-Jan-07 17:26 
QuestionProblems installing WSE 2.0 SP1 and SP2 Pin
JRINC9-Jan-07 10:39
memberJRINC9-Jan-07 10:39 
AnswerRe: Problems installing WSE 2.0 SP1 and SP2 Pin
Nirosh10-Jan-07 3:09
memberNirosh10-Jan-07 3:09 
Generalthis was useful to me - thanks Pin
CP Student31-Oct-06 18:57
memberCP Student31-Oct-06 18:57 
GeneralRe: this was useful to me - thanks Pin
Nirosh9-Nov-06 23:02
memberNirosh9-Nov-06 23:02 
GeneralUpload error Pin
Ricardo Mendes27-Oct-06 4:07
memberRicardo Mendes27-Oct-06 4:07 
GeneralRe: Upload error Pin
Germyan27-Oct-06 4:14
memberGermyan27-Oct-06 4:14 
GeneralRe: Upload error Pin
Ricardo Mendes27-Oct-06 5:32
memberRicardo Mendes27-Oct-06 5:32 
GeneralRe: Upload error Pin
Nirosh29-Oct-06 17:57
memberNirosh29-Oct-06 17:57 
GeneralRe: Upload error Pin
Samual A.29-Oct-06 18:40
memberSamual A.29-Oct-06 18:40 
QuestionError: Object reference not set to an instance of an object. Pin
schwartz_ken22-Aug-06 4:09
memberschwartz_ken22-Aug-06 4:09 
AnswerRe: Error: Object reference not set to an instance of an object. Pin
Nirosh22-Aug-06 18:59
memberNirosh22-Aug-06 18:59 
GeneralRe: Error: Object reference not set to an instance of an object. Pin
Nirosh22-Aug-06 19:08
memberNirosh22-Aug-06 19:08 
GeneralI want to send a file as dime attachment from client to Web Service Pin
lolokisu14-Aug-06 6:17
memberlolokisu14-Aug-06 6:17 
GeneralRe: I want to send a file as dime attachment from client to Web Service Pin
Nirosh18-Aug-06 1:13
memberNirosh18-Aug-06 1:13 
QuestionRegarding creating the proxy Pin
Venkat_8320-Jun-06 1:42
memberVenkat_8320-Jun-06 1:42 
QuestionRe: Regarding creating the proxy Pin
Venkat_8320-Jun-06 2:19
memberVenkat_8320-Jun-06 2:19 
AnswerRe: Regarding creating the proxy Pin
Nirosh18-Aug-06 1:19
memberNirosh18-Aug-06 1:19 
Generalthanks Pin
sameeraperera20-Sep-05 20:03
membersameeraperera20-Sep-05 20:03 
GeneralRe: thanks Pin
Fiendcom18-Feb-06 20:41
memberFiendcom18-Feb-06 20:41 
GeneralRe: thanks Pin
Nirosh7-Nov-06 17:58
memberNirosh7-Nov-06 17:58 
GeneralTimeZone <timeToleranceInSeconds> Pin
pkwan730-Aug-05 15:04
memberpkwan730-Aug-05 15:04 
GeneralRe: TimeZone Pin
Nirosh8-Sep-05 1:46
memberNirosh8-Sep-05 1:46 
GeneralOne more finding Pin
Meer Bakher29-Aug-05 7:12
memberMeer Bakher29-Aug-05 7:12 
Generalsame machine Pin
Meer Bakher29-Aug-05 5:40
memberMeer Bakher29-Aug-05 5:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.180216.1 | Last Updated 26 Apr 2005
Article Copyright 2004 by Nirosh
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid