Exemple #1
0
        private void Initialize(IXmlDictionary dictionary,
                                XmlDictionaryReaderQuotas quotas,
                                XmlBinaryReaderSession session,
                                OnXmlDictionaryReaderClose onClose)
        {
            if (quotas == null)
            {
                throw new ArgumentNullException("quotas");
            }
            if (dictionary == null)
            {
                dictionary = new XmlDictionary();
            }
            this.dictionary = dictionary;

            this.quota = quotas;

            if (session == null)
            {
                session = new XmlBinaryReaderSession();
            }
            this.session = session;

            on_close = onClose;
            NameTable nt = new NameTable();

            this.context = new XmlParserContext(nt,
                                                new XmlNamespaceManager(nt),
                                                null, XmlSpace.None);

            current = node = new NodeInfo();
            current.Reset();
            node_stack.Add(node);
        }
        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);
            }
        }
Exemple #3
0
 private void MoveToInitial(XmlDictionaryReaderQuotas quotas, XmlBinaryReaderSession session, OnXmlDictionaryReaderClose onClose)
 {
     MoveToInitial(quotas);
     _maxBytesPerRead = quotas.MaxBytesPerRead;
     _arrayState = ArrayState.None;
     _isTextWithEndElement = false;
 }
 public static XmlDictionaryReader CreateBinaryReader(
     Stream stream, IXmlDictionary dictionary,
     XmlDictionaryReaderQuotas quotas,
     XmlBinaryReaderSession session)
 {
     return(CreateBinaryReader(stream, dictionary, quotas,
                               session, null));
 }
Exemple #5
0
 public XmlBinaryDictionaryReader(Stream stream,
                                  IXmlDictionary dictionary,
                                  XmlDictionaryReaderQuotas quota,
                                  XmlBinaryReaderSession session,
                                  OnXmlDictionaryReaderClose onClose)
 {
     source = new StreamSource(stream);
     Initialize(dictionary, quota, session, onClose);
 }
 public static XmlDictionaryReader CreateBinaryReader(
     Stream stream, IXmlDictionary dictionary,
     XmlDictionaryReaderQuotas quotas,
     XmlBinaryReaderSession session,
     OnXmlDictionaryReaderClose onClose)
 {
     return(new XmlBinaryDictionaryReader(stream,
                                          dictionary, quotas, session, onClose));
 }
 void SetBuffer(Stream stream, byte[] buffer, int offset, int count, IXmlDictionary dictionary, XmlBinaryReaderSession session)
 {
     this.stream = stream;
     this.buffer = buffer;
     this.offsetMin = offset;
     this.offset = offset;
     this.offsetMax = offset + count;
     this.dictionary = dictionary;
     this.session = session;
 }
 public void SetBuffer(Stream stream, IXmlDictionary dictionary, XmlBinaryReaderSession session)
 {
     if (this.streamBuffer == null)
     {
         this.streamBuffer = new byte[0x80];
     }
     this.SetBuffer(stream, this.streamBuffer, 0, 0, dictionary, session);
     this.windowOffset    = 0;
     this.windowOffsetMax = this.streamBuffer.Length;
 }
 public void SetBuffer(Stream stream, IXmlDictionary dictionary, XmlBinaryReaderSession session)
 {
     if (streamBuffer == null)
     {
         streamBuffer = new byte[128];
     }
     SetBuffer(stream, streamBuffer, 0, 0, dictionary, session);
     this.windowOffset = 0;
     this.windowOffsetMax = streamBuffer.Length;
 }
 public static XmlDictionaryReader CreateBinaryReader(
     byte [] buffer, int offset, int count,
     IXmlDictionary dictionary,
     XmlDictionaryReaderQuotas quotas,
     XmlBinaryReaderSession session)
 {
     return(CreateBinaryReader(buffer, offset, count,
                               dictionary, quotas,
                               session, null));
 }
 public static XmlDictionaryReader CreateBinaryReader(byte[] buffer, int offset, int count,
                                                      IXmlDictionary dictionary,
                                                      XmlDictionaryReaderQuotas quotas,
                                                      XmlBinaryReaderSession session,
                                                      OnXmlDictionaryReaderClose onClose)
 {
     XmlBinaryReader reader = new XmlBinaryReader();
     reader.SetInput(buffer, offset, count, dictionary, quotas, session, onClose);
     return reader;
 }
