static void Main(string[] args) { WSDualHttpBinding binding = new WSDualHttpBinding(); // EndpointAddress baseAddress2 = new EndpointAddress("http://localhost:64080/crm"); binding.ClientBaseAddress = new Uri("http://localhost:64080/client"); binding.Security.Mode = WSDualHttpSecurityMode.None; Uri baseAddress = new Uri("http://localhost:64080/crm"); using (ServiceHost host = new ServiceHost(typeof(CrmRepositoryService), baseAddress)) { host.AddServiceEndpoint(typeof(ICRMRepository), binding, baseAddress); ServiceMetadataBehavior smb = new ServiceMetadataBehavior(); smb.HttpGetEnabled = true; smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15; host.Description.Behaviors.Add(smb); ServiceAuthenticationBehavior bechAuthenticationBehavior = new ServiceAuthenticationBehavior(); bechAuthenticationBehavior.AuthenticationSchemes = AuthenticationSchemes.None; host.Open(); Console.WriteLine($"The service is ready at {baseAddress}"); Console.WriteLine("Press <Enter> to stop the service."); Console.ReadLine(); // Close the ServiceHost. host.Close(); } }
protected override void OnOpened() { if (this.Description != null) { ServiceCredentials credentials = this.description.Behaviors.Find <ServiceCredentials>(); if (credentials != null) { ServiceCredentials credentials2 = credentials.Clone(); credentials2.MakeReadOnly(); this.readOnlyCredentials = credentials2; } ServiceAuthorizationBehavior behavior = this.description.Behaviors.Find <ServiceAuthorizationBehavior>(); if (behavior != null) { ServiceAuthorizationBehavior behavior2 = behavior.Clone(); behavior2.MakeReadOnly(); this.readOnlyAuthorization = behavior2; } ServiceAuthenticationBehavior behavior3 = this.description.Behaviors.Find <ServiceAuthenticationBehavior>(); if (behavior3 != null) { ServiceAuthenticationBehavior behavior4 = behavior3.Clone(); behavior3.MakeReadOnly(); this.readOnlyAuthentication = behavior4; } if (ManagementExtension.IsEnabled) { ManagementExtension.OnServiceOpened(this); } } base.OnOpened(); }
private ServiceAuthenticationBehavior EnsureAuthentication(System.ServiceModel.Description.ServiceDescription description) { ServiceAuthenticationBehavior item = description.Behaviors.Find <ServiceAuthenticationBehavior>(); if (item == null) { item = new ServiceAuthenticationBehavior(); description.Behaviors.Add(item); } return(item); }
protected internal override object CreateBehavior() { ServiceAuthenticationBehavior behavior = new ServiceAuthenticationBehavior(); string serviceAuthenticationManagerType = this.ServiceAuthenticationManagerType; if (!string.IsNullOrEmpty(serviceAuthenticationManagerType)) { Type c = Type.GetType(serviceAuthenticationManagerType, true); if (!typeof(ServiceAuthenticationManager).IsAssignableFrom(c)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(System.ServiceModel.SR.GetString("ConfigInvalidServiceAuthenticationManagerType", new object[] { serviceAuthenticationManagerType, typeof(ServiceAuthenticationManager) }))); } behavior.ServiceAuthenticationManager = (ServiceAuthenticationManager)Activator.CreateInstance(c); } return(behavior); }
protected internal override object CreateBehavior() { ServiceAuthenticationBehavior behavior = new ServiceAuthenticationBehavior(); string serviceAuthenticationManagerType = this.ServiceAuthenticationManagerType; if (!String.IsNullOrEmpty(serviceAuthenticationManagerType)) { Type type = Type.GetType(serviceAuthenticationManagerType, true); if (!typeof(ServiceAuthenticationManager).IsAssignableFrom(type)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException( SR.GetString(SR.ConfigInvalidServiceAuthenticationManagerType, serviceAuthenticationManagerType, typeof(ServiceAuthenticationManager)))); } behavior.ServiceAuthenticationManager = (ServiceAuthenticationManager)Activator.CreateInstance(type); } if (this.AuthenticationSchemes != AuthenticationSchemes.None) { behavior.AuthenticationSchemes = this.AuthenticationSchemes; } return(behavior); }
static void Main(string[] args) { string endpointPortSetting = ConfigurationManager.AppSettings.Get("CalcServiceEndpointPort"); int port = DefaultPort; if (!string.IsNullOrEmpty(endpointPortSetting)) { port = int.Parse(endpointPortSetting); } Uri endpointUri = GetBaseAddress(DefaultHostName, port, Uri.UriSchemeHttp); Console.WriteLine("Going to register endpoint : {0}", endpointUri.ToString()); // Self-hosting the service here. Alternative is to use IIS to host to service. var serviceHost = new ServiceHost(typeof(CalculatorService), endpointUri); try { serviceHost.AddServiceEndpoint(typeof(ICalc), new WSHttpBinding(), "CalculatorService"); // Setting the limits serviceHost.Description.Behaviors.Add( new ServiceThrottlingBehavior() { MaxConcurrentCalls = Int32.MaxValue, MaxConcurrentSessions = Int32.MaxValue, MaxConcurrentInstances = Int32.MaxValue, }); // Enable metadata exchange. serviceHost.Description.Behaviors.Add( new ServiceMetadataBehavior() { HttpGetEnabled = true, }); var sab = new ServiceAuthenticationBehavior(); sab.AuthenticationSchemes = System.Net.AuthenticationSchemes.None; serviceHost.Open(); Console.WriteLine("The service is ready."); // Close the ServiceHost to stop the service. Console.WriteLine("Press <Enter> to terminate the service."); Console.WriteLine(); Console.ReadLine(); Console.WriteLine("Shutting down service host."); serviceHost.Close(); } catch (CommunicationException ce) { Console.WriteLine("An exception occurred: {0}", ce.Message); serviceHost.Abort(); } catch (Exception e) { Console.WriteLine("An exception occurred: {0}", e.Message); serviceHost.Abort(); } finally { Console.ReadLine(); } }