Example #1
0
        /// <summary>
        /// Gets the summary request logs.
        /// </summary>
        /// <param name="soapRequest">The request xml for this SOAP call.</param>
        /// <returns>The summary request logs.</returns>
        protected override string GetSummaryRequestLogs(string soapRequest)
        {
            XmlDocument         xDoc  = SerializationUtilities.LoadXml(soapRequest);
            XmlNamespaceManager xmlns = new XmlNamespaceManager(xDoc.NameTable);

            xmlns.AddNamespace("soap", "http://schemas.xmlsoap.org/soap/envelope/");
            XmlNode methodNode =
                xDoc.SelectSingleNode("soap:Envelope/soap:Body/*", xmlns);
            string operators = "None";

            if (methodNode.Name == "mutate")
            {
                StringBuilder builder = new StringBuilder();
                foreach (XmlNode child in methodNode.ChildNodes)
                {
                    if (child.Name == "operations")
                    {
                        foreach (XmlNode grandChild in child.ChildNodes)
                        {
                            if (grandChild.Name == "operator")
                            {
                                builder.Append(grandChild.InnerText + "|");
                            }
                        }
                    }
                }
                operators = builder.ToString().TrimEnd('|');
            }
            return(string.Format(CultureInfo.InvariantCulture, "method={0},operator={1}",
                                 methodNode.Name, operators));
        }
        /// <summary>
        /// Deserialize the object from xml.
        /// </summary>
        /// <param name="reader">The xml reader for reading the
        /// serialized xml.</param>
        public virtual void ReadXml(XmlReader reader)
        {
            XmlDocument doc = SerializationUtilities.LoadXml(reader.ReadOuterXml());

            XmlNameTable xmlnt = doc.NameTable;
            XmlElement   root  = doc.CreateElement(XmlElementName, XmlNamespace);

            XmlNodeList xmlNodes = doc.DocumentElement.SelectNodes("*");

            foreach (XmlNode node in xmlNodes)
            {
                root.AppendChild(node);
            }
            doc.RemoveAll();
            doc.AppendChild(root);

            string contents = doc.OuterXml;

            foreach (string key in placeHolders.Keys)
            {
                if (placeHolders[key] != null)
                {
                    contents = contents.Replace(placeHolders[key], key);
                }
            }
            Stub = SerializationUtilities.DeserializeFromXmlText(contents, Stub.GetType());
        }
        /// <summary>
        /// Performs the SOAP and HTTP logging.
        /// </summary>
        /// <param name="service">The SOAP service.</param>
        /// <param name="soapResponse">The SOAP response xml.</param>
        /// <param name="soapRequest">The SOAP request xml.</param>
        private void PerformLogging(AdsClient service, string soapRequest, string soapResponse)
        {
            if (service == null || service.User == null || soapRequest == null || soapResponse == null)
            {
                return;
            }

            if (config.MaskCredentials)
            {
                XmlDocument xDoc = SerializationUtilities.LoadXml(soapRequest);
                MaskCredentialsInLogs(xDoc, GetFieldsToMask());
                soapRequest = xDoc.OuterXml;
            }

            string formattedSoapRequest  = FormatSoapRequest(service.LastRequest, soapRequest);
            string formattedSoapResponse = FormatSoapResponse(service.LastResponse, soapResponse);
            string formattedHttpRequest  = FormatHttpRequest(soapRequest);
            string formattedHttpResponse = FormatHttpResponse(soapResponse);

            string soapLog    = formattedSoapRequest + formattedSoapResponse;
            string requestLog = string.Format(CultureInfo.InvariantCulture, "host={0},url={1},{2},{3}",
                                              service.LastRequest.RequestUri.Host, service.LastRequest.RequestUri.AbsolutePath,
                                              formattedHttpRequest, formattedHttpResponse);

            ContextStore.AddKey("FormattedSoapLog", soapLog);
            ContextStore.AddKey("FormattedRequestLog", requestLog);

            bool isError = service.LastResponse != null && service.LastResponse is HttpWebResponse &&
                           (service.LastResponse as HttpWebResponse).StatusCode ==
                           HttpStatusCode.InternalServerError;

            TraceUtilities.WriteSoapXmlLogs(soapLog, isError);
            TraceUtilities.WriteRequestInfoLogs(requestLog, isError);
        }
 /// <summary>
 /// Appends the HTTP headers to SOAP xml.
 /// </summary>
 /// <param name="soapRequest">The SOAP request.</param>
 /// <param name="headers">The HTTP headers.</param>
 /// <returns>The modified SOAP xml for appending to the logs.</returns>
 protected string AppendHeadersToSoapXml(string soapRequest, string headers)
 {
     try {
         XmlDocument xDoc    = SerializationUtilities.LoadXml(soapRequest);
         XmlComment  comment = xDoc.CreateComment(headers);
         xDoc.DocumentElement.InsertBefore(comment, xDoc.DocumentElement.FirstChild);
         return(xDoc.OuterXml);
     } catch {
         return(string.Format("{0}\r\n{1}\r\n", headers, soapRequest));
     }
 }
        /// <summary>
        /// Calls the listeners.
        /// </summary>
        /// <param name="direction">The direction of SOAP message.</param>
        private void CallListeners(SoapMessageDirection direction)
        {
            XmlDocument document = SerializationUtilities.LoadXml(Encoding.UTF8.GetString(
                                                                      newStream.ToArray()));

            AdsClient service = (AdsClient)ContextStore.GetValue("SoapService");

            if (service != null)
            {
                service.User.CallListeners(document, service, direction);
            }
            byte[] bytes = Encoding.UTF8.GetBytes(document.OuterXml);
            newStream.SetLength(0);
            newStream.Write(bytes, 0, bytes.Length);
            newStream.Seek(0, SeekOrigin.Begin);
        }
        /// <summary>
        /// Serialize the object into an xml.
        /// </summary>
        /// <param name="writer">The writer to which the serialized data
        /// should be written.</param>
        public virtual void WriteXml(XmlWriter writer)
        {
            string contents = SerializationUtilities.SerializeAsXmlText(Stub);

            foreach (string key in placeHolders.Keys)
            {
                if (placeHolders[key] != null)
                {
                    contents = contents.Replace(key, placeHolders[key]);
                }
            }

            XmlDocument xDoc = SerializationUtilities.LoadXml(contents);

            writer.WriteRaw(xDoc.DocumentElement.InnerXml);
        }
