views:

475

answers:

1

I need a Win client for Amazon S3 that utilizes SOAP protocol for all transactions. As far as I see most solutions are REST based rather than SOAP. Any ideas?

EDIT:

Just want to clarify: please do not suggest using REST instead. I am perfectly aware of what can or cannot be done with either protocol. So if I ask for this specific solution, there is a reason for that.

What I need is a working software for Win platform that utilizes SOAP for Amazon S3, not suggestions how to do my job. Thank you.

+1  A: 
  1. Start Visual Studio 2008, create a new C# Windows console application.

  2. Add the S3 WSDL as a service reference. In Solution Explorer, right click References, select Add Service Reference. Type in the S3 WSDL address in the Address box: http://s3.amazonaws.com/doc/2006-03-01/AmazonS3.wsdl. Click Go. "AmazonS3" should show in the Services box. Enter a namespace. I entered Amazon.S3. Click OK.

  3. Modify Program.cs to look something like the following:


using System;
using System.Globalization;
using System.Text;
using System.Security.Cryptography;
using ConsoleApplication1.Amazon.S3;

namespace ConsoleApplication1 {
    class Program {
        private const string accessKeyId     = "YOURACCESSKEYIDHERE0";
        private const string secretAccessKey = "YOURSECRETACCESSKEYHEREANDYESITSTHATLONG";

        public static DateTime LocalNow() {
            DateTime now = DateTime.Now;
            return new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second, now.Millisecond, DateTimeKind.Local);
        }

       public static string SignRequest(string secret, string operation, DateTime timestamp) {
            HMACSHA1 hmac         = new HMACSHA1(Encoding.UTF8.GetBytes(secret));
            string   isoTimeStamp = timestamp.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffZ", CultureInfo.InvariantCulture);
            string   signMe       = "AmazonS3" + operation + isoTimeStamp;
            string   signature    = Convert.ToBase64String(hmac.ComputeHash(Encoding.UTF8.GetBytes(signMe)));
            return signature;
        }

        static void Main(string[] args) {
            DateTime       now    = LocalNow();
            AmazonS3Client client = new AmazonS3Client();

            var result = client.ListAllMyBuckets(
                accessKeyId,
                now,
                SignRequest(secretAccessKey, "ListAllMyBuckets", now));

            foreach (var bucket in result.Buckets) {
                Console.WriteLine(bucket.Name);
            }
        }
    }
}

If you now insert your access key ID and secret access key in the appropriate spots and run the program, you should get a listing of your S3 buckets.

The AmazonS3Client class has all the SOAP operations available as instance methods on it.

The Amazon website carries an older (VS2005 + WSE) C#/SOAP sample at http://developer.amazonwebservices.com/connect/entry.jspa?externalID=129&categoryID=47.

EDIT: posted a visual studio solution at http://flyingpies.wordpress.com/2009/08/04/the-shortest-ever-s3-csoapwcf-client/.

Oren Trutner