Exemple #1
0
        public void ServiceBuilderCanChain()
        {
            var services = new ServiceCollection();

            services.AddServiceModelServices();
            ServiceProvider serviceProvider = services.BuildServiceProvider();
            IServiceBuilder builder         = serviceProvider.GetRequiredService <IServiceBuilder>();

            Assert.Equal(builder, builder.AddService <SomeService>());
            Assert.Equal(builder, builder.AddService(typeof(SomeService)));
            Assert.Equal(builder, builder.AddServiceEndpoint <SomeService, IService>(new NoBinding(), new Uri("http://localhost:8088/SomeService.svc")));
            Assert.Equal(builder, builder.AddServiceEndpoint <SomeService, IService>(new NoBinding(), "http://localhost:8088/SomeService.svc"));
            Assert.Equal(builder, builder.AddServiceEndpoint <SomeService>(typeof(IService), new NoBinding(), new Uri("http://localhost:8088/SomeService.svc")));
            Assert.Equal(builder, builder.AddServiceEndpoint <SomeService>(typeof(IService), new NoBinding(), "http://localhost:8088/SomeService.svc"));
        }
        internal void ConfigureServiceBuilder(IServiceBuilder serviceBuilder)
        {
            foreach (var configDelegate in _configDelegates)
            {
                configDelegate(this);
            }

            serviceBuilder.AddService(_serviceType);
            foreach (var endpoint in _endpoints)
            {
                serviceBuilder.AddServiceEndpoint(_serviceType, endpoint.Contract, endpoint.Binding, endpoint.Address, endpoint.ListenUri);
            }

            _endpoints.Clear();
        }
        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();
        }