当前位置: 首页>>代码示例>>C#>>正文


C# IHttpResponse.WriteToResponse方法代码示例

本文整理汇总了C#中IHttpResponse.WriteToResponse方法的典型用法代码示例。如果您正苦于以下问题:C# IHttpResponse.WriteToResponse方法的具体用法?C# IHttpResponse.WriteToResponse怎么用?C# IHttpResponse.WriteToResponse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IHttpResponse的用法示例。


在下文中一共展示了IHttpResponse.WriteToResponse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ProcessRequest

		public override void ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, string operationName)
		{
			try
			{
                EndpointHost.Config.AssertFeatures(format);

                if (EndpointHost.ApplyPreRequestFilters(httpReq, httpRes)) return;

				httpReq.ResponseContentType = httpReq.GetQueryStringContentType() ?? this.HandlerContentType;
				var callback = httpReq.QueryString["callback"];
				var doJsonp = EndpointHost.Config.AllowJsonpRequests
							  && !string.IsNullOrEmpty(callback);

				var request = CreateRequest(httpReq, operationName);
				if (EndpointHost.ApplyRequestFilters(httpReq, httpRes, request)) return;

				var response = GetResponse(httpReq, httpRes, request);
				if (EndpointHost.ApplyResponseFilters(httpReq, httpRes, response)) return;

				if (doJsonp && !(response is CompressedResult))
					httpRes.WriteToResponse(httpReq, response, (callback + "(").ToUtf8Bytes(), ")".ToUtf8Bytes());
				else
					httpRes.WriteToResponse(httpReq, response);
			}
			catch (Exception ex)
			{
				if (!EndpointHost.Config.WriteErrorsToResponse) throw;
				HandleException(httpReq, httpRes, operationName, ex);
			}
		}
开发者ID:ELHANAFI,项目名称:ServiceStack,代码行数:30,代码来源:GenericHandler.cs

示例2: RequestFilter

        public static void RequestFilter(IHttpRequest req, IHttpResponse res, object requestDto)
        {
            var validator = ValidatorCache.GetValidator(req, requestDto.GetType());
            if (validator == null) return;

            var validatorWithHttpRequest = validator as IRequiresHttpRequest;
            if (validatorWithHttpRequest != null)
                validatorWithHttpRequest.HttpRequest = req;

            var ruleSet = req.HttpMethod;
            var validationResult = validator.Validate(
                new ValidationContext(requestDto, null, new MultiRuleSetValidatorSelector(ruleSet)));

            if (validationResult.IsValid) return;

            var errorResponse = DtoUtils.CreateErrorResponse(
                requestDto, validationResult.ToErrorResult());

            var validationFeature = EndpointHost.GetPlugin<ValidationFeature>();
            if (validationFeature != null && validationFeature.ErrorResponseFilter != null)
            {
                errorResponse = validationFeature.ErrorResponseFilter(validationResult, errorResponse);
            }

            res.WriteToResponse(req, errorResponse);
        }
开发者ID:JonCanning,项目名称:ServiceStack,代码行数:26,代码来源:ValidationFilters.cs

示例3: WriteDebugResponse

        public static void WriteDebugResponse(IHttpResponse httpRes, object response)
        {
            httpRes.WriteToResponse(response, WriteDebugRequest,
                new SerializationContext(MimeTypes.PlainText));

            httpRes.EndRequest();
        }
开发者ID:KennyBu,项目名称:ServiceStack,代码行数:7,代码来源:JsvSyncReplyHandler.cs

示例4: WriteDebugResponse

        public static void WriteDebugResponse(IHttpResponse httpRes, object response)
        {
            httpRes.WriteToResponse(response, WriteDebugRequest,
                new SerializationContext(ContentType.PlainText));

            //httpRes.Close();
        }
开发者ID:nigthwatch,项目名称:ServiceStack,代码行数:7,代码来源:JsvSyncReplyHandler.cs

示例5: WriteDebugResponse

        public static void WriteDebugResponse(IHttpResponse httpRes, object response)
        {
            httpRes.WriteToResponse(response, WriteDebugRequest,
                new SerializationContext(ContentType.PlainText));

            ServiceStack.WebHost.Endpoints.EndpointHost.AddGlobalResponseHeaders(httpRes);
            httpRes.Close();
        }
