Пример #1
0
        private static IResponseMessage GetResponseMessage(HttpResponseMessage response)
        {
            var headers = GetRpcHeaders(response.Headers);
            //var contentEncoding = response.Headers.GetValues("Transfer-Encoding").FirstOrDefault();
            string statusCode;
            var isSuccess = headers.TryGetValue(HeaderName.StatusCode, out statusCode)
                && statusCode == RpcStatusCode.Ok;

            var responseMessage = new ResponseMessage(response)
            {
                IsSuccess = isSuccess, // response.StatusCode == HttpStatusCode.OK,
                Result = response.Content.ReadAsStreamAsync().Result,
                Headers = headers,
            };
            return responseMessage;
        }
Пример #2
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="action"></param>
        /// <param name="content"></param>
        /// <param name="headers"></param>
        /// <returns></returns>
        public virtual Task<IResponseMessage> SendAsync(string action, Stream content, IDictionary<string, string> headers)
        {
            if (SendAsyncFunc != null)
                return SendAsyncFunc(action, content, headers);

            var outputStream = new MemoryStream();
            var responseHeader = new Dictionary<string, string>();

            var request = new GenericServerContext
            {
                RequestContentLength = (int)content.Length,
                RequestContentType = headers["Content-Type"],
                RequestPath = Address + action,
                RequestStream = content,
                RequestHeader = headers,

                ResponseStream = outputStream,
                ResponseHeader = responseHeader,
            };

            return _appHost.ProcessAsync(request).ContinueWith(tsk =>
            {
                var processed = tsk.Result;
                if (!processed)
                    return null;

                string statusCode;
                var isSuccess = responseHeader.TryGetValue(HeaderName.StatusCode, out statusCode)
                    && statusCode == RpcStatusCode.Ok;

                outputStream.Position = 0;
                var response = new ResponseMessage(null)
                {
                    Headers = responseHeader,
                    IsSuccess = isSuccess,
                    Result = outputStream,
                };

                return (IResponseMessage)response;
            });
        }
Пример #3
0
        private static ResponseMessage GetResponseMessage(HttpWebResponse response)
        {
            var headers = GetRpcHeaders(response.Headers);

            string statusCode;
            var isSuccess = headers.TryGetValue(HeaderName.StatusCode, out statusCode)
                && statusCode == RpcStatusCode.Ok;

            var responseMessage = new ResponseMessage(response)
            {
                IsSuccess = isSuccess,
                Result = response.GetResponseStream(),
                Headers = headers,
            };
            return responseMessage;
        }