DIME (Direct Internet Message Encapsulation) IS Part of The Microsoft Web Service Enhancements and Can Be Used to Upload Large Attachments Using SOAP.
I am Currently Working on a Project That Requires Me To Potentially Upload As Well AS Download Large Files VIA .NET WebServices.
One Challenge I Faced Was The Default Request Size Which Is Directed in The Machine.config And in A Hosted Environment I do Not Have Access To It. Easy, Override It in The Web.config.
Now using standard upload / download functionality in webservices forced me to convert the files to a Byte Array, this means that the actual attachment would be encapsulated within the SOAP envelope and can potentially make a 2MB file a 4 MB file. After some digging I started to take a look at DIME and found that it is extremely simple to upload files (as well as download) via a Webservice.One advantage is that the actually attachment is not posted within the SOAP Envelope thus making uploads quite a bit faster. (There Are More Reasons, I don't want to get info here.)
You Would Have to Download and Install WSE First, You Can Get That from Microsoft Here.
Let's start by Creating a New Solution In vs.Net and Add A Webservice Project To IT.
You will see what after installing the wse you will have new option WHEN Right CLICKING A Project As You can see in the picture below.
After you click on WSE Settings 2.0 you will be presented with a Dialog that lets you confiure your WebService application, essentially it will configure your web.config and add required references to the Project.Check both boxes as seen below.
Now Let's Write Some Code Which We Will Use to save the file tria will be ready.
Source Code:
Imports System.Web.ServicesImports System.IOImports Microsoft.Web.Services2Imports Microsoft.Web.Services2.Dime ....
The Next Thing We obviously Need To Do Is Write a Simple Client That Will Upload Attachments to the Server.
I Just Added A Windows Forms Project To The Solution, Put A Button and a OpenFiledialog To The Form, Set The OpenFiledialog To Allow Multiple Selects and That's IT.
As for the property of the process you need to go to the process you need to go to the WSE 2.0 settings again and now you can Just Check The first box (Both if it is an asp.net application)
Add Some Imports to the form and some code for the button clicet and you are almost done.
Source Code:
Private Sub Button1_Click (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'Show the OpenFileDialog and if they hit OK we go If Me.OpenFileDialog1.ShowDialog = DialogResult.OK Then' Setting the Cursor to wait Me.Cursor = Cursors.WaitCursor 'Initiate the Webservice Dim proxy As New DimeDemoWSE.Service1WseI have to stop here for a second because I overlooked it and was going nuts why something else did not work. As you see, you are referencing DimeDemoWSE.Service1WSE NOT.SERVICE1 The One You Wrote, VS.NET WILL GIVE You Your Standard WebService (WITHOUT The WSE Properties) That Uses WSE; Use The WSE One As Above.
Source Code:
'I want to count Total Files copied the cumbersome way. Dim totalfL As Integer' For Demo Purposes we get the time NOW .... Dim sTime As DateTime = Now 'Now we just iterate through the OpenFileDialog1 Selected Files Collection For Each f As String in OpenFileDialog1.FileNames Try 'S is our File Extension, which we will reference in a bit Dim s As String = New IO.FileInfo (f) .Extension' Now we define an attachement as a DimeAttachment (filetype, keep the content Type , the file name) Dim attachment As New DimeAttachment (s, TypeFormat.Unchanged, Me.OpenFileDialog1.FileName) 'Add the attachment to our WebService Call proxy.RequestSoapContext.Attachments.Add (attachment)' Run it and we are basically done. Proxy.uploadfile (new IO.fileinfo (f) .Name) Totalfl = 1 Catch exception msgbox (Ex.Message & Vbrlf & Vbrlf & "FileSize:" & new IO.fileinfo (f) End Next Dim ETIME AS DATETIME = NOW MSGBOX ("Copied" & Totalfl & "in "& DateIff (DateInterVal.Second, Stime, Etime) &" s ") me.cursor = cursors.default end if End Subthis is Basically It. Now if you intend to Upload Larger Files, Meaning Go in A Total over the 4MB Limit .
We are going to set 2 values here, the overrides value of the httprequestlimit as well below the wse attachement limit.open the Web.config and set as desired.source code:
...
And That's all flaks.
You Can Download The Above Sample Here