| | | 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.Collections.Generic; |
| | | 5 | | using System.Threading.Tasks; |
| | | 6 | | using CoreWCF.Configuration; |
| | | 7 | | using Microsoft.Extensions.Hosting; |
| | | 8 | | using Microsoft.Extensions.DependencyInjection; |
| | | 9 | | using System.Collections; |
| | | 10 | | using CoreWCF.Runtime; |
| | | 11 | | |
| | | 12 | | namespace CoreWCF.Channels.Framing |
| | | 13 | | { |
| | | 14 | | internal class ServerSessionConnectionReaderMiddleware |
| | | 15 | | { |
| | | 16 | | private readonly HandshakeDelegate _next; |
| | | 17 | | private readonly IServiceScopeFactory _servicesScopeFactory; |
| | | 18 | | private readonly IApplicationLifetime _appLifetime; |
| | 83 | 19 | | private readonly Hashtable _transportSettingsCache = new Hashtable(); |
| | 83 | 20 | | private readonly object _lock = new object(); |
| | | 21 | | |
| | 83 | 22 | | public ServerSessionConnectionReaderMiddleware(HandshakeDelegate next, IServiceScopeFactory servicesScopeFactory |
| | | 23 | | { |
| | 83 | 24 | | _next = next; |
| | 83 | 25 | | _servicesScopeFactory = servicesScopeFactory; |
| | 83 | 26 | | _appLifetime = appLifetime; |
| | 83 | 27 | | } |
| | | 28 | | |
| | | 29 | | public async Task OnConnectedAsync(FramingConnection connection) |
| | | 30 | | { |
| | | 31 | | ITransportFactorySettings settings; |
| | 64 | 32 | | if (_transportSettingsCache.Contains(connection.ServiceDispatcher)) |
| | | 33 | | { |
| | 15 | 34 | | settings = (ITransportFactorySettings)_transportSettingsCache[connection.ServiceDispatcher]; |
| | | 35 | | } |
| | | 36 | | else |
| | | 37 | | { |
| | 49 | 38 | | lock (_lock) |
| | | 39 | | { |
| | | 40 | | // Double locked checking not necessary as there's no functional harm to having multiple instances |
| | 49 | 41 | | BindingElementCollection be = connection.ServiceDispatcher.Binding.CreateBindingElements(); |
| | 49 | 42 | | TransportBindingElement tbe = be.Find<TransportBindingElement>(); |
| | 49 | 43 | | settings = new NetFramingTransportSettings |
| | 49 | 44 | | { |
| | 49 | 45 | | CloseTimeout = connection.ServiceDispatcher.Binding.CloseTimeout, |
| | 49 | 46 | | OpenTimeout = connection.ServiceDispatcher.Binding.OpenTimeout, |
| | 49 | 47 | | ReceiveTimeout = connection.ServiceDispatcher.Binding.ReceiveTimeout, |
| | 49 | 48 | | SendTimeout = connection.ServiceDispatcher.Binding.SendTimeout, |
| | 49 | 49 | | ManualAddressing = tbe.ManualAddressing, |
| | 49 | 50 | | BufferManager = connection.BufferManager, |
| | 49 | 51 | | MaxReceivedMessageSize = tbe.MaxReceivedMessageSize, |
| | 49 | 52 | | MessageEncoderFactory = connection.MessageEncoderFactory |
| | 49 | 53 | | }; |
| | 49 | 54 | | _transportSettingsCache[connection.ServiceDispatcher] = settings; |
| | 49 | 55 | | } |
| | | 56 | | } |
| | | 57 | | |
| | 64 | 58 | | var channel = new ServerFramingDuplexSessionChannel(connection, settings, false, _servicesScopeFactory.Creat |
| | 64 | 59 | | channel.ChannelDispatcher = await connection.ServiceDispatcher.CreateServiceChannelDispatcherAsync(channel); |
| | 64 | 60 | | await channel.StartReceivingAsync(); |
| | 63 | 61 | | await channel.CloseAsync(); |
| | 63 | 62 | | } |
| | | 63 | | } |
| | | 64 | | } |