Exemple #12
0
 public void SetBuffer(Stream stream, IXmlDictionary dictionary, XmlBinaryReaderSession session)
 {
     if (_streamBuffer == null)
     {
         _streamBuffer = new byte[128];
     }
     SetBuffer(stream, _streamBuffer, 0, 0, dictionary, session);
     _windowOffset    = 0;
     _windowOffsetMax = _streamBuffer.Length;
 }
Exemple #13
0
 private void SetBuffer(Stream stream, byte[] buffer, int offset, int count, IXmlDictionary dictionary, XmlBinaryReaderSession session)
 {
     _stream     = stream;
     _buffer     = buffer;
     _offsetMin  = offset;
     _offset     = offset;
     _offsetMax  = offset + count;
     _dictionary = dictionary;
     _session    = session;
 }
 private void SetBuffer(Stream stream, byte[] buffer, int offset, int count, IXmlDictionary dictionary, XmlBinaryReaderSession session)
 {
     this.stream     = stream;
     this.buffer     = buffer;
     this.offsetMin  = offset;
     this.offset     = offset;
     this.offsetMax  = offset + count;
     this.dictionary = dictionary;
     this.session    = session;
 }
Exemple #15
0
 public XmlBinaryDictionaryReader(byte [] buffer, int offset,
                                  int count, IXmlDictionary dictionary,
                                  XmlDictionaryReaderQuotas quota,
                                  XmlBinaryReaderSession session,
                                  OnXmlDictionaryReaderClose onClose)
 {
     source = /*new ArraySource (buffer, offset, count);*/
              new StreamSource(new MemoryStream(buffer, offset, count));
     Initialize(dictionary, quota, session, onClose);
 }
 public static XmlDictionaryReader CreateBinaryReader(
     byte [] buffer, int offset, int count,
     IXmlDictionary dictionary,
     XmlDictionaryReaderQuotas quotas,
     XmlBinaryReaderSession session,
     OnXmlDictionaryReaderClose onClose)
 {
     return(new XmlBinaryDictionaryReader(buffer,
                                          offset, count,
                                          dictionary, quotas, session, onClose));
 }
Exemple #17
0
 public void SetInput(Stream stream,
                      IXmlDictionary dictionary,
                     XmlDictionaryReaderQuotas quotas,
                     XmlBinaryReaderSession session)
 {
     if (stream == null)
         throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("stream");
     MoveToInitial(quotas, session, null);
     BufferReader.SetBuffer(stream, dictionary, session);
     _buffered = false;
 }
Exemple #18
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 Close()
 {
     if ((this.streamBuffer != null) && (this.streamBuffer.Length > 0x1000))
     {
         this.streamBuffer = null;
     }
     if (this.stream != null)
     {
         this.stream.Close();
         this.stream = null;
     }
     this.buffer          = emptyByteArray;
     this.offset          = 0;
     this.offsetMax       = 0;
     this.windowOffset    = 0;
     this.windowOffsetMax = 0;
     this.dictionary      = null;
     this.session         = null;
 }
        public XmlDictionaryString GetDictionaryString(int key)
        {
            IXmlDictionary      session;
            XmlDictionaryString str;

            if ((key & 1) != 0)
            {
                session = this.session;
            }
            else
            {
                session = this.dictionary;
            }
            if (!session.TryLookup((int)(key >> 1), out str))
            {
                XmlExceptionHelper.ThrowInvalidBinaryFormat(this.reader);
            }
            return(str);
        }
Exemple #21
0
 public void SetInput(byte[] buffer, int offset, int count,
                     IXmlDictionary dictionary,
                     XmlDictionaryReaderQuotas quotas,
                     XmlBinaryReaderSession session)
 {
     if (buffer == null)
         throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("buffer");
     if (offset < 0)
         throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(offset), SR.Format(SR.ValueMustBeNonNegative)));
     if (offset > buffer.Length)
         throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(offset), SR.Format(SR.OffsetExceedsBufferSize, buffer.Length)));
     if (count < 0)
         throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(count), SR.Format(SR.ValueMustBeNonNegative)));
     if (count > buffer.Length - offset)
         throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(count), SR.Format(SR.SizeExceedsRemainingBufferSpace, buffer.Length - offset)));
     MoveToInitial(quotas, session, null);
     BufferReader.SetBuffer(buffer, offset, count, dictionary, session);
     _buffered = true;
 }
 public void Close()
 {
     if ((this.streamBuffer != null) && (this.streamBuffer.Length > 0x1000))
     {
         this.streamBuffer = null;
     }
     if (this.stream != null)
     {
         this.stream.Close();
         this.stream = null;
     }
     this.buffer = emptyByteArray;
     this.offset = 0;
     this.offsetMax = 0;
     this.windowOffset = 0;
     this.windowOffsetMax = 0;
     this.dictionary = null;
     this.session = null;
 }
