【问题标题】:Amazon S3 client based on SOAP基于 SOAP 的 Amazon S3 客户端
【发布时间】:2010-11-16 19:27:49
【问题描述】:

我需要一个适用于所有事务的 Amazon S3 的 Win 客户端。据我所知,大多数解决方案都是基于 REST 而不是 SOAP。有什么想法吗?

编辑:

只是想澄清一下:请不要建议使用 REST。我完全清楚这两种协议能做什么或不能做什么。所以如果我要求这个特定的解决方案,那是有原因的。

我需要的是一个适用于 Win 平台的工作软件,该软件将 SOAP 用于 Amazon S3,而不是建议如何完成我的工作。谢谢你。

【问题讨论】:

  • 为什么需要 SOAP? S3 的 REST API 要简单得多,而且我认为 SOAP 缺少一些功能......
  • 我同意。 SOAP 应该是最后的手段。
  • 构建一个使用 SOAP 的小应用程序。需要一个类似的工作解决方案。
  • 您的 Windows 客户端使用哪种技术?
  • @Nick,您不能将现有的 REST 库之一用于 S3,而将 SOAP 用于您正在做的其他事情吗?

标签: soap amazon-s3 amazon-web-services


【解决方案1】:
  1. 启动 Visual Studio 2008,创建一个新的 C# Windows 控制台应用程序。

  2. 将 S3 WSDL 添加为服务引用。在解决方案资源管理器中,右键单击引用,选择添加服务引用。在地址框中键入 S3 WSDL 地址:http://s3.amazonaws.com/doc/2006-03-01/AmazonS3.wsdl。单击“前往”。 “AmazonS3”应显示在服务框中。输入命名空间。我进入了 Amazon.S3。点击确定。

  3. 将 Program.cs 修改为如下所示:


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);
            }
        }
    }
}

如果您现在将访问密钥 ID 和秘密访问密钥插入适当的位置并运行程序,您应该会获得 S3 存储桶的列表。

AmazonS3Client 类具有所有可用作实例方法的 SOAP 操作。

Amazon 网站在http://developer.amazonwebservices.com/connect/entry.jspa?externalID=129&categoryID=47 上带有较旧的 (VS2005 + WSE) C#/SOAP 示例。

编辑:在http://flyingpies.wordpress.com/2009/08/04/the-shortest-ever-s3-csoapwcf-client/ 发布了一个视觉工作室解决方案。

【讨论】:

    猜你喜欢
    • 2010-11-16
    • 1970-01-01
    • 2011-04-28
    • 2015-12-04
    • 2010-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多