引发了状态为TrustFailure的WebException.从SharePoint 2010调用AmazonS3 .net 3.5版本3 [英] A WebException with status TrustFailure was thrown. AmazonS3 .net 3.5 Version 3 invoking from sharepoint 2010

查看:329
本文介绍了引发了状态为TrustFailure的WebException.从SharePoint 2010调用AmazonS3 .net 3.5版本3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我正在使用适用于.net 3.5版本3的AmazonS3 Sdk在POC中进行CRUD操作.我正在尝试使用秘密密钥和访问密钥来检索特定存储桶名称的区域端点(位置),而存储桶名称(具有位置:欧盟(法兰克福)(eu-central-1)).为了建立联系 与AmazonS3并执行CRUD操作 因此,当我尝试从共享点获取Region Endpoint(网页使用SharePoint的母版页创建自己的页面)以创建具有Region Retrieve的AmazonS3Client实例时,我抛出了一个状态为TrustFailure的WebException.
使用以下代码:

Currently I am working in POC with CRUD operations using AmazonS3 Sdk for .net 3.5 version 3. I am trying to retrieve the Region Endpoint(Location) of the specific bucket name using secret key and Access Key and bucket name( has Location: EU (Frankfurt) (eu-central-1)). in order to establish connection with AmazonS3 and perform CRUD operations So I get the A WebException with status TrustFailure was thrown when I tried to get the Region Endpoint from share point(web page I create my own page using the master page of SharePoint) in order to create AmazonS3Client instance with Region Retrieve.
with the following code:

private string defaultAmazonHttpsHost = "https://s3.amazonaws.com";
private string defaultAmazonHttpHost = "http://s3.amazonaws.com"; 

private Amazon.RegionEndpoint GetRegionEndpoint(string bucket, BasicAWSCredentials amazonCredentials, bool useSSL)
{
    Amazon.RegionEndpoint regiongEndpoint = null;
    AmazonS3Config configurationClient = new AmazonS3Config();
    configurationClient.UseHttp = !useSSL;
    configurationClient.ServiceURL = useSSL ? defaultAmazonHttpsHost : defaultAmazonHttpHost;
    try
    {
        using (AmazonS3Client clientConnection = new AmazonS3Client(amazonCredentials, configurationClient))
        {
            GetBucketLocationRequest locationRequest = new GetBucketLocationRequest();
            locationRequest.BucketName = bucket;
            string locationName = clientConnection.GetBucketLocation(locationRequest).Location.Value;
            if (locationName.Equals("EU", StringComparison.InvariantCultureIgnoreCase))
            {
                regiongEndpoint = Amazon.RegionEndpoint.EUWest1;
            }
            else if (string.IsNullOrEmpty(locationName))
            {
                regiongEndpoint = Amazon.RegionEndpoint.USEast1;
            }
            else
            {
                regiongEndpoint = Amazon.RegionEndpoint.GetBySystemName(locationName);
            }
        }
    }
    catch (AmazonS3Exception amazonS3Exception)
    {
          throw amazonS3Exception;
    }
    catch (Exception unExpectedException)
    {
        throw unExpectedException;
    }
    return regiongEndpoint;
}
BasicAWSCredentials credentials = new BasicAWSCredentials("my access Key", "my secret key");
AmazonS3Config configurationAmazon = new AmazonS3Config();
configurationAmazon.RegionEndpoint = GetRegionEndpoint("bucketName", credentials, false);
 AmazonS3Client _s3 = new AmazonS3Client(credentials, configurationAmazon );

我的任务使用源信息与AmazonS3 Sdk .net 3.5版本3执行CRUD操作+测试连接: -密钥 -访问密钥 -桶名称

My task Perform CRUD operations + test connection with AmazonS3 Sdk .net 3.5 version 3 , with the source information : -secret key - access key - bucket Name

奇怪的是,该零件代码是否从另一个项目开始运行(执行)(例如,没有共享点交互:控制台项目),我没有收到此异常)你知道这是什么问题吗?

the strange is if this part code run(execute) since another Project (without share point interaction for example: Console Project) I do not get this exception) Do you know what is the problem?

推荐答案

我在执行对amazonS3的任何请求之前使用了以下内容,现在它可以按预期工作,我认为问题出在共享点正在使用的证书上.

I used the following before execute any request to amazonS3 and now it works as expected I think the problem was with the certificates that sharepoint is using .

ServicePointManager.ServerCertificateValidationCallback +=   
delegate(  
    object sender,   
    X509Certificate certificate,   
    X509Chain chain,   
    SslPolicyErrors sslPolicyErrors)  
    {  
         return true;  
    };  

查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