public void AfterSerialize(SoapMessage message)         //StreamOut
        {
            newStream.Position = 0;
            //Hack MemoryStream below because of XmlDocument bug closing stream
            byte []      tempBa    = new byte[newStream.Length];
            int          bytesRead = newStream.Read(tempBa, 0, (int)newStream.Length);
            MemoryStream ms        = new MemoryStream(tempBa);
            //BUG NOTE this closes the underlying stream on .NETcf
            XmlDocument xd = new XmlDocument();

            xd.Load(ms);             //MemoryStream will be closed now

            //outgoing
            //timestamp and routing
            HeadersHandler.AddHeaders(xd, message.Action, message.Url);
            XmlEncHandler.EncryptXml(xd);
            //Signature (or before enc.)?
            //Trace

            newStream.Position = 0;
            XmlTextWriter xtw = new XmlTextWriter(newStream, System.Text.Encoding.UTF8);

            xtw.Namespaces = true;
            xd.WriteTo(xtw);
            xtw.Flush();
            //xtw.Close();

            //these 2 lines have be called at a minimum
            newStream.Position = 0;
            Copy(newStream, oldStream);             //for next guy
            return;
        }
Example #2
0
        public void AfterSerialize(SoapMessage message)         //StreamOut
        {
            newStream.Position = 0;
            //Hack MemoryStream below because of XmlDocument bug closing stream
            byte []      tempBa    = new byte[newStream.Length];
            int          bytesRead = newStream.Read(tempBa, 0, (int)newStream.Length);
            MemoryStream ms        = new MemoryStream(tempBa);
            //BUG NOTE this closes the underlying stream on .NETcf
            XmlDocument xd = new XmlDocument();

            xd.Load(ms);             //MemoryStream will be closed now

            //OUTGOING

            //timestamp and routing
            SecConvHandler.TokenIssuerOut(xd);     //have to do body before signing
            HeadersHandler.AddHeaders(xd, message.Action, message.Url);
            XmlSigHandler.SignXml(xd);             //1st ... sign what you see
            XmlEncHandler.EncryptXml(xd);
            //SecConvHandler.ConversationOut(xd);
            //Trace

            //custom filters
            //should these happen before or after - BOTH!
            //should handle priorities of filters
            foreach (object oSof in OutputFilters)
            {
                SoapOutputFilter sof = (SoapOutputFilter)oSof;
                SoapEnvelope     se  = new SoapEnvelope();
                se.LoadXml(xd.OuterXml);
                se.Context = RequestSoapContext;
                sof.ProcessMessage(se);
                xd.LoadXml(se.OuterXml);                 //not performant
            }
            RequestSoapContext.Clear();
            OutputFilters.Clear();

            newStream.Position = 0;
            XmlTextWriter xtw = new XmlTextWriter(newStream, System.Text.Encoding.UTF8);

            xtw.Namespaces = true;
            xd.WriteTo(xtw);
            xtw.Flush();
            //xtw.Close();

            //these 2 lines have be called at a minimum
            newStream.Position = 0;
            Copy(newStream, oldStream);             //for next guy
            return;
        }