示例#1
0
        /// <summary>
        /// Gets the outgoing response.
        /// </summary>
        /// <param name="operationContext">The operation context.</param>
        /// <param name="response">The response.</param>
        /// <param name="responseStream">The response stream.</param>
        /// <returns>Outgoing response.</returns>
        private static Message GetOutgoingResponse(WebOperationContext operationContext, HttpResponseMessage response, Stream responseStream)
        {
            Message responseMessage;

            if (response.Content == null)
            {
                responseMessage = operationContext.CreateTextResponse(string.Empty);
            }
            else
            {
                responseMessage = response.Content.Headers.ContentType == null?
                                  operationContext.CreateStreamResponse(responseStream, "text/plain; charset=us-ascii") :
                                      operationContext.CreateStreamResponse(responseStream, response.Content.Headers.ContentType.ToString());
            }

            operationContext.OutgoingResponse.StatusCode = response.StatusCode;
            foreach (var header in response.Headers)
            {
                header.Value.ToList().ForEach(headerVal =>
                                              operationContext.OutgoingResponse.Headers.Add(header.Key, headerVal));
            }

            foreach (var header in response.Content.Headers)
            {
                header.Value.ToList().ForEach(headerVal =>
                                              operationContext.OutgoingResponse.Headers.Add(header.Key, headerVal));
            }

            return(responseMessage);
        }
示例#2
0
        private Message CreateValidResponse(WebOperationContext context, object value)
        {
            switch (context.IncomingRequest.Accept)
            {
            case "application/xml":
                return(context.CreateXmlResponse(value.ToString()));

            case "application/json":
                return(context.CreateJsonResponse(value.ToString()));

            default:
                return(context.CreateTextResponse(value.ToString()));
            }
        }
示例#3
0
 public static System.ServiceModel.Channels.Message createJsonWebResponse(WebOperationContext context, string json)
 {
     return context.CreateTextResponse(json, "application/json; charset=utf-8");
 }
示例#4
0
 private static Message CreateMessage(WebOperationContext context, string text)
 {
     return(context.CreateTextResponse(text, "text/plain", new UTF8Encoding(false)));
 }
示例#5
0
 private static Message CreateMessage(WebOperationContext context, string text)
 {
     return context.CreateTextResponse(text, "text/plain", new UTF8Encoding(false));
 }
示例#6
0
 private Message CreateErrorResponse(WebOperationContext context, string error)
 {
     return(context.CreateTextResponse(error));
 }
 public static Message ReturnError(WebOperationContext ctx, HttpStatusCode statusCode)
 {
     ctx.OutgoingResponse.StatusCode = statusCode;
     return(ctx.CreateTextResponse(statusCode.ToString(), "text/html"));
 }