WCF Client Logging to database for specific fields

mentaljatt

New Member
WCF Logging, frustrated to no end.Sorry, I don't do enough WCF logging (or even playing with soap, more back end, UI or Jquery).I know a lot of you will push me towards trace logging, but that is not an option.The end result here is to log certain nodes in a soap message, as well as scrub some credit card numbers. This has been implemented rather simply on the VB version of our sites, and I thought I could do this so much better. I am still bound by the original requirements for this logging.One - it needs to go to the database. Not just the whole XML chunk, but certain other elements and attributes.Two - the cared number needs to be scrubbed for the database but not for the request, so I cannot alter anything. Three - For searching and due to the number of requests, trace logging will fill too quickly.There are multiple requests that are being made. Here is an initial one.\[code\]<?xml version="1.0"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> <s:Header> <Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none" /> </s:Header> <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <mywebcall xmlns="http://webservice.com/"> <cardNumber xmlns="">1111111111111111111</cardNumber> <answersFromUser xmlns=""> <propertyName>Maiden Name</propertyName> <questionId>541</questionId> <response>Smith</response> </answersFromUser> </authenticateMontroseCaller> </s:Body></s:Envelope>\[/code\]I have been trying to use IClientMessageInspector, but can't seem to get anywhere. If I touch it, I change it. I can't use the request body. I've tried XPath and Linq to SQL, and still can't extract the body and the call correctly so I can check it and log it. Maybe I took too many days off for Christmas, but I am out of ideas. I just want to know the caller so that I can use this to act on the inner XML and save it accordingly. I've just been away from XML so long I am just randomly trying stuff and about to slam my head off the keyboard.\[code\] //How do I get the document to load? Should give me the body XmlDocument document = new XmlDocument(request.ToString()); XmlNamespaceManager nsmgr = new XmlNamespaceManager(document.NameTable); nsmgr.AddNamespace("soap", "http://schemas.xmlsoap.org/soap/envelope/"); document.Load(document.DocumentElement.SelectSingleNode("soap:Body",nsmgr).ChildNodes[0].OuterXml); Was also trying something like this // var t = request.GetType(); // MessageBuffer buffer = request.CreateBufferedCopy(Int32.MaxValue); // Message msg = buffer.CreateMessage(); // StringBuilder sb = new StringBuilder(); // using (System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(sb)) // { // msg.WriteMessage(xw); // xw.Close(); // } //// var xml = request.GetBody<typeof(t)>;\[/code\]But the type is always the envelope, and if I touch the body I change the message\[code\] //Tried some bad xpath XPathDocument doc = new XPathDocument(copy); XPathNavigator nav = doc.CreateNavigator(); XPathNodeIterator node = nav.Select() //var docxml = from c in xml.Elements("Envelope").Elements("Body").Select(x=> x.DescendantNodes()).ToList();\[/code\]//Tried spmething like this ... don't know why I thought it would work string copy = request.ToString();\[code\] XDocument xml = XDocument.Parse(copy); var docxml = from c in xml.Elements("Envelope").Elements("Body").Select(x => x.DescendantNodes()).ToList();\[/code\]
 
Back
Top