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); }
private void Initialize() { this.security = new HttpBindingSecurity(); this.httpTransportBindingElement = new HttpTransportBindingElement(); this.httpTransportBindingElement.ManualAddressing = true; this.httpsTransportBindingElement = new HttpsTransportBindingElement(); this.httpsTransportBindingElement.ManualAddressing = true; this.httpHandlerBindingElement = new HttpMessageHandlerBindingElement(); this.httpMessageEncodingBindingElement = new HttpMessageEncodingBindingElement(); }
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 }); } }
private void Initialize() { this.security = new HttpBindingSecurity(); this.httpTransportBindingElement = new HttpTransportBindingElement(); this.httpTransportBindingElement.ManualAddressing = true; this.httpsTransportBindingElement = new HttpsTransportBindingElement(); this.httpsTransportBindingElement.ManualAddressing = true; this.httpHandlerBindingElement = new HttpMessageHandlerBindingElement(); this.httpMessageEncodingBindingElement = new HttpMessageEncodingBindingElement(); }