示例#1
0
        public void Client_Can_Recover_From_QuotaExceededException()
        {
            using (IWindsorContainer container = Container)
            {
                container.Register(
                    Component.For <LogErrorHandler>(),
                    Component.For <IOperations>()
                    .ImplementedBy <Operations>()
                    .LifeStyle.Transient
                    .AsWcfService(
                        new DefaultServiceModel()
                        .AddEndpoints(WcfEndpoint
                                      .BoundTo(new NetTcpBinding {
                    PortSharingEnabled = true
                })
                                      .At("net.tcp://localhost/Operations"))),
                    Component.For <IOperations>()
                    .Named("client")
                    .LifeStyle.Transient
                    .AsWcfClient(
                        new DefaultClientModel(
                            WcfEndpoint
                            .ForContract <IOperations>()
                            .BoundTo(new NetTcpBinding {
                    PortSharingEnabled = true
                })
                            .At("net.tcp://localhost/Operations"))));

                WcfFacility     wcfFacility = container.Kernel.GetFacilities().OfType <WcfFacility>().Single();
                ServiceHost     host        = wcfFacility.Services.ManagedServiceHosts.Single();
                ServiceEndpoint endpoint    = host.Description.Endpoints.First();
                NetTcpBinding   binding     = endpoint.Binding as NetTcpBinding;
                Assert.IsNotNull(binding);

                long        maxMessageSize = binding.MaxReceivedMessageSize;
                IOperations client         = container.Resolve <IOperations>("client");

                try
                {
                    client.GetByteArrayInt(maxMessageSize + 1);
                }
                catch (CommunicationException e)
                {
                    if (!(e.InnerException is QuotaExceededException))
                    {
                        throw;
                    }
                }
                int i = client.GetInt();
                Assert.AreEqual(1, i);
            }
        }