コード例 #1
0
        public static HttpResponseMessageWrapperEx ToTransportResponse(this AppResponseMessage response)
        {
            // Could interact with the wrapper directly, but trying to use
            // http message as much as possible so that if we want to push
            // the wrapper contents into an http message, would prob have better result.
            var http = new HttpResponseMessage();

            http.Content = new StringContent(JsonConvert.SerializeObject(response));

            http.Headers.Add(ResponseIdHeader, response.Headers.MessageId);
            http.Headers.Date = response.Headers.CreatedOn;
            //http.Headers.Add(ResponseDateHeader, response.Headers.CreatedOn?.ToString());
            http.Headers.Add(ResponseChannelHeader, response.Headers.SourceChannel);

            var content = http.Content.ReadAsStringAsync().ConfigureAwait(false).GetAwaiter().GetResult();
            var wrapper = new HttpResponseMessageWrapperEx(http, content);

            // TODO: Should probably pass this in to forego the overhead of performing it twice.
            wrapper.RequestWrapper = response.AppRequestMessage.ToTransportRequest();

            return(wrapper);
        }
コード例 #2
0
 public static TResponse ToAppResponseMessage <TResponse>(this HttpResponseMessageWrapperEx wrapper) where TResponse : AppResponseMessage
 {
     return(JsonConvert.DeserializeObject <TResponse>(wrapper.Content));
 }