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"); } }
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"); } }