/* ******************************************************************* * Methods * *******************************************************************/ #region public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext) /// <summary> /// Called after an inbound message has been received but before the message is dispatched to the intended operation. /// </summary> /// <param name="request">The request message.</param> /// <param name="channel">The incoming channel.</param> /// <param name="instanceContext">The current service instance.</param> /// <returns> /// The object used to correlate state. This object is passed back in the <see cref="M:System.ServiceModel.Dispatcher.IDispatchMessageInspector.BeforeSendReply(System.ServiceModel.Channels.Message@,System.Object)"/> method. /// </returns> public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext) { CorsState state = null; HttpRequestMessageProperty responseProperty = null; if (request.Properties.ContainsKey(HttpRequestMessageProperty.Name)) { responseProperty = request.Properties[HttpRequestMessageProperty.Name] as HttpRequestMessageProperty; } if (responseProperty != null) { //Handle cors requests var origin = responseProperty.Headers["Origin"]; if (!string.IsNullOrEmpty(origin)) { state = new CorsState(); //if a cors options request (preflight) is detected, we create our own reply message and don't invoke any operation at all. if (responseProperty.Method == "OPTIONS") { state.Message = Message.CreateMessage(request.Version, FindReplyAction(request.Headers.Action), new EmptyBodyWriter()); } request.Properties.Add(CrossOriginResourceSharingPropertyName, state); } } return state; }
/* ******************************************************************* * Methods * *******************************************************************/ #region public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext) /// <summary> /// Called after an inbound message has been received but before the message is dispatched to the intended operation. /// </summary> /// <param name="request">The request message.</param> /// <param name="channel">The incoming channel.</param> /// <param name="instanceContext">The current service instance.</param> /// <returns> /// The object used to correlate state. This object is passed back in the <see cref="M:System.ServiceModel.Dispatcher.IDispatchMessageInspector.BeforeSendReply(System.ServiceModel.Channels.Message@,System.Object)"/> method. /// </returns> public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext) { CorsState state = null; HttpRequestMessageProperty responseProperty = null; if (request.Properties.ContainsKey(HttpRequestMessageProperty.Name)) { responseProperty = request.Properties[HttpRequestMessageProperty.Name] as HttpRequestMessageProperty; } if (responseProperty != null) { //Handle cors requests var origin = responseProperty.Headers["Origin"]; if (!string.IsNullOrEmpty(origin)) { state = new CorsState(); //if a cors options request (preflight) is detected, we create our own reply message and don't invoke any operation at all. if (responseProperty.Method == "OPTIONS") { state.Message = Message.CreateMessage(request.Version, FindReplyAction(request.Headers.Action), new EmptyBodyWriter()); } request.Properties.Add(CrossOriginResourceSharingPropertyName, state); } } return(state); }