Skip to content

Commit

Permalink
Added WNS Raw Support
Browse files Browse the repository at this point in the history
Disabled expect-100 for latency improvement
  • Loading branch information
Kristian R authored and Kristian R committed Apr 30, 2016
1 parent 5abac61 commit 2a54363
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
22 changes: 13 additions & 9 deletions PushSharp.Windows/WnsConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,13 @@ public async Task Send (WnsNotification notification)
//https://cloud.notify.windows.com/?token=.....
//Authorization: Bearer {AccessToken}
//

//TODO: Microsoft recommends we disable expect-100 to improve latency

// Not sure how to do this in httpclient
var http = new HttpClient ();
http.DefaultRequestHeaders.ExpectContinue = false; //Disable expect-100 to improve latency

http.DefaultRequestHeaders.TryAddWithoutValidation ("X-WNS-Type", string.Format ("wns/{0}", notification.Type.ToString().ToLower ()));

http.DefaultRequestHeaders.TryAddWithoutValidation ("X-WNS-Type", string.Format ("wns/{0}", notification.Type.ToString ().ToLower ()));
if(!http.DefaultRequestHeaders.Contains("Authorization")) //prevent double values
http.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", "Bearer " + accessToken);

Expand Down Expand Up @@ -92,13 +93,16 @@ public async Task Send (WnsNotification notification)

HttpContent content = null;

if (notification.Type == WnsNotificationType.Raw) {
content = new StreamContent (new MemoryStream (Encoding.UTF8.GetBytes (notification.Payload.ToString())));
} else {
if (notification.Type == WnsNotificationType.Raw)
{
content = new StreamContent(new MemoryStream(((WnsRawNotification)notification).RawData));
}
else
{
content = new StringContent(
notification.Payload.ToString(), // Get XML payload
Encoding.UTF8,
"text/xml");
notification.Payload.ToString(), // Get XML payload
Encoding.UTF8,
"text/xml");
}

var result = await http.PostAsync (notification.ChannelUri, content);
Expand Down
10 changes: 10 additions & 0 deletions PushSharp.Windows/WnsNotification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,15 @@ public override WnsNotificationType Type
public WnsNotificationCachePolicyType? CachePolicy { get; set; }
}

public class WnsRawNotification : WnsNotification
{
public override WnsNotificationType Type
{
get { return WnsNotificationType.Raw; }
}

public byte[] RawData { get; set; }
}

}

0 comments on commit 2a54363

Please sign in to comment.