diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/Constants.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/Constants.cs
index 9f83948cb3e5..1e320c4e82fd 100644
--- a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/Constants.cs
+++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/Constants.cs
@@ -61,5 +61,7 @@ internal static class Constants
internal const int CompatibilityLevel = 20; // Compatibility level for rules.
internal const string JsonNullValue = "null"; // String representation of null value in Json.
+
+ internal const string ContentTypeHeader = "Content-Type";
}
}
diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/Http/HttpContent.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/Http/HttpContent.cs
index 8af047318405..97089cda3ea2 100644
--- a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/Http/HttpContent.cs
+++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/Http/HttpContent.cs
@@ -15,6 +15,7 @@
using System;
using System.Collections.Generic;
+using System.Diagnostics;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;
@@ -22,6 +23,7 @@
using Windows.Storage.Streams;
using NetHttpContent = System.Net.Http.HttpContent;
+using NetHttpResponseMessage = System.Net.Http.HttpResponseMessage;
namespace Microsoft.WindowsAzure.ServiceLayer.Http
{
@@ -186,9 +188,37 @@ internal void SubmitTo(HttpRequestMessage request)
if (!string.IsNullOrEmpty(ContentType))
{
- content.Headers.Add("Content-Type", ContentType);
+ content.Headers.Add(Constants.ContentTypeHeader, ContentType);
}
request.Content = content;
}
+
+ ///
+ /// Creates a content from the HTTP response.
+ ///
+ /// Source HTTP response.
+ /// Content.
+ internal static HttpContent CreateFromResponse(NetHttpResponseMessage response)
+ {
+ Debug.Assert(response.IsSuccessStatusCode);
+ HttpContent content = null;
+
+ if (response.Content != null)
+ {
+ content = new HttpContent(new StreamContent(response.Content.ReadAsStreamAsync().Result));
+
+ IEnumerable contentTypes;
+
+ if (response.Content.Headers.TryGetValues(Constants.ContentTypeHeader, out contentTypes))
+ {
+ foreach (string type in contentTypes)
+ {
+ content.ContentType = type;
+ break;
+ }
+ }
+ }
+ return content;
+ }
}
}
diff --git a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/BrokeredMessageInfo.cs b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/BrokeredMessageInfo.cs
index bb56e8699e83..f9c6b6586d85 100644
--- a/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/BrokeredMessageInfo.cs
+++ b/microsoft-azure-servicelayer/Microsoft.WindowsAzure.ServiceLayer/ServiceBus/BrokeredMessageInfo.cs
@@ -18,14 +18,16 @@
using System.Diagnostics;
using System.IO;
using System.Linq;
-using System.Net;
-using System.Net.Http;
using System.Runtime.Serialization.Json;
using System.Text;
using System.Threading.Tasks;
+using Microsoft.WindowsAzure.ServiceLayer.Http;
using Windows.Foundation;
using Windows.Storage.Streams;
+using NetHttpContent = System.Net.Http.HttpContent;
+using NetHttpResponseMessage = System.Net.Http.HttpResponseMessage;
+
namespace Microsoft.WindowsAzure.ServiceLayer.ServiceBus
{
///
@@ -42,7 +44,7 @@ public sealed class BrokeredMessageInfo
///
public string ContentType
{
- get { return _content.Headers.ContentType.ToString(); }
+ get { return _content.ContentType; }
}
///
@@ -188,9 +190,7 @@ public string To
/// Content of the message.
public IAsyncOperation ReadContentAsStringAsync()
{
- return _content
- .ReadAsStringAsync()
- .AsAsyncOperation();
+ return _content.ReadAsStringAsync();
}
///
@@ -199,10 +199,7 @@ public IAsyncOperation ReadContentAsStringAsync()
/// Array of bytes.
public IAsyncOperation> ReadContentAsBytesAsync()
{
- return _content
- .ReadAsByteArrayAsync()
- .ContinueWith(t => (IEnumerable)t.Result, TaskContinuationOptions.OnlyOnRanToCompletion)
- .AsAsyncOperation();
+ return _content.ReadAsByteArrayAsync();
}
///
@@ -211,10 +208,7 @@ public IAsyncOperation> ReadContentAsBytesAsync()
/// Stream.
public IAsyncOperation ReadContentAsStreamAsync()
{
- return _content
- .ReadAsStreamAsync()
- .ContinueWith(t => t.Result.AsInputStream(), TaskContinuationOptions.OnlyOnRanToCompletion)
- .AsAsyncOperation();
+ return _content.ReadAsStreamAsync();
}
///
@@ -228,9 +222,8 @@ public IAsyncInfo CopyContentToAsync(IOutputStream stream)
{
throw new ArgumentNullException("stream");
}
- return _content
- .CopyToAsync(stream.AsStreamForWrite())
- .AsAsyncAction();
+
+ return _content.CopyToAsync(stream);
}
///
@@ -239,9 +232,9 @@ public IAsyncInfo CopyContentToAsync(IOutputStream stream)
///
/// Response with data.
///
- internal static BrokeredMessageInfo CreateFromPeekResponse(HttpResponseMessage response)
+ internal static BrokeredMessageInfo CreateFromPeekResponse(NetHttpResponseMessage response)
{
- if (response.StatusCode == HttpStatusCode.NoContent || response.StatusCode == HttpStatusCode.ResetContent)
+ if (response.StatusCode == System.Net.HttpStatusCode.NoContent || response.StatusCode == System.Net.HttpStatusCode.ResetContent)
{
return null;
}
@@ -252,10 +245,10 @@ internal static BrokeredMessageInfo CreateFromPeekResponse(HttpResponseMessage r
/// Constructor. Initializes the object from the HTTP response.
///
/// HTTP reponse with the data.
- internal BrokeredMessageInfo(HttpResponseMessage response)
+ internal BrokeredMessageInfo(NetHttpResponseMessage response)
{
Debug.Assert(response.IsSuccessStatusCode);
- _content = response.Content;
+ _content = HttpContent.CreateFromResponse(response);
_customProperties = new CustomPropertiesDictionary(response);
DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(Dictionary));