コード例 #1
0
        private void Initialize(CoordinationServiceConfiguration config)
        {
            DebugTrace.TraceEnter(this, "Initialize");
            this.config   = config;
            this.security = new CoordinationServiceSecurity();
            if ((config.Mode == 0) || ((config.Mode & ~(CoordinationServiceMode.ProtocolService | CoordinationServiceMode.Formatter)) != 0))
            {
                DiagnosticUtility.FailFast("Invalid CoordinationServiceMode");
            }
            if ((config.Mode & CoordinationServiceMode.ProtocolService) == 0)
            {
                if (!string.IsNullOrEmpty(config.BasePath))
                {
                    DiagnosticUtility.FailFast("A base path must not be provided if protocol service mode is not enabled");
                }
                if (!string.IsNullOrEmpty(config.HostName))
                {
                    DiagnosticUtility.FailFast("A hostname must not be provided if protocol service mode is not enabled");
                }
            }
            else
            {
                if (string.IsNullOrEmpty(config.BasePath))
                {
                    DiagnosticUtility.FailFast("A base path must be provided if protocol service mode is enabled");
                }
                if (string.IsNullOrEmpty(config.HostName))
                {
                    DiagnosticUtility.FailFast("A hostname must be provided if protocol service mode is enabled");
                }
                if (config.X509Certificate == null)
                {
                    DiagnosticUtility.FailFast("No authentication mechanism was provided for the protocol service");
                }
            }
            this.globalAclAuthz = new GlobalAclOperationRequirement(config.GlobalAclWindowsIdentities, config.GlobalAclX509CertificateThumbprints, this.protocolVersion);
            if ((this.config.Mode & CoordinationServiceMode.ProtocolService) != 0)
            {
                this.httpsBaseAddressUri     = new UriBuilder(Uri.UriSchemeHttps, this.config.HostName, this.config.HttpsPort, this.config.BasePath).Uri;
                this.namedPipeBaseAddressUri = new UriBuilder(Uri.UriSchemeNetPipe, "localhost", -1, this.config.HostName + "/" + this.config.BasePath).Uri;
            }
            this.namedPipeActivationBinding = new NamedPipeBinding(this.protocolVersion);
            if (this.config.RemoteClientsEnabled)
            {
                this.windowsActivationBinding = new WindowsRequestReplyBinding(this.protocolVersion);
            }
            this.interopDatagramBinding     = new Microsoft.Transactions.Wsat.Messaging.InteropDatagramBinding(this.protocolVersion);
            this.interopRegistrationBinding = new Microsoft.Transactions.Wsat.Messaging.InteropRegistrationBinding(this.httpsBaseAddressUri, this.config.SupportingTokensEnabled, this.protocolVersion);
            this.interopActivationBinding   = new Microsoft.Transactions.Wsat.Messaging.InteropActivationBinding(this.httpsBaseAddressUri, this.protocolVersion);
            ClientCredentials item = new ClientCredentials {
                ClientCertificate  = { Certificate = this.config.X509Certificate },
                ServiceCertificate = { DefaultCertificate = this.config.X509Certificate }
            };

            if ((this.config.Mode & CoordinationServiceMode.ProtocolService) != 0)
            {
                this.interopDatagramChannelFactory = this.CreateChannelFactory <IDatagramService>(this.interopDatagramBinding);
                this.interopDatagramChannelFactory.Endpoint.Behaviors.Remove <ClientCredentials>();
                this.interopDatagramChannelFactory.Endpoint.Behaviors.Add(item);
                this.OpenChannelFactory <IDatagramService>(this.interopDatagramChannelFactory);
                this.interopRegistrationChannelFactory = this.CreateChannelFactory <IRequestReplyService>(this.interopRegistrationBinding);
                this.interopRegistrationChannelFactory.Endpoint.Behaviors.Remove <ClientCredentials>();
                this.interopRegistrationChannelFactory.Endpoint.Behaviors.Add(item);
                this.OpenChannelFactory <IRequestReplyService>(this.interopRegistrationChannelFactory);
            }
            if ((config.Mode & CoordinationServiceMode.Formatter) != 0)
            {
                if (this.config.X509Certificate != null)
                {
                    this.interopActivationChannelFactory = this.CreateChannelFactory <IRequestReplyService>(this.interopActivationBinding);
                    this.interopActivationChannelFactory.Endpoint.Behaviors.Remove <ClientCredentials>();
                    this.interopActivationChannelFactory.Endpoint.Behaviors.Add(item);
                    this.OpenChannelFactory <IRequestReplyService>(this.interopActivationChannelFactory);
                }
                this.namedPipeActivationChannelFactory = this.CreateChannelFactory <IRequestReplyService>(this.namedPipeActivationBinding);
                this.OpenChannelFactory <IRequestReplyService>(this.namedPipeActivationChannelFactory);
                if (this.config.RemoteClientsEnabled)
                {
                    this.windowsActivationChannelFactory = this.CreateChannelFactory <IRequestReplyService>(this.windowsActivationBinding);
                    this.OpenChannelFactory <IRequestReplyService>(this.windowsActivationChannelFactory);
                }
            }
            this.requestReplyChannelCache = new ChannelMruCache <IRequestReplyService>();
            if ((this.config.Mode & CoordinationServiceMode.ProtocolService) != 0)
            {
                this.datagramChannelCache = new ChannelMruCache <IDatagramService>();
            }
            DebugTrace.TraceLeave(this, "Initialize");
        }
