public void ConfigureService(System.ServiceModel.Description.ServiceDescription serviceDescription, System.ServiceModel.ServiceHostBase serviceHostBase) { var host = (serviceHostBase as ServiceHost); if (host != null) { var address = serviceHostBase.Description.Endpoints.First().Address; var contract = serviceHostBase.Description.Endpoints.First().Contract; if (address.ToString().ToLower().Contains("http")) { // clear existing host.Description.Endpoints.Clear(); // Use HTTPS (SSL) for communication var binding = new WS2007HttpBinding(SecurityMode.Transport); binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows; MaxSetter.SetMaxes(binding); if (address.Uri.ToString().Contains("http://")) { var uri = address.Uri.ToString().Replace("http://", "https://"); if (ServiceHelpersConfigSection.Settings != null && ServiceHelpersConfigSection.Settings.SSLPort > 0) { uri = uri.Replace(address.Uri.Port.ToString(), ServiceHelpersConfigSection.Settings.SSLPort.ToString()); } address = new EndpointAddress(new Uri(uri)); } var endpoint = host.AddServiceEndpoint(contract.ContractType, binding, address.Uri); } } DisableErrorMasking.Disable(serviceHostBase); }
public void ConfigureService(System.ServiceModel.Description.ServiceDescription serviceDescription, System.ServiceModel.ServiceHostBase serviceHostBase) { var host = (serviceHostBase as ServiceHost); if (host != null) { // Don't use this crappy binding var address = serviceHostBase.Description.Endpoints.First().Address; var contract = serviceHostBase.Description.Endpoints.First().Contract; // clear existing host.Description.Endpoints.Clear(); var binding = new WS2007HttpBinding(); binding.Security.Mode = SecurityMode.TransportWithMessageCredential; binding.Security.Message.ClientCredentialType = MessageCredentialType.Certificate; binding.Security.Message.EstablishSecurityContext = false; binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate; MaxSetter.SetMaxes(binding); if (address.Uri.ToString().Contains("http://")) { address = new EndpointAddress(new Uri(address.Uri.ToString().Replace("http://", "https://"))); } var endpoint = host.AddServiceEndpoint(contract.ContractType, binding, address.Uri); host.Description.Behaviors.Add(new ServiceMetadataBehavior() { HttpGetEnabled = true, HttpsGetEnabled = true }); } DisableErrorMasking.Disable(serviceHostBase); }