soap - 基于 SOAP 的 Amazon S3 客户端

标签 soap amazon-s3 amazon-web-services

我需要一个针对所有事务使用 SOAP 协议(protocol)的 Amazon S3 的 Win 客户端。据我所知,大多数解决方案都是基于 REST 而不是 SOAP。有任何想法吗?

编辑:

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

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

最佳答案

  • 启动 Visual Studio 2008,创建一个新的 C# Windows 控制台应用程序。
  • 添加 S3 WSDL 作为服务引用。在解决方案资源管理器中,右键单击引用,选择添加服务引用。在地址框中输入 S3 WSDL 地址:http://s3.amazonaws.com/doc/2006-03-01/AmazonS3.wsdl .单击“前往”。 “AmazonS3”应显示在服务框中。输入命名空间。我进入了 Amazon.S3。单击确定。
  • 将 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);
                }
            }
        }
    }
    

    如果您现在将访问 key ID 和 secret 访问 key 插入适当的位置并运行程序,您应该会获得 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/ 发布了一个 Visual Studio 解决方案.

    关于soap - 基于 SOAP 的 Amazon S3 客户端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1229659/

    相关文章:

    xml - 尝试从 Node.js 获取信息 SOAP 时出错

    amazon-s3 - 如何对 Amazon S3 等云存储系统进行基准测试

    hadoop - hive 与 Tez : Unable to load AWS credentials from any provider in the chain

    ios - AWS Cognito 用户池 - "Value null at ' userName' 未能满足约束 : Member must not be null"- iOS

    java - 轴 2 错误 : Invalid white space character (0x4) in text to output

    .net - 安全 token 无法进行身份验证或授权(.net、soap1.2)

    php - 通过 PHP Curl 调用 SoapAction

    amazon-s3 - 默认情况下强制 Amazon S3 发送 Access-Control-Allow-Origin header

    javascript - 创建一个有全局二级索引错误的表

    amazon-web-services - 尽管没有可用的现货实例,AWS ECS 任务仍在运行