Пример #1
0
        public void AfterSerialize(SoapMessage message)         //StreamOut
        {
            //HACK because .NETcf does not add Headers in BeforeSerialize above
            if (System.Environment.OSVersion.Platform == PlatformID.WinCE)
            {
                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

                HeadersHandler.AddHeaders(xd, message.Action, message.Url);

                newStream.Position = 0;
                XmlTextWriter xtw = new XmlTextWriter(newStream, System.Text.Encoding.UTF8);
                xtw.Namespaces = true;
                xd.WriteTo(xtw);
                xtw.Flush();
                //xtw.Close();
            }             //END WinCE HACK

            //these 2 lines have be called at a minimum
            newStream.Position = 0;
            Copy(newStream, oldStream);             //for next guy
            return;
        }
Пример #2
0
        public void BeforeDeserialize(SoapMessage message)         //StreamIn
        {
            Copy(oldStream, newStream);
            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

            HeadersHandler.CheckHeaders(xd);

            //newStream is too big now
            newStream.SetLength(0);             //doing a new MemoryStream here was bad
            XmlTextWriter xtw = new XmlTextWriter(newStream, System.Text.Encoding.UTF8);

            xtw.Namespaces = true;
            xd.WriteTo(xtw);
            xtw.Flush();
            //xtw.Close();
            newStream.Position = 0;
            return;
        }
Пример #3
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
            HeadersHandler.AddHeaders(xd, message.Action, message.Url);
            //XmlEncHandler.EncryptXml(xd);
            XmlSigHandler.SignXml(xd);             //or before XmlEnc.
            //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;
        }
Пример #4
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;
        }
Пример #5
0
        /*
         * ChainStream
         * BeforeSerial
         * AfterSerial
         * ChainStream
         * BeforeDeserial
         * AfterDeserial
         */

        public void BeforeDeserialize(SoapMessage message)         //StreamIn
        {
            Copy(oldStream, newStream);
            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

            //INCOMING

            int        xmlSigCnt   = 0;
            XmlElement xmlSigElem  = LameXpath.SelectSingleNode(xd, Elem.Signature, null, ref xmlSigCnt);
            int        xmlEncCnt   = 0;
            XmlElement xmlEncElem  = LameXpath.SelectSingleNode(xd, Elem.EncryptedKey, null, ref xmlEncCnt);
            int        xmlEncCnt2  = 0;
            XmlElement xmlEncElem2 = LameXpath.SelectSingleNode(xd, Elem.ReferenceList, null, ref xmlEncCnt2);

            //TODO make sure not 0
            xmlEncCnt = Math.Min(xmlEncCnt, xmlEncCnt2);

            if (xmlSigElem != null && (xmlEncElem != null || xmlEncElem2 != null))
            {
                if (xmlSigCnt <= xmlEncCnt)
                {
                    //Signature then Encryption means encrypt 1st (Release)
                    XmlSigHandler.VerifySig(xd);
                    xd = XmlEncHandler.DecryptXml(xd);
                }
                else
                {
                    //Encryption then Signature means sign 1st (TechPreview) sign what you see
                    xd = XmlEncHandler.DecryptXml(xd);
                    XmlSigHandler.VerifySig(xd);
                }
                HeadersHandler.CheckHeaders(xd);
            }
            else             //default to 2.0 Release
            {
                //Trace
                XmlSigHandler.VerifySig(xd);                 //used to be after for TP
                xd = XmlEncHandler.DecryptXml(xd);
                HeadersHandler.CheckHeaders(xd);
                //timestamp and routing
            }

            //custom filters
            foreach (object oSif in InputFilters)
            {
                SoapInputFilter sif = (SoapInputFilter)oSif;
                SoapEnvelope    se  = new SoapEnvelope();
                se.LoadXml(xd.OuterXml);
                se.Context = ResponseSoapContext;
                sif.ProcessMessage(se);
                xd.LoadXml(se.OuterXml);                 //not performant
            }
            ResponseSoapContext.Clear();
            InputFilters.Clear();

            //newStream is too big now
            newStream.SetLength(0);             //doing a new MemoryStream here was bad
            XmlTextWriter xtw = new XmlTextWriter(newStream, System.Text.Encoding.UTF8);

            xtw.Namespaces = true;
            xd.WriteTo(xtw);
            xtw.Flush();
            //xtw.Close();
            newStream.Position = 0;
            return;
        }