void Initialize (WebHttpSecurityMode mode) { security.Mode = mode; // MSDN says that this security mode can be set only // at .ctor(), so there is no problem on depending on // this value here. t = mode == WebHttpSecurityMode.Transport ? new HttpsTransportBindingElement () : new HttpTransportBindingElement (); t.ManualAddressing = true; }
void Initialize(WebHttpSecurityMode mode) { security.Mode = mode; // MSDN says that this security mode can be set only // at .ctor(), so there is no problem on depending on // this value here. t = mode == WebHttpSecurityMode.Transport ? new HttpsTransportBindingElement() : new HttpTransportBindingElement(); t.ManualAddressing = true; }
// This method constructs a WebHttpBinding endpoint with all the appropriate // settings for talking to our services. private static ServiceEndpoint ConstructEndpoint(string serviceUri, WebHttpSecurityMode securityMode) { var contract = ContractDescription.GetContract(typeof(IFredContract)); var binding = new WebHttpBinding(securityMode); var address = new EndpointAddress(serviceUri); var endpoint = new ServiceEndpoint( contract, binding, address); //custom stuff. You may or may not need these settings, but I do.. //I would think you need at least the behavior, as it is likely required, as it is in the web.config. //------------- var webHttpBehavior = new WebHttpBehavior() { FaultExceptionEnabled = true }; endpoint.Behaviors.Add(webHttpBehavior); //------------- return(endpoint); }
public WebHttpBinding(WebHttpSecurityMode mode) { Initialize(mode); }
protected virtual void InitializeRestWebServiceServiceHost <R, I>( bool startRestWebService, WcfRestWebServiceAppSettings settings, WebHttpSecurityMode webHttpSecurityMode, HttpClientCredentialType httpClientCredentialType, UserNamePasswordValidator userNamePasswordValidator, out string restWebServiceUrl, out string restWebServiceStartedLogMessage) where R : WcfRestServiceWindows where I : IWcfRestServiceWindows { GOCWindows.Instance.JsonSerializer.IncludeOrmTypeNamesInJsonResponse = settings.RestServiceIncludeOrmTypeNamesInJsonResponse; GOCWindows.Instance.SetEncoding(settings.RestServiceTextResponseEncoding); WebHttpBinding webHttpBinding = new WebHttpBinding() { MaxBufferPoolSize = settings.RestServiceMaxBufferPoolSize, MaxBufferSize = Convert.ToInt32(settings.RestServiceMaxBufferSize), MaxReceivedMessageSize = settings.RestServiceMaxReceivedMessageSize }; if (settings.RestServiceUseAuthentication) { webHttpBinding.Security.Mode = webHttpSecurityMode; webHttpBinding.Security.Transport.ClientCredentialType = httpClientCredentialType; } CustomBinding customBinding = GetBinding(settings, webHttpBinding); ServiceHost serviceHost = new ServiceHost(typeof(R)); restWebServiceUrl = string.Format("http://127.0.0.1:{0}/{1}", settings.RestServicePortNumber, settings.RestServiceHostAddressSuffix); SetServiceHostDebugBehavior(serviceHost, settings); SetServiceHostThrottlingBehavior(serviceHost, settings); ConfigurationFileHelperWindows.SetApplicationServiceModelPerformanceCounters(settings.RestServicePerformanceCounterScope); ServiceEndpoint httpEndpoint = serviceHost.AddServiceEndpoint(typeof(I), customBinding, restWebServiceUrl); httpEndpoint.Behaviors.Add(new WebHttpBehavior()); httpEndpoint.EndpointBehaviors.Add(new WcfServiceMessageInspectorBehaviorWindows(settings.RestServiceTraceHttpMessages, settings.RestServiceTraceHttpMessageHeaders)); if (settings.RestServiceUseAuthentication && (userNamePasswordValidator != null)) { serviceHost.Credentials.UserNameAuthentication.UserNamePasswordValidationMode = System.ServiceModel.Security.UserNamePasswordValidationMode.Custom; serviceHost.Credentials.UserNameAuthentication.CustomUserNamePasswordValidator = userNamePasswordValidator; } if (startRestWebService) { if (GOCWindows.Instance.GetByTypeName <ServiceHost>() != null) { GOCWindows.Instance.DeleteByTypeName <ServiceHost>(); } GOCWindows.Instance.AddByTypeName(serviceHost); //The service's stop method will access it from the GOC to close the service host. serviceHost.Open(); restWebServiceStartedLogMessage = string.Format($"Started - {settings.ApplicationName}: {restWebServiceUrl}"); GOCWindows.Instance.Logger.LogMessage(new LogMessage(restWebServiceStartedLogMessage, LogMessageType.SuccessAudit, LoggingLevel.Minimum)); } else { restWebServiceStartedLogMessage = string.Format($"Not Started - {settings.ApplicationName}: {restWebServiceUrl}"); } }
internal static bool IsDefined(WebHttpSecurityMode value) { return(value == WebHttpSecurityMode.None || value == WebHttpSecurityMode.Transport || value == WebHttpSecurityMode.TransportCredentialOnly); }
/// <summary> /// Initializes a new instance of the <see cref="T:System.ServiceModel.WebHttpBinding"/> class with the type of security used by the binding explicitly specified. /// </summary> /// <param name="securityMode">The value of <see cref="T:System.ServiceModel.WebHttpSecurityMode"/> that specifies the type of security that is used to configure a service endpoint to receive HTTP requests.</param><exception cref="T:System.ArgumentOutOfRangeException">The <paramref name="securityMode"/> specified is not a valid <see cref="T:System.ServiceModel.WebHttpSecurityMode"/>.</exception> public SecureWebHttpBinding(WebHttpSecurityMode securityMode) : base(securityMode) { }
public WebHttpBinding (WebHttpSecurityMode mode) { Initialize (mode); }
public WebHttpBinding(WebHttpSecurityMode securityMode) : base() { Initialize(); this.security.Mode = securityMode; }
public CustomWebHttpBinding(WebHttpSecurityMode securityMode) : base(securityMode) { }
internal static bool IsDefined(WebHttpSecurityMode value) { return (value == WebHttpSecurityMode.None || value == WebHttpSecurityMode.Transport || value == WebHttpSecurityMode.TransportCredentialOnly); }
public TextMessageProxy(string url, WebHttpSecurityMode securityMode = WebHttpSecurityMode.None) : base(ConstructEndpoint(url, securityMode)) { }