public void ApplyDispatchBehavior(OperationDescription operationDescription, DispatchOperation dispatchOperation) { Logger.Debug(LogCategory.WebService, "ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher) :: Adding custom CORS Behaviour to WCF Endpoint."); // CORSEnabledOperationAttribute corsEnabledOperation = operationDescription.OperationBehaviors.OfType <CORSEnabledOperationAttribute>().FirstOrDefault(); if (corsEnabledOperation != null) { DispatchRuntime dispatchRuntime = dispatchOperation.Parent; if (dispatchRuntime != null) { lock (_lock) { CORSEnabledMessageInspector inspector = dispatchRuntime.MessageInspectors.OfType <CORSEnabledMessageInspector>().FirstOrDefault(); if (inspector == null) { inspector = new CORSEnabledMessageInspector(); dispatchRuntime.MessageInspectors.Add(inspector); } // inspector.AddOperation(operationDescription.Name, corsEnabledOperation); } } else { } // not expected :: operation does not have a parent Endpoint?.. } else { } // not expected :: operation is not a [CORSEnabledOperation]?.. }
public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext) { HttpRequestMessageProperty httpProp = (request.Properties[HttpRequestMessageProperty.Name] as HttpRequestMessageProperty); if (httpProp != null) { object tmp; request.Properties.TryGetValue(WebHttpDispatchOperationSelector.HttpOperationNamePropertyName, out tmp); string operationName = ((tmp as string) ?? string.Empty); if (httpProp != null && string.IsNullOrEmpty(operationName) == false) { CORSEnabledOperationAttribute corsEnabledOperation = this.GetOperation(operationName); if (corsEnabledOperation != null) { string origin = httpProp.Headers[CORSEnabledOperationAttribute.Origin]; if (origin != null) { return(origin); } else { } // does not contain Origin Header } else { } // not [CORSEnabled] operation contract } else { } // not operation contract } else { } // not HttpRequest return(null); }
public CORSEnabledOperationAttribute GetOperation(string operationName) { CORSEnabledOperationAttribute ret = null; // if (string.IsNullOrEmpty(operationName) == true) { throw new ArgumentNullException(nameof(operationName)); } // if (this._corsEnabledOperations.ContainsKey(operationName) == true) { ret = this._corsEnabledOperations[operationName]; } // return(ret); }
public void AddOperation(string operationName, CORSEnabledOperationAttribute corsEnabledOperation) { if (string.IsNullOrEmpty(operationName) == true) { throw new ArgumentNullException(nameof(operationName)); } if (corsEnabledOperation == null) { throw new ArgumentNullException(nameof(corsEnabledOperation)); } // if (this._corsEnabledOperations.ContainsKey(operationName) == true) { this._corsEnabledOperations[operationName] = corsEnabledOperation; } else { this._corsEnabledOperations.Add(operationName, corsEnabledOperation); } }