private void ProcessRequest(SoapMessage message, Boolean isclient) { if (Trace.CorrelationManager.ActivityId == Guid.Empty) { Guid newGuid = Guid.NewGuid(); Trace.CorrelationManager.ActivityId = newGuid; } MessageProcessor ctx = MessageProcessor.Instance; MessageCorrelator mc = new MessageCorrelator(); mc.MessageID = Guid.NewGuid().ToString(); if (isclient) { mc.threadid = MessageProcessor.GetTransactionThreadId(Thread.CurrentContext.ContextID.ToString() + Thread.CurrentThread.ManagedThreadId.ToString() + ":" + Thread.GetDomainID().ToString() + Thread.CurrentThread.Name); if (String.IsNullOrEmpty(mc.threadid)) { mc.threadid = Guid.NewGuid().ToString(); } if (MessageProcessor.GetConfig.DependencyInjectionEnabled) { message.Headers.Add(new FGSMSSoapHeaderRelatedMessageASPNET(mc.MessageID)); message.Headers.Add(new FGSMSSoapHeaderTransactionThreadIdASPNET(mc.threadid)); } } else //service processing a request { IEnumerator it = message.Headers.GetEnumerator(); while (it.MoveNext()) { SoapUnknownHeader e = it.Current as SoapUnknownHeader; if (e != null) { //if (e.Element.Name.Equals(FGSMSSoapHeaderTransactionThreadIdWCF.Name2) && e.Element.NamespaceURI.Equals(FGSMSSoapHeaderTransactionThreadIdWCF.Namespace2)) //{ // mc.threadid = e.Element.InnerText; //} if (e.Element.Name.Equals(FGSMSSoapHeaderRelatedMessageIdWCF.Name2) && e.Element.NamespaceURI.Equals(FGSMSSoapHeaderRelatedMessageIdWCF.Namespace2)) { mc.relatedtransactionid = e.Element.InnerText; } if (e.Element.Name.Equals(FGSMSSoapHeaderTransactionThreadIdWCF.Name2) && e.Element.NamespaceURI.Equals(FGSMSSoapHeaderTransactionThreadIdWCF.Namespace2)) { mc.threadid = e.Element.InnerText; } } } } if (String.IsNullOrEmpty(mc.threadid)) { mc.threadid = Guid.NewGuid().ToString(); } MessageProcessor.SetTransactionThreadId(Thread.CurrentContext.ContextID.ToString() + Thread.CurrentThread.ManagedThreadId.ToString() + ":" + Thread.GetDomainID().ToString() + Thread.CurrentThread.Name, mc.threadid); try { Uri url = new Uri("urn:undeterminable"); if (!isclient && System.Web.HttpContext.Current != null) { url = System.Web.HttpContext.Current.Request.Url; } else { url = new Uri(message.Url); } AgentMessageTable hashtable = AgentMessageTable.Instance; if (isclient) { localhashcode = message.GetHashCode(); } else if (HttpContext.Current != null) { localhashcode = HttpContext.Current.Request.GetHashCode(); } else { //uh oh, http context is null and this is a server side request, unexpected. } if (HttpContext.Current == null) { mc.RecievedAt = DateTime.Now; mc.RequestMessage = StreamtoString(message.Stream); mc.requestsize = mc.RequestMessage.Length; mc.originalUrl = mc.URL = url.ToString(); mc.RequestHeaders = new System.Collections.Specialized.NameValueCollection(); // mc.RequestHeaders.Add("Content-Type", message.ContentType); // mc.RequestHeaders.Add("Content-Encoding", message.ContentEncoding); mc.RequestHeaders.Add("SOAPAction", message.Action); mc.soapAction = message.Action; AgentMessageTable.AddRequest(mc, localhashcode); /* AgentMessageTable.AddRequest(localhashcode, * DateTime.Now, * StreamtoString(message.Stream), * //InputMessageToString(message), * url.ToString() * // message.ToString() * );*/ } else { mc.RecievedAt = DateTime.Now; mc.RequestMessage = StreamtoString(message.Stream); mc.requestsize = mc.RequestMessage.Length; mc.originalUrl = mc.URL = url.ToString(); mc.RequestHeaders = new System.Collections.Specialized.NameValueCollection(); mc.RequestHeaders = HttpContext.Current.Request.Headers; mc.userp = HttpContext.Current.User; try { mc.soapAction = message.Action; } catch { } if (String.IsNullOrEmpty(mc.soapAction)) { mc.soapAction = mc.RequestHeaders["SOAPAction"]; } if (HttpContext.Current.Request.ClientCertificate != null) { mc.ClientCertificate = new X509Certificate2(HttpContext.Current.Request.ClientCertificate.Certificate); } AgentMessageTable.AddRequest(mc, localhashcode); /* * AgentMessageTable.AddRequest(localhashcode, * DateTime.Now, * StreamtoString(message.Stream), * //OutputMessageToString(message), * url.ToString()); * // message.ToString()*/ } } catch (Exception ex) { Logger.error(ex, this.GetType().FullName + " error caught processing a request "); } // PurgeOldMessages(); }
private void Write(SoapMessage message) { double timePassed = 0; var n = DateTime.Now; if (oldTime != null) { timePassed = n.Subtract(oldTime).TotalSeconds; } oldTime = n; bool writeStream = message.Stage == SoapMessageStage.AfterSerialize | message.Stage == SoapMessageStage.BeforeDeserialize; bool isInput = message.Stage == SoapMessageStage.BeforeDeserialize | message.Stage == SoapMessageStage.AfterDeserialize; if (writeStream) { if (isInput) { Copy(oldStream, logStream); } else { logStream.Position = 0; Copy(logStream, oldStream); } logStream.Position = 0; } FileStream fs = GetFileStream(); StreamWriter w = new StreamWriter(fs); w.WriteLine("----------------------------------------------------------------"); w.WriteLine(string.Format("{0:yyyy-MM-ddTHH:mm:ss.ffffffzzz} ({1:0.000}) {2} {3}", DateTime.Now, timePassed, message.GetHashCode(), message.Stage)); if (message.Stage == SoapMessageStage.BeforeSerialize) { w.WriteLine(string.Format("Action: {0}", message.Url)); w.WriteLine(string.Format("URL: {0}", message.Action)); } if (writeStream) { w.WriteLine("----------------"); w.Flush(); Copy(logStream, fs); } w.Close(); if (isInput) { logStream.Position = 0; } }