| | | 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.Generic; |
| | | 6 | | using System.Collections.ObjectModel; |
| | | 7 | | using System.Globalization; |
| | | 8 | | using System.Text; |
| | | 9 | | using CoreWCF.Channels; |
| | | 10 | | using CoreWCF.Description; |
| | | 11 | | using CoreWCF.Dispatcher; |
| | | 12 | | using CoreWCF.Runtime; |
| | | 13 | | |
| | | 14 | | namespace CoreWCF |
| | | 15 | | { |
| | | 16 | | public abstract class ServiceHostBase : CommunicationObject, IExtensibleObject<ServiceHostBase>, IDisposable |
| | | 17 | | { |
| | 0 | 18 | | internal static readonly Uri s_emptyUri = new Uri(string.Empty, UriKind.RelativeOrAbsolute); |
| | | 19 | | private bool _initializeDescriptionHasFinished; |
| | 591 | 20 | | private TimeSpan _closeTimeout = ServiceDefaults.ServiceHostCloseTimeout; |
| | | 21 | | private readonly ExtensionCollection<ServiceHostBase> _extensions; |
| | | 22 | | private ReadOnlyCollection<Uri> _externalBaseAddresses; |
| | | 23 | | private IDictionary<string, ContractDescription> _implementedContracts; |
| | | 24 | | private readonly IInstanceContextManager _instances; |
| | 591 | 25 | | private TimeSpan _openTimeout = ServiceDefaults.OpenTimeout; |
| | | 26 | | |
| | | 27 | | //ServiceAuthenticationBehavior readOnlyAuthentication; |
| | | 28 | | //EventTraceActivity eventTraceActivity; |
| | | 29 | | |
| | | 30 | | #pragma warning disable CS0067 // The event is never used - see issue #288 |
| | | 31 | | public event EventHandler<UnknownMessageReceivedEventArgs> UnknownMessageReceived; |
| | | 32 | | #pragma warning restore CS0067 // The event is never used |
| | | 33 | | |
| | 591 | 34 | | protected ServiceHostBase() |
| | | 35 | | { |
| | 591 | 36 | | InternalBaseAddresses = new UriSchemeKeyedCollection(ThisLock); |
| | 591 | 37 | | ChannelDispatchers = new ChannelDispatcherCollection(this, ThisLock); |
| | 591 | 38 | | _extensions = new ExtensionCollection<ServiceHostBase>(this, ThisLock); |
| | 591 | 39 | | _instances = new InstanceContextManager(ThisLock); |
| | 591 | 40 | | } |
| | | 41 | | |
| | | 42 | | public ServiceAuthorizationBehavior Authorization |
| | | 43 | | { |
| | | 44 | | get |
| | | 45 | | { |
| | 9 | 46 | | if (Description == null) |
| | | 47 | | { |
| | 0 | 48 | | return null; |
| | | 49 | | } |
| | 9 | 50 | | else if (State == CommunicationState.Created || State == CommunicationState.Opening) |
| | | 51 | | { |
| | 9 | 52 | | return EnsureAuthorization(Description); |
| | | 53 | | } |
| | | 54 | | else |
| | | 55 | | { |
| | 0 | 56 | | return null; |
| | | 57 | | } |
| | | 58 | | } |
| | | 59 | | } |
| | | 60 | | |
| | | 61 | | // TODO: Bring in ServiceAuthenticationBehavior |
| | | 62 | | //public ServiceAuthenticationBehavior Authentication |
| | | 63 | | //{ |
| | | 64 | | // get |
| | | 65 | | // { |
| | | 66 | | // if (this.Description == null) |
| | | 67 | | // { |
| | | 68 | | // return null; |
| | | 69 | | // } |
| | | 70 | | // else if (this.State == CommunicationState.Created || this.State == CommunicationState.Opening) |
| | | 71 | | // { |
| | | 72 | | // return EnsureAuthentication(this.Description); |
| | | 73 | | // } |
| | | 74 | | // else |
| | | 75 | | // { |
| | | 76 | | // return this.readOnlyAuthentication; |
| | | 77 | | // } |
| | | 78 | | // } |
| | | 79 | | //} |
| | | 80 | | |
| | | 81 | | public ReadOnlyCollection<Uri> BaseAddresses |
| | | 82 | | { |
| | | 83 | | get |
| | | 84 | | { |
| | 1176 | 85 | | _externalBaseAddresses = new ReadOnlyCollection<Uri>(new List<Uri>(InternalBaseAddresses)); |
| | 1176 | 86 | | return _externalBaseAddresses; |
| | | 87 | | } |
| | | 88 | | } |
| | | 89 | | |
| | 7639 | 90 | | public ChannelDispatcherCollection ChannelDispatchers { get; } |
| | | 91 | | |
| | | 92 | | public TimeSpan CloseTimeout |
| | | 93 | | { |
| | 2851 | 94 | | get { return _closeTimeout; } |
| | | 95 | | set |
| | | 96 | | { |
| | 0 | 97 | | if (value < TimeSpan.Zero) |
| | | 98 | | { |
| | 0 | 99 | | string message = SRCommon.SFxTimeoutOutOfRange0; |
| | 0 | 100 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val |
| | | 101 | | } |
| | 0 | 102 | | if (TimeoutHelper.IsTooLarge(value)) |
| | | 103 | | { |
| | 0 | 104 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val |
| | | 105 | | } |
| | | 106 | | |
| | 0 | 107 | | lock (ThisLock) |
| | | 108 | | { |
| | 0 | 109 | | ThrowIfClosedOrOpened(); |
| | 0 | 110 | | _closeTimeout = value; |
| | 0 | 111 | | } |
| | 0 | 112 | | } |
| | | 113 | | } |
| | | 114 | | |
| | | 115 | | public ServiceCredentials Credentials |
| | | 116 | | { |
| | | 117 | | get |
| | | 118 | | { |
| | 17 | 119 | | if (Description == null) |
| | | 120 | | { |
| | 0 | 121 | | return null; |
| | | 122 | | } |
| | 17 | 123 | | else if (State == CommunicationState.Created || State == CommunicationState.Opening) |
| | | 124 | | { |
| | 17 | 125 | | return Description.EnsureCredentials(); |
| | | 126 | | } |
| | | 127 | | else |
| | | 128 | | { |
| | 0 | 129 | | return null; |
| | | 130 | | } |
| | | 131 | | } |
| | | 132 | | } |
| | | 133 | | |
| | | 134 | | protected override TimeSpan DefaultCloseTimeout |
| | | 135 | | { |
| | 519 | 136 | | get { return CloseTimeout; } |
| | | 137 | | } |
| | | 138 | | |
| | | 139 | | protected override TimeSpan DefaultOpenTimeout |
| | | 140 | | { |
| | 2 | 141 | | get { return OpenTimeout; } |
| | | 142 | | } |
| | | 143 | | |
| | 3901 | 144 | | public ServiceDescription Description { get; private set; } |
| | | 145 | | |
| | | 146 | | public IExtensionCollection<ServiceHostBase> Extensions |
| | | 147 | | { |
| | 1206 | 148 | | get { return _extensions; } |
| | | 149 | | } |
| | | 150 | | |
| | | 151 | | protected internal IDictionary<string, ContractDescription> ImplementedContracts |
| | | 152 | | { |
| | 1152 | 153 | | get { return _implementedContracts; } |
| | | 154 | | } |
| | | 155 | | |
| | 3009 | 156 | | internal UriSchemeKeyedCollection InternalBaseAddresses { get; } |
| | | 157 | | |
| | | 158 | | public int ManualFlowControlLimit |
| | | 159 | | { |
| | 0 | 160 | | get { return 0; /*return this.ServiceThrottle.ManualFlowControlLimit;*/ } |
| | 0 | 161 | | set { /*this.ServiceThrottle.ManualFlowControlLimit = value;*/ } |
| | | 162 | | } |
| | | 163 | | |
| | | 164 | | public TimeSpan OpenTimeout |
| | | 165 | | { |
| | 74 | 166 | | get { return _openTimeout; } |
| | | 167 | | set |
| | | 168 | | { |
| | 0 | 169 | | if (value < TimeSpan.Zero) |
| | | 170 | | { |
| | 0 | 171 | | string message = SRCommon.SFxTimeoutOutOfRange0; |
| | 0 | 172 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val |
| | | 173 | | } |
| | 0 | 174 | | if (TimeoutHelper.IsTooLarge(value)) |
| | | 175 | | { |
| | 0 | 176 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val |
| | | 177 | | } |
| | | 178 | | |
| | 0 | 179 | | lock (ThisLock) |
| | | 180 | | { |
| | 0 | 181 | | ThrowIfClosedOrOpened(); |
| | 0 | 182 | | _openTimeout = value; |
| | 0 | 183 | | } |
| | 0 | 184 | | } |
| | | 185 | | } |
| | | 186 | | |
| | | 187 | | internal virtual object DisposableInstance |
| | | 188 | | { |
| | | 189 | | get |
| | | 190 | | { |
| | 0 | 191 | | return null; |
| | | 192 | | } |
| | | 193 | | } |
| | | 194 | | |
| | | 195 | | protected void AddBaseAddress(Uri baseAddress) |
| | | 196 | | { |
| | 471 | 197 | | if (_initializeDescriptionHasFinished) |
| | | 198 | | { |
| | 0 | 199 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException( |
| | 0 | 200 | | SR.SFxCannotCallAddBaseAddress)); |
| | | 201 | | } |
| | | 202 | | |
| | 471 | 203 | | InternalBaseAddresses.Add(baseAddress); |
| | 471 | 204 | | } |
| | | 205 | | |
| | | 206 | | internal Uri MakeAbsoluteUri(Uri relativeOrAbsoluteUri, Binding binding) |
| | | 207 | | { |
| | 641 | 208 | | return MakeAbsoluteUri(relativeOrAbsoluteUri, binding, InternalBaseAddresses); |
| | | 209 | | } |
| | | 210 | | |
| | | 211 | | internal static Uri MakeAbsoluteUri(Uri relativeOrAbsoluteUri, Binding binding, UriSchemeKeyedCollection baseAdd |
| | | 212 | | { |
| | 641 | 213 | | Uri result = relativeOrAbsoluteUri; |
| | 641 | 214 | | if (!result.IsAbsoluteUri) |
| | | 215 | | { |
| | 527 | 216 | | if (binding.Scheme == string.Empty) |
| | | 217 | | { |
| | 0 | 218 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.SFxCustom |
| | | 219 | | } |
| | 527 | 220 | | result = GetVia(binding.Scheme, result, baseAddresses); |
| | 527 | 221 | | if (result == null) |
| | | 222 | | { |
| | 0 | 223 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR |
| | | 224 | | } |
| | | 225 | | } |
| | | 226 | | |
| | 641 | 227 | | return result; |
| | | 228 | | } |
| | | 229 | | |
| | | 230 | | protected virtual void ApplyConfiguration() |
| | | 231 | | { |
| | 580 | 232 | | if (Description == null) |
| | | 233 | | { |
| | 0 | 234 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.SFxServiceHos |
| | | 235 | | } |
| | | 236 | | |
| | 580 | 237 | | EnsureAuthenticationAuthorizationDebug(Description); |
| | 580 | 238 | | } |
| | | 239 | | |
| | | 240 | | internal void EnsureAuthenticationAuthorizationDebug(ServiceDescription description) |
| | | 241 | | { |
| | | 242 | | //EnsureAuthentication(description); |
| | 580 | 243 | | EnsureAuthorization(description); |
| | 580 | 244 | | EnsureDebug(description); |
| | 580 | 245 | | } |
| | | 246 | | |
| | | 247 | | internal virtual void BindInstance(InstanceContext instance) |
| | | 248 | | { |
| | 2463 | 249 | | _instances.Add(instance); |
| | | 250 | | //if (null != this.servicePerformanceCounters) |
| | | 251 | | //{ |
| | | 252 | | // lock (this.ThisLock) |
| | | 253 | | // { |
| | | 254 | | // if (null != this.servicePerformanceCounters) |
| | | 255 | | // { |
| | | 256 | | // this.servicePerformanceCounters.ServiceInstanceCreated(); |
| | | 257 | | // } |
| | | 258 | | // } |
| | | 259 | | //} |
| | 2463 | 260 | | } |
| | | 261 | | |
| | | 262 | | void IDisposable.Dispose() |
| | | 263 | | { |
| | 518 | 264 | | CloseAsync().GetAwaiter().GetResult(); |
| | 518 | 265 | | } |
| | | 266 | | |
| | | 267 | | protected abstract ServiceDescription CreateDescription(out IDictionary<string, ContractDescription> implemented |
| | | 268 | | |
| | | 269 | | protected virtual void InitializeRuntime() |
| | | 270 | | { |
| | 0 | 271 | | throw new PlatformNotSupportedException(); |
| | | 272 | | } |
| | | 273 | | |
| | | 274 | | private ServiceAuthorizationBehavior EnsureAuthorization(ServiceDescription description) |
| | | 275 | | { |
| | | 276 | | Fx.Assert(State == CommunicationState.Created || State == CommunicationState.Opening, ""); |
| | 589 | 277 | | ServiceAuthorizationBehavior behavior = description.Behaviors.Find<ServiceAuthorizationBehavior>(); |
| | | 278 | | |
| | 589 | 279 | | if (behavior == null) |
| | | 280 | | { |
| | 0 | 281 | | behavior = description.ServiceProvider.GetService(typeof(ServiceAuthorizationBehavior)) as ServiceAuthor |
| | | 282 | | } |
| | | 283 | | |
| | 589 | 284 | | return behavior; |
| | | 285 | | } |
| | | 286 | | |
| | | 287 | | //ServiceAuthenticationBehavior EnsureAuthentication(ServiceDescription description) |
| | | 288 | | //{ |
| | | 289 | | // Fx.Assert(this.State == CommunicationState.Created || this.State == CommunicationState.Opening, ""); |
| | | 290 | | // ServiceAuthenticationBehavior a = description.Behaviors.Find<ServiceAuthenticationBehavior>(); |
| | | 291 | | |
| | | 292 | | // if (a == null) |
| | | 293 | | // { |
| | | 294 | | // a = new ServiceAuthenticationBehavior(); |
| | | 295 | | // description.Behaviors.Add(a); |
| | | 296 | | // } |
| | | 297 | | // return a; |
| | | 298 | | //} |
| | | 299 | | |
| | | 300 | | private ServiceDebugBehavior EnsureDebug(ServiceDescription description) |
| | | 301 | | { |
| | | 302 | | Fx.Assert(State == CommunicationState.Created || State == CommunicationState.Opening, ""); |
| | 580 | 303 | | ServiceDebugBehavior m = description.Behaviors.Find<ServiceDebugBehavior>(); |
| | | 304 | | |
| | 580 | 305 | | if (m == null) |
| | | 306 | | { |
| | 580 | 307 | | m = new ServiceDebugBehavior(); |
| | 580 | 308 | | description.Behaviors.Add(m); |
| | | 309 | | } |
| | | 310 | | |
| | 580 | 311 | | return m; |
| | | 312 | | } |
| | | 313 | | |
| | | 314 | | internal static string GetBaseAddressSchemes(UriSchemeKeyedCollection uriSchemeKeyedCollection) |
| | | 315 | | { |
| | 0 | 316 | | StringBuilder buffer = new StringBuilder(); |
| | 0 | 317 | | bool firstScheme = true; |
| | 0 | 318 | | foreach (Uri address in uriSchemeKeyedCollection) |
| | | 319 | | { |
| | 0 | 320 | | if (firstScheme) |
| | | 321 | | { |
| | 0 | 322 | | buffer.Append(address.Scheme); |
| | 0 | 323 | | firstScheme = false; |
| | | 324 | | } |
| | | 325 | | else |
| | | 326 | | { |
| | 0 | 327 | | buffer.Append(CultureInfo.CurrentCulture.TextInfo.ListSeparator).Append(address.Scheme); |
| | | 328 | | } |
| | | 329 | | } |
| | | 330 | | |
| | 0 | 331 | | return buffer.ToString(); |
| | | 332 | | } |
| | | 333 | | |
| | | 334 | | internal static Uri GetVia(string scheme, Uri address, UriSchemeKeyedCollection baseAddresses) |
| | | 335 | | { |
| | 527 | 336 | | Uri via = address; |
| | 527 | 337 | | if (!via.IsAbsoluteUri) |
| | | 338 | | { |
| | 527 | 339 | | Uri baseAddress = null; |
| | 1665 | 340 | | foreach(var ba in baseAddresses) |
| | | 341 | | { |
| | 569 | 342 | | if (ba.Scheme.Equals(scheme)) |
| | | 343 | | { |
| | 527 | 344 | | baseAddress = ba; |
| | 527 | 345 | | break; |
| | | 346 | | } |
| | | 347 | | } |
| | 527 | 348 | | if (baseAddress == null) |
| | | 349 | | { |
| | 0 | 350 | | return null; |
| | | 351 | | } |
| | | 352 | | |
| | 527 | 353 | | via = GetUri(baseAddress, address); |
| | | 354 | | } |
| | 527 | 355 | | return via; |
| | | 356 | | } |
| | | 357 | | |
| | | 358 | | internal Uri GetVia(string scheme, Uri address) |
| | | 359 | | { |
| | 1202 | 360 | | if (!address.IsAbsoluteUri) |
| | | 361 | | { |
| | 1176 | 362 | | Uri baseAddress = null; |
| | 4095 | 363 | | foreach (var ba in BaseAddresses) |
| | | 364 | | { |
| | 1112 | 365 | | if (ba.Scheme.Equals(scheme)) |
| | | 366 | | { |
| | 481 | 367 | | baseAddress = ba; |
| | 481 | 368 | | break; |
| | | 369 | | } |
| | | 370 | | } |
| | | 371 | | |
| | 1176 | 372 | | if (baseAddress == null) |
| | | 373 | | { |
| | 695 | 374 | | return null; |
| | | 375 | | } |
| | | 376 | | |
| | 481 | 377 | | return GetUri(baseAddress, address.OriginalString); |
| | | 378 | | } |
| | | 379 | | |
| | 26 | 380 | | return address; |
| | | 381 | | } |
| | | 382 | | |
| | | 383 | | private static Uri GetUri(Uri baseUri, string path) |
| | | 384 | | { |
| | 481 | 385 | | if (path.StartsWith("/", StringComparison.Ordinal) || path.StartsWith("\\", StringComparison.Ordinal)) |
| | | 386 | | { |
| | 0 | 387 | | int i = 1; |
| | 0 | 388 | | for (; i < path.Length; ++i) |
| | | 389 | | { |
| | 0 | 390 | | if (path[i] != '/' && path[i] != '\\') |
| | | 391 | | { |
| | | 392 | | break; |
| | | 393 | | } |
| | | 394 | | } |
| | 0 | 395 | | path = path.Substring(i); |
| | | 396 | | } |
| | | 397 | | |
| | 481 | 398 | | if (path.Length == 0) |
| | 481 | 399 | | return baseUri; |
| | | 400 | | |
| | 0 | 401 | | if (!baseUri.AbsoluteUri.EndsWith("/", StringComparison.Ordinal)) |
| | | 402 | | { |
| | 0 | 403 | | baseUri = new Uri(baseUri.AbsoluteUri + "/"); |
| | | 404 | | } |
| | 0 | 405 | | return new Uri(baseUri, path); |
| | | 406 | | } |
| | | 407 | | |
| | | 408 | | internal static Uri GetUri(Uri baseUri, Uri relativeUri) |
| | | 409 | | { |
| | 527 | 410 | | string path = relativeUri.OriginalString; |
| | 527 | 411 | | if (path.StartsWith("/", StringComparison.Ordinal) || path.StartsWith("\\", StringComparison.Ordinal)) |
| | | 412 | | { |
| | 477 | 413 | | int i = 1; |
| | 477 | 414 | | for (; i < path.Length; ++i) |
| | | 415 | | { |
| | 477 | 416 | | if (path[i] != '/' && path[i] != '\\') |
| | | 417 | | { |
| | | 418 | | break; |
| | | 419 | | } |
| | | 420 | | } |
| | 477 | 421 | | path = path.Substring(i); |
| | | 422 | | } |
| | | 423 | | |
| | | 424 | | // new Uri(Uri, string.Empty) is broken |
| | 527 | 425 | | if (path.Length == 0) |
| | | 426 | | { |
| | 1 | 427 | | return baseUri; |
| | | 428 | | } |
| | | 429 | | |
| | 526 | 430 | | if (!baseUri.AbsoluteUri.EndsWith("/", StringComparison.Ordinal)) |
| | | 431 | | { |
| | 13 | 432 | | baseUri = new Uri(baseUri.AbsoluteUri + "/"); |
| | | 433 | | } |
| | | 434 | | |
| | 526 | 435 | | return new Uri(baseUri, path); |
| | | 436 | | } |
| | | 437 | | |
| | | 438 | | //public int IncrementManualFlowControlLimit(int incrementBy) |
| | | 439 | | //{ |
| | | 440 | | // throw new PlatformNotSupportedException(); |
| | | 441 | | //} |
| | | 442 | | |
| | | 443 | | protected void InitializeDescription(UriSchemeKeyedCollection baseAddresses) |
| | | 444 | | { |
| | 1354 | 445 | | foreach (Uri baseAddress in baseAddresses) |
| | | 446 | | { |
| | 90 | 447 | | InternalBaseAddresses.Add(baseAddress); |
| | | 448 | | } |
| | | 449 | | |
| | 587 | 450 | | Description = CreateDescription(out _implementedContracts); |
| | 580 | 451 | | ApplyConfiguration(); |
| | 580 | 452 | | _initializeDescriptionHasFinished = true; |
| | 580 | 453 | | } |
| | | 454 | | |
| | | 455 | | // Configuration |
| | | 456 | | //protected void LoadConfigurationSection(ServiceElement serviceSection) |
| | | 457 | | //{ |
| | | 458 | | // throw new PlatformNotSupportedException(); |
| | | 459 | | //} |
| | | 460 | | |
| | | 461 | | internal void OnAddChannelDispatcher(ChannelDispatcherBase channelDispatcher) |
| | | 462 | | { |
| | 640 | 463 | | lock (ThisLock) |
| | | 464 | | { |
| | 640 | 465 | | ThrowIfClosedOrOpened(); |
| | 640 | 466 | | channelDispatcher.AttachInternal(this); |
| | 640 | 467 | | channelDispatcher.Faulted += new EventHandler(OnChannelDispatcherFaulted); |
| | 640 | 468 | | } |
| | 640 | 469 | | } |
| | | 470 | | |
| | | 471 | | internal void OnRemoveChannelDispatcher(ChannelDispatcherBase channelDispatcher) |
| | | 472 | | { |
| | 0 | 473 | | lock (ThisLock) |
| | | 474 | | { |
| | 0 | 475 | | ThrowIfClosedOrOpened(); |
| | 0 | 476 | | channelDispatcher.DetachInternal(this); |
| | 0 | 477 | | } |
| | 0 | 478 | | } |
| | | 479 | | |
| | | 480 | | private void OnChannelDispatcherFaulted(object sender, EventArgs e) |
| | | 481 | | { |
| | 0 | 482 | | Fault(); |
| | 0 | 483 | | } |
| | | 484 | | |
| | | 485 | | //protected void ReleasePerformanceCounters() |
| | | 486 | | //{ |
| | | 487 | | // throw new PlatformNotSupportedException(); |
| | | 488 | | //} |
| | | 489 | | |
| | | 490 | | internal virtual void UnbindInstance(InstanceContext instance) |
| | | 491 | | { |
| | 2390 | 492 | | _instances.Remove(instance); |
| | | 493 | | //if (null != this.servicePerformanceCounters) |
| | | 494 | | //{ |
| | | 495 | | // lock (this.ThisLock) |
| | | 496 | | // { |
| | | 497 | | // if (null != this.servicePerformanceCounters) |
| | | 498 | | // { |
| | | 499 | | // this.servicePerformanceCounters.ServiceInstanceRemoved(); |
| | | 500 | | // } |
| | | 501 | | // } |
| | | 502 | | //} |
| | 2390 | 503 | | } |
| | | 504 | | |
| | | 505 | | private class ImplementedContractsContractResolver : IContractResolver |
| | | 506 | | { |
| | | 507 | | private readonly IDictionary<string, ContractDescription> _implementedContracts; |
| | | 508 | | |
| | 0 | 509 | | public ImplementedContractsContractResolver(IDictionary<string, ContractDescription> implementedContracts) |
| | | 510 | | { |
| | 0 | 511 | | _implementedContracts = implementedContracts; |
| | 0 | 512 | | } |
| | | 513 | | |
| | | 514 | | public ContractDescription ResolveContract(string contractName) |
| | | 515 | | { |
| | 0 | 516 | | return _implementedContracts != null && _implementedContracts.ContainsKey(contractName) ? _implementedCo |
| | | 517 | | } |
| | | 518 | | } |
| | | 519 | | |
| | | 520 | | internal class ServiceAndBehaviorsContractResolver : IContractResolver |
| | | 521 | | { |
| | | 522 | | private readonly IContractResolver _serviceResolver; |
| | | 523 | | |
| | 0 | 524 | | public Dictionary<string, ContractDescription> BehaviorContracts { get; } |
| | | 525 | | |
| | 0 | 526 | | public ServiceAndBehaviorsContractResolver(IContractResolver serviceResolver) |
| | | 527 | | { |
| | 0 | 528 | | _serviceResolver = serviceResolver; |
| | 0 | 529 | | BehaviorContracts = new Dictionary<string, ContractDescription>(); |
| | 0 | 530 | | } |
| | | 531 | | |
| | | 532 | | public ContractDescription ResolveContract(string contractName) |
| | | 533 | | { |
| | 0 | 534 | | ContractDescription contract = _serviceResolver.ResolveContract(contractName); |
| | | 535 | | |
| | 0 | 536 | | if (contract == null) |
| | | 537 | | { |
| | 0 | 538 | | contract = BehaviorContracts.ContainsKey(contractName) ? BehaviorContracts[contractName] : null; |
| | | 539 | | } |
| | | 540 | | |
| | 0 | 541 | | return contract; |
| | | 542 | | } |
| | | 543 | | } |
| | | 544 | | } |
| | | 545 | | } |