/// <summary> /// Extracts the service query and original message body from <paramref name="message"/> . /// May create a new message with the original body contents. /// </summary> /// <param name="message">The message to use for deserialization.</param> /// <returns>The extracted service query.</returns> /// <remarks>The message passed in will not be disposed. This message belongs to the /// caller.</remarks> internal static ServiceQuery GetServiceQuery(ref Message message) { ServiceQuery serviceQuery = null; if (!message.IsEmpty) { XmlDictionaryReader reader = message.GetReaderAtBodyContents(); // If the message root is not <MessageRoot> then the message does not contain QueryOptions. // So re-write the stream back to a message. if (reader.IsStartElement(MessageUtility.MessageRootElementName)) { // Go to the <QueryOptions> node. reader.Read(); // <MessageRoot> reader.ReadStartElement(MessageUtility.QueryOptionsListElementName); // <QueryOptions> serviceQuery = MessageUtility.ReadServiceQuery(reader); // <QueryOption></QueryOption> // Go to the starting node of the original message. reader.ReadEndElement(); // </QueryOptions> reader = XmlDictionaryReader.CreateDictionaryReader(reader.ReadSubtree()); // Remainder of the message } // Note: we must use this overload to get a streamed message. This incurs the least // cost on GetReaderAtBodyContents which is the most expensive call in this path. // Note: We do not care about the new message enforcing the max size of headers // since it has already been enforced with the old message. Message newMessage = Message.CreateMessage(reader, Int32.MaxValue, message.Version); newMessage.Headers.CopyHeadersFrom(message); newMessage.Properties.CopyProperties(message.Properties); message = newMessage; } return(serviceQuery); }
public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext) { int headerPosition = request.Headers.FindHeader(QueryHeaderName, QueryHeaderNamespace); if (headerPosition > -1) { XmlDictionaryReader reader = request.Headers.GetReaderAtHeader(headerPosition); ServiceQuery serviceQuery = MessageUtility.ReadServiceQuery(reader); request.Properties[QueryPropertyName] = serviceQuery; } return(null); }
public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext) { int headerPosition = request.Headers.FindHeader(QueryHeaderName, QueryHeaderNamespace); if (headerPosition > -1) { XmlDictionaryReader reader = request.Headers.GetReaderAtHeader(headerPosition); // Advance to contents, ReadServiceQuery expect to be on the QueryOption if (reader.IsStartElement(QueryPropertyName)) { reader.Read(); } ServiceQuery serviceQuery = MessageUtility.ReadServiceQuery(reader); request.Properties[QueryPropertyName] = serviceQuery; } return(null); }