public async Task DispatchAsync(Message message) { if (message == null) //0 bytes { //We have already closed all channels, return. (Couldn't use DoneReceivingInCurrentState()) if (_channel.State == CommunicationState.Closed || _channel.State == CommunicationState.Closing || _channel.State == CommunicationState.Closed) { return; } else { await _serviceChannelDispatcher.DispatchAsync(message); return; } } IServiceDispatcher serviceDispatcher = _demuxer.MatchDispatcher(message); if (serviceDispatcher == null) { ErrorBehavior.ThrowAndCatch( new EndpointNotFoundException(SR.Format(SR.UnableToDemuxChannel, message.Headers.Action)), message); await _demuxer.EndpointNotFoundAsync((IDuplexSessionChannel)_channel, message); return; } _serviceChannelDispatcher = await serviceDispatcher.CreateServiceChannelDispatcherAsync(_channel); await _serviceChannelDispatcher.DispatchAsync(message); }
private void BuildHandler() { BindingElementCollection be = _serviceDispatcher.Binding.CreateBindingElements(); MessageEncodingBindingElement mebe = be.Find <MessageEncodingBindingElement>(); if (mebe == null) { throw new ArgumentException("Must provide a MessageEncodingBindingElement", nameof(_serviceDispatcher.Binding)); } HttpTransportBindingElement tbe = be.Find <HttpTransportBindingElement>(); if (tbe == null) { throw new ArgumentException("Must provide a HttpTransportBindingElement", nameof(_serviceDispatcher.Binding)); } var httpSettings = new HttpTransportSettings { BufferManager = BufferManager.CreateBufferManager(DefaultMaxBufferPoolSize, tbe.MaxBufferSize), OpenTimeout = _serviceDispatcher.Binding.OpenTimeout, ReceiveTimeout = _serviceDispatcher.Binding.ReceiveTimeout, SendTimeout = _serviceDispatcher.Binding.SendTimeout, CloseTimeout = _serviceDispatcher.Binding.CloseTimeout, MaxBufferSize = tbe.MaxBufferSize, MaxReceivedMessageSize = tbe.MaxReceivedMessageSize, MessageEncoderFactory = mebe.CreateMessageEncoderFactory(), ManualAddressing = tbe.ManualAddressing, TransferMode = tbe.TransferMode, KeepAliveEnabled = tbe.KeepAliveEnabled, AnonymousUriPrefixMatcher = new HttpAnonymousUriPrefixMatcher(), AuthenticationScheme = tbe.AuthenticationScheme, WebSocketSettings = tbe.WebSocketSettings.Clone() }; _httpSettings = httpSettings; WebSocketOptions = CreateWebSocketOptions(tbe); if (WebSocketOptions == null) { _replyChannel = new AspNetCoreReplyChannel(_servicesScopeFactory.CreateScope().ServiceProvider, _httpSettings); _replyChannelDispatcherTask = _serviceDispatcher.CreateServiceChannelDispatcherAsync(_replyChannel); } }
public async Task DispatchAsync(RequestContext context) { // TODO: Find way to avoid instantiating a new ServiceChannelDispatcher each time IServiceDispatcher serviceDispatcher = _demuxer.MatchDispatcher(context.RequestMessage); if (serviceDispatcher == null) { ErrorBehavior.ThrowAndCatch( new EndpointNotFoundException(SR.Format(SR.UnableToDemuxChannel, context.RequestMessage.Headers.Action)), context.RequestMessage); } // TODO: if serviceDispatcher == null, use the EndpointNotFound code path IServiceChannelDispatcher serviceChannelDispatcher = await serviceDispatcher.CreateServiceChannelDispatcherAsync(_channel); await serviceChannelDispatcher.DispatchAsync(context); }
public static void BuildDispatcherWithConfiguration_XmlSerializer() { string serviceAddress = "http://localhost/dummy"; var services = new ServiceCollection(); services.AddLogging(); services.AddServiceModelServices(); IServer server = new MockServer(); services.AddSingleton(server); services.AddSingleton(typeof(ILogger <>), typeof(NullLogger <>)); services.RegisterApplicationLifetime(); ServiceProvider serviceProvider = services.BuildServiceProvider(); IServiceBuilder serviceBuilder = serviceProvider.GetRequiredService <IServiceBuilder>(); serviceBuilder.BaseAddresses.Add(new Uri(serviceAddress)); serviceBuilder.AddService <SimpleXmlSerializerService>(); var binding = new CustomBinding("BindingName", "BindingNS"); binding.Elements.Add(new MockTransportBindingElement()); serviceBuilder.AddServiceEndpoint <SimpleXmlSerializerService, ISimpleXmlSerializerService>(binding, serviceAddress); serviceBuilder.OpenAsync().GetAwaiter().GetResult(); IDispatcherBuilder dispatcherBuilder = serviceProvider.GetRequiredService <IDispatcherBuilder>(); System.Collections.Generic.List <IServiceDispatcher> dispatchers = dispatcherBuilder.BuildDispatchers(typeof(SimpleXmlSerializerService)); Assert.Single(dispatchers); IServiceDispatcher serviceDispatcher = dispatchers[0]; Assert.Equal("foo", serviceDispatcher.Binding.Scheme); Assert.Equal(serviceAddress, serviceDispatcher.BaseAddress.ToString()); IChannel mockChannel = new MockReplyChannel(serviceProvider); IServiceChannelDispatcher dispatcher = serviceDispatcher.CreateServiceChannelDispatcherAsync(mockChannel).Result; var requestContext = XmlSerializerTestRequestContext.Create(serviceAddress); dispatcher.DispatchAsync(requestContext).Wait(); Assert.True(requestContext.WaitForReply(TimeSpan.FromSeconds(5)), "Dispatcher didn't send reply"); requestContext.ValidateReply(); }