Exemple #23
0
 public void Close()
 {
     if (_streamBuffer != null && _streamBuffer.Length > 4096)
     {
         _streamBuffer = null;
     }
     if (_stream != null)
     {
         _stream.Dispose();
         _stream = null;
     }
     _buffer          = Array.Empty <byte>();
     _offset          = 0;
     _offsetMax       = 0;
     _windowOffset    = 0;
     _windowOffsetMax = 0;
     _dictionary      = null;
     _session         = null;
 }
Exemple #24
0
 public void SetBuffer(byte[] buffer, int offset, int count, IXmlDictionary dictionary, XmlBinaryReaderSession session)
 {
     SetBuffer(null, buffer, offset, count, dictionary, session);
 }
 public static XmlDictionaryReader CreateBinaryReader(byte[] buffer, int offset, int count, IXmlDictionary dictionary, XmlDictionaryReaderQuotas quotas, XmlBinaryReaderSession session)
 {
     return CreateBinaryReader(buffer, offset, count, dictionary, quotas, session, null);
 }
Exemple #26
0
		private void Initialize (IXmlDictionary dictionary,
			XmlDictionaryReaderQuotas quotas,
			XmlBinaryReaderSession session,
			OnXmlDictionaryReaderClose onClose)
		{
			if (quotas == null)
				throw new ArgumentNullException ("quotas");
			if (dictionary == null)
				dictionary = new XmlDictionary ();
			this.dictionary = dictionary;

			this.quota = quotas;

			if (session == null)
				session = new XmlBinaryReaderSession ();
			this.session = session;

			on_close = onClose;
			NameTable nt = new NameTable ();
			this.context = new XmlParserContext (nt,
				new XmlNamespaceManager (nt),
				null, XmlSpace.None);

			current = node = new NodeInfo ();
			current.Reset ();
			node_stack.Add (node);
		}
Exemple #27
0
		public XmlBinaryDictionaryReader (Stream stream,
			IXmlDictionary dictionary,
			XmlDictionaryReaderQuotas quota,
			XmlBinaryReaderSession session,
			OnXmlDictionaryReaderClose onClose)
		{
			source = new StreamSource (stream);
			Initialize (dictionary, quota, session, onClose);
		}
Exemple #28
0
		public XmlBinaryDictionaryReader (byte [] buffer, int offset,
			int count, IXmlDictionary dictionary,
			XmlDictionaryReaderQuotas quota,
			XmlBinaryReaderSession session,
			OnXmlDictionaryReaderClose onClose)
		{
			source = /*new ArraySource (buffer, offset, count);*/
				new StreamSource (new MemoryStream (buffer, offset, count));
			Initialize (dictionary, quota, session, onClose);
		}
 public string ToString(IXmlDictionary staticDictionary, XmlBinaryReaderSession readerSession)
 {
     return this.ToString(staticDictionary, readerSession, true);
 }
 public MessagePatterns(IXmlDictionary dictionary, XmlBinaryReaderSession readerSession, MessageVersion messageVersion)
 {
     this.dictionary = dictionary;
     this.readerSession = readerSession;
     this.messageVersion = messageVersion;
 }
