#pragma warning disable 1998
        protected override async Task<Stream> WriteLinkContentAsync(string linkIdent)
        {
            var message = new ODataRequestMessage();
            using (var messageWriter = new ODataMessageWriter(message, GetWriterSettings(), _model))
            {
                var link = new ODataEntityReferenceLink { Url = Utils.CreateAbsoluteUri(_session.Settings.BaseUri.AbsoluteUri, linkIdent) };
                messageWriter.WriteEntityReferenceLink(link);

#if SILVERLIGHT
                return message.GetStream();
#else
                return await message.GetStreamAsync();
#endif
            }
        }
        protected override async Task<Stream> WriteStreamContentAsync(Stream stream)
        {
            var message = new ODataRequestMessage();
            using (var messageWriter = new ODataMessageWriter(message, GetWriterSettings(true), _model))
            {
#if SILVERLIGHT
                messageWriter.WriteValue(Utils.StreamToString(stream));
#else
                await messageWriter.WriteValueAsync(Utils.StreamToString(stream));
#endif
                return await message.GetStreamAsync();
            }
        }
        protected override async Task<Stream> WriteStreamContentAsync(Stream stream, bool writeAsText)
        {
            var message = new ODataRequestMessage();
            using (var messageWriter = new ODataMessageWriter(message, GetWriterSettings(true), _model))
            {
                var value = writeAsText ? (object)Utils.StreamToString(stream) : Utils.StreamToByteArray(stream);
#if SILVERLIGHT
                messageWriter.WriteValue(value);
#else
                await messageWriter.WriteValueAsync(value);
#endif
                return await message.GetStreamAsync();
            }
        }
#pragma warning restore 1998

        protected override async Task<Stream> WriteActionContentAsync(string actionName, IDictionary<string, object> parameters)
        {
            var message = new ODataRequestMessage();
            using (var messageWriter = new ODataMessageWriter(message, GetWriterSettings(), _model))
            {
                var action = _model.SchemaElements
                    .Where(x => x.SchemaElementKind == EdmSchemaElementKind.EntityContainer)
                    .SelectMany(x => (x as IEdmEntityContainer).FunctionImports())
                    .BestMatch(x => x.Name, actionName, _session.Pluralizer);
                var parameterWriter = messageWriter.CreateODataParameterWriter(action);

                parameterWriter.WriteStart();

                foreach (var parameter in parameters)
                {
                    if (!(parameter.Value is string) && parameter.Value is IEnumerable)
                    {
                        var collectionWriter = parameterWriter.CreateCollectionWriter(parameter.Key);
                        collectionWriter.WriteStart(new ODataCollectionStart());
                        foreach (var item in parameter.Value as IEnumerable)
                        {
                            collectionWriter.WriteItem(item);
                        }
                        collectionWriter.WriteEnd();
                    }
                    else
                    {
                        parameterWriter.WriteValue(parameter.Key, parameter.Value);
                    }
                }

                parameterWriter.WriteEnd();
                return await message.GetStreamAsync();
            }
        }
        protected override async Task<Stream> WriteActionContentAsync(string actionName, IDictionary<string, object> parameters)
        {
            var message = new ODataRequestMessage();
            using (var messageWriter = new ODataMessageWriter(message, GetWriterSettings(), _model))
            {
                var action = _model.SchemaElements
                    .Where(x => x.SchemaElementKind == EdmSchemaElementKind.EntityContainer)
                    .SelectMany(x => (x as IEdmEntityContainer).FunctionImports())
                    .BestMatch(x => x.Name, actionName, _session.Pluralizer);
                var parameterWriter = messageWriter.CreateODataParameterWriter(action);

                parameterWriter.WriteStart();

                foreach (var parameter in parameters)
                {
                    var actionParameter = action.Parameters.BestMatch(x => x.Name, parameter.Key, _session.Pluralizer);
                    if (actionParameter == null)
                        throw new UnresolvableObjectException(parameter.Key, string.Format("Parameter [{0}] not found for action [{1}]", parameter.Key, actionName));

                    if (actionParameter.Type.Definition.TypeKind == EdmTypeKind.Collection)
                    {
                        var collectionWriter = parameterWriter.CreateCollectionWriter(parameter.Key);
                        collectionWriter.WriteStart(new ODataCollectionStart());
                        foreach (var item in parameter.Value as IEnumerable)
                        {
                            collectionWriter.WriteItem(item);
                        }
                        collectionWriter.WriteEnd();
                    }
                    else
                    {
                        parameterWriter.WriteValue(parameter.Key, parameter.Value);
                    }
                }

                parameterWriter.WriteEnd();
                return await message.GetStreamAsync();
            }
        }