Exemplo n.º 1
0
        private SendMessageResponse DoSendMessage(SendMessageRequest request)
        {
            List<string> lParams = new List<string>();

            lParams.Add(string.Format("&AWSAccessKeyId={0}", Util.UrlEncode(AccessKey)));
            lParams.Add(string.Format("&Action={0}", "SendMessage"));
            lParams.Add(string.Format("&DelaySeconds={0}", request.DelaySeconds));
            lParams.Add(string.Format("&MessageBody={0}", Util.UrlEncode(request.MessageBody)));
            lParams.Add(string.Format("&SignatureMethod={0}", "HmacSHA256"));
            lParams.Add(string.Format("&SignatureVersion={0}", "2"));
            lParams.Add(string.Format("&Timestamp={0}", Util.UrlEncode(DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssZ"))));
            lParams.Add(string.Format("&Version={0}", "2012-11-05"));

            lParams.Sort(StringComparer.Ordinal);

            var parameters = string.Join("", lParams);
            parameters = parameters.Substring(1);

            string sig = Util.GetSignature(request.QueueUrl, "GET", parameters, SecretKey);
            parameters = string.Format("{0}&Signature={1}", parameters, Util.UrlEncode(sig));

            var wRequest = WebRequest.Create(string.Format("{0}?{1}", request.QueueUrl, parameters)) as HttpWebRequest;
            wRequest.Method = "GET";
            wRequest.ContentType = "application/x-www-form-urlencoded";
            wRequest.KeepAlive = false;

            using (var response = wRequest.GetResponse() as HttpWebResponse)
            using (var stream = response.GetResponseStream())
            using (var reader = new StreamReader(stream))
            {
                var body = reader.ReadToEnd();
                var element = XElement.Parse(body);

                XmlSerializer serializer = new XmlSerializer(typeof(SendMessageResponse));
                var sendMessageResponse = (SendMessageResponse)serializer.Deserialize(element.CreateReader());
                return sendMessageResponse;
            }
        }
Exemplo n.º 2
0
 public SendMessageResponse SendMessage(SendMessageRequest request)
 {
     return Util.RetryMethod<SendMessageResponse>(() => DoSendMessage(request), RetryCount);
 }