Example #7
0
        /// <summary>
        /// Masks the contents of the traced message.
        /// </summary>
        /// <param name="body">The message body.</param>
        /// <param name="keysToMask">The keys for which values should be masked
        /// in the message body.</param>
        /// <returns>
        /// The formatted message body.
        /// </returns>
        public override string MaskContents(string body, ISet <string> keysToMask)
        {
            XmlDocument         xDoc  = SerializationUtilities.LoadXml(body);
            XmlNamespaceManager xmlns = new XmlNamespaceManager(xDoc.NameTable);

            xmlns.AddNamespace("soap", "http://schemas.xmlsoap.org/soap/envelope/");
            XmlNodeList nodes =
                xDoc.SelectNodes("soap:Envelope/soap:Header/descendant::*", xmlns);

            foreach (XmlElement node in nodes)
            {
                if (keysToMask.Contains(node.LocalName))
                {
                    node.InnerText = MASK_PATTERN;
                }
            }
            return(xDoc.OuterXml);
        }
Example #8
0
        /// <summary>
        /// Gets the summary response logs.
        /// </summary>
        /// <param name="soapResponse">The response xml for this SOAP call.</param>
        /// <returns>The summary response logs.</returns>
        protected override string GetSummaryResponseLogs(string soapResponse)
        {
            XmlDocument         xDoc  = SerializationUtilities.LoadXml(soapResponse);
            XmlNamespaceManager xmlns = new XmlNamespaceManager(xDoc.NameTable);

            xmlns.AddNamespace("soap", "http://schemas.xmlsoap.org/soap/envelope/");
            XmlNodeList childNodes =
                xDoc.SelectNodes("soap:Envelope/soap:Header/*", xmlns);

            if (childNodes.Count == 1 && childNodes[0].Name == "ResponseHeader")
            {
                childNodes = childNodes[0].ChildNodes;
            }
            StringBuilder responseText = new StringBuilder();

            foreach (XmlNode childNode in childNodes)
            {
                if (childNode is XmlElement)
                {
                    responseText.AppendFormat("{0}={1},", childNode.Name, childNode.InnerText);
                }
            }
            return(responseText.ToString().TrimEnd(','));
        }