Ejemplo n.º 1
0
        static EndpointDiscoveryMetadata GetEndpointDiscoveryMetadata(ServiceEndpoint endpoint, Uri listenUri)
        {
            EndpointDiscoveryMetadata endpointDiscoveryMetadata = new EndpointDiscoveryMetadata();

            endpointDiscoveryMetadata.Address = endpoint.Address;
            endpointDiscoveryMetadata.ListenUris.Add(listenUri);

            EndpointDiscoveryBehavior endpointDiscoveryBehavior = endpoint.Behaviors.Find <EndpointDiscoveryBehavior>();

            if (endpointDiscoveryBehavior != null)
            {
                if (!endpointDiscoveryBehavior.Enabled)
                {
                    if (TD.EndpointDiscoverabilityDisabledIsEnabled())
                    {
                        TD.EndpointDiscoverabilityDisabled(endpoint.Address.ToString(), listenUri.ToString());
                    }
                    return(null);
                }

                if (TD.EndpointDiscoverabilityEnabledIsEnabled())
                {
                    TD.EndpointDiscoverabilityEnabled(endpoint.Address.ToString(), listenUri.ToString());
                }

                if (endpointDiscoveryBehavior.InternalContractTypeNames != null)
                {
                    foreach (XmlQualifiedName contractTypeName in endpointDiscoveryBehavior.InternalContractTypeNames)
                    {
                        endpointDiscoveryMetadata.ContractTypeNames.Add(contractTypeName);
                    }
                }

                if (endpointDiscoveryBehavior.InternalScopes != null)
                {
                    foreach (Uri scope in endpointDiscoveryBehavior.InternalScopes)
                    {
                        endpointDiscoveryMetadata.Scopes.Add(scope);
                    }
                }
                if (endpointDiscoveryBehavior.InternalExtensions != null)
                {
                    foreach (XElement xElement in endpointDiscoveryBehavior.InternalExtensions)
                    {
                        endpointDiscoveryMetadata.Extensions.Add(xElement);
                    }
                }
            }

            XmlQualifiedName defaultContractTypeName = new XmlQualifiedName(endpoint.Contract.Name, endpoint.Contract.Namespace);

            if (!endpointDiscoveryMetadata.ContractTypeNames.Contains(defaultContractTypeName))
            {
                endpointDiscoveryMetadata.ContractTypeNames.Add(defaultContractTypeName);
            }

            return(endpointDiscoveryMetadata);
        }