Inheritance: MessageEncoder
Example #1
0
                public WriteMessageAsyncResult(Message message, Stream stream, WebMessageEncoder webMessageEncoder, AsyncCallback callback, object state)
                    : base(callback, state)
                {
                    this.message           = message;
                    this.stream            = stream;
                    this.webMessageEncoder = webMessageEncoder;

                    WebContentFormat messageFormat = webMessageEncoder.ExtractFormatFromMessage(message);
                    JavascriptCallbackResponseMessageProperty javascriptResponseMessageProperty;

                    switch (messageFormat)
                    {
                    case WebContentFormat.Json:
                        this.encoder = webMessageEncoder.JsonMessageEncoder;
                        this.Schedule();
                        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);
                        }
                        this.encoder = webMessageEncoder.TextMessageEncoder;
                        this.Schedule();
                        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);
                        }

                        handleEndWriteMessage = new AsyncCompletion(HandleEndWriteMessage);
                        IAsyncResult result = webMessageEncoder.RawMessageEncoder.BeginWriteMessage(message, stream, PrepareAsyncCompletion(HandleEndWriteMessage), this);
                        if (SyncContinue(result))
                        {
                            this.Complete(true);
                        }
                        break;

                    default:
                        throw Fx.AssertAndThrow("This should never get hit because GetFormatForContentType shouldn't return a WebContentFormat other than Json, Xml, and Raw");
                    }
                }
                public WriteMessageAsyncResult(Message message, Stream stream, WebMessageEncoder webMessageEncoder, AsyncCallback callback, object state)
                    : base(callback, state)
                {
                    this.message = message;
                    this.stream = stream;
                    this.webMessageEncoder = webMessageEncoder;

                    WebContentFormat messageFormat = webMessageEncoder.ExtractFormatFromMessage(message);
                    JavascriptCallbackResponseMessageProperty javascriptResponseMessageProperty;

                    switch (messageFormat)
                    {
                        case WebContentFormat.Json:
                            this.encoder = webMessageEncoder.JsonMessageEncoder;
                            this.Schedule();
                            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);
                            }
                            this.encoder = webMessageEncoder.TextMessageEncoder;
                            this.Schedule();
                            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);
                            }

                            handleEndWriteMessage = new AsyncCompletion(HandleEndWriteMessage);
                            IAsyncResult result = webMessageEncoder.RawMessageEncoder.BeginWriteMessage(message, stream, PrepareAsyncCompletion(HandleEndWriteMessage), this);
                            if (SyncContinue(result))
                            {
                                this.Complete(true);
                            }
                            break;

                        default:
                            throw Fx.AssertAndThrow("This should never get hit because GetFormatForContentType shouldn't return a WebContentFormat other than Json, Xml, and Raw");
                    }
                }
 public WebMessageEncoderFactory(Encoding writeEncoding, int maxReadPoolSize, int maxWritePoolSize, XmlDictionaryReaderQuotas quotas, WebContentTypeMapper contentTypeMapper, bool javascriptCallbackEnabled)
 {
     messageEncoder = new WebMessageEncoder(writeEncoding, maxReadPoolSize, maxWritePoolSize, quotas, contentTypeMapper, javascriptCallbackEnabled);
 }
Example #4
0
 public WebMessageEncoderFactory(Encoding writeEncoding, int maxReadPoolSize, int maxWritePoolSize, XmlDictionaryReaderQuotas quotas, WebContentTypeMapper contentTypeMapper, bool javascriptCallbackEnabled)
 {
     messageEncoder = new WebMessageEncoder(writeEncoding, maxReadPoolSize, maxWritePoolSize, quotas, contentTypeMapper, javascriptCallbackEnabled);
 }