private void OnMessageReceived(string fromAddress, string toAddress, string message, string messageType, string messageId, string smsc, string pdu, string gateway, DateTime sendTime, DateTime receiveTime) { SmsHolder hld = new SmsHolder(); hld.fromAddress = fromAddress; hld.gateway = gateway; hld.message = message; hld.toAddress = toAddress; try { HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(@"http://localhost:54345/Sms/RecieveMessage"); httpWebRequest.ContentType = "application/x-www-form-urlencoded"; httpWebRequest.Method = "POST"; string queryString = "key=" + HttpUtility.UrlEncode("givemeaccesstotoyou") + "&message=" + HttpUtility.UrlEncode(message) + "&gateway=" + HttpUtility.UrlEncode(gateway) + "&from=" + HttpUtility.UrlEncode(fromAddress) + "&to=" + HttpUtility.UrlEncode(toAddress); byte[] byteData = UTF8Encoding.UTF8.GetBytes(queryString); httpWebRequest.ContentLength = byteData.Length; using (Stream postStream = httpWebRequest.GetRequestStream()) { postStream.Write(byteData, 0, byteData.Length); } using (HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse()) { string responseText = new StreamReader(httpWebResponse.GetResponseStream()).ReadToEnd(); if (httpWebResponse.StatusCode == HttpStatusCode.OK) { PostEventLog("Send ok:" + responseText, responseText, EventLog.Information); //PostEventLog("Send error:"+DateTime.Now.ToString(), httpWebResponse.StatusCode.ToString(), EventLog.Error); } else { PostEventLog("Send error:" + httpWebResponse.StatusCode.ToString(), httpWebResponse.StatusCode.ToString(), EventLog.Error); } } } catch (Exception e) { WebException exc = e as WebException; //AddToQueue(hld); if (exc != null) { string responseText = new StreamReader(exc.Response.GetResponseStream()).ReadToEnd(); PostEventLog("Send error:" + responseText, responseText, EventLog.Error); } else PostEventLog(e.Message, e.ToString(), EventLog.Error); //PostSendResult("1", "", StatusCode.SendError, "Error: message rejected", "", e.Message, false); } // // e.g. // PostSendMessage(fromAddress, "", "We have received your message", "sms.text", "", "", ""); // }
private void AddToQueue(SmsHolder hld) { smsQueue.Add(hld); }