Пример #1
0
        ServiceEndpoint AddServiceEndpointCore(XName serviceContractName, Binding binding, EndpointAddress address,
                                               Uri listenUri = null, string behaviorConfigurationName = null)
        {
            if (serviceContractName == null)
            {
                throw FxTrace.Exception.ArgumentNull("serviceContractName");
            }
            if (this.inferredContracts == null)
            {
                throw FxTrace.Exception.AsError(new InvalidOperationException(
                                                    SR.ContractNotFoundInAddServiceEndpoint(serviceContractName.LocalName, serviceContractName.NamespaceName)));
            }

            ServiceEndpoint     serviceEndpoint;
            ContractDescription description;

            ContractInferenceHelper.ProvideDefaultNamespace(ref serviceContractName);

            if (this.inferredContracts.TryGetValue(serviceContractName, out description))
            {
                serviceEndpoint = new ServiceEndpoint(description, binding, address);

                if (!string.IsNullOrEmpty(behaviorConfigurationName))
                {
                    ConfigLoader.LoadChannelBehaviors(behaviorConfigurationName, null, serviceEndpoint.Behaviors);
                }
            }
            else if (serviceContractName == mexContractXName)  // Special case for mex endpoint
            {
                if (!this.Description.Behaviors.Contains(mexBehaviorType))
                {
                    throw FxTrace.Exception.AsError(new InvalidOperationException(
                                                        SR.ServiceMetadataBehaviorNotFoundForServiceMetadataEndpoint(this.Description.Name)));
                }

                serviceEndpoint = new ServiceMetadataEndpoint(binding, address);
            }
            else
            {
                throw FxTrace.Exception.AsError(new InvalidOperationException(
                                                    SR.ContractNotFoundInAddServiceEndpoint(serviceContractName.LocalName, serviceContractName.NamespaceName)));
            }

            if (listenUri != null)
            {
                listenUri = base.MakeAbsoluteUri(listenUri, binding);
                serviceEndpoint.ListenUri = listenUri;
            }

            base.Description.Endpoints.Add(serviceEndpoint);

            if (TD.ServiceEndpointAddedIsEnabled())
            {
                TD.ServiceEndpointAdded(address.Uri.ToString(), binding.GetType().ToString(), serviceEndpoint.Contract.Name);
            }

            return(serviceEndpoint);
        }