protected override void OnWriteStartAddressHeader(XmlDictionaryWriter writer)
 {
     XmlDictionaryReader addressHeaderReader = this.GetAddressHeaderReader();
     writer.WriteStartElement(addressHeaderReader.Prefix, addressHeaderReader.LocalName, addressHeaderReader.NamespaceURI);
     writer.WriteAttributes(addressHeaderReader, false);
     addressHeaderReader.Close();
 }
 protected override void OnWriteStartHeader(XmlDictionaryWriter writer, MessageVersion messageVersion)
 {
     if (!this.IsMessageVersionSupported(messageVersion))
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(System.ServiceModel.SR.GetString("MessageHeaderVersionNotSupported", new object[] { base.GetType().FullName, messageVersion.ToString() }), "version"));
     }
     XmlDictionaryReader headerReader = this.GetHeaderReader();
     writer.WriteStartElement(headerReader.Prefix, headerReader.LocalName, headerReader.NamespaceURI);
     writer.WriteAttributes(headerReader, false);
     headerReader.Close();
 }
        protected override void OnWriteStartBody(XmlDictionaryWriter writer)
        {
            if (this.state == BodyState.Created)
            {
                this.InnerMessage.WriteStartBody(writer);
                return;
            }

            XmlDictionaryReader reader = CreateFullBodyReader();
            reader.MoveToContent();
            writer.WriteStartElement(reader.Prefix, reader.LocalName, reader.NamespaceURI);
            writer.WriteAttributes(reader, false);
            reader.Close();
        }
            protected override void OnWriteBodyContents(XmlDictionaryWriter writer)
            {
                XmlDictionaryReader reader = this.originalMessage.GetReaderAtBodyContents();

                // Write root StartElement
                writer.WriteStartElement(reader.Prefix, reader.LocalName, reader.NamespaceURI);
                writer.WriteAttributes(reader, true);
                reader.ReadStartElement();

                // Write QueryResult StartElement
                writer.WriteStartElement(reader.Prefix, reader.LocalName, reader.NamespaceURI);
                writer.WriteAttributes(reader, true);

                // Write QueryResult content
                string nodeName = reader.LocalName;
                reader.Read();

                while (reader.NodeType != XmlNodeType.EndElement || reader.Name != nodeName)
                {
                    XmlReader subtree = reader.ReadSubtree();
                    writer.WriteNode(subtree, false);
                    reader.ReadEndElement();
                }

                // Insert metadata start
                writer.WriteStartElement("Metadata");
                writer.WriteAttributeString("type", "array");
                // This two foreach loops are to ensure we write the return entity of the query first, then all the rest.
                // This is a requirement of the RIA/JS client side implementation. If modifying this, client side needs update too.
                foreach (ServiceMetadataGenerator.TypeMetadata map in ServiceMetadataGenerator.EntitiesMetadata)
                {
                    if (map.Name == this.entityTypeName)
                    {
                        writer.WriteStartElement("item");
                        writer.WriteAttributeString("type", "object");
                        map.WriteJson(writer);
                        writer.WriteEndElement();
                        break;
                    }
                }
                foreach (ServiceMetadataGenerator.TypeMetadata map in ServiceMetadataGenerator.EntitiesMetadata)
                {
                    if (map.Name != this.entityTypeName)
                    {
                        writer.WriteStartElement("item");
                        writer.WriteAttributeString("type", "object");
                        map.WriteJson(writer);
                        writer.WriteEndElement();
                    }
                }
                writer.WriteEndElement();
                // Insert metadata end

                // Close QueryResult
                writer.WriteEndElement();
                // Close root
                writer.WriteEndElement();
            }
Пример #5
0
 protected override void OnWriteStartHeader(XmlDictionaryWriter writer, MessageVersion messageVersion)
 {
     if (!IsMessageVersionSupported(messageVersion))
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.Format(SR.MessageHeaderVersionNotSupported, this.GetType().FullName, messageVersion.ToString()), "version"));
     XmlDictionaryReader reader = GetHeaderReader();
     writer.WriteStartElement(reader.Prefix, reader.LocalName, reader.NamespaceURI);
     writer.WriteAttributes(reader, false);
     reader.Dispose();
 }
Пример #6
0
 public override void WriteObjectContent(XmlDictionaryWriter writer, object graph)
 {
     if (writer == null) throw new ArgumentNullException("writer");
     if (writer.WriteState != WriteState.Element)
         throw new SerializationException(string.Format("WriteState '{0}' not valid. Caller must write start element before serializing in contentOnly mode.",
             writer.WriteState));
     using (MemoryStream memoryStream = new MemoryStream())
     {
         using (XmlDictionaryWriter bufferWriter = XmlDictionaryWriter.CreateTextWriter(memoryStream, Encoding.UTF8))
         {
             serializer.Serialize(bufferWriter, graph);
             bufferWriter.Flush();
             memoryStream.Position = 0;
             using (XmlReader reader = new XmlTextReader(memoryStream))
             {
                 reader.MoveToContent();
                 writer.WriteAttributes(reader, false);
                 if (reader.Read()) // move off start node (we want to skip it)
                 {
                     while (reader.NodeType != XmlNodeType.EndElement) // also skip end node.
                         writer.WriteNode(reader, false); // this will take us to the start of the next child node, or the end node.
                     reader.ReadEndElement(); // not necessary, but clean
                 }
             }
         }
     }
 }
        protected override void OnWriteStartBody(XmlDictionaryWriter writer)
        {
            if (this.startBodyFragment != null || this.fullBodyFragment != null)
            {
                WriteStartInnerMessageWithId(writer);
                return;
            }

            switch (this.state)
            {
                case BodyState.Created:
                case BodyState.Encrypted:
                    this.InnerMessage.WriteStartBody(writer);
                    return;
                case BodyState.Signed:
                case BodyState.EncryptedThenSigned:
                    XmlDictionaryReader reader = fullBodyBuffer.GetReader(0);
                    writer.WriteStartElement(reader.Prefix, reader.LocalName, reader.NamespaceURI);
                    writer.WriteAttributes(reader, false);
                    reader.Close();
                    return;
                case BodyState.SignedThenEncrypted:
                    writer.WriteStartElement(this.bodyPrefix, XD.MessageDictionary.Body, this.Version.Envelope.DictionaryNamespace);
                    if (this.bodyAttributes != null)
                    {
                        XmlAttributeHolder.WriteAttributes(this.bodyAttributes, writer);
                    }
                    return;
                default:
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateBadStateException("OnWriteStartBody"));
            }
        }