Exemple #31
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]).
			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 static XmlDictionaryReader CreateBinaryReader(Stream stream, IXmlDictionary dictionary, XmlDictionaryReaderQuotas quotas, XmlBinaryReaderSession session)
 {
     return CreateBinaryReader(stream, dictionary, quotas, session, null);
 }
            public override ArraySegment<byte> WriteMessage(Message message, int maxMessageSize, BufferManager bufferManager, int messageOffset)
            {
                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,
                        SR.ValueMustBeNonNegative));
                }

                EventTraceActivity eventTraceActivity = null;
                if (WcfEventSource.Instance.BinaryMessageEncodingStartIsEnabled())
                {
                    eventTraceActivity = EventTraceActivityHelper.TryExtractActivity(message);
                    WcfEventSource.Instance.BinaryMessageEncodingStart(eventTraceActivity);
                }

                message.Properties.Encoder = this;

                if (_isSession)
                {
                    if (_writerSession == null)
                    {
                        _writerSession = new XmlBinaryWriterSessionWithQuota(_maxSessionSize);
                        _sessionMessageWriter = new BinaryBufferedMessageWriter(_factory._binaryVersion.Dictionary, _writerSession);
                    }
                    messageOffset += IntEncoder.MaxEncodedSize;
                }

                if (messageOffset < 0)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("messageOffset", messageOffset,
                        SR.ValueMustBeNonNegative));
                }

                if (messageOffset > maxMessageSize)
                {
                    string excMsg = SR.Format(SR.MaxSentMessageSizeExceeded, maxMessageSize);
                    if (WcfEventSource.Instance.MaxSentMessageSizeExceededIsEnabled())
                    {
                        WcfEventSource.Instance.MaxSentMessageSizeExceeded(excMsg);
                    }
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new QuotaExceededException(excMsg));
                }

                ThrowIfMismatchedMessageVersion(message);
                BinaryBufferedMessageWriter messageWriter;
                if (_isSession)
                {
                    messageWriter = _sessionMessageWriter;
                }
                else
                {
                    messageWriter = _factory.TakeBufferedWriter();
                }
                ArraySegment<byte> messageData = messageWriter.WriteMessage(message, bufferManager, messageOffset, maxMessageSize);

                if (MessageLogger.LogMessagesAtTransportLevel && !_readerSessionForLoggingIsInvalid)
                {
                    if (_isSession)
                    {
                        if (_readerSessionForLogging == null)
                        {
                            _readerSessionForLogging = new XmlBinaryReaderSession();
                        }
                        if (_writerSession.HasNewStrings)
                        {
                            foreach (XmlDictionaryString xmlDictionaryString in _writerSession.GetNewStrings())
                            {
                                _readerSessionForLogging.Add(_writeIdCounter++, xmlDictionaryString.Value);
                            }
                        }
                    }
                    XmlDictionaryReader xmlDictionaryReader = XmlDictionaryReader.CreateBinaryReader(messageData.Array, messageData.Offset, messageData.Count, XD.Dictionary, XmlDictionaryReaderQuotas.Max, _readerSessionForLogging);
                    MessageLogger.LogMessage(ref message, xmlDictionaryReader, MessageLoggingSource.TransportSend);
                }
                else
                {
                    _readerSessionForLoggingIsInvalid = true;
                }
                if (_isSession)
                {
                    messageData = AddSessionInformationToMessage(messageData, bufferManager, maxMessageSize);
                }
                else
                {
                    _factory.ReturnMessageWriter(messageWriter);
                }

                CompressionFormat compressionFormat = this.CheckCompressedWrite(message);
                if (compressionFormat != CompressionFormat.None)
                {
                    MessageEncoderCompressionHandler.CompressBuffer(ref messageData, bufferManager, compressionFormat);
                }

                return messageData;
            }
            public override Message ReadMessage(ArraySegment<byte> buffer, BufferManager bufferManager, string contentType)
            {
                if (bufferManager == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("bufferManager");
                }

                CompressionFormat compressionFormat = this.CheckContentType(contentType);

                if (WcfEventSource.Instance.BinaryMessageDecodingStartIsEnabled())
                {
                    WcfEventSource.Instance.BinaryMessageDecodingStart();
                }

                if (compressionFormat != CompressionFormat.None)
                {
                    MessageEncoderCompressionHandler.DecompressBuffer(ref buffer, bufferManager, compressionFormat, _maxReceivedMessageSize);
                }

                if (_isSession)
                {
                    if (_readerSession == null)
                    {
                        _readerSession = new XmlBinaryReaderSession();
                        _messagePatterns = new MessagePatterns(_factory._binaryVersion.Dictionary, _readerSession, this.MessageVersion);
                    }
                    try
                    {
                        buffer = ExtractSessionInformationFromMessage(buffer);
                    }
                    catch (InvalidDataException)
                    {
                        MessageLogger.LogMessage(buffer, MessageLoggingSource.Malformed);
                        throw;
                    }
                }
                BinaryBufferedMessageData messageData = _factory.TakeBufferedData(this);
                Message message;
                if (_messagePatterns != null)
                {
                    message = _messagePatterns.TryCreateMessage(buffer.Array, buffer.Offset, buffer.Count, bufferManager, messageData);
                }
                else
                {
                    message = null;
                }
                if (message == null)
                {
                    messageData.Open(buffer, bufferManager);
                    RecycledMessageState messageState = messageData.TakeMessageState();
                    if (messageState == null)
                    {
                        messageState = new RecycledMessageState();
                    }
                    message = new BufferedMessage(messageData, messageState);
                }
                message.Properties.Encoder = this;

                if (MessageLogger.LogMessagesAtTransportLevel)
                {
                    MessageLogger.LogMessage(ref message, MessageLoggingSource.TransportReceive);
                }

                return message;
            }
 public MessagePatterns(IXmlDictionary dictionary, XmlBinaryReaderSession readerSession, MessageVersion messageVersion)
 {
     _dictionary = dictionary;
     _readerSession = readerSession;
     _messageVersion = messageVersion;
 }
 public void SetInput(byte[] buffer, int offset, int count, IXmlDictionary dictionary, XmlDictionaryReaderQuotas quotas, XmlBinaryReaderSession session, OnXmlDictionaryReaderClose onClose)
 {
     if (buffer == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("buffer");
     }
     if (offset < 0)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("offset", System.Runtime.Serialization.SR.GetString("ValueMustBeNonNegative")));
     }
     if (offset > buffer.Length)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("offset", System.Runtime.Serialization.SR.GetString("OffsetExceedsBufferSize", new object[] { buffer.Length })));
     }
     if (count < 0)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("count", System.Runtime.Serialization.SR.GetString("ValueMustBeNonNegative")));
     }
     if (count > (buffer.Length - offset))
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("count", System.Runtime.Serialization.SR.GetString("SizeExceedsRemainingBufferSpace", new object[] { buffer.Length - offset })));
     }
     this.MoveToInitial(quotas, session, onClose);
     base.BufferReader.SetBuffer(buffer, offset, count, dictionary, session);
     this.buffered = true;
 }
 public void SetBuffer(byte[] buffer, int offset, int count, IXmlDictionary dictionary, XmlBinaryReaderSession session)
 {
     SetBuffer(null, buffer, offset, count, dictionary, session);
 }
 public static XmlDictionaryReader CreateBinaryReader(Stream stream,
                                                      IXmlDictionary dictionary,
                                                      XmlDictionaryReaderQuotas quotas,
                                                      XmlBinaryReaderSession session,
                                                      OnXmlDictionaryReaderClose onClose)
 {
     XmlBinaryReader reader = new XmlBinaryReader();
     reader.SetInput(stream, dictionary, quotas, session, onClose);
     return reader;
 }
