Ejemplo n.º 1
0
        public IServiceEndpointBinder <TService> GenerateServiceEndpointBinder <TService>(Type?serviceInstanceType)
        {
            if (serviceInstanceType != null && !ServiceContract.IsServiceInstanceType(serviceInstanceType))
            {
                throw new ArgumentOutOfRangeException(nameof(serviceInstanceType));
            }

            var serviceType = typeof(TService);

            ContractDescription description;
            Type contractType;
            Type channelType;

            lock (ProxyAssembly.SyncRoot)
            {
                (description, contractType) = GenerateContract(serviceType);
                channelType = ProxyAssembly.DefaultModule.GetType(ContractDescription.GetEndpointClassName(serviceType), false, false) !;
                if (channelType == null)
                {
                    var serviceBuilder = new EmitServiceEndpointBuilder(description);
                    channelType = serviceBuilder.Build(ProxyAssembly.DefaultModule, Logger);
                }
            }

            return(new EmitServiceEndpointBinder <TService>(description, serviceInstanceType, contractType, channelType, Logger));
        }