/// <summary> /// Called after a service method is executed. /// </summary> /// <param name="serviceContext">The service context.</param> /// <param name="behaviorContext">The "method executed" behavior context.</param> public override void OnMethodExecuted(IServiceContext serviceContext, MethodExecutedContext behaviorContext) { if (serviceContext == null) { throw new ArgumentNullException("serviceContext"); } HttpContextBase httpContext = serviceContext.GetHttpContext(); if (httpContext == null) { throw new ArgumentException(Resources.Global.MissingHttpContext, "serviceContext"); } httpContext.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1)); httpContext.Response.Cache.SetValidUntilExpires(false); httpContext.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches); httpContext.Response.Cache.SetCacheability(HttpCacheability.NoCache); httpContext.Response.Cache.SetNoStore(); }
/// <summary> /// Called after a service method is executed. /// </summary> /// <param name="serviceContext">The service context.</param> /// <param name="behaviorContext">The "method executed" behavior context.</param> public override void OnMethodExecuted(IServiceContext serviceContext, MethodExecutedContext behaviorContext) { if (serviceContext == null) { throw new ArgumentNullException("serviceContext"); } if (serviceContext.Request.Method != HttpMethod.Get && serviceContext.Request.Method != HttpMethod.Head) { return; } HttpContext httpContext = HttpContext.Current; if (httpContext == null) { return; } using (var page = new OutputCachedPage(CacheSettings)) { page.ProcessRequest(httpContext); } }
/// <summary> /// Called after a service method is executed. /// </summary> /// <param name="serviceContext">The service context.</param> /// <param name="behaviorContext">The "method executed" behavior context.</param> public override void OnMethodExecuted(IServiceContext serviceContext, MethodExecutedContext behaviorContext) { timer.Stop(); serviceContext.Response.Output.WriteLine(2).WriteFormat("Response generated in {0} ms ({1} ticks)", timer.ElapsedMilliseconds, timer.ElapsedTicks); }
/// <summary> /// Called after a service method is executed. /// </summary> /// <param name="serviceContext">The service context.</param> /// <param name="behaviorContext">The "method executed" behavior context.</param> public override void OnMethodExecuted(IServiceContext serviceContext, MethodExecutedContext behaviorContext) { serviceContext.Response.Output.WriteLine(2).WriteFormat("Action '{0}' executed", behaviorContext.GetMethodName()); }
/// <summary> /// Called after a service method is executed. /// </summary> /// <param name="serviceContext">The service context.</param> /// <param name="behaviorContext">The "method executed" behavior context.</param> public virtual void OnMethodExecuted(IServiceContext serviceContext, MethodExecutedContext behaviorContext) { }
public void MethodExecutedContextShouldBePopulatedForSelfContainedService() { var service = new TestSelfContainedService(); MethodInfo method = service.GetType().GetMethod("GetOK"); Assert.That(method, Is.Not.Null); var returnedObject = String.Copy("OK"); var behaviorContext = new MethodExecutedContext(service, method, returnedObject); Assert.That(behaviorContext.Service, Is.SameAs(service)); Assert.That(behaviorContext.Method, Is.SameAs(method)); Assert.That(behaviorContext.ReturnedObject, Is.SameAs(returnedObject)); Assert.That(behaviorContext.GetServiceContractType(), Is.EqualTo(typeof(TestSelfContainedService))); Assert.That(behaviorContext.GetServiceType(), Is.EqualTo(typeof(TestSelfContainedService))); Assert.That(behaviorContext.GetMethodName(), Is.EqualTo(method.Name)); var httpMethods = behaviorContext.GetSupportedHttpMethods().ToList(); Assert.That(httpMethods.Contains(HttpMethod.Get), Is.True); Assert.That(httpMethods.Contains(HttpMethod.Head), Is.False); Assert.That(httpMethods.Contains(HttpMethod.Post), Is.False); Assert.That(httpMethods.Contains(HttpMethod.Put), Is.False); Assert.That(httpMethods.Contains(HttpMethod.Patch), Is.False); Assert.That(httpMethods.Contains(HttpMethod.Delete), Is.False); }