コード例 #1
0
ファイル: WSCFZipFilter.cs プロジェクト: tmzani/CrawlWave
        /// <summary>
        /// Processes the SOAP Messages and compresses them if necessary
        /// </summary>
        /// <param name="envelope">The <see cref="SoapEnvelope"/> to process.</param>
        public override void ProcessMessage(SoapEnvelope envelope)
        {
            if (!enabled)
            {
                return;
            }
            //add an attribute to specify that the filter has been applied on this envelope.
            XmlElement soapHeader = envelope.CreateHeader();

            if (envelope.Body.InnerText.Length < minFilterSize)
            {
                return;
            }
            else
            {
                soapHeader.AppendChild(CreateCustomHeader(soapHeader, "1"));
            }
            //compress the body element.
            MemoryStream result = new MemoryStream(WSCFCompression.Compress(Encoding.UTF8.GetBytes(envelope.Body.InnerXml)));

            //Attach zipped result to the envelope.
            Microsoft.Web.Services2.Attachments.Attachment attch = new Microsoft.Web.Services2.Attachments.Attachment("APPLICATION/OCTET-STREAM", result);
            envelope.Context.Attachments.Add(attch);

            //remove old body.
            XmlElement newBody = envelope.CreateBody();

            newBody.RemoveAll();
            envelope.SetBodyObject(newBody);
            GC.Collect();
        }
コード例 #2
0
ファイル: WSCFUnzipFilter.cs プロジェクト: tmzani/CrawlWave
        /// <summary>
        /// Processes the SOAP Messages and decompresses them if necessary
        /// </summary>
        /// <param name="envelope">The <see cref="SoapEnvelope"/> to process.</param>
        public override void ProcessMessage(SoapEnvelope envelope)
        {
            if (envelope.Header == null)
            {
                return;
            }
            //check if the ZipFilter has been applied.
            XmlNodeList elemList = envelope.Header.GetElementsByTagName(Constants.WSCFCompressionElement);

            if (elemList.Count == 0)
            {
                return;
            }
            //The header contains the element, let's check if the body is compressed
            if (elemList[0].Attributes[Constants.WSCFAttribute].Value.Equals("0"))
            {
                return;
            }
            //make sure we decompress using the same method we used for compression.
            WSCFCompression.CompressionProvider = (CompressionType)Convert.ToInt32((string)elemList[0].Attributes[Constants.WSCFTypeAttribute].Value);
            //remove the element from the envelope, it's no longer necessary.
            envelope.Header.RemoveChild(elemList[0]);
            //decompress the envelope attachments
            MemoryStream outStream = WSCFCompression.DeCompressToStream(envelope.Context.Attachments[0].Stream);
            //replace the body element.
            XmlElement body = envelope.CreateBody();

            body.InnerXml = System.Text.Encoding.UTF8.GetString(outStream.ToArray());
            GC.Collect();
        }