private void AddWebClientHeaders(WebClient client, string serverUrl) { var token = SASTokenGenerator.GetSASToken(serverUrl, _sasName, _sasKey, TimeSpan.FromMinutes(60)); client.Headers.Add("Content-Type", "application/atom+xml;type=entry;charset=utf-8"); client.Headers.Add("Authorization", token); client.Headers.Add("x-ms-version", "2013-04"); }
private async Task SendNotification(NotificationHubMessage notification) { try { if (notification == null) { throw new ArgumentNullException("notification"); } if (String.IsNullOrEmpty(notification.Body)) { throw new ArgumentException("The Body property is empty", "notification"); } if (String.IsNullOrEmpty(notification.ContentType)) { throw new ArgumentException("The ContentType property is empty", "notification"); } var serverUrl = _endpoint + '/' + Path + "/messages?api-version=2013-04"; Debug.WriteLine("Sending Notification..."); Debug.WriteLine("url:" + serverUrl); Debug.WriteLine("payload:" + notification.Body); using (var client = new WebClient()) { var token = SASTokenGenerator.GetSASToken(serverUrl, _sasName, _sasKey, TimeSpan.FromMinutes(60)); client.Headers.Add("Authorization", token); client.Headers.Add("Content-Type", notification.ContentType); if (!String.IsNullOrEmpty(notification.Tag)) { client.Headers.Add("ServiceBusNotification-Tags", notification.Tag); } foreach (var header in notification.Headers) { client.Headers.Add(header.Key, header.Value); } var result = await client.UploadStringTaskAsync(serverUrl, "POST", notification.Body); Debug.WriteLine("registration result:" + result); } } catch (Exception ex) { Debug.WriteLine(ex.Message); throw; } }