コード例 #2
0
        private CoordinationServiceHost CreateService(object dispatcher, System.Type contract, string pathSuffix)
        {
            Binding                 namedPipeActivationBinding;
            ServiceCredentials      serviceCredentials;
            CoordinationServiceHost host = new CoordinationServiceHost(this, dispatcher)
            {
                InternalBaseAddresses = { this.httpsBaseAddressUri }
            };
            ServiceAuthorizationBehavior behavior = host.Description.Behaviors.Find <ServiceAuthorizationBehavior>();

            behavior.PrincipalPermissionMode     = PrincipalPermissionMode.None;
            behavior.ServiceAuthorizationManager = this.globalAclAuthz;
            if (dispatcher is IWSActivationCoordinator)
            {
                host.InternalBaseAddresses.Add(this.namedPipeBaseAddressUri);
                namedPipeActivationBinding = this.namedPipeActivationBinding;
                host.AddServiceEndpoint(contract, namedPipeActivationBinding, pathSuffix);
                if (this.config.RemoteClientsEnabled)
                {
                    namedPipeActivationBinding = this.windowsActivationBinding;
                    host.AddServiceEndpoint(contract, namedPipeActivationBinding, pathSuffix + "Remote/");
                }
                namedPipeActivationBinding = this.interopActivationBinding;
                serviceCredentials         = new DefaultServiceCredentials();
            }
            else if (dispatcher is IWSRegistrationCoordinator)
            {
                namedPipeActivationBinding = this.interopRegistrationBinding;
                if (this.config.SupportingTokensEnabled)
                {
                    serviceCredentials = this.interopRegistrationBinding.SupportingTokenBindingElement.ServiceCredentials;
                }
                else
                {
                    serviceCredentials = new DefaultServiceCredentials();
                }
            }
            else
            {
                namedPipeActivationBinding = this.interopDatagramBinding;
                serviceCredentials         = new DefaultServiceCredentials();
            }
            host.AddServiceEndpoint(contract, namedPipeActivationBinding, pathSuffix);
            serviceCredentials.WindowsAuthentication.IncludeWindowsGroups = true;
            serviceCredentials.ServiceCertificate.Certificate             = this.config.X509Certificate;
            serviceCredentials.ClientCertificate.Certificate = this.config.X509Certificate;
            host.Description.Behaviors.Add(serviceCredentials);
            ServiceMetadataBehavior behavior2 = host.Description.Behaviors.Find <ServiceMetadataBehavior>();

            if (behavior2 != null)
            {
                if (DebugTrace.Verbose)
                {
                    DebugTrace.Trace(TraceLevel.Verbose, "Disabling WS-MeX support");
                }
                behavior2.HttpGetEnabled  = false;
                behavior2.HttpsGetEnabled = false;
            }
            ServiceDebugBehavior behavior3 = host.Description.Behaviors.Find <ServiceDebugBehavior>();

            if (behavior3 != null)
            {
                if (DebugTrace.Verbose)
                {
                    DebugTrace.Trace(TraceLevel.Verbose, "Disabling WS-MeX support");
                }
                behavior3.HttpHelpPageEnabled  = false;
                behavior3.HttpsHelpPageEnabled = false;
            }
            return(host);
        }