| | | 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.Threading; |
| | | 6 | | using System.Threading.Tasks; |
| | | 7 | | using Microsoft.Extensions.DependencyInjection; |
| | | 8 | | |
| | | 9 | | namespace CoreWCF.Channels |
| | | 10 | | { |
| | | 11 | | // tracks StreamUpgradeProvider so that the channel can outlive the Listener |
| | | 12 | | internal class ConnectionOrientedTransportReplyChannel : ReplyChannel |
| | | 13 | | { |
| | | 14 | | private StreamUpgradeProvider _upgrade; |
| | | 15 | | private IServiceProvider _serviceProvider; |
| | | 16 | | |
| | | 17 | | public ConnectionOrientedTransportReplyChannel(ITransportFactorySettings settings, EndpointAddress localAddress, |
| | 28 | 18 | | : base(settings, localAddress) |
| | | 19 | | { |
| | 28 | 20 | | _serviceProvider = serviceProvider; |
| | 28 | 21 | | } |
| | | 22 | | |
| | | 23 | | public bool TransferUpgrade(StreamUpgradeProvider upgrade) |
| | | 24 | | { |
| | 0 | 25 | | lock (ThisLock) |
| | | 26 | | { |
| | 0 | 27 | | if (State != CommunicationState.Opened) |
| | | 28 | | { |
| | 0 | 29 | | return false; |
| | | 30 | | } |
| | | 31 | | |
| | 0 | 32 | | _upgrade = upgrade; |
| | 0 | 33 | | return true; |
| | | 34 | | } |
| | 0 | 35 | | } |
| | | 36 | | |
| | | 37 | | protected override void OnAbort() |
| | | 38 | | { |
| | 0 | 39 | | if (_upgrade != null) |
| | | 40 | | { |
| | 0 | 41 | | _upgrade.Abort(); |
| | | 42 | | } |
| | 0 | 43 | | base.OnAbort(); |
| | 0 | 44 | | } |
| | | 45 | | |
| | | 46 | | protected override async Task OnCloseAsync(CancellationToken token) |
| | | 47 | | { |
| | 0 | 48 | | if (_upgrade != null) |
| | | 49 | | { |
| | 0 | 50 | | await _upgrade.CloseAsync(token); |
| | | 51 | | } |
| | | 52 | | |
| | 0 | 53 | | await base.OnCloseAsync(token); |
| | | 54 | | |
| | 0 | 55 | | if (_serviceProvider is IAsyncDisposable asyncDisposable) |
| | | 56 | | { |
| | 0 | 57 | | await asyncDisposable.DisposeAsync(); |
| | | 58 | | } |
| | 0 | 59 | | else if (_serviceProvider is IDisposable disposable) |
| | | 60 | | { |
| | 0 | 61 | | disposable.Dispose(); |
| | | 62 | | } |
| | | 63 | | |
| | 0 | 64 | | _serviceProvider = null; |
| | 0 | 65 | | } |
| | | 66 | | |
| | | 67 | | public override T GetProperty<T>() |
| | | 68 | | { |
| | 84 | 69 | | T service = _serviceProvider.GetService<T>(); |
| | 84 | 70 | | if (service == null) |
| | | 71 | | { |
| | 28 | 72 | | service = base.GetProperty<T>(); |
| | | 73 | | } |
| | | 74 | | |
| | 84 | 75 | | return service; |
| | | 76 | | } |
| | | 77 | | } |
| | | 78 | | } |