Reputation: 31
I've referenced this section in the API documentation, but I'm not sure if the request I'm sending out via the API is correct. This is what my code looks like:
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");
}
}
}
Am I doing something wrong?
Upvotes: 1
Views: 393
Reputation: 1286
When using Begin* methods, you need to call the matching End* method to complete the request and retrieve the result object. Take a look at this guide for a number of examples.
Here's a simplified sample from the guide that illustrates the basic approach:
// 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
}
Upvotes: 1