Exemple #39
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;
			}
			
			}
		}
		public void ReadMessage ()
		{
			using (var ms = File.OpenRead ("Test/System.ServiceModel.Channels/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);
					}
				}
*/
			}
		}
 public void Close()
 {
     if (streamBuffer != null && streamBuffer.Length > 4096)
     {
         streamBuffer = null;
     }
     if (stream != null)
     {
         stream.Close();
         this.stream = null;
     }
     this.buffer = emptyByteArray;
     this.offset = 0;
     this.offsetMax = 0;
     this.windowOffset = 0;
     this.windowOffsetMax = 0;
     this.dictionary = null;
     this.session = null;
 }
		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
		}
Exemple #43
0
		public static XmlDictionaryReader CreateBinaryReader (
			Stream stream, IXmlDictionary dictionary,
			XmlDictionaryReaderQuotas quotas,
			XmlBinaryReaderSession session,
			OnXmlDictionaryReaderClose onClose)
		{
			return new XmlBinaryDictionaryReader (stream,
				dictionary, quotas, session, onClose);
		}
 public void SetInput(Stream stream, IXmlDictionary dictionary, XmlDictionaryReaderQuotas quotas, XmlBinaryReaderSession session, OnXmlDictionaryReaderClose onClose)
 {
     if (stream == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("stream");
     }
     this.MoveToInitial(quotas, session, onClose);
     base.BufferReader.SetBuffer(stream, dictionary, session);
     this.buffered = false;
 }
        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();
        }