public void AttributeWithSessionQNameIndex()
        {
            XmlDictionaryString    ds;
            XmlDictionary          dic = new XmlDictionary();
            XmlBinaryReaderSession ses = new XmlBinaryReaderSession();

            ses.Add(0, "SessionLookupValue");

            // <d a="QNameIndex(0x18,1)"></d>
            byte [] bytes = new byte [] { 0x40, 0x01, 0x64, 0x04, 0x01, 0x61, 0xbc, 0x18, 0x01, 0x01 };

            XmlDictionaryReader reader = XmlDictionaryReader.CreateBinaryReader(
                new MemoryStream(bytes), dic, new XmlDictionaryReaderQuotas(), ses);

            Assert.IsTrue(reader.Read(), "#1");
            AssertNode(XmlNodeType.Element, "d", "", "", 0, reader, "#2");
            reader.MoveToAttribute(0);
            if (reader.LocalName != "a")
            {
                reader.MoveToAttribute(1);
            }
            AssertNode(XmlNodeType.Attribute, "a", "", "y:SessionLookupValue", 1, reader, "#3");
            Assert.IsTrue(reader.ReadAttributeValue(), "#4");
            AssertNode(XmlNodeType.Text, "a", "", "y:SessionLookupValue", 2, reader, "#5");
            reader.MoveToContent();
            Assert.IsFalse(reader.ReadAttributeValue(), "#6");
        }
Exemplo n.º 2
0
        public string GetValue(IXmlDictionary staticDictionary, XmlBinaryReaderSession readerSession)
        {
            int id = this.DictionaryId / 2;
            XmlDictionaryString dicString = XmlDictionaryString.Empty;
            bool found;

            if (this.IsSession)
            {
                if (readerSession == null)
                {
                    return(null);
                }

                found = readerSession.TryLookup(id, out dicString);
            }
            else
            {
                if (staticDictionary == null)
                {
                    return(null);
                }

                found = staticDictionary.TryLookup(id, out dicString);
            }

            if (found)
            {
                return(dicString.Value);
            }
            else
            {
                throw new ArgumentException("Cannot find value for dictionary string with ID = " + this.DictionaryId);
            }
        }
Exemplo n.º 3
0
 static void Test()
 {
     MemoryStream           serializedStream = new MemoryStream();
     XmlBinaryReaderSession readerSession    = MyReaderSession.CreateReaderSession(serializedStream);
     XmlDictionaryReader    xdr    = XmlDictionaryReader.CreateBinaryReader(serializedStream, null, XmlDictionaryReaderQuotas.Max, readerSession);
     DataContractSerializer dcs    = new DataContractSerializer(typeof(List <Character>));
     List <Character>       result = (List <Character>)dcs.ReadObject(xdr);
 }
Exemplo n.º 4
0
        public Message ReadSizedMessage()
        {
            // FIXME: implement full [MC-NMF].

            var packetType = s.ReadByte();

            if (packetType == EndRecord)
            {
                return(null);
            }
            if (packetType != SizedEnvelopeRecord)
            {
                throw new NotImplementedException(String.Format("Packet type {0:X} is not implemented", packetType));
            }

            byte [] buffer = ReadSizedChunk();

            var ms = new MemoryStream(buffer, 0, buffer.Length);

            // FIXME: turned out that it could be either in-band dictionary ([MC-NBFSE]), or a mere xml body ([MC-NBFS]).
            if (EncodingRecord != EncodingBinaryWithDictionary)
            {
                throw new NotImplementedException(String.Format("Message encoding {0:X} is not implemented yet", EncodingRecord));
            }

            // Encoding type 8:
            // the returned buffer consists of a serialized reader
            // session and the binary xml body.

            var session = reader_session ?? new XmlBinaryReaderSession();

            reader_session = session;
            byte [] rsbuf = new TcpBinaryFrameManager(0, ms, is_service_side).ReadSizedChunk();
            using (var rms = new MemoryStream(rsbuf, 0, rsbuf.Length)) {
                var rbr = new BinaryReader(rms, Encoding.UTF8);
                while (rms.Position < rms.Length)
                {
                    session.Add(reader_session_items++, rbr.ReadString());
                }
            }
            var benc = Encoder as BinaryMessageEncoder;

            if (benc != null)
            {
                benc.CurrentReaderSession = session;
            }

            // FIXME: supply maxSizeOfHeaders.
            Message msg = Encoder.ReadMessage(ms, 0x10000);

            if (benc != null)
            {
                benc.CurrentReaderSession = null;
            }

            return(msg);
        }
            public override Message ReadMessage(ArraySegment <byte> buffer, BufferManager bufferManager, string contentType)
            {
                Message message;

                if (bufferManager == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("bufferManager");
                }
                if (((contentType != null) && (contentType != this.ContentType)) && !contentType.StartsWith(this.ContentType, StringComparison.OrdinalIgnoreCase))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ProtocolException(System.ServiceModel.SR.GetString("EncoderUnrecognizedContentType", new object[] { contentType, this.ContentType })));
                }
                if (this.isSession)
                {
                    if (this.readerSession == null)
                    {
                        this.readerSession   = new XmlBinaryReaderSession();
                        this.messagePatterns = new MessagePatterns(this.factory.binaryVersion.Dictionary, this.readerSession, this.MessageVersion);
                    }
                    try
                    {
                        buffer = this.ExtractSessionInformationFromMessage(buffer);
                    }
                    catch (InvalidDataException)
                    {
                        MessageLogger.LogMessage(buffer, MessageLoggingSource.Malformed);
                        throw;
                    }
                }
                BinaryMessageEncoderFactory.BinaryBufferedMessageData messageData = this.factory.TakeBufferedData(this);
                if (this.messagePatterns != null)
                {
                    message = this.messagePatterns.TryCreateMessage(buffer.Array, buffer.Offset, buffer.Count, bufferManager, messageData);
                }
                else
                {
                    message = null;
                }
                if (message == null)
                {
                    messageData.Open(buffer, bufferManager);
                    RecycledMessageState recycledMessageState = messageData.TakeMessageState();
                    if (recycledMessageState == null)
                    {
                        recycledMessageState = new RecycledMessageState();
                    }
                    message = new BufferedMessage(messageData, recycledMessageState);
                }
                message.Properties.Encoder = this;
                if (MessageLogger.LogMessagesAtTransportLevel)
                {
                    MessageLogger.LogMessage(ref message, MessageLoggingSource.TransportReceive);
                }
                return(message);
            }
