Пример #1
0
        public EndpointAddress GetAddress(ServiceHostBase host)
        {
            if (this.AddressUri == null)
            {
                string endpointName = ContractValidationHelper.GetErrorMessageEndpointName(this.Name);
                string contractName = ContractValidationHelper.GetErrorMessageEndpointServiceContractName(this.ServiceContractName);
                throw FxTrace.Exception.AsError(new InvalidOperationException(
                                                    SMASR.MissingUriInEndpoint(endpointName, contractName)));
            }

            Uri address = null;

            if (this.AddressUri.IsAbsoluteUri)
            {
                address = this.AddressUri;
            }
            else
            {
                if (this.Binding == null)
                {
                    string endpointName = ContractValidationHelper.GetErrorMessageEndpointName(this.Name);
                    string contractName = ContractValidationHelper.GetErrorMessageEndpointServiceContractName(this.ServiceContractName);
                    throw FxTrace.Exception.AsError(new InvalidOperationException(
                                                        SMASR.RelativeUriRequiresBinding(endpointName, contractName, this.AddressUri)));
                }
                if (host == null)
                {
                    string endpointName = ContractValidationHelper.GetErrorMessageEndpointName(this.Name);
                    string contractName = ContractValidationHelper.GetErrorMessageEndpointServiceContractName(this.ServiceContractName);
                    throw FxTrace.Exception.AsError(new InvalidOperationException(
                                                        SMASR.RelativeUriRequiresHost(endpointName, contractName, this.AddressUri)));
                }
                address = host.MakeAbsoluteUri(this.AddressUri, this.Binding);
            }

            return(new EndpointAddress(address, this.Identity, new AddressHeaderCollection(this.Headers)));
        }