/// <summary> /// Parses a collection of query string values as a <see cref="System.Json.JsonObject"/>. /// </summary> /// <param name="queryStringValues">The collection of query string values.</param> /// <param name="maxDepth">The maximum depth of object graph encoded as x-www-form-urlencoded.</param> /// <returns>The <see cref="System.Json.JsonObject"/> corresponding to the given query string values.</returns> internal static JsonObject ParseFormUrlEncoded(IEnumerable <Tuple <string, string> > queryStringValues, int maxDepth) { DiagnosticUtility.ExceptionUtility.ThrowOnNull(queryStringValues, "queryString"); return(FormUrlEncodedExtensions.Parse(queryStringValues, maxDepth)); }
public void DeserializeRequest(Message message, object[] parameters) { JsonValue jsonValue = null; bool isJsonInput = false; if (message != null) { if (message.IsEmpty) { Encoding contentEncoding; if (IsContentTypeSupported(WebOperationContext.Current.IncomingRequest.ContentType, ApplicationJsonContentType, out contentEncoding)) { isJsonInput = true; jsonValue = null; } } else if (message.Properties.ContainsKey(WebBodyFormatMessageProperty.Name)) { WebBodyFormatMessageProperty bodyFormatProperty = (WebBodyFormatMessageProperty)message.Properties[WebBodyFormatMessageProperty.Name]; if (bodyFormatProperty.Format == WebContentFormat.Json) { isJsonInput = true; jsonValue = DeserializeFromJXML(message); } } } if (!isJsonInput) { Encoding contentEncoding; if (!IsContentTypeSupported(WebOperationContext.Current.IncomingRequest.ContentType, FormUrlEncodedContentType, out contentEncoding)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.ExpectUrlEncodedOrJson)); } string formData = string.Empty; if (message != null && !message.IsEmpty) { XmlDictionaryReader bodyReader = message.GetReaderAtBodyContents(); bodyReader.ReadStartElement(BinaryElementName); using (Stream s = new MemoryStream(bodyReader.ReadContentAsBase64())) { if (contentEncoding == null) { formData = new StreamReader(s).ReadToEnd(); } else { formData = new StreamReader(s, contentEncoding).ReadToEnd(); } } } jsonValue = FormUrlEncodedExtensions.ParseFormUrlEncoded(formData, this.readerQuotas.MaxDepth); } UriTemplateMatch match = WebOperationContext.Current.IncomingRequest.UriTemplateMatch; MessagePartDescriptionCollection messageParts = this.operationDescription.Messages[0].Body.Parts; Func <MessagePartDescription, object> binder = this.CreateParameterBinder(match); object[] values = messageParts.Select(p => binder(p)).ToArray(); values[this.jsonValuePosition] = jsonValue; values.CopyTo(parameters, 0); }