コード例 #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);
            }
        }
        public void Can_Call_From_Client_To_Closed_Service_()
        {
            using (IWindsorContainer container = Container)
            {
                container.Register(
                    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"))));

                IOperations client = container.Resolve <IOperations>("client");
                client.GetInt();

                // Shutdown the server
                WcfFacility wcfFacility = container.Kernel.GetFacilities().OfType <WcfFacility>().Single();
                ServiceHost host        = wcfFacility.Services.ManagedServiceHosts.Single();
                host.Close();

                client.GetInt();
            }
        }
        public void Can_Call_From_Client_To_None_Existing_EndPoint()
        {
            using (IWindsorContainer container = Container)
            {
                container.Register(
                    Component.For <IOperations>()
                    .Named("client")
                    .LifeStyle.Transient
                    .AsWcfClient(
                        new DefaultClientModel(
                            WcfEndpoint
                            .ForContract <IOperations>()
                            .BoundTo(new NetTcpBinding {
                    PortSharingEnabled = true
                })
                            .At("net.tcp://localhost/Operations"))));

                IOperations client = container.Resolve <IOperations>("client");
                client.GetInt();
            }
        }
        public void Can_Apply_Specific_ServiceBehavior()
        {
            using (IWindsorContainer container = Container)
            {
                container.Register(
                    Component.For <ServiceBehavior4IOperations2>()
                    .Named("serviceBehaviorIOperations2")
                    .Attribute(WcfConstants.ExtensionScopeKey).Eq(WcfExtensionScope.Explicit),
                    Component.For <IOperations>()
                    .ImplementedBy <Operations>()
                    .LifeStyle.Transient
                    .AsWcfService(
                        new DefaultServiceModel()
                        .AddEndpoints(WcfEndpoint
                                      .BoundTo(new NetTcpBinding {
                    PortSharingEnabled = true
                })
                                      .At("net.tcp://localhost/Operations"))),
                    Component.For <IOperations2>()
                    .ImplementedBy <Operations2>()
                    .LifeStyle.Transient
                    .AsWcfService(
                        new DefaultServiceModel()
                        .AddEndpoints(WcfEndpoint
                                      .BoundTo(new NetTcpBinding {
                    PortSharingEnabled = true
                })
                                      .At("net.tcp://localhost/Operations2"))
                        .AddExtensions("serviceBehaviorIOperations2")));

                WcfFacility wcfFacility = container.Kernel.GetFacilities().OfType <WcfFacility>().Single();

                // IOperations is PerSession
                // Check on behavior + check nr. instances created
                ServiceHost host = wcfFacility.Services.ManagedServiceHosts.Single(h => h.Description.Endpoints.Any(e => e.Contract.ContractType == typeof(IOperations)));
                ServiceBehaviorAttribute serviceBehavior = host.Description.Behaviors.OfType <ServiceBehaviorAttribute>().SingleOrDefault();
                Assert.IsNotNull(serviceBehavior);
                Assert.AreEqual(InstanceContextMode.PerSession, serviceBehavior.InstanceContextMode);

                IOperations client = GetClient();
                Operations.s_GetIntResults.Clear();

                client.GetInt();
                client.GetInt();
                Assert.AreEqual(2, Operations.s_GetIntResults.Count);
                Assert.AreEqual(1, Operations.s_GetIntResults[0]);
                Assert.AreEqual(2, Operations.s_GetIntResults[1]);

                // IOperations2 is PerCall
                // Check on behavior + check nr. instances created
                ServiceHost host2 = wcfFacility.Services.ManagedServiceHosts.Single(h => h.Description.Endpoints.Any(e => e.Contract.ContractType == typeof(IOperations2)));
                ServiceBehaviorAttribute serviceBehavior2 = host2.Description.Behaviors.OfType <ServiceBehaviorAttribute>().SingleOrDefault();
                Assert.IsNotNull(serviceBehavior2);
                Assert.AreEqual(InstanceContextMode.PerCall, serviceBehavior2.InstanceContextMode);

                IOperations2 client2 = GetClient2();
                Operations2.s_GetIntResults.Clear();

                client2.GetInt();
                client2.GetInt();
                Assert.AreEqual(2, Operations2.s_GetIntResults.Count);
                Assert.IsTrue(Operations2.s_GetIntResults.All(r => r == 1));
            }
        }