This blog is subject the DISCLAIMER below.

Thursday, March 27, 2008

Amazon S3 via C#

Amazon Simple Storage Service (Amazon S3) via C#

Amazon S3 is storage for the Internet. It is designed to make web-scale computing easier for developers. It’s provides a simple web services interface that can be used to store and retrieve any amount of data, at any time, from anywhere on the web.

It uses standards-based REST and SOAP interfaces so it is platform independent and language independent.

It `s commercial but highly scalable, reliable, fast and inexpensive data storage infrastructure.

To know more about its advantage and the cost click here:

I am writing here to give you my experiences and tricks which I faced it when I started in develop the service using Dot Net (C#) and soap.

First trick:

When you work using .Net, you must use WSE 2.0 NOT WSE 3.0 as Amazon support DIME (WSE 2.0) NOT MTOM (WSE 3.0).

Second trick:

You can only using the class System.Web.Services.Protocols.SoapHttpClientProtocol, if you want upload files to AWS (Amazon Web Service) that are less than one Megabytes.

Here is an excellent example that server the required (files less than megabyte) with complete demo code for view and upload files.

Third trick:

If your files are bigger than one Megabytes (ten, twenty or may be 50 megabytes), you must to change the class System.Web.Services.Protocols.SoapHttpClientProtocol to Microsoft.Web.Services2.WebServicesClientProtocol . (As mentioned in this link)!default.jspa?categoryID=103&externalID=689&fromSearchPage=true

Then follow the last trick...

Last trick:

You must raise the Timeout property that inherits the Microsoft.Web.Services2.WebServicesClientProtocol (the AmazonS3class if you opened the following example) more time out (this property measures in milliseconds) .

Here it an excellent example that server the required (more than one megabyte) with complete code.!default.jspa?categoryID=47&externalID=690&fromSearchPage=true

The Amazon S3 Developer Guide :


Anonymous said...

WSE 2.0 SP3 is not supported with versions of Visual Studio later than Visual Studio .NET 2003.
Does that mean that I cannot use it in Visual Studio 2005, or it is just not recommended?
I do have an application written in vs 2005 that uploads files to aws s3 using PutObjectInline method. I now want to upload files larger that 1MB. That means using PutObject with WSE 2.0 DIME attachments. Can I do it from that application, or I have to rewrite it under vs2003?

Alex, Romania

Ahmed Essawy said...

No Alex you can do it ..I do it by Visual Studio 2005 and WSE 2.0 without problems ..
I got WSE 2.0 from here

it will be from the same application and also by PutObjectInline function..
but as I mentioned before in this article must to
modify your proxy class to support Microsoft.Web.Services2
and you must raise the Timeout property that inherits the Microsoft.Web.Services2.WebServicesClientProtocol to have more time out (this property measures in milliseconds).
anyway ..I can sent you my application if you need it (it supports the upload files with any size) .

Ahmed Essawy said...

I have checked my code it is as you ask PutObject Not PutObjectInline

gautam said...


I am using the Amozon S3 in the Windows Application, so we are using the Webservice com.amazonaws.s3. Can you please help me to upload the file more then 1MB in my Windows Application.

This is really urgent, please reply.


Ahmed Essawy said...

Dear Gautam,
The following link is a C# project which I wrote while I was writing this article from 8 months ago.

This project is console application that do what are you want (uploading file with large size).

INSTRUCTION to run the project :
1-you must to fill awsAccessKeyId and awsSecretAccessKey variables with your keys.(you can find them in S3Driver.cs)

2-this project was for uploading all PDF files from selected folder in your disk to AmazonWebService .
So the console application should pass the following parameters but you can change this parameters and the whole project upon your request :
"-PDFFolder" the folder have your PDF file to upload .
"-log_folder": the folder you want to log in .
"-log_file ": the file you want to log in .
"-Done_folder": will be filled with uploaded PDF files.

3-”bucketname” is other variables you must to fill with the name of your bucket in Amazon . (you can find this variable also in S3Driver.cs)