Exemplo n.º 6
0
 private void loadDynamicDictionaryToolStripMenuItem_Click(object sender, EventArgs e)
 {
     string[] allLines = this.ReadAllLinesFromDialog();
     if (allLines != null)
     {
         this.readerSession = new XmlBinaryReaderSession();
         for (int i = 0; i < allLines.Length; i++)
         {
             this.readerSession.Add(i, allLines[i]);
         }
     }
 }
        public void Beyond128DictionaryEntries()
        {
            XmlDictionaryString ds;
            MemoryStream        ms  = new MemoryStream();
            XmlDictionary       dic = new XmlDictionary();

            for (int i = 0; i < 260; i++)
            {
                Assert.AreEqual(i, dic.Add("n" + i).Key, "dic");
            }
            XmlDictionary          dic2    = new XmlDictionary();
            XmlBinaryReaderSession session = new XmlBinaryReaderSession();
            int idx;

            for (int i = 0; i < 260; i++)
            {
                Assert.AreEqual(i, session.Add(i, "s" + i).Key, "session");
            }

            byte [] bytes = new byte []
            {
                // so, when it went beyond 128, the index
                // becomes 2 bytes, where
                // - the first byte always becomes > 80, and
                // - the second byte becomes (n / 0x80) * 2.
                0x42, 0x80, 2, 0x0A, 0x82, 2,
                0x42, 0x85, 2, 0x0A, 0x87, 2,
                0x42, 0x88, 2, 0x0A, 0x8B, 2,
                0x42, 0x80, 4, 0x0A, 0x81, 4,
                1, 1, 1, 1
            };

            XmlDictionaryReader reader = XmlDictionaryReader.CreateBinaryReader(new MemoryStream(bytes), dic, new XmlDictionaryReaderQuotas(), session);

            Assert.IsTrue(reader.Read(), "#r1");
            Assert.AreEqual("n128", reader.LocalName, "#l1");
            Assert.IsTrue(reader.Read(), "#r2");
            Assert.AreEqual("s130", reader.LocalName, "#l1");
            Assert.IsTrue(reader.Read(), "#r3");
            Assert.AreEqual("n132", reader.LocalName, "#l1");
            Assert.IsTrue(reader.Read(), "#r4");
            Assert.AreEqual("n256", reader.LocalName, "#l1");
            for (int i = 0; i < 4; i++)
            {
                Assert.IsTrue(reader.Read(), "#re" + i);
                Assert.AreEqual(XmlNodeType.EndElement, reader.NodeType, "#ne" + i);
            }
            Assert.IsFalse(reader.Read()); // EOF
        }
Exemplo n.º 8
0
        public static XmlBinaryReaderSession CreateReaderSession(Stream stream)
        {
            XmlBinaryReaderSession result = new XmlBinaryReaderSession();
            int nextId = 0;
            int bytesRead;
            int sessionSize = ReadMB31(stream, out bytesRead);

            while (sessionSize > 0)
            {
                int stringSize = ReadMB31(stream, out bytesRead);
                sessionSize -= bytesRead + stringSize;
                byte[] stringBytes = new byte[stringSize];
                stream.Read(stringBytes, 0, stringBytes.Length);
                string dicString = Encoding.UTF8.GetString(stringBytes);
                result.Add(nextId++, dicString);
            }

            return(result);
        }
 public static XmlDictionaryReader CreateBinaryReader(Stream stream, IXmlDictionary dictionary, XmlDictionaryReaderQuotas quotas, XmlBinaryReaderSession session);
 public static XmlDictionaryReader CreateBinaryReader(byte[] buffer, int offset, int count, IXmlDictionary dictionary, XmlDictionaryReaderQuotas quotas, XmlBinaryReaderSession session);
Exemplo n.º 11
0
 private void unloadDynamicDictionaryToolStripMenuItem_Click(object sender, EventArgs e)
 {
     this.readerSession = null;
 }
 public static XmlDictionaryReader CreateBinaryReader(Stream stream, IXmlDictionary dictionary, XmlDictionaryReaderQuotas quotas, XmlBinaryReaderSession session);
