public void HttpSelfHostConfiguration_Settings_PropagateToBinding() { // Arrange HttpBinding binding = new HttpBinding(); binding.ConfigureTransportBindingElement = ConfigureTransportBindingElement; HttpSelfHostConfiguration config = new HttpSelfHostConfiguration("http://localhost") { MaxBufferSize = 10, MaxReceivedMessageSize = 11, ReceiveTimeout = new TimeSpan(1, 0, 0), SendTimeout = new TimeSpan(1, 0, 0), TransferMode = TransferMode.StreamedResponse, HostNameComparisonMode = HostNameComparisonMode.WeakWildcard }; // Act config.ConfigureBinding(binding); // Assert Assert.Equal(10, binding.MaxBufferSize); Assert.Equal(11, binding.MaxReceivedMessageSize); Assert.Equal(new TimeSpan(1, 0, 0), binding.ReceiveTimeout); Assert.Equal(new TimeSpan(1, 0, 0), binding.SendTimeout); Assert.Equal(TransferMode.StreamedResponse, binding.TransferMode); Assert.Equal(HostNameComparisonMode.WeakWildcard, binding.HostNameComparisonMode); Assert.Equal(Net.AuthenticationSchemes.Ntlm, binding.CreateBindingElements().Find <HttpTransportBindingElement>().AuthenticationScheme); }
public static ServiceHost CreateHost <T>(bool asynchronousSendEnabled, bool customBinding, bool faultDetail, bool streamed, HttpMessageHandlerFactory httpMessageHandlerFactory) where T : TestServiceBase { var webHost = new WebServiceHost(typeof(T), TestServiceCommon.ServiceAddress); if (faultDetail && webHost.Description.Behaviors.Contains(typeof(ServiceDebugBehavior))) { var debug = webHost.Description.Behaviors[typeof(ServiceDebugBehavior)] as ServiceDebugBehavior; debug.IncludeExceptionDetailInFaults = true; } Binding httpBinding = null; if (customBinding) { var bindingElement = new HttpMessageHandlerBindingElement(); bindingElement.MessageHandlerFactory = httpMessageHandlerFactory; var httpMsgBinding = new HttpBinding(); if (streamed) { httpMsgBinding.TransferMode = TransferMode.Streamed; } var bindingElements = httpMsgBinding.CreateBindingElements(); bindingElements.Insert(0, bindingElement); httpBinding = new CustomBinding(bindingElements); } else { var httpMsgBinding = new HttpBinding() { MessageHandlerFactory = httpMessageHandlerFactory }; if (streamed) { httpMsgBinding.TransferMode = TransferMode.Streamed; } httpBinding = httpMsgBinding; } var endpoint = webHost.AddServiceEndpoint(typeof(ITestServiceContract), httpBinding, ""); ServiceDebugBehavior debugBehavior = webHost.Description.Behaviors.Find <ServiceDebugBehavior>(); DispatcherSynchronizationBehavior synchronizationBehavior = new DispatcherSynchronizationBehavior() { AsynchronousSendEnabled = asynchronousSendEnabled }; endpoint.Behaviors.Add(synchronizationBehavior); endpoint.Behaviors.Add(new TestHttpBindingParameterBehavior(debugBehavior, synchronizationBehavior)); webHost.Open(); return(webHost); }
public static Binding CreateBinding(bool customBinding, HttpMessageHandlerFactory httpMessageHandlerFactory) { if (customBinding) { var bindingElement = new HttpMessageHandlerBindingElement(); bindingElement.MessageHandlerFactory = httpMessageHandlerFactory; var httpBinding = new HttpBinding(); var bindingElements = httpBinding.CreateBindingElements(); bindingElements.Insert(0, bindingElement); return(new CustomBinding(bindingElements)); } else { return(new HttpBinding() { MessageHandlerFactory = httpMessageHandlerFactory }); } }