| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System; |
| | | 5 | | using System.Collections.ObjectModel; |
| | | 6 | | using System.Globalization; |
| | | 7 | | using CoreWCF.Channels; |
| | | 8 | | using CoreWCF.Collections.Generic; |
| | | 9 | | |
| | | 10 | | namespace CoreWCF.Description |
| | | 11 | | { |
| | | 12 | | public class ServiceEndpoint |
| | | 13 | | { |
| | | 14 | | private ContractDescription _contract; |
| | | 15 | | private Uri _listenUri; |
| | | 16 | | private ListenUriMode _listenUriMode = ListenUriMode.Explicit; |
| | | 17 | | private KeyedByTypeCollection<IEndpointBehavior> _behaviors; |
| | | 18 | | private string _id; |
| | | 19 | | private XmlName _name; |
| | | 20 | | |
| | 42 | 21 | | public ServiceEndpoint(ContractDescription contract) |
| | | 22 | | { |
| | 42 | 23 | | _contract = contract ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(contract)); |
| | 42 | 24 | | } |
| | | 25 | | |
| | 641 | 26 | | public ServiceEndpoint(ContractDescription contract, Binding binding, EndpointAddress address) |
| | | 27 | | { |
| | 641 | 28 | | _contract = contract ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(contract)); |
| | 641 | 29 | | Binding = binding; |
| | 641 | 30 | | Address = address; |
| | 641 | 31 | | } |
| | | 32 | | |
| | 7129 | 33 | | public EndpointAddress Address { get; set; } |
| | | 34 | | |
| | | 35 | | public KeyedCollection<Type, IEndpointBehavior> EndpointBehaviors |
| | | 36 | | { |
| | 2969 | 37 | | get { return Behaviors; } |
| | | 38 | | } |
| | | 39 | | |
| | | 40 | | internal KeyedByTypeCollection<IEndpointBehavior> Behaviors |
| | | 41 | | { |
| | | 42 | | get |
| | | 43 | | { |
| | 5726 | 44 | | if (_behaviors == null) |
| | | 45 | | { |
| | 673 | 46 | | _behaviors = new KeyedByTypeCollection<IEndpointBehavior>(); |
| | | 47 | | } |
| | | 48 | | |
| | 5726 | 49 | | return _behaviors; |
| | | 50 | | } |
| | | 51 | | } |
| | | 52 | | |
| | 8219 | 53 | | public Binding Binding { get; set; } |
| | | 54 | | |
| | | 55 | | public ContractDescription Contract |
| | | 56 | | { |
| | 14759 | 57 | | get { return _contract; } |
| | | 58 | | set |
| | | 59 | | { |
| | 0 | 60 | | _contract = value ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(value)); |
| | 0 | 61 | | } |
| | | 62 | | } |
| | | 63 | | |
| | | 64 | | public bool IsSystemEndpoint |
| | | 65 | | { |
| | 1890 | 66 | | get; |
| | 0 | 67 | | set; |
| | | 68 | | } |
| | | 69 | | |
| | | 70 | | public string Name |
| | | 71 | | { |
| | | 72 | | get |
| | | 73 | | { |
| | 96 | 74 | | if (!XmlName.IsNullOrEmpty(_name)) |
| | | 75 | | { |
| | 64 | 76 | | return _name.EncodedName; |
| | | 77 | | } |
| | 32 | 78 | | else if (Binding != null) |
| | | 79 | | { |
| | 32 | 80 | | return string.Format(CultureInfo.InvariantCulture, "{0}_{1}", new XmlName(Binding.Name).EncodedName, |
| | | 81 | | } |
| | | 82 | | else |
| | | 83 | | { |
| | 0 | 84 | | return Contract.Name; |
| | | 85 | | } |
| | | 86 | | } |
| | | 87 | | set |
| | | 88 | | { |
| | 32 | 89 | | _name = new XmlName(value, true /*isEncoded*/); |
| | 32 | 90 | | } |
| | | 91 | | } |
| | | 92 | | |
| | | 93 | | public Uri ListenUri |
| | | 94 | | { |
| | | 95 | | get |
| | | 96 | | { |
| | 641 | 97 | | if (_listenUri == null) |
| | | 98 | | { |
| | 641 | 99 | | if (Address == null) |
| | | 100 | | { |
| | 0 | 101 | | return null; |
| | | 102 | | } |
| | | 103 | | else |
| | | 104 | | { |
| | 641 | 105 | | return Address.Uri; |
| | | 106 | | } |
| | | 107 | | } |
| | | 108 | | else |
| | | 109 | | { |
| | 0 | 110 | | return _listenUri; |
| | | 111 | | } |
| | | 112 | | } |
| | | 113 | | set |
| | | 114 | | { |
| | 0 | 115 | | if (value != null && !value.IsAbsoluteUri) |
| | | 116 | | { |
| | 0 | 117 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(nameof(value), SR.UriMustBeAbsolute); |
| | | 118 | | } |
| | 0 | 119 | | _listenUri = value; |
| | 0 | 120 | | } |
| | | 121 | | } |
| | | 122 | | |
| | | 123 | | internal ListenUriMode ListenUriMode |
| | | 124 | | { |
| | 641 | 125 | | get { return _listenUriMode; } |
| | | 126 | | set |
| | | 127 | | { |
| | 0 | 128 | | if (!ListenUriModeHelper.IsDefined(value)) |
| | | 129 | | { |
| | 0 | 130 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val |
| | | 131 | | } |
| | 0 | 132 | | _listenUriMode = value; |
| | 0 | 133 | | } |
| | | 134 | | } |
| | | 135 | | |
| | | 136 | | public string Id |
| | | 137 | | { |
| | | 138 | | get |
| | | 139 | | { |
| | 673 | 140 | | if (_id == null) |
| | | 141 | | { |
| | 641 | 142 | | _id = Guid.NewGuid().ToString(); |
| | | 143 | | } |
| | | 144 | | |
| | 673 | 145 | | return _id; |
| | | 146 | | } |
| | | 147 | | } |
| | | 148 | | |
| | | 149 | | internal Uri UnresolvedAddress |
| | | 150 | | { |
| | 0 | 151 | | get; |
| | 0 | 152 | | set; |
| | | 153 | | } |
| | | 154 | | |
| | | 155 | | internal Uri UnresolvedListenUri |
| | | 156 | | { |
| | 0 | 157 | | get; |
| | 0 | 158 | | set; |
| | | 159 | | } |
| | | 160 | | |
| | | 161 | | // This method ensures that the description object graph is structurally sound and that none |
| | | 162 | | // of the fundamental SFx framework assumptions have been violated. |
| | | 163 | | internal void EnsureInvariants() |
| | | 164 | | { |
| | 641 | 165 | | if (Binding == null) |
| | | 166 | | { |
| | 0 | 167 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.AChannelServi |
| | | 168 | | } |
| | 641 | 169 | | if (Contract == null) |
| | | 170 | | { |
| | 0 | 171 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.AChannelServi |
| | | 172 | | } |
| | 641 | 173 | | Contract.EnsureInvariants(); |
| | 641 | 174 | | Binding.EnsureInvariants(Contract.Name); |
| | 641 | 175 | | } |
| | | 176 | | |
| | | 177 | | internal void ValidateForClient() |
| | | 178 | | { |
| | 0 | 179 | | Validate(true, false); |
| | 0 | 180 | | } |
| | | 181 | | |
| | | 182 | | internal void ValidateForService(bool runOperationValidators) |
| | | 183 | | { |
| | 641 | 184 | | Validate(runOperationValidators, true); |
| | 641 | 185 | | } |
| | | 186 | | |
| | 0 | 187 | | internal bool IsFullyConfigured { get; set; } = false; |
| | | 188 | | |
| | | 189 | | // for V1 legacy reasons, a mex endpoint is considered a system endpoint even if IsSystemEndpoint = false |
| | | 190 | | internal bool InternalIsSystemEndpoint(ServiceDescription description) |
| | | 191 | | { |
| | | 192 | | //if (ServiceMetadataBehavior.IsMetadataEndpoint(description, this)) |
| | | 193 | | //{ |
| | | 194 | | // return true; |
| | | 195 | | //} |
| | 1858 | 196 | | return IsSystemEndpoint; |
| | | 197 | | } |
| | | 198 | | |
| | | 199 | | // This method runs validators (both builtin and ones in description). |
| | | 200 | | // Precondition: EnsureInvariants() should already have been called. |
| | | 201 | | private void Validate(bool runOperationValidators, bool isForService) |
| | | 202 | | { |
| | | 203 | | // contract behaviors |
| | 641 | 204 | | ContractDescription contract = Contract; |
| | 2576 | 205 | | for (int j = 0; j < contract.ContractBehaviors.Count; j++) |
| | | 206 | | { |
| | 647 | 207 | | IContractBehavior iContractBehavior = contract.ContractBehaviors[j]; |
| | 647 | 208 | | iContractBehavior.Validate(contract, this); |
| | | 209 | | } |
| | | 210 | | // endpoint behaviors |
| | 2720 | 211 | | for (int j = 0; j < EndpointBehaviors.Count; j++) |
| | | 212 | | { |
| | 719 | 213 | | IEndpointBehavior ieb = EndpointBehaviors[j]; |
| | 719 | 214 | | ieb.Validate(this); |
| | | 215 | | } |
| | | 216 | | // operation behaviors |
| | 641 | 217 | | if (runOperationValidators) |
| | | 218 | | { |
| | 6444 | 219 | | for (int j = 0; j < contract.Operations.Count; j++) |
| | | 220 | | { |
| | 2645 | 221 | | OperationDescription op = contract.Operations[j]; |
| | 2645 | 222 | | TaskOperationDescriptionValidator.Validate(op, isForService); |
| | 21500 | 223 | | for (int k = 0; k < op.OperationBehaviors.Count; k++) |
| | | 224 | | { |
| | 8105 | 225 | | IOperationBehavior iob = op.OperationBehaviors[k]; |
| | 8105 | 226 | | iob.Validate(op); |
| | | 227 | | } |
| | | 228 | | } |
| | | 229 | | } |
| | 641 | 230 | | } |
| | | 231 | | } |
| | | 232 | | } |