2013-03-13 78 views
1

我在API文檔中引用了this部分,但我不確定通過API發出的請求是否正確。這是我的代碼看起來像:如何獲取Amazon Cloudfront .NET API中的失效請求列表?

public class CfListInvalidation 
{ 
    string accessKeyID = ConfigurationManager.AppSettings["awsAccessID"]; 
    string secretAccessKeyID = ConfigurationManager.AppSettings["awsSecretAnswer"]; 
    string distributionId = ConfigurationManager.AppSettings["distributionId"]; 
    AmazonCloudFront client; 

    public void SendCommand() 
    { 

     Console.WriteLine("Connecting to Amazon Cloud Front..."); 

     using (client = AWSClientFactory.CreateAmazonCloudFrontClient(accessKeyID, secretAccessKeyID)) 
     { 
      ListInvalidationsResult result = new ListInvalidationsResult(); 

      IAsyncResult r = client.BeginListInvalidations(new ListInvalidationsRequest 
      { 
       DistributionId = distributionId,           
      }, new AsyncCallback(CfListInvalidation.CompleteRead), result);     

     } 
    } 

    static void CompleteRead(IAsyncResult result) 
    { 
     ListInvalidationsResult r = result.AsyncState as ListInvalidationsResult; 

     if (r != null && r.InvalidationList != null) 
     { 
      Console.WriteLine("listing items.."); 

      foreach (InvalidationSummary s in r.InvalidationList.Items) 
      { 
       Console.WriteLine(string.Format("ID: {0} - Status: {1}", s.Id, s.Status)); 
      } 
     } 

     else { 
      Console.WriteLine("No Items Found"); 
     } 
    } 
} 

我做錯了什麼?

+0

你有沒有遇到任何問題,或者你只是想確保你的做法是正確的? – 2013-04-08 22:24:39

回答

1

使用Begin *方法時,您需要調用匹配的End *方法來完成請求並檢索結果對象。看一看this guide的一些例子。

下面是從圖示的基本方法指導簡化樣本:

// Begin method 
client.BeginPutObject(request, CallbackWithClient, client); 

// Callback 
public static void CallbackWithClient(IAsyncResult asyncResult) 
{ 
    AmazonS3Client s3Client = (AmazonS3Client) asyncResult.AsyncState; 
    PutObjectResponse response = s3Client.EndPutObject(asyncResult); 

    // Process the response 
}