本文整理汇总了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);
}
}
示例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);
}
示例3: WriteDebugResponse
public static void WriteDebugResponse(IHttpResponse httpRes, object response)
{
httpRes.WriteToResponse(response, WriteDebugRequest,
new SerializationContext(MimeTypes.PlainText));
httpRes.EndRequest();
}
示例4: WriteDebugResponse
public static void WriteDebugResponse(IHttpResponse httpRes, object response)
{
httpRes.WriteToResponse(response, WriteDebugRequest,
new SerializationContext(ContentType.PlainText));
//httpRes.Close();
}
示例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();
}
示例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);
}
}
示例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);
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例11: WriteDebugResponse
public static void WriteDebugResponse(IHttpResponse httpRes, object response)
{
httpRes.WriteToResponse(response, WriteDebugRequest, ContentType.PlainText);
httpRes.OutputStream.Close();
}
示例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);
}
}
示例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);
}
}
示例14: WriteDebugResponse
public Task WriteDebugResponse(IHttpResponse httpRes, object response)
{
return httpRes.WriteToResponse(response, WriteDebugRequest,
new SerializationContext(MimeTypes.PlainText));
}
示例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);
}
}