Ejemplo n.º 1
0
        protected virtual void InitializeRuntime()
        {
            //First validate the description, which should call all behaviors
            //'Validate' method.
            ValidateDescription();

            //Build all ChannelDispatchers, one dispatcher per user configured EndPoint.
            //We must keep thet ServiceEndpoints as a seperate collection, since the user
            //can change the collection in the description during the behaviors events.
            ServiceEndpoint[] endPoints = new ServiceEndpoint[Description.Endpoints.Count];
            Description.Endpoints.CopyTo(endPoints, 0);
            var builder = new DispatcherBuilder(this);

            foreach (ServiceEndpoint se in endPoints)
            {
                var commonParams = new BindingParameterCollection();
                foreach (IServiceBehavior b in Description.Behaviors)
                {
                    b.AddBindingParameters(Description, this, Description.Endpoints, commonParams);
                }

                var channel = builder.BuildChannelDispatcher(Description.ServiceType, se, commonParams);
                if (!ChannelDispatchers.Contains(channel))
                {
                    ChannelDispatchers.Add(channel);
                }
            }

            //After the ChannelDispatchers are created, and attached to the service host
            //Apply dispatching behaviors.
            //
            // This behavior application order is tricky: first only
            // ServiceDebugBehavior and ServiceMetadataBehavior are
            // applied, and then other service behaviors are applied.
            // It is because those two behaviors adds ChannelDispatchers
            // and any other service behaviors must be applied to
            // those newly populated dispatchers.
            foreach (IServiceBehavior b in Description.Behaviors)
            {
                if (b is ServiceMetadataBehavior || b is ServiceDebugBehavior)
                {
                    b.ApplyDispatchBehavior(Description, this);
                }
            }
            foreach (IServiceBehavior b in Description.Behaviors)
            {
                if (!(b is ServiceMetadataBehavior || b is ServiceDebugBehavior))
                {
                    b.ApplyDispatchBehavior(Description, this);
                }
            }

            builder.ApplyDispatchBehaviors();
        }
Ejemplo n.º 2
0
        protected virtual void InitializeRuntime()
        {
            //First validate the description, which should call all behaviors
            //'Validate' method.
            ValidateDescription();

            //Build all ChannelDispatchers, one dispatcher per user configured EndPoint.
            //We must keep thet ServiceEndpoints as a seperate collection, since the user
            //can change the collection in the description during the behaviors events.
            Dictionary <ServiceEndpoint, ChannelDispatcher> endPointToDispatcher = new Dictionary <ServiceEndpoint, ChannelDispatcher>();

            ServiceEndpoint[] endPoints = new ServiceEndpoint[Description.Endpoints.Count];
            Description.Endpoints.CopyTo(endPoints, 0);
            foreach (ServiceEndpoint se in endPoints)
            {
                var commonParams = new BindingParameterCollection();
                foreach (IServiceBehavior b in Description.Behaviors)
                {
                    b.AddBindingParameters(Description, this, Description.Endpoints, commonParams);
                }

                var channel = new DispatcherBuilder().BuildChannelDispatcher(Description.ServiceType, se, commonParams);
                ChannelDispatchers.Add(channel);
                endPointToDispatcher[se] = channel;
            }

            //After the ChannelDispatchers are created, and attached to the service host
            //Apply dispatching behaviors.
            foreach (IServiceBehavior b in Description.Behaviors)
            {
                b.ApplyDispatchBehavior(Description, this);
            }

            foreach (KeyValuePair <ServiceEndpoint, ChannelDispatcher> val in endPointToDispatcher)
            {
                foreach (var ed in val.Value.Endpoints)
                {
                    ApplyDispatchBehavior(ed, val.Key);
                }
            }
        }