public override Message ReadMessage(Stream stream, int maxSizeOfHeaders, string contentType) { if (stream == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("stream")); } WebContentFormat format = GetFormatForContentType(contentType); Message message; switch (format) { case WebContentFormat.Json: message = JsonMessageEncoder.ReadMessage(stream, maxSizeOfHeaders, contentType); message.Properties.Add(WebBodyFormatMessageProperty.Name, WebBodyFormatMessageProperty.JsonProperty); break; case WebContentFormat.Xml: message = TextMessageEncoder.ReadMessage(stream, maxSizeOfHeaders, contentType); message.Properties.Add(WebBodyFormatMessageProperty.Name, WebBodyFormatMessageProperty.XmlProperty); break; case WebContentFormat.Raw: message = RawMessageEncoder.ReadMessage(stream, maxSizeOfHeaders, contentType); message.Properties.Add(WebBodyFormatMessageProperty.Name, WebBodyFormatMessageProperty.RawProperty); break; default: throw Fx.AssertAndThrow("This should never get hit because GetFormatForContentType shouldn't return a WebContentFormat other than Json, Xml, and Raw"); } return(message); }
public TextMessageEncoderFactory( TextMessageEncodingBindingElement owner) { this.owner = owner; encoder = new TextMessageEncoder( MessageVersion, owner.WriteEncoding); }
public WriteMessageAsyncResult(Message message, Stream stream, TextMessageEncoder textEncoder, AsyncCallback callback, object state) : base(callback, state) { this.message = message; this.textEncoder = textEncoder; this.xmlWriter = textEncoder.TakeStreamedWriter(stream); this.eventTraceActivity = null; if (TD.TextMessageEncodingStartIsEnabled()) { this.eventTraceActivity = EventTraceActivityHelper.TryExtractActivity(message); TD.TextMessageEncodingStart(this.eventTraceActivity); } if (!textEncoder.optimizeWriteForUTF8) { xmlWriter.WriteStartDocument(); } IAsyncResult result = message.BeginWriteMessage(this.xmlWriter, PrepareAsyncCompletion(onWriteMessage), this); if (SyncContinue(result)) { this.Complete(true); } }
public UTF8BufferedMessageData(TextMessageEncoder messageEncoder, int maxReaderPoolSize) : base(messageEncoder.RecycledStatePool) { this.messageEncoder = messageEncoder; readerPool = new Pool <XmlDictionaryReader>(maxReaderPoolSize); onClose = new OnXmlDictionaryReaderClose(OnXmlReaderClosed); }
public HttpChannelFactory(HttpTransportBindingElement source, BindingContext ctx) : base(source, ctx) { ClientCredentials = ctx.BindingParameters.Find <ClientCredentials> (); foreach (BindingElement be in ctx.Binding.Elements) { MessageEncodingBindingElement mbe = be as MessageEncodingBindingElement; if (mbe != null) { MessageEncoder = CreateEncoder <TChannel> (mbe); break; } #if NET_2_1 var cbe = be as HttpCookieContainerBindingElement; if (cbe != null) { cookie_manager = cbe.GetProperty <IHttpCookieContainerManager> (ctx); } #endif } if (MessageEncoder == null) { MessageEncoder = new TextMessageEncoder(MessageVersion.Default, Encoding.UTF8); } }
public TextMessageEncoderFactory ( TextMessageEncodingBindingElement owner) { this.owner = owner; encoder = new TextMessageEncoder ( MessageVersion, owner.WriteEncoding); }
public override ArraySegment <byte> WriteMessage(Message message, int maxMessageSize, BufferManager bufferManager, int messageOffset) { if (message == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("message")); } if (bufferManager == null) { throw TraceUtility.ThrowHelperError(new ArgumentNullException("bufferManager"), message); } if (maxMessageSize < 0) { throw TraceUtility.ThrowHelperError(new ArgumentOutOfRangeException("maxMessageSize", maxMessageSize, SR2.GetString(SR2.ValueMustBeNonNegative)), message); } if (messageOffset < 0 || messageOffset > maxMessageSize) { throw TraceUtility.ThrowHelperError(new ArgumentOutOfRangeException("messageOffset", messageOffset, SR2.GetString(SR2.JsonValueMustBeInRange, 0, maxMessageSize)), message); } ThrowIfMismatchedMessageVersion(message); WebContentFormat messageFormat = ExtractFormatFromMessage(message); JavascriptCallbackResponseMessageProperty javascriptResponseMessageProperty; switch (messageFormat) { case WebContentFormat.Json: return(JsonMessageEncoder.WriteMessage(message, maxMessageSize, bufferManager, messageOffset)); case WebContentFormat.Xml: if (message.Properties.TryGetValue <JavascriptCallbackResponseMessageProperty>(JavascriptCallbackResponseMessageProperty.Name, out javascriptResponseMessageProperty) && javascriptResponseMessageProperty != null && !String.IsNullOrEmpty(javascriptResponseMessageProperty.CallbackFunctionName)) { throw TraceUtility.ThrowHelperError(new InvalidOperationException(SR2.JavascriptCallbackNotsupported), message); } return(TextMessageEncoder.WriteMessage(message, maxMessageSize, bufferManager, messageOffset)); case WebContentFormat.Raw: if (message.Properties.TryGetValue <JavascriptCallbackResponseMessageProperty>(JavascriptCallbackResponseMessageProperty.Name, out javascriptResponseMessageProperty) && javascriptResponseMessageProperty != null && !String.IsNullOrEmpty(javascriptResponseMessageProperty.CallbackFunctionName)) { throw TraceUtility.ThrowHelperError(new InvalidOperationException(SR2.JavascriptCallbackNotsupported), message); } return(RawMessageEncoder.WriteMessage(message, maxMessageSize, bufferManager, messageOffset)); default: throw Fx.AssertAndThrow("This should never get hit because GetFormatForContentType shouldn't return a WebContentFormat other than Json, Xml, and Raw"); } }
WebContentFormat GetFormatForContentType(string contentType) { WebContentFormat messageFormat; if (TryGetContentTypeMapping(contentType, out messageFormat) && (messageFormat != WebContentFormat.Default)) { if (DiagnosticUtility.ShouldTraceInformation) { if (string.IsNullOrEmpty(contentType)) { contentType = "<null>"; } TraceUtility.TraceEvent(TraceEventType.Information, TraceCode.RequestFormatSelectedFromContentTypeMapper, SR2.GetString(SR2.TraceCodeRequestFormatSelectedFromContentTypeMapper, messageFormat.ToString(), contentType)); } return(messageFormat); } // Don't pass on null content types to IsContentTypeSupported methods -- they might throw. // If null content type isn't already mapped, return the default format of Raw. if (contentType == null) { messageFormat = WebContentFormat.Raw; } else if (JsonMessageEncoder.IsContentTypeSupported(contentType)) { messageFormat = WebContentFormat.Json; } else if (TextMessageEncoder.IsContentTypeSupported(contentType)) { messageFormat = WebContentFormat.Xml; } else { messageFormat = WebContentFormat.Raw; } if (DiagnosticUtility.ShouldTraceInformation) { TraceUtility.TraceEvent(TraceEventType.Information, TraceCode.RequestFormatSelectedByEncoderDefaults, SR2.GetString(SR2.TraceCodeRequestFormatSelectedByEncoderDefaults, messageFormat.ToString(), contentType)); } return(messageFormat); }
public override void WriteMessage(Message message, Stream stream) { if (message == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("message")); } if (stream == null) { throw TraceUtility.ThrowHelperError(new ArgumentNullException("stream"), message); } ThrowIfMismatchedMessageVersion(message); WebContentFormat messageFormat = ExtractFormatFromMessage(message); JavascriptCallbackResponseMessageProperty javascriptResponseMessageProperty; switch (messageFormat) { case WebContentFormat.Json: JsonMessageEncoder.WriteMessage(message, stream); break; case WebContentFormat.Xml: if (message.Properties.TryGetValue <JavascriptCallbackResponseMessageProperty>(JavascriptCallbackResponseMessageProperty.Name, out javascriptResponseMessageProperty) && javascriptResponseMessageProperty != null && !String.IsNullOrEmpty(javascriptResponseMessageProperty.CallbackFunctionName)) { throw TraceUtility.ThrowHelperError(new InvalidOperationException(SR2.JavascriptCallbackNotsupported), message); } TextMessageEncoder.WriteMessage(message, stream); break; case WebContentFormat.Raw: if (message.Properties.TryGetValue <JavascriptCallbackResponseMessageProperty>(JavascriptCallbackResponseMessageProperty.Name, out javascriptResponseMessageProperty) && javascriptResponseMessageProperty != null && !String.IsNullOrEmpty(javascriptResponseMessageProperty.CallbackFunctionName)) { throw TraceUtility.ThrowHelperError(new InvalidOperationException(SR2.JavascriptCallbackNotsupported), message); } RawMessageEncoder.WriteMessage(message, stream); break; default: throw Fx.AssertAndThrow("This should never get hit because GetFormatForContentType shouldn't return a WebContentFormat other than Json, Xml, and Raw"); } }
public HttpChannelListenerBase(HttpTransportBindingElement source, BindingContext context) : base(context) { if (ServiceHostBase.CurrentServiceHostHack != null) { DispatcherBuilder.ChannelDispatcherSetter = delegate(ChannelDispatcher cd) { this.ChannelDispatcher = cd; } } ; this.Source = source; // The null Uri check looks weird, but it seems the listener can be built without it. // See HttpTransportBindingElementTest.BuildChannelListenerWithoutListenUri(). if (Uri != null && source.Scheme != Uri.Scheme) { throw new ArgumentException(String.Format("Requested listen uri scheme must be {0}, but was {1}.", source.Scheme, Uri.Scheme)); } foreach (BindingElement be in context.Binding.Elements) { MessageEncodingBindingElement mbe = be as MessageEncodingBindingElement; if (mbe != null) { MessageEncoder = CreateEncoder <TChannel> (mbe); break; } } if (MessageEncoder == null) { MessageEncoder = new TextMessageEncoder(MessageVersion.Default, Encoding.UTF8); } if (context.BindingParameters.Contains(typeof(ServiceCredentials))) { SecurityTokenManager = new ServiceCredentialsSecurityTokenManager((ServiceCredentials)context.BindingParameters [typeof(ServiceCredentials)]); } }
public TextBufferedMessageWriter(TextMessageEncoder messageEncoder) { _messageEncoder = messageEncoder; }
public UTF8BufferedMessageData(TextMessageEncoder messageEncoder, int maxReaderPoolSize) : base(messageEncoder.RecycledStatePool) { _messageEncoder = messageEncoder; }
public TextMessageEncoderFactory(MessageVersion version, Encoding writeEncoding, int maxReadPoolSize, int maxWritePoolSize, XmlDictionaryReaderQuotas quotas) { _messageEncoder = new TextMessageEncoder(version, writeEncoding, maxReadPoolSize, maxWritePoolSize, quotas); }
public TextMessageEncoderFactory(System.ServiceModel.Channels.MessageVersion version, Encoding writeEncoding, int maxReadPoolSize, int maxWritePoolSize, XmlDictionaryReaderQuotas quotas) { this.messageEncoder = new TextMessageEncoder(version, writeEncoding, maxReadPoolSize, maxWritePoolSize, quotas); }
public UTF8BufferedMessageData(TextMessageEncoder messageEncoder, int maxReaderPoolSize) : base(messageEncoder.RecycledStatePool) { _messageEncoder = messageEncoder; }
public TextMessageEncoderFactory(MessageVersion version, Encoding writeEncoding, int maxReadPoolSize, int maxWritePoolSize, XmlDictionaryReaderQuotas quotas) { messageEncoder = new TextMessageEncoder(version, writeEncoding, maxReadPoolSize, maxWritePoolSize, quotas); }
public WriteMessageAsyncResult(Message message, Stream stream, TextMessageEncoder textEncoder, AsyncCallback callback, object state) : base(callback, state) { this.message = message; this.textEncoder = textEncoder; this.xmlWriter = textEncoder.TakeStreamedWriter(stream); this.eventTraceActivity = null; if (TD.TextMessageEncodingStartIsEnabled()) { this.eventTraceActivity = EventTraceActivityHelper.TryExtractActivity(message); TD.TextMessageEncodingStart(this.eventTraceActivity); } if (!textEncoder.optimizeWriteForUTF8) { xmlWriter.WriteStartDocument(); } IAsyncResult result = message.BeginWriteMessage(this.xmlWriter, PrepareAsyncCompletion(onWriteMessage), this); if (SyncContinue(result)) { this.Complete(true); } }
public UTF8BufferedMessageData(TextMessageEncoder messageEncoder, int maxReaderPoolSize) : base(messageEncoder.RecycledStatePool) { this.messageEncoder = messageEncoder; readerPool = new Pool<XmlDictionaryReader>(maxReaderPoolSize); onClose = new OnXmlDictionaryReaderClose(OnXmlReaderClosed); }
public override bool IsContentTypeSupported(string contentType) { if (contentType == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("contentType"); } WebContentFormat messageFormat; if (TryGetContentTypeMapping(contentType, out messageFormat) && (messageFormat != WebContentFormat.Default)) { return(true); } return(RawMessageEncoder.IsContentTypeSupported(contentType) || JsonMessageEncoder.IsContentTypeSupported(contentType) || TextMessageEncoder.IsContentTypeSupported(contentType)); }
public TextBufferedMessageWriter(TextMessageEncoder messageEncoder) { this.messageEncoder = messageEncoder; }