73 lines · 3.3 KB · C#
RawDownload
//******************************************************************************************************//  FormatSpecificationInspector.cs - Gbtc////  Copyright © 2012, Grid Protection Alliance.  All Rights Reserved.////  Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See//  the NOTICE file distributed with this work for additional information regarding copyright ownership.//  The GPA licenses this file to you under the MIT License (MIT), the "License"; you may//  not use this file except in compliance with the License. You may obtain a copy of the License at:////      http://www.opensource.org/licenses/MIT////  Unless agreed to in writing, the subject software distributed under the License is distributed on an//  "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the//  License for the specific language governing permissions and limitations.////  Code Modification History://  ----------------------------------------------------------------------------------------------------//  01/30/2015 - A.S. Bikle//       Generated original version of source code.////****************************************************************************************************** #if !MONO using System.ServiceModel;using System.ServiceModel.Channels;using System.ServiceModel.Dispatcher;using System.ServiceModel.Web; namespace GSF.ServiceModel.Activation{    /// <summary>    /// Message inspector intended to be attached to WCF REST endpoints.    /// Examines incoming requests for "application/json" in the "Accept" header, and sets the response format to Json when present.    /// </summary>    public class FormatSpecificationInspector : IDispatchMessageInspector    {        /// <summary>        /// Called after an inbound message has been received but before the message is dispatched to the intended operation.        /// </summary>        /// <returns>        /// The object used to correlate state. This object is passed back in the <see cref="BeforeSendReply"/> method.        /// </returns>        /// <param name="request">The request message.</param><param name="channel">The incoming channel.</param>        /// <param name="instanceContext">The current service instance.</param>        public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext)        {            WebOperationContext context = WebOperationContext.Current;             if ((object)context == null)                return null;             string acceptHeader = context.IncomingRequest.Headers["Accept"];             if ((object)acceptHeader != null && acceptHeader.Contains("application/json"))                context.OutgoingResponse.Format = WebMessageFormat.Json;             return null;        }         /// <summary>        /// Called after the operation has returned but before the reply message is sent.        /// </summary>        /// <param name="reply">The reply message. This value is null if the operation is one way.</param>        /// <param name="correlationState">The correlation object returned from the <see cref="AfterReceiveRequest"/> method.</param>        public void BeforeSendReply(ref System.ServiceModel.Channels.Message reply, object correlationState)        {        }    }} #endif

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t