开发者ID:assaframan,项目名称:ServiceStack,代码行数:8,代码来源:JsvSyncReplyHandler.cs

示例6: ProcessRequest

        public override void ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, string operationName)
        {
            try
            {
                if (EndpointHost.ApplyPreRequestFilters(httpReq, httpRes)) return;

                var restPath = GetRestPath(httpReq.HttpMethod, httpReq.PathInfo);
                if (restPath == null)
                    throw new NotSupportedException("No RestPath found for: " + httpReq.HttpMethod + " " + httpReq.PathInfo);

                operationName = restPath.RequestType.Name;

                var callback = httpReq.GetJsonpCallback();
                var doJsonp = EndpointHost.Config.AllowJsonpRequests
                              && !string.IsNullOrEmpty(callback);

                var responseContentType = httpReq.ResponseContentType;
                EndpointHost.Config.AssertContentType(responseContentType);

                var request = GetRequest(httpReq, restPath);
                if (EndpointHost.ApplyRequestFilters(httpReq, httpRes, request)) return;

                var response = GetResponse(httpReq, httpRes, request);
                if (EndpointHost.ApplyResponseFilters(httpReq, httpRes, response)) return;

                if (responseContentType.Contains("jsv") && !string.IsNullOrEmpty(httpReq.QueryString["debug"]))
                {
                    JsvSyncReplyHandler.WriteDebugResponse(httpRes, response);
                    return;
                }

                if (doJsonp && !(response is CompressedResult))
                    httpRes.WriteToResponse(httpReq, response, (callback + "(").ToUtf8Bytes(), ")".ToUtf8Bytes());
                else
                    httpRes.WriteToResponse(httpReq, response);
            }
            catch (Exception ex)
            {
                if (!EndpointHost.Config.WriteErrorsToResponse) throw;
                HandleException(httpReq, httpRes, operationName, ex);
            }
        }
开发者ID:grammarware,项目名称:fodder,代码行数:42,代码来源:src_ServiceStack_WebHost_Endpoints_RestHandler.cs

示例7: ProcessRequest

        public void ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, string operationName)
        {
            if (Action == null)
                throw new Exception("Action was not supplied to ActionHandler");
            
            if (httpReq.OperationName == null)
                httpReq.SetOperationName(OperationName);

            var response = Action(httpReq, httpRes);
            httpRes.WriteToResponse(httpReq, response);
        }
开发者ID:remkoboschker,项目名称:ServiceStack,代码行数:11,代码来源:ActionHandler.cs

示例8: ProcessRequestAsync

        public override Task ProcessRequestAsync(IHttpRequest httpReq, IHttpResponse httpRes, string operationName)
        {
			try
            {
                var appHost = HostContext.AppHost;
                appHost.AssertFeatures(format);

                if (appHost.ApplyPreRequestFilters(httpReq, httpRes))
                    return EmptyTask;

                httpReq.ResponseContentType = httpReq.GetQueryStringContentType() ?? this.HandlerContentType;
                var callback = httpReq.QueryString["callback"];
                var doJsonp = HostContext.Config.AllowJsonpRequests
                              && !string.IsNullOrEmpty(callback);

                var request = CreateRequest(httpReq, operationName);
                if (appHost.ApplyRequestFilters(httpReq, httpRes, request))
                    return EmptyTask;

                var rawResponse = GetResponse(httpReq, httpRes, request);
                return HandleResponse(rawResponse, response => 
                {
                    if (appHost.ApplyResponseFilters(httpReq, httpRes, response))
                        return EmptyTask;

                    if (doJsonp && !(response is CompressedResult))
                        return httpRes.WriteToResponse(httpReq, response, (callback + "(").ToUtf8Bytes(),")".ToUtf8Bytes());

                    return httpRes.WriteToResponse(httpReq, response);
                },
                ex => !HostContext.Config.WriteErrorsToResponse
                    ? ex.AsTaskException()
                    : HandleException(httpReq, httpRes, operationName, ex));
            }
            catch (Exception ex)
            {
                return !HostContext.Config.WriteErrorsToResponse
                    ? ex.AsTaskException()
                    : HandleException(httpReq, httpRes, operationName, ex);
            }
        }
