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; }
/* * 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; }