Пример #8
0
 public override void WriteAttributes(XmlReader reader, bool defattr)
 {
     writer.WriteAttributes(reader, defattr);
 }
 protected override void OnWriteStartHeaders(XmlDictionaryWriter writer)
 {
     using (XmlDictionaryReader reader = this.GetMessageReader())
     {
         reader.MoveToContent();
         EnvelopeVersion envelope = this.Version.Envelope;
         reader.Read();
         if (ReceivedMessage.HasHeaderElement(reader, envelope))
         {
             writer.WriteStartElement(reader.Prefix, "Header", envelope.Namespace);
             writer.WriteAttributes(reader, false);
         }
         else
         {
             writer.WriteStartElement("s", "Header", envelope.Namespace);
         }
     }
 }
 protected override void OnWriteStartEnvelope(XmlDictionaryWriter writer)
 {
     using (XmlDictionaryReader reader = this.GetMessageReader())
     {
         reader.MoveToContent();
         EnvelopeVersion envelope = this.Version.Envelope;
         writer.WriteStartElement(reader.Prefix, "Envelope", envelope.Namespace);
         writer.WriteAttributes(reader, false);
     }
 }
 protected override void OnWriteStartBody(XmlDictionaryWriter writer)
 {
     using (XmlDictionaryReader reader = this.GetBufferedReaderAtBody())
     {
         writer.WriteStartElement(reader.Prefix, "Body", this.Version.Envelope.Namespace);
         writer.WriteAttributes(reader, false);
     }
 }
        protected override void OnWriteStartBody(XmlDictionaryWriter writer)
        {
            if ((this.startBodyFragment != null) || (this.fullBodyFragment != null))
            {
                this.WriteStartInnerMessageWithId(writer);
            }
            else
            {
                switch (this.state)
                {
                    case BodyState.Created:
                    case BodyState.Encrypted:
                        base.InnerMessage.WriteStartBody(writer);
                        return;

                    case BodyState.Signed:
                    case BodyState.EncryptedThenSigned:
                    {
                        XmlDictionaryReader reader = this.fullBodyBuffer.GetReader(0);
                        writer.WriteStartElement(reader.Prefix, reader.LocalName, reader.NamespaceURI);
                        writer.WriteAttributes(reader, false);
                        reader.Close();
                        return;
                    }
                    case BodyState.SignedThenEncrypted:
                        writer.WriteStartElement(this.bodyPrefix, System.ServiceModel.XD.MessageDictionary.Body, this.Version.Envelope.DictionaryNamespace);
                        if (this.bodyAttributes != null)
                        {
                            System.IdentityModel.XmlAttributeHolder.WriteAttributes(this.bodyAttributes, writer);
                        }
                        return;
                }
                throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(this.CreateBadStateException("OnWriteStartBody"));
            }
        }
Пример #13
0
 protected override void OnWriteStartBody(XmlDictionaryWriter writer)
 {
     switch (this.state)
     {
         case BodyState.Created:
             this.InnerMessage.WriteStartBody(writer);
             return;
         case BodyState.Signed:
             using (XmlDictionaryReader reader = Utility.CreateReader(this.fullBodyBuffer))
             {
                 reader.MoveToStartElement();
                 writer.WriteStartElement(reader.Prefix, reader.LocalName, reader.NamespaceURI);
                 writer.WriteAttributes(reader, false);
             }
             return;
         default:
             throw new ArgumentException("Can't write the message because it is in a bad or unknown state");
     }
 }
Пример #14
0
        /// <summary>
        /// Writes header attributes.
        /// </summary>
        /// <param name="writer">The writer.</param>
        /// <param name="messageVersion">The message version.</param>
        /// <exception cref="System.ArgumentNullException">
        /// writer
        /// or
        /// messageVersion
        /// </exception>
        /// <exception cref="ArgumentNullException">The <paramref name="writer"/> parameter is null.</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="messageVersion"/> parameter is null.</exception>
        protected void OnWriteHeaderAttributes(XmlDictionaryWriter writer, MessageVersion messageVersion)
        {
            if (writer == null)
                throw new ArgumentNullException("writer");

            if (messageVersion == null)
                throw new ArgumentNullException("messageVersion");

            WriteHeaderAttributes(writer, messageVersion);
            using (var xmlNodeReader = new XmlNodeReader(_headerValue))
            {
                using (var reader = XmlDictionaryReader.CreateDictionaryReader(xmlNodeReader))
                {
                    reader.MoveToContent();
                    writer.WriteAttributes(reader, false);
                }
            }
        }