开发者ID:rjdudley,项目名称:ServiceStack,代码行数:41,代码来源:GenericHandler.cs

示例9: RequestFilter

        public void RequestFilter(IHttpRequest req, IHttpResponse res, object requestDto)
        {
            var validator = ValidatorCache.GetValidator(req, requestDto.GetType());
            if (validator != null)
            {
                string ruleSet = req.HttpMethod;
                var validationResult = validator.Validate(
                    new ValidationContext(requestDto, null, new MultiRuleSetValidatorSelector(ruleSet)));

                if (validationResult.IsValid) return;

                var errorResponse = ServiceUtils.CreateErrorResponse(
                    requestDto, validationResult.ToErrorResult());

                res.WriteToResponse(req, errorResponse);
            }
        }
开发者ID:austinvernsonger,项目名称:ServiceStack,代码行数:17,代码来源:ValidationFilters.cs

示例10: ValidateRequest

        public void ValidateRequest(IHttpRequest req, IHttpResponse res, object requestDto)
        {
            var validatorType = typeof(IValidator<>).MakeGenericType(requestDto.GetType());
            var resolver = typeof(IHttpRequest).GetMethod("TryResolve")
                .MakeGenericMethod(validatorType);

            var validator = (IValidator)resolver.Invoke(req, null);
            if (validator != null)
            {
                string ruleSet = req.HttpMethod;
                var validationResult = validator.Validate(new ValidationContext(requestDto, null, new MultiRuleSetValidatorSelector(ruleSet)));

                var translator = new ResponseStatusTranslator();
                ResponseStatus responseStatus = translator.Parse(validationResult.AsSerializable());
                res.WriteToResponse(req, responseStatus);
            }
        }
开发者ID:corneliutusnea,项目名称:ServiceStack,代码行数:17,代码来源:ValidationFilter.cs

示例11: WriteDebugResponse

 public static void WriteDebugResponse(IHttpResponse httpRes, object response)
 {
     httpRes.WriteToResponse(response, WriteDebugRequest, ContentType.PlainText);
     httpRes.OutputStream.Close();
 }
开发者ID:ischyrus,项目名称:ServiceStack,代码行数:5,代码来源:JsvSyncReplyHandler.cs

示例12: ProcessRequestAsync

        public override Task ProcessRequestAsync(IHttpRequest httpReq, IHttpResponse httpRes, string operationName)
        {
            try
            {
                var appHost = HostContext.AppHost;
                if (appHost.ApplyPreRequestFilters(httpReq, httpRes)) 
                    return EmptyTask;
                
                var restPath = GetRestPath(httpReq.HttpMethod, httpReq.PathInfo);
                if (restPath == null)
                {
                    return new NotSupportedException("No RestPath found for: " + httpReq.HttpMethod + " " + httpReq.PathInfo)
                        .AsTaskException();
                }

                operationName = restPath.RequestType.Name;

                var callback = httpReq.GetJsonpCallback();
                var doJsonp = HostContext.Config.AllowJsonpRequests
                              && !string.IsNullOrEmpty(callback);

                if (ResponseContentType != null)
                    httpReq.ResponseContentType = ResponseContentType;

                var responseContentType = httpReq.ResponseContentType;
                appHost.AssertContentType(responseContentType);

                var request = GetRequest(httpReq, restPath);
                if (appHost.ApplyRequestFilters(httpReq, httpRes, request)) 
                    return EmptyTask;

                var rawResponse = GetResponse(httpReq, httpRes, request);
                return HandleResponse(rawResponse, response => 
                {
                    if (appHost.ApplyResponseFilters(httpReq, httpRes, response)) 
                        return EmptyTask;

                    if (responseContentType.Contains("jsv") && !string.IsNullOrEmpty(httpReq.QueryString["debug"]))
                        return WriteDebugResponse(httpRes, response);

                    if (doJsonp && !(response is CompressedResult))
                        return httpRes.WriteToResponse(httpReq, response, (callback + "(").ToUtf8Bytes(), ")".ToUtf8Bytes());
                    
                    return httpRes.WriteToResponse(httpReq, response);
                },  
                ex => !HostContext.Config.WriteErrorsToResponse 
                    ? ex.AsTaskException() 
                    : HandleException(httpReq, httpRes, operationName, ex));
            }
            catch (Exception ex)
            {
                return !HostContext.Config.WriteErrorsToResponse 
                    ? ex.AsTaskException() 
                    : HandleException(httpReq, httpRes, operationName, ex);
            }
        }
