Ejemplo n.º 1
0
        public string SendSms(string recipient, string sender, string message, ContentType contentType)
        {
            CmMessage cmMessage = new CmMessage()
            {
                Id          = Guid.NewGuid().ToString("N"),
                From        = sender,
                To          = recipient,
                Body        = message,
                ContentType = contentType,
                MinimumNumberofMessageParts = 1,
                MaximumNumberofMessageParts = 8
            };
            string requestContent = CmXmlGenerator.Generate(_productionToken, cmMessage);

            try
            {
                WebClient webClient = new WebClient();
                webClient.Encoding = Encoding.UTF8;
                webClient.Headers.Add("Content-Type", "application/xml;charset=utf-8");
                return(webClient.UploadString(ApiBaseUrl, requestContent));
            }
            catch (WebException wex)
            {
                return(string.Format("{0} - {1}", wex.Status, wex.Message));
            }
        }
Ejemplo n.º 2
0
        public static string Generate(string productionToken, CmMessage message)
        {
            XElement xml = new XElement("MESSAGES", new XElement("AUTHENTICATION", new XElement("PRODUCTTOKEN", productionToken)),
                                        new XElement("MSG",
                                                     new XElement("FROM", message.From),
                                                     new XElement("TO", message.To),
                                                     new XElement("DCS", message.ContentType == ContentType.Text ? ContentType.Text.ToString("D") : ContentType.UnicodeText.ToString("D")),
                                                     new XElement("BODY", message.Body),
                                                     new XElement("MINIMUMNUMBEROFMESSAGEPARTS", message.MinimumNumberofMessageParts),
                                                     new XElement("MAXIMUMNUMBEROFMESSAGEPARTS", message.MaximumNumberofMessageParts)
                                                     ));

            return(xml.ToString());
        }