コード例 #1
0
        /// <summary>
        /// Creates a contract from the specified description.
        /// </summary>
        /// <param name="description">The description to create a contract from.</param>
        /// <returns>A <see cref="ContractDescription"/>.</returns>
        private ContractDescription CreateContract(DomainServiceDescription description)
        {
            Type domainServiceType = description.DomainServiceType;

            // PERF: We should consider just looking at [ServiceDescription] directly.
            ServiceDescription serviceDesc = ServiceDescription.GetService(domainServiceType);

            // Use names from [ServiceContract], if specified.
            if (TypeDescriptor.GetAttributes(domainServiceType)[typeof(ServiceContractAttribute)]
                is ServiceContractAttribute sca)
            {
                if (!string.IsNullOrEmpty(sca.Name))
                {
                    serviceDesc.Name = sca.Name;
                }
                if (!string.IsNullOrEmpty(sca.Namespace))
                {
                    serviceDesc.Namespace = sca.Namespace;
                }
            }

            ContractDescription contractDesc = new ContractDescription(serviceDesc.Name, serviceDesc.Namespace)
            {
                ConfigurationName = serviceDesc.ConfigurationName,
                ContractType      = domainServiceType
            };

            // Add domain service behavior which takes care of instantiating DomainServices.
            ServiceUtility.EnsureBehavior <DomainServiceBehavior>(contractDesc);
            // Disable metadata generation by default
            contractDesc.Behaviors.Add(new ServiceMetadataContractBehavior()
            {
                MetadataGenerationDisabled = true
            });

            // Load the ContractDescription from the DomainServiceDescription.
            ServiceUtility.PopulateContractDescription(contractDesc, description);

            return(contractDesc);
        }