Пример #1
0
        public virtual async Task WriteMessageAsync(Message message, PipeWriter pipeWriter)
        {
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            if (pipeWriter == null)
            {
                throw new ArgumentNullException(nameof(pipeWriter));
            }

            ThrowIfMismatchedMessageVersion(message);

            using var bufferTextWriter = new BufferTextWriter(pipeWriter, _writeEncoding);
            using var xmlTextWriter    = XmlWriter.Create(bufferTextWriter, new XmlWriterSettings
            {
                OmitXmlDeclaration = _optimizeWriteForUtf8 && _omitXmlDeclaration,                 //can only omit if utf-8
                Indent             = _indentXml,
                Encoding           = _writeEncoding
            });
            var xmlWriter = XmlDictionaryWriter.CreateDictionaryWriter(xmlTextWriter);

            WriteXmlCore(message, xmlWriter);

            await pipeWriter.FlushAsync();
        }
Пример #2
0
        public virtual async Task WriteMessageAsync(Message message, PipeWriter pipeWriter)
        {
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            if (pipeWriter == null)
            {
                throw new ArgumentNullException(nameof(pipeWriter));
            }

            ThrowIfMismatchedMessageVersion(message);

            using var bufferTextWriter = new BufferTextWriter(pipeWriter, _writeEncoding);
            using var xmlTextWriter    = new XmlTextWriter(bufferTextWriter);

            var xmlWriter = XmlDictionaryWriter.CreateDictionaryWriter(xmlTextWriter);

            if (_optimizeWriteForUtf8)
            {
                message.WriteMessage(xmlWriter);
            }
            else
            {
                xmlWriter.WriteStartDocument();
                message.WriteMessage(xmlWriter);
                xmlWriter.WriteEndDocument();
            }

            xmlWriter.Flush();
            xmlWriter.Dispose();

            await pipeWriter.FlushAsync();
        }