Exemplo n.º 13
0
        public string ToString(IXmlDictionary staticDictionary, XmlBinaryReaderSession readerSession, bool printChildren)
        {
            StringBuilder sb          = new StringBuilder();
            int           actualDepth = depth;

            if (nodeType == XmlBinaryNodeType.EndElement)
            {
                actualDepth--;
            }
            string identString = "  ";

            if (printChildren)
            {
                for (int i = 0; i < actualDepth; i++)
                {
                    sb.Append(identString);
                }
            }

            sb.Append(XmlBinaryNodeType.GetNodeName(nodeType));
            switch (nodeType)
            {
            case XmlBinaryNodeType.EndElement:
                sb.Append(".");
                break;

            case XmlBinaryNodeType.ShortElement:
            case XmlBinaryNodeType.ShortDictionaryElement:
            case XmlBinaryNodeType.Element:
            case XmlBinaryNodeType.DictionaryElement:
            case XmlBinaryNodeType.PrefixElementA:
            case XmlBinaryNodeType.PrefixElementB:
            case XmlBinaryNodeType.PrefixElementC:
            case XmlBinaryNodeType.PrefixElementD:
            case XmlBinaryNodeType.PrefixElementE:
            case XmlBinaryNodeType.PrefixElementF:
            case XmlBinaryNodeType.PrefixElementG:
            case XmlBinaryNodeType.PrefixElementH:
            case XmlBinaryNodeType.PrefixElementI:
            case XmlBinaryNodeType.PrefixElementJ:
            case XmlBinaryNodeType.PrefixElementK:
            case XmlBinaryNodeType.PrefixElementL:
            case XmlBinaryNodeType.PrefixElementM:
            case XmlBinaryNodeType.PrefixElementN:
            case XmlBinaryNodeType.PrefixElementO:
            case XmlBinaryNodeType.PrefixElementP:
            case XmlBinaryNodeType.PrefixElementQ:
            case XmlBinaryNodeType.PrefixElementR:
            case XmlBinaryNodeType.PrefixElementS:
            case XmlBinaryNodeType.PrefixElementT:
            case XmlBinaryNodeType.PrefixElementU:
            case XmlBinaryNodeType.PrefixElementV:
            case XmlBinaryNodeType.PrefixElementW:
            case XmlBinaryNodeType.PrefixElementX:
            case XmlBinaryNodeType.PrefixElementY:
            case XmlBinaryNodeType.PrefixElementZ:
            case XmlBinaryNodeType.PrefixDictionaryElementA:
            case XmlBinaryNodeType.PrefixDictionaryElementB:
            case XmlBinaryNodeType.PrefixDictionaryElementC:
            case XmlBinaryNodeType.PrefixDictionaryElementD:
            case XmlBinaryNodeType.PrefixDictionaryElementE:
            case XmlBinaryNodeType.PrefixDictionaryElementF:
            case XmlBinaryNodeType.PrefixDictionaryElementG:
            case XmlBinaryNodeType.PrefixDictionaryElementH:
            case XmlBinaryNodeType.PrefixDictionaryElementI:
            case XmlBinaryNodeType.PrefixDictionaryElementJ:
            case XmlBinaryNodeType.PrefixDictionaryElementK:
            case XmlBinaryNodeType.PrefixDictionaryElementL:
            case XmlBinaryNodeType.PrefixDictionaryElementM:
            case XmlBinaryNodeType.PrefixDictionaryElementN:
            case XmlBinaryNodeType.PrefixDictionaryElementO:
            case XmlBinaryNodeType.PrefixDictionaryElementP:
            case XmlBinaryNodeType.PrefixDictionaryElementQ:
            case XmlBinaryNodeType.PrefixDictionaryElementR:
            case XmlBinaryNodeType.PrefixDictionaryElementS:
            case XmlBinaryNodeType.PrefixDictionaryElementT:
            case XmlBinaryNodeType.PrefixDictionaryElementU:
            case XmlBinaryNodeType.PrefixDictionaryElementV:
            case XmlBinaryNodeType.PrefixDictionaryElementW:
            case XmlBinaryNodeType.PrefixDictionaryElementX:
            case XmlBinaryNodeType.PrefixDictionaryElementY:
            case XmlBinaryNodeType.PrefixDictionaryElementZ:
                sb.Append(": ");
                if (this.Prefix != null && !XmlBinaryNodeType.IsPrefixNode(this.NodeType))
                {
                    sb.AppendFormat("{0}:", this.Prefix);
                }
                if (XmlBinaryNodeType.IsDictionaryElementNode(nodeType))
                {
                    this.ThrowIfMissingRequiredProperty("DictionaryLocalName", this.DictionaryLocalName);
                    string value = this.DictionaryLocalName.GetValue(staticDictionary, readerSession);
                    sb.AppendFormat("dict[key={0}{1}{2}]",
                                    this.DictionaryLocalName.DictionaryId,
                                    this.DictionaryLocalName.IsSession ? " (session)" : "",
                                    value == null ? "" : "value=" + value);
                }
                else
                {
                    this.ThrowIfMissingRequiredProperty("LocalName", this.LocalName);
                    sb.Append(this.LocalName);
                }
                break;

            case XmlBinaryNodeType.EmptyText:
            case XmlBinaryNodeType.EmptyTextWithEndElement:
            case XmlBinaryNodeType.ZeroText:
            case XmlBinaryNodeType.ZeroTextWithEndElement:
            case XmlBinaryNodeType.OneText:
            case XmlBinaryNodeType.OneTextWithEndElement:
            case XmlBinaryNodeType.FalseText:
            case XmlBinaryNodeType.FalseTextWithEndElement:
            case XmlBinaryNodeType.TrueText:
            case XmlBinaryNodeType.TrueTextWithEndElement:
            case XmlBinaryNodeType.Chars8Text:
            case XmlBinaryNodeType.Chars8TextWithEndElement:
            case XmlBinaryNodeType.Chars16Text:
            case XmlBinaryNodeType.Chars16TextWithEndElement:
            case XmlBinaryNodeType.Chars32Text:
            case XmlBinaryNodeType.Chars32TextWithEndElement:
            case XmlBinaryNodeType.UnicodeChars8Text:
            case XmlBinaryNodeType.UnicodeChars8TextWithEndElement:
            case XmlBinaryNodeType.UnicodeChars16Text:
            case XmlBinaryNodeType.UnicodeChars16TextWithEndElement:
            case XmlBinaryNodeType.UnicodeChars32Text:
            case XmlBinaryNodeType.UnicodeChars32TextWithEndElement:
            case XmlBinaryNodeType.Comment:
                this.ThrowIfMissingRequiredProperty("Text", this.Text);
                sb.AppendFormat(" (length={0}): \"{1}\"", this.Text.Length, this.Text);
                break;

            case XmlBinaryNodeType.DictionaryText:
            case XmlBinaryNodeType.DictionaryTextWithEndElement:
                this.ThrowIfMissingRequiredProperty("DictionaryText", this.DictionaryText);
                string dicTextValue = this.DictionaryText.GetValue(staticDictionary, readerSession);
                sb.AppendFormat(": dict[key={0}{1}{2}]",
                                this.DictionaryText.DictionaryId,
                                this.DictionaryText.IsSession ? "(session)" : "",
                                dicTextValue == null ? "" : ",value=\"" + dicTextValue + "\"");
                break;

            case XmlBinaryNodeType.Int8Text:
            case XmlBinaryNodeType.Int8TextWithEndElement:
            case XmlBinaryNodeType.Int16Text:
            case XmlBinaryNodeType.Int16TextWithEndElement:
            case XmlBinaryNodeType.Int32Text:
            case XmlBinaryNodeType.Int32TextWithEndElement:
                sb.AppendFormat(": {0}", this.IntValue);
                break;

            case XmlBinaryNodeType.Int64Text:
            case XmlBinaryNodeType.Int64TextWithEndElement:
                sb.AppendFormat(": {0}", this.LongValue);
                break;

            case XmlBinaryNodeType.UInt64Text:
            case XmlBinaryNodeType.UInt64TextWithEndElement:
                sb.AppendFormat(": {0}", (ulong)this.LongValue);
                break;

            case XmlBinaryNodeType.FloatText:
            case XmlBinaryNodeType.FloatTextWithEndElement:
                sb.AppendFormat(": {0}", this.FloatValue);
                break;

            case XmlBinaryNodeType.DoubleText:
            case XmlBinaryNodeType.DoubleTextWithEndElement:
                sb.AppendFormat(": {0}", this.DoubleValue);
                break;

            case XmlBinaryNodeType.DecimalText:
            case XmlBinaryNodeType.DecimalTextWithEndElement:
                sb.AppendFormat(": {0}", this.DecimalValue);
                break;

            case XmlBinaryNodeType.DateTimeText:
            case XmlBinaryNodeType.DateTimeTextWithEndElement:
                sb.AppendFormat(": {0} ({1})", this.DateTimeValue, this.DateTimeValue.Kind);
                break;

            case XmlBinaryNodeType.TimeSpanText:
            case XmlBinaryNodeType.TimeSpanTextWithEndElement:
                sb.AppendFormat(": {0}", this.TimeSpanValue);
                break;

            case XmlBinaryNodeType.Bytes8Text:
            case XmlBinaryNodeType.Bytes8TextWithEndElement:
            case XmlBinaryNodeType.Bytes16Text:
            case XmlBinaryNodeType.Bytes16TextWithEndElement:
            case XmlBinaryNodeType.Bytes32Text:
            case XmlBinaryNodeType.Bytes32TextWithEndElement:
                this.ThrowIfMissingRequiredProperty("Bytes", this.Bytes);
                sb.AppendFormat(" (size={0}): ", this.Bytes.Length);
                sb.Append('{');
                for (int i = 0; i < this.Bytes.Length; i++)
                {
                    if (i != 0)
                    {
                        sb.Append(',');
                    }
                    sb.AppendFormat("{0:X2}", this.Bytes[i]);
                }
                sb.Append('}');
                break;

            case XmlBinaryNodeType.GuidText:
            case XmlBinaryNodeType.GuidTextWithEndElement:
                sb.Append(": ");
                sb.Append(this.GuidValue.ToString("B"));
                break;

            case XmlBinaryNodeType.UniqueIdText:
            case XmlBinaryNodeType.UniqueIdTextWithEndElement:
                sb.Append(": ");
                this.ThrowIfMissingRequiredProperty("UniqueIdValue", this.UniqueIdValue);
                sb.Append(this.UniqueIdValue.ToString());
                break;

            case XmlBinaryNodeType.ShortAttribute:
            case XmlBinaryNodeType.ShortDictionaryAttribute:
            case XmlBinaryNodeType.Attribute:
            case XmlBinaryNodeType.DictionaryAttribute:
            case XmlBinaryNodeType.PrefixAttributeA:
            case XmlBinaryNodeType.PrefixAttributeB:
            case XmlBinaryNodeType.PrefixAttributeC:
            case XmlBinaryNodeType.PrefixAttributeD:
            case XmlBinaryNodeType.PrefixAttributeE:
            case XmlBinaryNodeType.PrefixAttributeF:
            case XmlBinaryNodeType.PrefixAttributeG:
            case XmlBinaryNodeType.PrefixAttributeH:
            case XmlBinaryNodeType.PrefixAttributeI:
            case XmlBinaryNodeType.PrefixAttributeJ:
            case XmlBinaryNodeType.PrefixAttributeK:
            case XmlBinaryNodeType.PrefixAttributeL:
            case XmlBinaryNodeType.PrefixAttributeM:
            case XmlBinaryNodeType.PrefixAttributeN:
            case XmlBinaryNodeType.PrefixAttributeO:
            case XmlBinaryNodeType.PrefixAttributeP:
            case XmlBinaryNodeType.PrefixAttributeQ:
            case XmlBinaryNodeType.PrefixAttributeR:
            case XmlBinaryNodeType.PrefixAttributeS:
            case XmlBinaryNodeType.PrefixAttributeT:
            case XmlBinaryNodeType.PrefixAttributeU:
            case XmlBinaryNodeType.PrefixAttributeV:
            case XmlBinaryNodeType.PrefixAttributeW:
            case XmlBinaryNodeType.PrefixAttributeX:
            case XmlBinaryNodeType.PrefixAttributeY:
            case XmlBinaryNodeType.PrefixAttributeZ:
            case XmlBinaryNodeType.PrefixDictionaryAttributeA:
            case XmlBinaryNodeType.PrefixDictionaryAttributeB:
            case XmlBinaryNodeType.PrefixDictionaryAttributeC:
            case XmlBinaryNodeType.PrefixDictionaryAttributeD:
            case XmlBinaryNodeType.PrefixDictionaryAttributeE:
            case XmlBinaryNodeType.PrefixDictionaryAttributeF:
            case XmlBinaryNodeType.PrefixDictionaryAttributeG:
            case XmlBinaryNodeType.PrefixDictionaryAttributeH:
            case XmlBinaryNodeType.PrefixDictionaryAttributeI:
            case XmlBinaryNodeType.PrefixDictionaryAttributeJ:
            case XmlBinaryNodeType.PrefixDictionaryAttributeK:
            case XmlBinaryNodeType.PrefixDictionaryAttributeL:
            case XmlBinaryNodeType.PrefixDictionaryAttributeM:
            case XmlBinaryNodeType.PrefixDictionaryAttributeN:
            case XmlBinaryNodeType.PrefixDictionaryAttributeO:
            case XmlBinaryNodeType.PrefixDictionaryAttributeP:
            case XmlBinaryNodeType.PrefixDictionaryAttributeQ:
            case XmlBinaryNodeType.PrefixDictionaryAttributeR:
            case XmlBinaryNodeType.PrefixDictionaryAttributeS:
            case XmlBinaryNodeType.PrefixDictionaryAttributeT:
            case XmlBinaryNodeType.PrefixDictionaryAttributeU:
            case XmlBinaryNodeType.PrefixDictionaryAttributeV:
            case XmlBinaryNodeType.PrefixDictionaryAttributeW:
            case XmlBinaryNodeType.PrefixDictionaryAttributeX:
            case XmlBinaryNodeType.PrefixDictionaryAttributeY:
            case XmlBinaryNodeType.PrefixDictionaryAttributeZ:
                sb.Append(": ");
                if (this.Prefix != null && !XmlBinaryNodeType.IsPrefixNode(this.NodeType))
                {
                    sb.AppendFormat("{0}:", this.Prefix);
                }
                if (XmlBinaryNodeType.IsDictionaryAttributeNode(nodeType))
                {
                    this.ThrowIfMissingRequiredProperty("DictionaryLocalName", this.DictionaryLocalName);
                    string prefixDictAttrValue = this.DictionaryLocalName.GetValue(staticDictionary, readerSession);
                    sb.AppendFormat("dict[key={0}{1}{2}]",
                                    this.DictionaryLocalName.DictionaryId,
                                    this.DictionaryLocalName.IsSession ? "(session)" : "",
                                    prefixDictAttrValue == null ? "" : ",value=" + prefixDictAttrValue);
                }
                else
                {
                    this.ThrowIfMissingRequiredProperty("LocalName", this.LocalName);
                    sb.Append(this.LocalName);
                }
                break;

            case XmlBinaryNodeType.ShortXmlnsAttribute:
            case XmlBinaryNodeType.XmlnsAttribute:
            case XmlBinaryNodeType.ShortDictionaryXmlnsAttribute:
            case XmlBinaryNodeType.DictionaryXmlnsAttribute:
                sb.Append(": xmlns");
                if (this.Prefix != null)
                {
                    sb.Append(':');
                    sb.Append(this.Prefix);
                }
                sb.Append('=');
                if (XmlBinaryNodeType.IsDictionaryAttributeNode(nodeType))
                {
                    this.ThrowIfMissingRequiredProperty("DictionaryNamespaceURI", this.DictionaryNamespaceURI);
                    string namespaceUriDictValue = this.DictionaryNamespaceURI.GetValue(staticDictionary, readerSession);
                    sb.AppendFormat("dict[key={0}{1}{2}]",
                                    this.DictionaryNamespaceURI.DictionaryId,
                                    this.DictionaryNamespaceURI.IsSession ? "(session)" : "",
                                    namespaceUriDictValue == null ? "" : ",value=" + namespaceUriDictValue);
                }
                else
                {
                    sb.AppendFormat("\"{0}\"", this.NamespaceURI);
                }
                break;

            case XmlBinaryNodeType.Array:
                sb.Append(':');
                if (printChildren)
                {
                    sb.Append(Environment.NewLine);
                    sb.Append(this.Children[0].ToString(staticDictionary, readerSession));     // element node
                    for (int i = 0; i < this.Children[0].Depth; i++)
                    {
                        sb.Append(identString);
                    }
                    sb.Append(this.ArrayElements.ToString());
                    sb.Append(Environment.NewLine);
                    if (this.Children.Count > 1)      // also has an EndElement node
                    {
                        sb.Append(this.Children[1].ToString(staticDictionary, readerSession));
                    }
                }
                break;

            case XmlBinaryNodeType.StartListText:
            case XmlBinaryNodeType.StartListTextWithEndElement:
                sb.Append(":");
                break;

            case XmlBinaryNodeType.EndListText:
            case XmlBinaryNodeType.EndListTextWithEndElement:
                sb.Append(".");
                break;

            default:
                throw new ArgumentException(String.Format("Error, the code is not ready to handle the type {0:X2} ({1}) yet", nodeType, XmlBinaryNodeType.GetNodeName(nodeType)));
            }

            if (nodeType != XmlBinaryNodeType.Array) // already taken care of
            {
                if (printChildren)
                {
                    sb.Append(Environment.NewLine);
                    for (int i = 0; i < children.Count; i++)
                    {
                        sb.Append(children[i].ToString(staticDictionary, readerSession));
                    }
                }
            }

            return(sb.ToString());
        }