开发者ID:rjdudley,项目名称:ServiceStack,代码行数:56,代码来源:RestHandler.cs

示例13: ProcessRequest

        public override void ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, string operationName)
        {
            try
            {
                var contentType = httpReq.GetQueryStringContentType() ?? this.HandlerContentType;
                var callback = httpReq.QueryString["callback"];
                var doJsonp = EndpointHost.Config.AllowJsonpRequests
                              && !string.IsNullOrEmpty(callback);

                var request = CreateRequest(httpReq, operationName);

                var response = GetResponse(httpReq, request);

                var serializer = GetStreamSerializer(contentType);

                if (doJsonp) httpRes.Write(callback + "(");

                httpRes.WriteToResponse(response, serializer, contentType);

                if (doJsonp) httpRes.Write(")");

            }
            catch (Exception ex)
            {
                var errorMessage = string.Format("Error occured while Processing Request: {0}", ex.Message);
                Log.Error(errorMessage, ex);

                httpRes.WriteErrorToResponse(HandlerContentType, operationName, errorMessage, ex);
            }
        }
开发者ID:firstsee,项目名称:ServiceStack,代码行数:30,代码来源:GenericHandler.cs

示例14: WriteDebugResponse

 public Task WriteDebugResponse(IHttpResponse httpRes, object response)
 {
     return httpRes.WriteToResponse(response, WriteDebugRequest,
         new SerializationContext(MimeTypes.PlainText));
 }
开发者ID:rjdudley,项目名称:ServiceStack,代码行数:5,代码来源:ServiceStackHandlerBase.cs

示例15: ProcessRequest

        public override void ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, string operationName)
        {
            var responseContentType = EndpointHost.Config.DefaultContentType;
            try
            {
                var restPath = GetRestPath(httpReq.HttpMethod, httpReq.PathInfo);
                if (restPath == null)
                    throw new NotSupportedException("No RestPath found for: " + httpReq.HttpMethod + " " + httpReq.PathInfo);

                operationName = restPath.RequestType.Name;

                var callback = httpReq.QueryString["callback"];
                var doJsonp = EndpointHost.Config.AllowJsonpRequests
                              && !string.IsNullOrEmpty(callback);

                responseContentType = httpReq.ResponseContentType;
                EndpointHost.Config.AssertContentType(responseContentType);

                var request = GetRequest(httpReq, restPath);
                if (EndpointHost.ApplyRequestFilters(httpReq, httpRes, request)) return;

                var response = GetResponse(httpReq, request);
                if (EndpointHost.ApplyResponseFilters(httpReq, httpRes, response)) return;

                if (responseContentType.Contains("jsv") && !string.IsNullOrEmpty(httpReq.QueryString["debug"]))
                {
                    JsvSyncReplyHandler.WriteDebugResponse(httpRes, response);
                    return;
                }

                if (doJsonp)
                    httpRes.WriteToResponse(httpReq, response, (callback + "(").ToUtf8Bytes(), ")".ToUtf8Bytes());
                else
                    httpRes.WriteToResponse(httpReq, response);
            }
            catch (Exception ex)
            {
                var errorMessage = string.Format("Error occured while Processing Request: {0}", ex.Message);
                Log.Error(errorMessage, ex);

                var attrEndpointType = ContentType.GetEndpointAttributes(responseContentType);
                httpRes.WriteErrorToResponse(attrEndpointType, operationName, errorMessage, ex);
            }
        }
开发者ID:nuxleus,项目名称:ServiceStack,代码行数:44,代码来源:RestHandler.cs


注:本文中的IHttpResponse.WriteToResponse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。