Пример #1
0
        /// <summary>
        /// Invoked during the transition of a communication object into the opening state.
        /// </summary>
        protected override void OnOpening()
        {
            if (this.Description == null)
            {
                return;
            }

            DisableServiceDebugAndMetadataBehaviors(this.Description);
            ServiceDebugBehavior debugBehavior = this.Description.Behaviors.Find<ServiceDebugBehavior>();
            foreach (ServiceEndpoint serviceEndpoint in this.Description.Endpoints)
            {
                if (serviceEndpoint.Binding != null)
                {
                    if (serviceEndpoint.Binding.CreateBindingElements().Find<HttpMessageHandlerBindingElement>() != null)
                    {
                        DispatcherSynchronizationBehavior synchronizationBehavior = serviceEndpoint.Behaviors.Find<DispatcherSynchronizationBehavior>();
                        if (synchronizationBehavior == null)
                        {
                            synchronizationBehavior = new DispatcherSynchronizationBehavior() { AsynchronousSendEnabled = true };
                            serviceEndpoint.Behaviors.Add(synchronizationBehavior);
                        }

                        if (serviceEndpoint.Behaviors.Find<HttpBindingParameterBehavior>() == null)
                        {
                            serviceEndpoint.Behaviors.Add(new HttpBindingParameterBehavior(debugBehavior, synchronizationBehavior));
                        }
                    }

                    if (serviceEndpoint.Binding.CreateBindingElements().Find<HttpMessageEncodingBindingElement>() != null)
                    {
                        if (serviceEndpoint.Behaviors.Find<HttpBehavior>() == null)
                        {
                            if (serviceEndpoint.Behaviors.Find<HttpBehavior>() == null)
                            {
                                serviceEndpoint.Behaviors.Add(new HttpBehavior());
                            }
                        }
                    }
                }
            }

            base.OnOpening();
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="HttpBindingParameterBehavior"/> class.
 /// </summary>
 /// <param name="serviceDebugBehavior">Optional service debug behavior (can be null).</param>
 /// <param name="dispatcherSynchronizationBehavior">Optional dispatcher synchronization behavior (can be null).</param>
 public TestHttpBindingParameterBehavior(ServiceDebugBehavior serviceDebugBehavior, DispatcherSynchronizationBehavior dispatcherSynchronizationBehavior)
 {
     this.serviceDebugBehavior = serviceDebugBehavior;
     this.dispatcherSynchronizationBehavior = dispatcherSynchronizationBehavior;
 }