示例#1
0
        public void Install(ServiceEndpoint endpoint, bool withContract, IKernel kernel, IWcfBurden burden)
        {
            var extension = GetInstance(kernel, burden);

            if (extension is IEndpointBehavior)
            {
                endpoint.Behaviors.Add((IEndpointBehavior)extension);
            }
            else if (extension is IOperationBehavior)
            {
                if (withContract)
                {
                    foreach (var operation in endpoint.Contract.Operations)
                    {
                        operation.Behaviors.Add((IOperationBehavior)extension);
                    }
                }
            }
            else if (extension is IContractBehavior)
            {
                if (withContract)
                {
                    endpoint.Contract.Behaviors.Add((IContractBehavior)extension);
                }
            }
            else if (extension is IErrorHandler)
            {
                WcfUtils.RegisterErrorHandler(endpoint, (IErrorHandler)extension, true);
            }
            else if (WcfUtils.AttachExtension(endpoint.Behaviors, extension) == false)
            {
                if (withContract && !WcfUtils.AttachExtension(endpoint.Contract.Behaviors, extension))
                {
                    Type owner = null;

                    if (WcfUtils.IsExtension(extension, ref owner))
                    {
                        if (typeof(IOperationBehavior).IsAssignableFrom(owner))
                        {
                            foreach (var operation in endpoint.Contract.Operations)
                            {
                                WcfUtils.AttachExtension(operation.Behaviors, extension, owner);
                            }
                        }
                    }
                }
            }
        }