Пример #1
0
        public void ConfigureServiceHost(ServiceHost host, ServiceHostConfigurationArgs args)
        {
            WSHttpBinding binding = new WSHttpBinding();
            binding.MaxReceivedMessageSize = args.MaxReceivedMessageSize;
            binding.ReaderQuotas.MaxStringContentLength = args.MaxReceivedMessageSize;
            binding.ReaderQuotas.MaxArrayLength = args.MaxReceivedMessageSize;
            binding.Security.Mode = WebServicesSettings.Default.SecurityMode;
            binding.Security.Message.ClientCredentialType = args.Authenticated
                                                                ? MessageCredentialType.UserName
                                                                : MessageCredentialType.None;
            // establish endpoint
            host.AddServiceEndpoint(args.ServiceContract, binding, "");

            // expose meta-data via HTTP GET
            ServiceMetadataBehavior metadataBehavior = host.Description.Behaviors.Find<ServiceMetadataBehavior>();
            if (metadataBehavior == null)
            {
                metadataBehavior = new ServiceMetadataBehavior();
                metadataBehavior.HttpGetEnabled = true;
                host.Description.Behaviors.Add(metadataBehavior);
            }

            // set up the certificate 
            if (WebServicesSettings.Default.SecurityMode == SecurityMode.Message 
                || WebServicesSettings.Default.SecurityMode==SecurityMode.TransportWithMessageCredential)
            {
                host.Credentials.ServiceCertificate.SetCertificate(
                    StoreLocation.LocalMachine, StoreName.My, X509FindType.FindBySubjectName, args.HostUri.Host);
            }
        }
Пример #2
0
		public void ConfigureServiceHost(ServiceHost host, ServiceHostConfigurationArgs args)
		{
			WSHttpBinding binding = new WSHttpBinding();
			binding.MaxReceivedMessageSize = args.MaxReceivedMessageSize;

			if (args.SendTimeoutSeconds > 0)
				binding.SendTimeout = TimeSpan.FromSeconds(args.SendTimeoutSeconds);

			binding.ReaderQuotas.MaxStringContentLength = args.MaxReceivedMessageSize;
			binding.ReaderQuotas.MaxArrayLength = args.MaxReceivedMessageSize;
			binding.Security.Mode = WebServicesSettings.Default.SecurityMode;
			binding.Security.Message.ClientCredentialType = args.Authenticated
			                                                	? MessageCredentialType.UserName
			                                                	: MessageCredentialType.None;
			// establish endpoint
			host.AddServiceEndpoint(args.ServiceContract, binding, "");

			// expose meta-data via HTTP GET
			ServiceMetadataBehavior metadataBehavior = host.Description.Behaviors.Find<ServiceMetadataBehavior>();
			if (metadataBehavior == null)
			{
				metadataBehavior = new ServiceMetadataBehavior();
				metadataBehavior.HttpGetEnabled = true;
				host.Description.Behaviors.Add(metadataBehavior);
			}

			//TODO (Rockstar): remove this after refactoring to do per-sop edits
			foreach (var endpoint in host.Description.Endpoints)
				foreach (var operation in endpoint.Contract.Operations)
					operation.Behaviors.Find<DataContractSerializerOperationBehavior>().MaxItemsInObjectGraph = args.MaxReceivedMessageSize;

			// set up the certificate 
			if (WebServicesSettings.Default.SecurityMode == SecurityMode.Message
			    || WebServicesSettings.Default.SecurityMode == SecurityMode.TransportWithMessageCredential)
			{
				host.Credentials.ServiceCertificate.SetCertificate(
					StoreLocation.LocalMachine, StoreName.My, X509FindType.FindBySubjectName, args.HostUri.Host);
			}
		}
Пример #3
0
		public void ConfigureServiceHost(ServiceHost host, ServiceHostConfigurationArgs args)
		{
			var settings = new EnterpriseImageServerServiceSettings();

			// Per MSDN: Transport security is provided externally to WCF. If you are creating a self-hosted WCF application, you can bind an SSL certificate to the address using the HttpCfg.exe tool.
			// The service may appears running but client will not be able to connect. For this reason, it's best to explicitly disallow this mode.
			if (settings.SecurityMode == SecurityMode.Transport)
			{
				throw new Exception("Transport security is not supported. Please change EnterpriseImageServerServiceSettings.SecurityMode");
			}
			

			var binding = new WSHttpBinding
				{
					MaxReceivedMessageSize = args.MaxReceivedMessageSize
				};

			if (args.SendTimeoutSeconds > 0)
				binding.SendTimeout = TimeSpan.FromSeconds(args.SendTimeoutSeconds);

			binding.ReaderQuotas.MaxStringContentLength = (int)Math.Min(int.MaxValue, args.MaxReceivedMessageSize);
			binding.ReaderQuotas.MaxArrayLength = (int)Math.Min(int.MaxValue, args.MaxReceivedMessageSize);
			binding.Security.Mode = settings.SecurityMode;
			binding.Security.Message.ClientCredentialType = args.Authenticated
			                                                	? MessageCredentialType.UserName
			                                                	: MessageCredentialType.None;


			// TransportWithMessageCredential cannot be used in conjuction with ClientCredentialType=None
			if (binding.Security.Mode == SecurityMode.TransportWithMessageCredential &&
			    binding.Security.Message.ClientCredentialType == MessageCredentialType.None)
			{
				throw new Exception(string.Format("TransportWithMessageCredential is not supported for '{0}' service. Please change EnterpriseImageServerServiceSettings.SecurityMode", args.ServiceContract.Name));
			}
			

			// establish endpoint
			host.AddServiceEndpoint(args.ServiceContract, binding, "");

			// expose meta-data via HTTP GET
			var metadataBehavior = host.Description.Behaviors.Find<ServiceMetadataBehavior>();
			if (metadataBehavior == null)
			{
				metadataBehavior = new ServiceMetadataBehavior
					{
						HttpGetEnabled = true
					};
				host.Description.Behaviors.Add(metadataBehavior);
			}

			//TODO (Rockstar): remove this after refactoring to do per-sop edits
			foreach (var endpoint in host.Description.Endpoints)
				foreach (var operation in endpoint.Contract.Operations)
					operation.Behaviors.Find<DataContractSerializerOperationBehavior>().MaxItemsInObjectGraph = (int)Math.Min(int.MaxValue, args.MaxReceivedMessageSize);

			// set up the certificate 
			if (settings.SecurityMode == SecurityMode.Message
				|| settings.SecurityMode == SecurityMode.TransportWithMessageCredential)
			{
				host.Credentials.ServiceCertificate.SetCertificate(
					StoreLocation.LocalMachine, StoreName.My, X509FindType.FindBySubjectName, args.HostUri.Host);
			}
		}