Exemplo n.º 14
0
 public string ToString(IXmlDictionary staticDictionary, XmlBinaryReaderSession readerSession)
 {
     return(this.ToString(staticDictionary, readerSession, true));
 }
Exemplo n.º 15
0
        public Message ReadSizedMessage()
        {
            // FIXME: implement full [MC-NMF].

            int packetType;

            try {
                packetType = s.ReadByte();
            } catch (IOException) {
                // it is already disconnected
                return(null);
            } catch (SocketException) {
                // it is already disconnected
                return(null);
            }
            // FIXME: .NET never results in -1, so there may be implementation mismatch in Socket (but might be in other places)
            if (packetType == -1)
            {
                return(null);
            }
            // FIXME: The client should wait for EndRecord, but if we try to send it, the socket blocks and becomes unable to work anymore.
            if (packetType == EndRecord)
            {
                return(null);
            }
            if (packetType != SizedEnvelopeRecord)
            {
                if (is_service_side)
                {
                    // reconnect
                    ProcessPreambleRecipient(packetType);
                    ProcessPreambleAckRecipient();
                }
                else
                {
                    throw new NotImplementedException(String.Format("Packet type {0:X} is not implemented", packetType));
                }
            }

            byte [] buffer = ReadSizedChunk();

            var ms = new MemoryStream(buffer, 0, buffer.Length);

            // FIXME: turned out that it could be either in-band dictionary ([MC-NBFSE]), or a mere xml body ([MC-NBFS]).
            if (EncodingRecord != EncodingBinaryWithDictionary)
            {
                throw new NotImplementedException(String.Format("Message encoding {0:X} is not implemented yet", EncodingRecord));
            }

            // Encoding type 8:
            // the returned buffer consists of a serialized reader
            // session and the binary xml body.

            var session = reader_session ?? new XmlBinaryReaderSession();

            reader_session = session;
            byte [] rsbuf = new TcpBinaryFrameManager(0, ms, is_service_side).ReadSizedChunk();
            using (var rms = new MemoryStream(rsbuf, 0, rsbuf.Length)) {
                var rbr = new BinaryReader(rms, Encoding.UTF8);
                while (rms.Position < rms.Length)
                {
                    session.Add(reader_session_items++, rbr.ReadString());
                }
            }
            var benc = Encoder as BinaryMessageEncoder;

            if (benc != null)
            {
                benc.CurrentReaderSession = session;
            }

            // FIXME: supply maxSizeOfHeaders.
            Message msg = Encoder.ReadMessage(ms, 0x10000);

            if (benc != null)
            {
                benc.CurrentReaderSession = null;
            }

            return(msg);
        }
 public MessagePatterns(IXmlDictionary dictionary, XmlBinaryReaderSession readerSession, MessageVersion messageVersion)
 {
     this.dictionary     = dictionary;
     this.readerSession  = readerSession;
     this.messageVersion = messageVersion;
 }
        public void ReadMessage()
        {
            using (var ms = File.OpenRead(TestResourceHelper.GetFullPathOfResource("Test/Resources/binary-message.raw"))) {
                var     session = new XmlBinaryReaderSession();
                byte [] rsbuf   = new BinaryFrameSupportReader(ms).ReadSizedChunk();
                int     count   = 0;
                using (var rms = new MemoryStream(rsbuf, 0, rsbuf.Length)) {
                    var rbr = new BinaryReader(rms, Encoding.UTF8);
                    while (rms.Position < rms.Length)
                    {
                        session.Add(count++, rbr.ReadString());
                    }
                }
                var xr = XmlDictionaryReader.CreateBinaryReader(ms, BinaryFrameSupportReader.soap_dictionary, new XmlDictionaryReaderQuotas(), session);

                string soapNS  = "http://www.w3.org/2003/05/soap-envelope";
                string addrNS  = "http://www.w3.org/2005/08/addressing";
                string xmlnsNS = "http://www.w3.org/2000/xmlns/";
                string peerNS  = "http://schemas.microsoft.com/net/2006/05/peer";

                xr.MoveToContent();
                AssertNode(xr, 0, XmlNodeType.Element, "s", "Envelope", soapNS, String.Empty, "#1");
                Assert.AreEqual(2, xr.AttributeCount, "#1-1-1");
                Assert.IsTrue(xr.MoveToAttribute("s", xmlnsNS), "#1-2");
                AssertNode(xr, 1, XmlNodeType.Attribute, "xmlns", "s", xmlnsNS, soapNS, "#2");
                Assert.IsTrue(xr.MoveToAttribute("a", xmlnsNS), "#2-2");
                AssertNode(xr, 1, XmlNodeType.Attribute, "xmlns", "a", xmlnsNS, addrNS, "#3");
                Assert.IsTrue(xr.Read(), "#3-2");
                AssertNode(xr, 1, XmlNodeType.Element, "s", "Header", soapNS, String.Empty, "#4");
                Assert.IsTrue(xr.Read(), "#4-2");
                AssertNode(xr, 2, XmlNodeType.Element, "a", "Action", addrNS, String.Empty, "#5");
                Assert.IsTrue(xr.MoveToAttribute("mustUnderstand", soapNS), "#5-2");
                AssertNode(xr, 3, XmlNodeType.Attribute, "s", "mustUnderstand", soapNS, "1", "#6");
                Assert.IsTrue(xr.Read(), "#6-2");
                AssertNode(xr, 3, XmlNodeType.Text, "", "", "", "http://schemas.microsoft.com/net/2006/05/peer/resolver/Resolve", "#7");
                Assert.IsTrue(xr.Read(), "#7-2");
                AssertNode(xr, 2, XmlNodeType.EndElement, "a", "Action", addrNS, String.Empty, "#8");
                Assert.IsTrue(xr.Read(), "#8-2");
                AssertNode(xr, 2, XmlNodeType.Element, "a", "MessageID", addrNS, String.Empty, "#9");
                Assert.IsTrue(xr.Read(), "#9-2");
                Assert.AreEqual(XmlNodeType.Text, xr.NodeType, "#10");
                Assert.IsTrue(xr.Read(), "#10-2");
                AssertNode(xr, 2, XmlNodeType.EndElement, "a", "MessageID", addrNS, String.Empty, "#11");
                Assert.IsTrue(xr.Read(), "#11-2"); // -> a:ReplyTo
                AssertNode(xr, 2, XmlNodeType.Element, "a", "ReplyTo", addrNS, String.Empty, "#12");
                xr.Skip();                         // -> a:To
                AssertNode(xr, 2, XmlNodeType.Element, "a", "To", addrNS, String.Empty, "#13");
                xr.Skip();                         // -> /s:Header
                AssertNode(xr, 1, XmlNodeType.EndElement, "s", "Header", soapNS, String.Empty, "#14");

                Assert.IsTrue(xr.Read(), "#14-2");
                AssertNode(xr, 1, XmlNodeType.Element, "s", "Body", soapNS, String.Empty, "#15");
                Assert.IsTrue(xr.Read(), "#15-2");
                AssertNode(xr, 2, XmlNodeType.Element, "", "Resolve", peerNS, String.Empty, "#16");
                Assert.IsTrue(xr.MoveToAttribute("xmlns"), "#16-2");
                AssertNode(xr, 3, XmlNodeType.Attribute, "", "xmlns", xmlnsNS, peerNS, "#17");
                Assert.IsTrue(xr.Read(), "#17-2");
                AssertNode(xr, 3, XmlNodeType.Element, "", "ClientId", peerNS, String.Empty, "#18");

/*
 *                              while (!xr.EOF) {
 *                                      xr.Read ();
 *                                      Console.WriteLine ("{0}: {1}:{2} {3} {4}", xr.NodeType, xr.Prefix, xr.LocalName, xr.NamespaceURI, xr.Value);
 *                                      for (int i = 0; i < xr.AttributeCount; i++) {
 *                                              xr.MoveToAttribute (i);
 *                                              Console.WriteLine ("  Attribute: {0}:{1} {2} {3}", xr.Prefix, xr.LocalName, xr.NamespaceURI, xr.Value);
 *                                      }
 *                              }
 */
            }
        }
