Exemple #1
0
        public async Task ConvertResponse <T>(ServiceResponse <T> response, HttpResponse httpResponse, HttpDataSerializerOptions options) where T : new()
        {
            var serializedData = await _serializer.SerializeResponse(response, typeof(ServiceResponse <T>), options);

            var contentType = _serializer.ContentType;
            var encoding    = _serializer.Encoding;

            httpResponse.StatusCode  = response.MetaData.Result.HttpStatusCode();
            httpResponse.ContentType = contentType;

            await httpResponse.WriteAsync(serializedData, encoding);
        }
Exemple #2
0
        public async Task <HttpResponseMessage> ConvertResponse(HttpRequestMessage request, ServiceResponse response, Type type)
        {
            var options        = CreateOptionsFromHeaders(request.Headers);
            var serializedData = await _serializer.SerializeResponse(response, type, options);

            var contentType = _serializer.ContentType;
            var encoding    = _serializer.Encoding;
            var httpMsg     = new HttpResponseMessage
            {
                StatusCode = (HttpStatusCode)response.MetaData.Result.HttpStatusCode(),
                Content    = new StringContent(serializedData, encoding, contentType)
            };

            httpMsg.Headers.Add(nameof(response.MetaData.CorrelationId), $"{response.MetaData.CorrelationId}");

            return(httpMsg);
        }