Пример #1
0
        public object BeforeSendRequest(ref Message request, IClientChannel channel)
        {
            // make sure the channel uses the shared cookie container
            channel.GetProperty <IHttpCookieContainerManager>().CookieContainer =
                _factory.CookieContainer;

            request.Headers.Action = RewriteAction(request.Headers.Action);

            // Check for Query Options
            if (OperationContext.Current != null)
            {
                object queryProperty;
                object includeTotalCountProperty;

                OperationContext.Current.OutgoingMessageProperties.TryGetValue(QueryPropertyName, out queryProperty);
                OperationContext.Current.OutgoingMessageProperties.TryGetValue(IncludeTotalCountPropertyName, out includeTotalCountProperty);

                // Add Query Options header if any options were specified
                if (queryProperty != null || includeTotalCountProperty != null)
                {
                    var queryParts        = (queryProperty != null) ? QuerySerializer.Serialize((IQueryable)queryProperty) : null;
                    var includeTotalCount = (bool?)includeTotalCountProperty;

                    // Prepare the request message copy to be modified
                    MessageBuffer buffer = request.CreateBufferedCopy(Int32.MaxValue);
                    request = buffer.CreateMessage();
                    var header = new QueryOptionsHeader(queryParts, includeTotalCount == true);
                    request.Headers.Add(header);
                }
            }

            return(null);
        }
Пример #2
0
            object IClientMessageInspector.BeforeSendRequest(ref Message request, IClientChannel channel)
            {
                request.Headers.Action = RewriteAction(request.Headers.Action);

                // Add Query Options if any are set
                var messageProperties = OperationContext.Current?.OutgoingMessageProperties;

                if (messageProperties != null)
                {
                    messageProperties.TryGetValue(QueryPropertyName, out object queryProperty);
                    messageProperties.TryGetValue(IncludeTotalCountPropertyName, out object includeTotalCountProperty);

                    // Add Query Options header if any options were specified
                    if (queryProperty != null || includeTotalCountProperty != null)
                    {
                        var queryParts        = (queryProperty != null) ? QuerySerializer.Serialize((IQueryable)queryProperty) : null;
                        var includeTotalCount = (bool?)includeTotalCountProperty;

                        var header = new QueryOptionsHeader(queryParts, includeTotalCount == true);
                        request.Headers.Add(header);
                    }
                }

                return(null);
            }