/// <summary> /// Deserializes the message into requests parameters. Also parses query parameters /// from the request and stores the results in the original message. /// </summary> /// <param name="message">The incoming message to deserialize.</param> /// <param name="parameters">The parameters that are passed to the query operation. /// </param> void IDispatchMessageFormatter.DeserializeRequest(Message message, object[] parameters) { Message originalMessage = message; var isPost = MessageUtility.IsHttpPOSTMethod(message.Properties); // If user tried to GET a query with side-effects then fail // Note: This should never ever happen since it would fail earlier in the WCF pipeline since the method should be "POST"-only if (_queryHasSideEffects && !isPost) { throw new FaultException("Must use POST to for queries with side effects"); } if (isPost) { // If the HTTP Method is POST, get the query from the message body instead from the URL ServiceQuery serviceQuery = MessageUtility.GetServiceQuery(ref message); if (serviceQuery != null) { // Since a new message is returned by the GetServiceQueryFromMessageBody, the OperationContext does not find the property // if set on the new message. So we set the property directly on the current OperationContext IncomingMessageProperties. OperationContext.Current.IncomingMessageProperties[ServiceQuery.QueryPropertyName] = serviceQuery; } } else if (!String.IsNullOrEmpty(message.Properties.Via.Query)) { string query = HttpUtility.UrlDecode(message.Properties.Via.Query); string fullRequestUrl = HttpUtility.UrlDecode(HttpContext.Current.Request.RawUrl); message.Properties[ServiceQuery.QueryPropertyName] = DomainServiceWebHttpBehavior.GetServiceQuery(query, fullRequestUrl); } try { this._innerDispatchMessageFormatter.DeserializeRequest(message, parameters); } finally { // The original message belongs to the service model pipeline. We cannot // dispose it. On the other hand we could have just created a new message. If // that is the case we are responsible for disposing the new message. if (message != originalMessage) { message.Properties.Clear(); message.Headers.Clear(); message.Close(); } } }
public void GetElementsFromBodyTest_NoServiceQuery() { Message originalMessage; Message message; originalMessage = message = GetSampleMessage(false); ServiceQuery serviceQuery = MessageUtility.GetServiceQuery(ref message); // no service query Assert.AreEqual(null, serviceQuery, "service query not null"); // the message did not change, it should compare XmlDictionaryReader reader = MessageUtilityTest.CreateReaderFromMessage(message); MessageUtilityTest.CompareSampleMessage(reader); // cleanup reader.Close(); originalMessage.Close(); }
public void GetElementsFromBodyTest_WithServiceQuery() { Message originalMessage; Message message; originalMessage = message = GetSampleMessage(true); ServiceQuery serviceQuery = MessageUtility.GetServiceQuery(ref message); Assert.IsNotNull(serviceQuery); Assert.AreEqual(2, serviceQuery.QueryParts.Count()); ServiceQueryPart[] parts = serviceQuery.QueryParts.ToArray(); Assert.AreEqual(parts[0].ToString(), @"where=(it.City.StartsWith(""R"")&&(it.AddressID<400))"); Assert.AreEqual(parts[1].ToString(), "orderby=it.AddressId"); Assert.AreEqual(true, serviceQuery.IncludeTotalCount); Assert.AreEqual(2, serviceQuery.QueryParts.Count()); XmlDictionaryReader reader = MessageUtilityTest.CreateReaderFromMessage(message); MessageUtilityTest.CompareSampleMessage(reader); // cleanup reader.Close(); originalMessage.Close(); }