public MultiplexingFormatMapping(Encoding writeEncoding, WebContentTypeMapper contentTypeMapper) { if (writeEncoding == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("writeEncoding"); } this.writeEncoding = writeEncoding; this.writeCharset = TextEncoderDefaults.EncodingToCharSet(writeEncoding); this.contentTypeMapper = contentTypeMapper; }
internal static WebContentTypeMapper GetContentTypeMapper(string contentTypeMapperType) { WebContentTypeMapper contentTypeMapper = null; if (!string.IsNullOrEmpty(contentTypeMapperType)) { Type type = System.Type.GetType(contentTypeMapperType, true); if (!WebContentTypeMapperType.IsAssignableFrom(type)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException( SR2.GetString(SR2.ConfigInvalidWebContentTypeMapperType, contentTypeMapperType, WebContentTypeMapperType.ToString()))); } contentTypeMapper = (WebContentTypeMapper)Activator.CreateInstance(type); } return(contentTypeMapper); }
public static CustomBinding AddContentMapper(this Binding model, WebContentTypeMapper mapper) { var binding = new CustomBinding(); // Add in the encoding binding binding.Elements.Add(new WebMessageEncodingBindingElement() { ContentTypeMapper = mapper }); // Add in the binding elements from the root binding, skipping the encoding foreach (var item in model.CreateBindingElements() .Where(item => !(item is WebMessageEncodingBindingElement)) // We need to keep ours .Where(item => !(item is TextMessageEncodingBindingElement))) // We don't want these (replace with WebMessage) { binding.Elements.Add(item); } return(binding); }
public JsonFormatMapping(Encoding writeEncoding, WebContentTypeMapper contentTypeMapper) : base(writeEncoding, contentTypeMapper) { }