Exemplo n.º 18
0
        static void Main(string[] args)
        {
            List <Character> instance = new List <Character>
            {
                new Character {
                    Name = "Shaggy", Age = 19, DateOfBirth = new DateTime(1991, 9, 13), Type = "Human"
                },
                new Character {
                    Name = "Scooby", Age = 10, DateOfBirth = new DateTime(2000, 5, 20), Type = "Dog"
                },
                new Character {
                    Name = "Scrappy", Age = 3, DateOfBirth = new DateTime(2008, 1, 2), Type = "Dog"
                },
                new Character {
                    Name = "Fred", Age = 22, DateOfBirth = new DateTime(1988, 5, 29), Type = "Human"
                },
                new Character {
                    Name = "Velma", Age = 24, DateOfBirth = new DateTime(1986, 5, 30), Type = "Human"
                },
                new Character {
                    Name = "Daphne", Age = 20, DateOfBirth = new DateTime(1990, 5, 1), Type = "Human"
                },
            };

            Func <Stream, XmlBinaryWriterSession, XmlDictionaryWriter> createTextXmlWriter =
                (s, xbws) => XmlDictionaryWriter.CreateTextWriter(s);
            Func <Stream, XmlBinaryWriterSession, XmlDictionaryWriter> createNoDictBinaryWriter =
                (s, xbws) => XmlDictionaryWriter.CreateBinaryWriter(s);
            Func <Stream, XmlBinaryWriterSession, XmlDictionaryWriter> createDictBinaryWriter =
                (s, xbws) => XmlDictionaryWriter.CreateBinaryWriter(s, null, xbws);

            Func <Stream, XmlBinaryReaderSession, XmlDictionaryReader> createTextXmlReader =
                (s, xbrs) => XmlDictionaryReader.CreateTextReader(s, XmlDictionaryReaderQuotas.Max);
            Func <Stream, XmlBinaryReaderSession, XmlDictionaryReader> createNoDictBinaryReader =
                (s, xbrs) => XmlDictionaryReader.CreateBinaryReader(s, XmlDictionaryReaderQuotas.Max);
            Func <Stream, XmlBinaryReaderSession, XmlDictionaryReader> createDictBinaryReader =
                (s, xbrs) => XmlDictionaryReader.CreateBinaryReader(s, null, XmlDictionaryReaderQuotas.Max, xbrs);

            List <
                Tuple <
                    string,
                    Func <Stream, XmlBinaryWriterSession, XmlDictionaryWriter>,
                    Func <Stream, XmlBinaryReaderSession, XmlDictionaryReader> > > tests;

            tests = new List <Tuple <string, Func <Stream, XmlBinaryWriterSession, XmlDictionaryWriter>, Func <Stream, XmlBinaryReaderSession, XmlDictionaryReader> > >();
            tests.Add(
                new Tuple <string, Func <Stream, XmlBinaryWriterSession, XmlDictionaryWriter>, Func <Stream, XmlBinaryReaderSession, XmlDictionaryReader> >(
                    "Text/XML",
                    createTextXmlWriter,
                    createTextXmlReader));
            tests.Add(
                new Tuple <string, Func <Stream, XmlBinaryWriterSession, XmlDictionaryWriter>, Func <Stream, XmlBinaryReaderSession, XmlDictionaryReader> >(
                    "Binary/no dict",
                    createNoDictBinaryWriter,
                    createNoDictBinaryReader));
            tests.Add(
                new Tuple <string, Func <Stream, XmlBinaryWriterSession, XmlDictionaryWriter>, Func <Stream, XmlBinaryReaderSession, XmlDictionaryReader> >(
                    "Binary/with dict",
                    createDictBinaryWriter,
                    createDictBinaryReader));

            foreach (var test in tests)
            {
                Console.WriteLine(test.Item1);
                bool            needsDict     = test.Item2 == createDictBinaryWriter;
                MemoryStream    ms            = new MemoryStream();
                MyWriterSession writerSession = null;
                if (needsDict)
                {
                    writerSession = new MyWriterSession();
                }

                XmlDictionaryWriter xdw = test.Item2(ms, writerSession);
                Serialize(xdw, instance);
                if (needsDict)
                {
                    MemoryStream newMs = new MemoryStream();
                    writerSession.SaveDictionaryStrings(newMs);
                    ms.Position = 0;
                    ms.CopyTo(newMs);
                    ms = newMs;
                }

                Console.WriteLine("  Serialized, size = {0}", ms.Position);
                File.WriteAllBytes(@"c:\temp\serialized.bin", ms.ToArray());
                ms.Position = 0;
                XmlBinaryReaderSession readerSession = null;
                if (needsDict)
                {
                    readerSession = MyReaderSession.CreateReaderSession(ms);
                }

                XmlDictionaryReader xdr          = test.Item3(ms, readerSession);
                List <Character>    deserialized = Deserialize <List <Character> >(xdr);
                Console.WriteLine("  Deserialized: {0}", deserialized);
            }
        }
