コード例 #1
0
        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]?..
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
 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);
     }
 }