Languages »
XML »
Web Services
Beginner
Configure DIME with WSE 2.0
By Nirosh
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.
|
C#, XML, HTML, Windows, .NET, .NET 1.1, WinForms, IIS 5, IIS 5.1, IIS 6, VS.NET2003, IE 6.0, IE 5.5, IIS, Visual Studio, IE, Dev
Posted: 27 Oct 2004
Updated: 25 Apr 2005
Views: 100,580
Bookmarked: 27 times
|
|
|
|
|
Introduction
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.
Background
- 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.
Requirements
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:
- Go to File menu and create a New Project.
- In the Project Types pane, select Visual C# Projects.
- In the Templates pane, select ASP.NET Web Service.
- Fill the Location box with the project name: http://localhost/MyDimeTest.
- Click OK button to add the MyDimeTest project to the solution.
- Go to Solution Explorer and change the name of Service1.asmx to DimeService.asmx by selecting the Properties of the file.
- 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.
- In the Solution Explorer, right click on the project name, you will see "WSE 2.0 Settings ..." just below the "Property" menu item.
- Select "WSE 2.0 Settings ...".
- 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.
- Add
using statement to the DimeService.asmx.cs file: using Microsoft.Web.Services2.Dime;
using Microsoft.Web.Services2;
using System.Net;
- 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".
- 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:
[WebMethod]
public void CreateDimedImage()
{
SoapContext respContext = ResponseSoapContext.Current;
DimeAttachment dimeAttach = new DimeAttachment(
"image/gif", TypeFormat.MediaType,
"C:\\test.gif");
respContext.Attachments.Add(dimeAttach);
}
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:
- Go to File menu and create a New Project.
- In the Project Types pane, select Visual C# Projects.
- In the Templates pane, select Windows Application.
- Fill the Name box with the project name: DimeClient.
- Click OK button to add the DimeClient project to the solution.
- In Solution Explorer, select View Designer for
DimeClient Windows Form.
- Add a
PictureBox control to the form from the Tool Bar.
- 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.
- In the Solution Explorer, right click on the project name, you will see "WSE 2.0 Settings ..." just below the "Property" menu item.
- Select "WSE 2.0 Settings ...".
- 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.
- In Solution Explorer, right-click References, and then select Add Web Reference.
- In the address window, enter http://localhost/MyDimeTest/DimeService.asmx, and then click the arrow icon.
- Name your proxy class as "
pxy" and click Add Reference.
- 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();
lobjProxy.CreateDimedImage();
if (lobjProxy.ResponseSoapContext.Attachments.Count == 1)
{
this.pictureBox1.Image = new Bitmap(
lobjProxy.ResponseSoapContext.Attachments[0].Stream);
}
else
{
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" />
Example
This example demonstrates a instant of sending an attachment of size 8 MB and the timeout is set to 45 seconds: <configuration>
<system.web>
<httpRuntime maxRequestLength="8000"
useFullyQualifiedRedirectUrl="true"
executionTimeout="45" />
</system.web>
</configuration>
<microsoft.web.services2> Settings<microsoft.web.services2>
<messaging>
<maxRequestLength>"size in kbytes"</maxRequestLength>
</messaging>
<diagnostics />
</microsoft.web.services2>
Example<configuration>
<microsoft.web.services2>
<messaging>
<maxRequestLength>8000</maxRequestLength>
</messaging>
<diagnostics />
</microsoft.web.services2>
</configuration>
Last Updated
The article was updated on 19th of April 2005.
| You must Sign In to use this message board. |
|
| | Msgs 1 to 25 of 72 (Total in Forum: 72) (Refresh) | FirstPrevNext |
|
 |
|
|
hi! are consumers of the web service required to install WSE as well? what if, let's say, consumers of my web service are php and java web applications? what adjustments do they need to make? by the way, thanks for the great article!
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
If you have PHP and Java clients talking to your Application Server, they have to have the compliancy with the correct WSDL version.
In case they also use DIME then they need to use a third party DIME parser to pass the attachement. Failing to do so, you have to send it as a regular byte[].
But there are many other feature in WSE, the answer to your question depend on what features you are using at the server base.
The problem become verse as you ungrade from WSE 2.0 to WSE 3.0 where the large binary files send using another technology called MTOM. In that case those who are (third party clients) already using DIME parser are in deep trouble as MTOM is not compliant with DIME parsers.
If this doesn't help, give little more data then I can give you a more specific answer..
Thanks,
L.W.C. Nirosh. Colombo, Sri Lanka.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
[quote] In case they also use DIME then they need to use a third party DIME parser to pass the attachement. Failing to do so, you have to send it as a regular byte[]. [/quote]
there's a big possibility that they're not using DIME. does this mean that they won't *understand* the attachment? if it's not too much to ask, how can i send the file as a regular byte (code snippet will be great) or can you point me to the topic that i should read. thanks man, you're a great help!
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Ok, if you are not going to use DIME and not going to use any other client dependant feature that comes with WSE then your client does not need to have WSE install? Pretty obviously
Public byte[] GetData() { //Read the file data and return the file’s byte[] }
You can read the file from the hard drive to a byte[] very easily (refer to System.IO.File name space). When you send a binary data as a byte[] it is going to create a bulky SOAP message, which will increase the network traffic (I do not recommend sending file bigger that 20 MB this way) so to reduce the file size you should consider compressing it before sending over the network. (Search for SharpZipLib, it is a open source compression library). In case when you send compressed data the client has to decompress it before he/ she use the file.
L.W.C. Nirosh. Colombo, Sri Lanka.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
okay! thanks man! my sole requirement is to stream some files to client applications and im looking for elegant solutions to my problem. looks like im back to streaming bytes.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
Now here is a problem, i am required to send the attachment AND the other attributes (sender and receiver;s email, message, subject line) all at the same time. I tried it but it didn't work. DIME can send ONLY attachments, not the entire message that i could figure out. I can use any other technique but it needs to be using BINARY SOAP...
Please HELP !!!
Ankit
|
| Sign In·View Thread·PermaLink | 5.00/5 (1 vote) |
|
|
|
 |
|
|
What is the real requirement for you do send a e-mail with a attachment via a web method of a web service?
I can generally say that you can send the binary (attachement) as a DIME attachement while sending all other parameters through a return object of the web method
e.g.: [WebMethod] public MailObject GetMail(param) { // Attache the mail attachement as a dime attachement // return the MailObject after filling required properties }
L.W.C. Nirosh. Colombo, Sri Lanka.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hello!
hey brother, I need to send a soap message with an attached file... this article serves me very well to do this...
but in my pc, in my office I cannot install the WSE 2.0 package... if you have any idea of the couse of that... please help me!
I work with VS 2003... and this works very well... so a I don´t know why I can´t install this WSE 2.0 packages...
Thanks!...
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi JRINC,
First time I am hearing a such issue, could you pass me the exact issue you are facing? What happen when you try to install WSE 2.0?
Let me have the followings detail of the system you are facing issues
1. Operating System/ Service Pack Version 2. Visual Studio version 3. .Net Framework Version 4. The exact error you get and when that error occurs
Thanks
L.W.C. Nirosh. Colombo, Sri Lanka.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
 |
|
|
Hi. I have a WinForms application and a web service. I'm trying to send to the web service a file with 4,5MB but I'm not having success.
I've put the following configuration in the App.config and in the Web.config and still it doesn't work:
<microsoft.web.services2> <messaging> <maxRequestLength>-1</maxRequestLength> </messaging> <security> <timeToleranceInSeconds>86400</timeToleranceInSeconds> </security> </microsoft.web.services2>
Does anyone know what I'm doing wrong? I'm receiving a 'Maximum request length exceeded.' message.
Thanks in advance.
Ricardo
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Seems you are ignoring the first setting..
httpRuntime maxRequestLength="8000" useFullyQualifiedRedirectUrl="true" executionTimeout="300" Don't you??
Add this as well.. and it should solve the issue..
G
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Thanks. But now I have another problem. I can upload the file but I cannot download it. I've put the tag you said in the App.config but it didn't work.
Any ideas?
Ricardo
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
There can have several reasons to this issue.. get me a more specific error then I will be able to answer you..
L.W.C. Nirosh, Colombo, Sri Lanka.
|
| Sign In·View Thread·PermaLink | 1.00/5 (1 vote) |
|
|
|
 |
|
|
 |
|
|
Hi,
I'm having some trouble getting this code to work. Here's some background: Initially, I set up both the client and service on my local machine. After installing MS's Web Service Enhancements, things ran fine.
However, when I moved the Service to a different machine, I get the following error: An unhandled exception of type 'System.Web.Services.Protocols.SoapException' occurred in system.web.services.dll Additional information: Server was unable to process request. --> Object reference not set to an instance of an object.
This error is occurring here ( in the Rerence.cs file) ...
public void CreateDimedImage() { this.Invoke("CreateDimedImage", new object[0]); }
Steps taken so far: 1) Installed WSE on the computer 2) set permissions on the folder to "Everyone" having all rights. 3) Created a different web reference in the client for the version of the service on the 2nd computer, and changed the code in Form1_Load() method accordingly. 4) Ensured that the file is there (I get a different error message when the file isn't there) 5) I even attempted to run the entire thing (client and service) on this second machine, but get the same message...
Any help or suggestions are greatly appreciated.
Ken Schwartz
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi,
A frustrating question Ah...?
If the things working fine when they are on the same server and not when they are seperated only possible thing would be a proxy configuration issue..
This is what could happen with you.
As you add a new web reference to the new server the client automatically remove the DIME enable state of the client. So what you could do is right click the project as indicated and make your client dime enable again..
This should indeed solve your problem.
L.W.C. Nirosh, Software Engineer, TextCENTRIC Technology, Colombo, Sri Lanka.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Just a another thing..
if you think that it is not flexible, you may make your web service a dynamic ..
steps to do it
1. Right click on your (web reference) proxy 2. Go to Properties 3. Change the URL behavior from Static to Dynamic
You will see it add a app.config file, Go to app.config file and see that your proxy url is in the configuration file. This way you can publish your web service in any server and configure it just by changing the app.config or web.config of the client application (Note: As long as web service is not differ from one server to another).
If you are not depending upon DIME strictly the latest technology is called MTOM which has introduced with WSE 3.0. If you are still not ready with VS 2005 you may not consider moving to MTOM as yet.
L.W.C. Nirosh, Software Engineer, TextCENTRIC Technology, Colombo, Sri Lanka.
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
Please advice how I use the code ?
My problem is if I send the file name to attach as Dime my web service is running on the server and cannot find the file.
I am told to send the file as dime atachment and let the web service read as dime attachment as the user do not want to share a folder and get the file droped there ?
Prakash
Prakash
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
You got to give enough permission for your web service to access and read the file from the local folder..
These are the steps
1. Create a folder out side of the web server root directory (C:\Test) 2. Place the file you want to send out in side teh folder 3. Right click on the folder 4. Share the folder and give full access to ASP_NET user, this permission should be enough to read a file from the location. 5. Attached the file as a dime attachement before responding to the request.
Hope this is not a late reply
L.W.C. Nirosh, Software Engineer, TextCENTRIC Technology, Colombo, Sri Lanka.
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
Hi,
I was trying to implement sending image attachment through DIME in .NET and I came across your example, I did exactly the samething that you had mentioned in the example.
First I installed the WSE 2.0 and WSE 3.0 on my machine, and after creating the web service when i right clicked on the project for configuring the WSE 2.0 settings I found only the WSE 3.0 settings in the menu and I did the changes that you had mentioned to that in the web service project and as well as in the client project, then I compiled the web service project it was successfull and then I deployed the web service in the IIS, and in the client project I added this web service as web reference and tried to compile the client project then it threw the error which states as below.
Error 1 The type or namespace name 'DimeServiceWse' does not exist in the namespace 'DimeClient.pxy' (are you missing an assembly reference?) E:\Dot Net 2005 Projs (MOM)\DimeClient\DimeClient\Form1.cs 20 17 DimeClient
My question is why it is not showing the WSE 2.0 settings in the menu eventhough the WSE 2.0 is installed on the system ?
Can I send the attachments by using WSE 3.0 ?, if so what changes do i need to make in the code ?
kindly help me in this regard.
Thanking you in Advance, Venkat.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi Nirosh,
After carrying out a little bit of research work I came to know the reason why the WSE 2.0 settings is not getting displayed ? the thing is that the WSE 2.0 is made for the .NET 1.1 framework i.e. for the visual studio .NET 2003.
In the previous post I forgot to mention that I am using visual studio .NET 2005, so I need to use only WSE 3.0
Is there any classes are there in WSE 3.0 like DIME as in WSE 2.0 for sending the attachments through SOAP.
Kindly help me to solve the above problem.
Thanking you in advance, Venkat.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi,
WSE 3.0 is using a new method called MTOM to send attachment, or rather binary data.
Pros
Once you are configured with MTOM you may just return the byte arrary of the file just like any other return type.. e.g. [WebMethod] byte[] GetMyFile() { return the byte array of the file }
Once you have installed WSE 3.0 and your application is configured with MTOM the system will recognize the data type and treat it in a special way and allow you to transfer the file afficiently.
Cons
If your client if only capable of reading a DIME attachement (Third parties who are having dime parsers) will not be able to read the message return type since it is compressed and optimized for binary trafsfering
L.W.C. Nirosh, Software Engineer, TextCENTRIC Technology, Colombo, Sri Lanka.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
General News Question Answer Joke Rant Admin
|