Exemplo n.º 19
0
        public Message ReadSizedMessage()
        {
            lock (read_lock)
            {
                // FIXME: implement full [MC-NMF].

                int packetType;
                try
                {
                    packetType = s.ReadByte();
                }
                catch (IOException)
                {
                    // it is already disconnected
                    return(null);
                }
                catch (SocketException)
                {
                    // it is already disconnected
                    return(null);
                }
                // FIXME: .NET never results in -1, so there may be implementation mismatch in Socket (but might be in other places)
                if (packetType == -1)
                {
                    return(null);
                }
                // FIXME: The client should wait for EndRecord, but if we try to send it, the socket blocks and becomes unable to work anymore.
                if (packetType == EndRecord)
                {
                    return(null);
                }
                if (packetType != SizedEnvelopeRecord)
                {
                    if (is_service_side)
                    {
                        // reconnect
                        ProcessPreambleRecipient(packetType);
                        ProcessPreambleAckRecipient();
                    }
                    else
                    {
                        throw new NotImplementedException(String.Format("Packet type {0:X} is not implemented", packetType));
                    }
                }

                byte [] buffer = ReadSizedChunk();
                var     ms     = new MemoryStream(buffer, 0, buffer.Length);

                // FIXME: turned out that it could be either in-band dictionary ([MC-NBFSE]), or a mere xml body ([MC-NBFS]).
                bool inBandDic = false;
                XmlBinaryReaderSession session = null;
                switch (EncodingRecord)
                {
                case Soap11EncodingUtf8:
                case Soap11EncodingUtf16:
                case Soap11EncodingUtf16LE:
                case Soap12EncodingUtf8:
                case Soap12EncodingUtf16:
                case Soap12EncodingUtf16LE:
                    if (!(Encoder is TextMessageEncoder))
                    {
                        throw new InvalidOperationException(String.Format("Unexpected message encoding value in the received message: {0:X}", EncodingRecord));
                    }
                    break;

                case Soap12EncodingMtom:
                    if (!(Encoder is MtomMessageEncoder))
                    {
                        throw new InvalidOperationException(String.Format("Unexpected message encoding value in the received message: {0:X}", EncodingRecord));
                    }
                    break;

                default:
                    throw new InvalidOperationException(String.Format("Unexpected message encoding value in the received message: {0:X}", EncodingRecord));

                case Soap12EncodingBinaryWithDictionary:
                    inBandDic = true;
                    goto case Soap12EncodingBinary;

                case Soap12EncodingBinary:
                    session        = inBandDic ? (reader_session ?? new XmlBinaryReaderSession()) : null;
                    reader_session = session;
                    if (inBandDic)
                    {
                        byte [] rsbuf = new TcpBinaryFrameManager(0, ms, is_service_side).ReadSizedChunk();
                        using (var rms = new MemoryStream(rsbuf, 0, rsbuf.Length))
                        {
                            var rbr = new BinaryReader(rms, Encoding.UTF8);
                            while (rms.Position < rms.Length)
                            {
                                session.Add(reader_session_items++, rbr.ReadString());
                            }
                        }
                    }
                    break;
                }
                var benc = Encoder as BinaryMessageEncoder;
                lock (Encoder)
                {
                    if (benc != null)
                    {
                        benc.CurrentReaderSession = session;
                    }

                    // FIXME: supply maxSizeOfHeaders.
                    Message msg = Encoder.ReadMessage(ms, 0x10000);
                    if (benc != null)
                    {
                        benc.CurrentReaderSession = null;
                    }
                    return(msg);
                }
            }
        }
