0

首先,AWS C# SDK 会自我检查吗?现在,我有代码可以做类似的事情

md5检查

List<string> msgs = new List<string>();
ReceiveMessageResponse response = this.getMessageRoutine(num);
foreach (Message m in response.ReceiveMessageResult.Message) {
   if (m.MD5OfBody.ToUpper() != Global.StringFunctions.CalculateMD5Hash(m.Body)) {
       throw new Exception("TODO IMPLEMENT: RECEIVED MESSAGE IS CORRUPT");
   }
       msgs.Add(m.Body);
}
return msgs;

验证发出的用户定义的 ID 在响应中返回,并且服务器生成的消息的 md5 与发送的消息匹配

            foreach (SendMessageBatchResultEntry e in response.SendMessageBatchResult.SendMessageBatchResultEntry) {

                foreach (SendMessageBatchRequestEntry r in entry) {
                    if (r.Id == e.Id) {
                        if (Global.StringFunctions.CalculateMD5Hash(r.MessageBody) != e.MD5OfMessageBody.ToUpper()) {
                            throw new Exception("TODO IMPLEMENT THIS: MD5 MISMATCH BETWEEN AWS:LOCAL (" + e.MD5OfMessageBody.ToUpper() + " : " + Global.StringFunctions.CalculateMD5Hash(r.MessageBody)+")");
                        }
                        entry.Remove(r);
                        break;
                    }
                    throw new Exception("TODO IMPLEMENT THIS: INVALID ID IN RESPONSE");
                }
            }
            if (entry.Count != 0) {
                throw new Exception("TODO IMPLEMENT: NOT ALL MESSAGES SENT HAD A CORRESPONDING CALLBACK");
            }

有没有更好的实现类似这样的东西,比如 request.checkResponse(response) ?

4

1 回答 1

2

最新版本的适用于 .NET 的 AWS 开发工具包( 1.5.23 ) 包括 MD5 哈希检查,作为发送单个消息、发送一批消息和接收消息的一部分。如果这对您不起作用,我们很想听听为什么以及如何使它变得更好。

谢谢!

于 2013-06-14T22:48:24.390 回答