public object AfterReceiveRequest(ref System.ServiceModel.Channels.Message request, IClientChannel channel, InstanceContext instanceContext) { Uri originalURI = null; if (request.Properties.ContainsKey("OriginalHttpRequestUri")) { originalURI = request.Properties["OriginalHttpRequestUri"] as Uri; } else { //When running in WCF ServiceHost mode , the OriginalHttpRequestUri is inaccissible as the host does not support it originalURI = request.Properties.Via; } #region Log only interesting operations string lastSegment = originalURI.Segments.Last(); if (ignorePoints.Any(fo => lastSegment.Contains(fo))) { return(null); } #endregion HttpRequestMessageProperty httpmsg = (HttpRequestMessageProperty)request.Properties[HttpRequestMessageProperty.Name]; if (httpmsg != null && httpmsg.Headers != null && httpmsg.Headers.AllKeys.Contains(LogIndexHeader)) { PTEntities ctx = new PTEntities(); int LogIndex; if (!Int32.TryParse(httpmsg.Headers[LogIndexHeader], out LogIndex)) { return(null); } TestOperation t = ctx.TestOperations.FirstOrDefault(to => (to.Id == LogIndex)); if (t == null) { return(null); } LogEntry le = new LogEntry { TestOperation = t, URI = originalURI.ToString(), Verb = httpmsg.Method }; ctx.AddObject("LogEntries", le); // skip loging of the logIndex header foreach (var key in httpmsg.Headers.AllKeys.Where(k => !k.Equals(LogIndexHeader, StringComparison.OrdinalIgnoreCase))) { ctx.AddObject("LogEntryHeaders", new LogEntryHeader { LogEntry = le, Header = key, Value = httpmsg.Headers[key] }); } ctx.SaveChanges(); return(new MyCorrelation { Uri = originalURI, LogIndex = httpmsg.Headers[LogIndexHeader] }); } return(null); }
public void BeforeSendReply(ref System.ServiceModel.Channels.Message reply, object correlationState) { if (correlationState != null && correlationState is MyCorrelation) { MyCorrelation myCor = correlationState as MyCorrelation; HttpResponseMessageProperty httpmsg = (HttpResponseMessageProperty)reply.Properties[HttpResponseMessageProperty.Name]; if (httpmsg != null && httpmsg.Headers != null) { PTEntities ctx = new PTEntities(); int LogIndex; if (!Int32.TryParse(myCor.LogIndex, out LogIndex)) { return; } TestOperation t = ctx.TestOperations.FirstOrDefault(to => (to.Id == LogIndex)); if (t == null) { return; } LogEntry le = new LogEntry { TestOperation = t, URI = myCor.Uri.ToString(), Verb = "RESPONSE" }; ctx.AddObject("LogEntries", le); // skip loging of the logIndex header foreach (var key in httpmsg.Headers.AllKeys.Where(k => !k.Equals(LogIndexHeader, StringComparison.OrdinalIgnoreCase))) { ctx.AddObject("LogEntryHeaders", new LogEntryHeader { LogEntry = le, Header = key, Value = httpmsg.Headers[key] }); } ctx.SaveChanges(); } } }
public void BeforeSendReply(ref System.ServiceModel.Channels.Message reply, object correlationState) { if (correlationState != null && correlationState is MyCorrelation) { MyCorrelation myCor = correlationState as MyCorrelation; HttpResponseMessageProperty httpmsg = (HttpResponseMessageProperty)reply.Properties[HttpResponseMessageProperty.Name]; if (httpmsg != null && httpmsg.Headers != null) { PTEntities ctx = new PTEntities(); int LogIndex; if (!Int32.TryParse(myCor.LogIndex, out LogIndex)) return; TestOperation t = ctx.TestOperations.FirstOrDefault(to => (to.Id == LogIndex)); if (t == null) return; LogEntry le = new LogEntry { TestOperation = t, URI = myCor.Uri.ToString(), Verb = "RESPONSE" }; ctx.AddObject("LogEntries", le); // skip loging of the logIndex header foreach (var key in httpmsg.Headers.AllKeys.Where(k => !k.Equals(LogIndexHeader, StringComparison.OrdinalIgnoreCase))) { ctx.AddObject("LogEntryHeaders", new LogEntryHeader { LogEntry = le, Header = key, Value = httpmsg.Headers[key] }); } ctx.SaveChanges(); } } }
public object AfterReceiveRequest(ref System.ServiceModel.Channels.Message request, IClientChannel channel, InstanceContext instanceContext) { Uri originalURI = null; if (request.Properties.ContainsKey("OriginalHttpRequestUri")) { originalURI = request.Properties["OriginalHttpRequestUri"] as Uri; } else { //When running in WCF ServiceHost mode , the OriginalHttpRequestUri is inaccissible as the host does not support it originalURI = request.Properties.Via; } #region Log only interesting operations string lastSegment = originalURI.Segments.Last(); if (ignorePoints.Any(fo => lastSegment.Contains(fo))) return null; #endregion HttpRequestMessageProperty httpmsg = (HttpRequestMessageProperty)request.Properties[HttpRequestMessageProperty.Name]; if (httpmsg != null && httpmsg.Headers != null && httpmsg.Headers.AllKeys.Contains(LogIndexHeader)) { PTEntities ctx = new PTEntities(); int LogIndex; if (!Int32.TryParse(httpmsg.Headers[LogIndexHeader], out LogIndex)) return null; TestOperation t = ctx.TestOperations.FirstOrDefault(to => (to.Id == LogIndex)); if (t == null) return null; LogEntry le = new LogEntry { TestOperation = t, URI = originalURI.ToString(), Verb = httpmsg.Method }; ctx.AddObject("LogEntries", le); // skip loging of the logIndex header foreach (var key in httpmsg.Headers.AllKeys.Where(k => !k.Equals(LogIndexHeader, StringComparison.OrdinalIgnoreCase))) { ctx.AddObject("LogEntryHeaders", new LogEntryHeader { LogEntry = le, Header = key, Value = httpmsg.Headers[key] }); } ctx.SaveChanges(); return new MyCorrelation { Uri = originalURI, LogIndex = httpmsg.Headers[LogIndexHeader] }; } return null; }