Exemplo n.º 20
0
        private static bool TryParseArgs(string[] args, out string binaryFileName, out IXmlDictionary xmlDictionary, out XmlBinaryReaderSession readerSession)
        {
            binaryFileName = null;
            xmlDictionary  = null;
            readerSession  = null;
            bool   useDictionaries       = true;
            string staticDictionaryFile  = null;
            string dynamicDictionaryFile = null;
            int    offset = 0;

            while (offset < args.Length)
            {
                if (args[offset] == "-static")
                {
                    if (offset + 1 >= args.Length)
                    {
                        return(false);
                    }

                    staticDictionaryFile = args[offset + 1];
                    offset += 2;
                }
                if (args[offset] == "-session")
                {
                    if (offset + 1 >= args.Length)
                    {
                        return(false);
                    }

                    dynamicDictionaryFile = args[offset + 1];
                    offset += 2;
                }
                else if (args[offset] == "-noDict")
                {
                    offset++;
                    useDictionaries = false;
                }
                else
                {
                    binaryFileName = args[offset];
                    offset++;
                    if (offset != args.Length)
                    {
                        return(false);
                    }
                }
            }

            if (useDictionaries)
            {
                if (staticDictionaryFile == null)
                {
                    xmlDictionary = WcfDictionary.GetStaticDictionary();
                }
                else
                {
                    XmlDictionary temp = new XmlDictionary();
                    xmlDictionary = temp;
                    foreach (string entry in File.ReadAllLines(staticDictionaryFile))
                    {
                        temp.Add(entry);
                    }
                }

                readerSession = new XmlBinaryReaderSession();
                if (dynamicDictionaryFile == null)
                {
                    for (int i = 0; i < 200; i++)
                    {
                        readerSession.Add(i, "session_" + i);
                    }
                }
                else
                {
                    string[] lines = File.ReadAllLines(dynamicDictionaryFile);
                    for (int i = 0; i < lines.Length; i++)
                    {
                        readerSession.Add(i, lines[i]);
                    }
                }
            }
            else
            {
                readerSession = null;
                xmlDictionary = null;
            }

            return(true);
        }
            public override ArraySegment <byte> WriteMessage(Message message, int maxMessageSize, BufferManager bufferManager, int messageOffset)
            {
                BinaryMessageEncoderFactory.BinaryBufferedMessageWriter sessionMessageWriter;
                if (message == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("message");
                }
                if (bufferManager == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("bufferManager");
                }
                if (maxMessageSize < 0)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("maxMessageSize", maxMessageSize, System.ServiceModel.SR.GetString("ValueMustBeNonNegative")));
                }
                message.Properties.Encoder = this;
                if (this.isSession)
                {
                    if (this.writerSession == null)
                    {
                        this.writerSession        = new BinaryMessageEncoderFactory.XmlBinaryWriterSessionWithQuota(this.maxSessionSize);
                        this.sessionMessageWriter = new BinaryMessageEncoderFactory.BinaryBufferedMessageWriter(this.factory.binaryVersion.Dictionary, this.writerSession);
                    }
                    messageOffset += 5;
                }
                if (messageOffset < 0)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("messageOffset", messageOffset, System.ServiceModel.SR.GetString("ValueMustBeNonNegative")));
                }
                if (messageOffset > maxMessageSize)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new QuotaExceededException(System.ServiceModel.SR.GetString("MaxSentMessageSizeExceeded", new object[] { maxMessageSize })));
                }
                base.ThrowIfMismatchedMessageVersion(message);
                if (this.isSession)
                {
                    sessionMessageWriter = this.sessionMessageWriter;
                }
                else
                {
                    sessionMessageWriter = this.factory.TakeBufferedWriter();
                }
                ArraySegment <byte> messageData = sessionMessageWriter.WriteMessage(message, bufferManager, messageOffset, maxMessageSize);

                if (MessageLogger.LogMessagesAtTransportLevel && !this.readerSessionForLoggingIsInvalid)
                {
                    if (this.isSession)
                    {
                        if (this.readerSessionForLogging == null)
                        {
                            this.readerSessionForLogging = new XmlBinaryReaderSession();
                        }
                        if (this.writerSession.HasNewStrings)
                        {
                            foreach (XmlDictionaryString str in this.writerSession.GetNewStrings())
                            {
                                this.readerSessionForLogging.Add(this.writeIdCounter++, str.Value);
                            }
                        }
                    }
                    XmlDictionaryReader reader = XmlDictionaryReader.CreateBinaryReader(messageData.Array, messageData.Offset, messageData.Count, XD.Dictionary, XmlDictionaryReaderQuotas.Max, this.readerSessionForLogging, null);
                    MessageLogger.LogMessage(ref message, reader, MessageLoggingSource.TransportSend);
                }
                else
                {
                    this.readerSessionForLoggingIsInvalid = true;
                }
                if (this.isSession)
                {
                    return(this.AddSessionInformationToMessage(messageData, bufferManager, maxMessageSize));
                }
                this.factory.ReturnMessageWriter(sessionMessageWriter);
                return(messageData);
            }
 public static XmlDictionaryReader CreateBinaryReader(byte[] buffer, int offset, int count, IXmlDictionary dictionary, XmlDictionaryReaderQuotas quotas, XmlBinaryReaderSession session);