1 //------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation. All rights reserved.
3 //------------------------------------------------------------
5 namespace System.ServiceModel.Description
8 using System.Collections.Generic;
9 using System.Collections.ObjectModel;
10 using System.ComponentModel;
11 using System.Diagnostics;
12 using System.Globalization;
13 using System.ServiceModel;
14 using System.ServiceModel.Channels;
15 using System.ServiceModel.Dispatcher;
17 [DebuggerDisplay("Address={address}")]
18 [DebuggerDisplay("Name={name}")]
19 public class ServiceEndpoint
21 EndpointAddress address;
23 ContractDescription contract;
25 ListenUriMode listenUriMode = ListenUriMode.Explicit;
26 KeyedByTypeCollection<IEndpointBehavior> behaviors;
29 bool isEndpointFullyConfigured = false;
31 public ServiceEndpoint(ContractDescription contract)
34 throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("contract");
35 this.contract = contract;
38 public ServiceEndpoint(ContractDescription contract, Binding binding, EndpointAddress address)
41 throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("contract");
43 this.contract = contract;
44 this.binding = binding;
45 this.address = address;
48 public EndpointAddress Address
50 get { return this.address; }
51 set { this.address = value; }
54 public KeyedCollection<Type, IEndpointBehavior> EndpointBehaviors
56 get { return this.Behaviors; }
59 [EditorBrowsable(EditorBrowsableState.Never)]
60 public KeyedByTypeCollection<IEndpointBehavior> Behaviors
64 if (this.behaviors == null)
66 this.behaviors = new KeyedByTypeCollection<IEndpointBehavior>();
69 return this.behaviors;
73 public Binding Binding
75 get { return this.binding; }
76 set { this.binding = value; }
79 public ContractDescription Contract
81 get { return this.contract; }
86 throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("value");
88 this.contract = value;
92 public bool IsSystemEndpoint
102 if (!XmlName.IsNullOrEmpty(name))
104 return name.EncodedName;
106 else if (binding != null)
108 // [....]: composing names have potential problem of generating name that looks like an encoded name, consider avoiding '_'
109 return String.Format(CultureInfo.InvariantCulture, "{0}_{1}", new XmlName(Binding.Name).EncodedName, Contract.Name);
113 return Contract.Name;
118 name = new XmlName(value, true /*isEncoded*/);
126 if (this.listenUri == null)
128 if (this.address == null)
134 return this.address.Uri;
139 return this.listenUri;
144 if (value != null && !value.IsAbsoluteUri)
146 throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("value", SR.GetString(SR.UriMustBeAbsolute));
148 this.listenUri = value;
152 public ListenUriMode ListenUriMode
154 get { return this.listenUriMode; }
157 if (!ListenUriModeHelper.IsDefined(value))
159 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value"));
161 this.listenUriMode = value;
170 id = Guid.NewGuid().ToString();
175 internal Uri UnresolvedAddress
181 internal Uri UnresolvedListenUri
187 // This method ensures that the description object graph is structurally sound and that none
188 // of the fundamental SFx framework assumptions have been violated.
189 internal void EnsureInvariants()
193 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.AChannelServiceEndpointSBindingIsNull0)));
195 if (Contract == null)
197 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.AChannelServiceEndpointSContractIsNull0)));
199 this.Contract.EnsureInvariants();
200 this.Binding.EnsureInvariants(this.Contract.Name);
203 internal void ValidateForClient()
205 Validate(true, false);
208 internal void ValidateForService(bool runOperationValidators)
210 Validate(runOperationValidators, true);
213 internal bool IsFullyConfigured
215 get { return this.isEndpointFullyConfigured; }
216 set { this.isEndpointFullyConfigured = value; }
219 // for V1 legacy reasons, a mex endpoint is considered a system endpoint even if IsSystemEndpoint = false
220 internal bool InternalIsSystemEndpoint(ServiceDescription description)
222 if (ServiceMetadataBehavior.IsMetadataEndpoint(description, this))
226 return this.IsSystemEndpoint;
229 // This method runs validators (both builtin and ones in description).
230 // Precondition: EnsureInvariants() should already have been called.
231 void Validate(bool runOperationValidators, bool isForService)
233 // contract behaviors
234 ContractDescription contract = this.Contract;
235 for (int j = 0; j < contract.Behaviors.Count; j++)
237 IContractBehavior iContractBehavior = contract.Behaviors[j];
238 iContractBehavior.Validate(contract, this);
240 // endpoint behaviors
243 (PartialTrustValidationBehavior.Instance as IEndpointBehavior).Validate(this);
244 #pragma warning disable 0618
245 (PeerValidationBehavior.Instance as IEndpointBehavior).Validate(this);
246 #pragma warning restore 0618
247 (TransactionValidationBehavior.Instance as IEndpointBehavior).Validate(this);
248 (SecurityValidationBehavior.Instance as IEndpointBehavior).Validate(this);
249 (System.ServiceModel.MsmqIntegration.MsmqIntegrationValidationBehavior.Instance as IEndpointBehavior).Validate(this);
251 for (int j = 0; j < this.Behaviors.Count; j++)
253 IEndpointBehavior ieb = this.Behaviors[j];
256 // operation behaviors
257 if (runOperationValidators)
259 for (int j = 0; j < contract.Operations.Count; j++)
261 OperationDescription op = contract.Operations[j];
262 TaskOperationDescriptionValidator.Validate(op, isForService);
263 for (int k = 0; k < op.Behaviors.Count; k++)
265 IOperationBehavior iob = op.Behaviors[k];