public void Install(IWindsorContainer container, IConfigurationStore store)
        {
            container.AddFacility <WcfFacility>(r => { r.CloseTimeout = TimeSpan.Zero; });

            var endpoint = ConfigurationManager.AppSettings.Get("Endpoint_Service");

            var returnFaults = new ServiceDebugBehavior
            {
                IncludeExceptionDetailInFaults = true,
                HttpHelpPageEnabled            = true
            };

            container.Register(Component.For <IServiceBehavior>().Instance(returnFaults));

            container.Register(
                Component.For <IClockService>()
                .ImplementedBy <ClockService>()
                .Named("ClockService")
                .LifestyleTransient()
                .AsWcfService(new DefaultServiceModel()
                              .AddBaseAddresses(endpoint)
                              .PublishMetadata(mex => { mex.EnableHttpGet(); })
                              .AddEndpoints(WcfEndpoint
                                            .ForContract <IClockService>()
                                            .BoundTo(Binding.WS_DUAL_HTTP).At(endpoint)
                                            )
                              )
                );
        }
Exemple #2
0
        public void Install(IWindsorContainer container, IConfigurationStore store)
        {
            container.AddFacility <WcfFacility>(f => { f.CloseTimeout = TimeSpan.Zero; });

            var returnFaults = new ServiceDebugBehavior
            {
                IncludeExceptionDetailInFaults = true,
                HttpHelpPageEnabled            = true
            };

            container.Register(Component.For <IServiceBehavior>().Instance(returnFaults));

            var endpoint = ConfigurationManager.AppSettings.Get("Endpoint_Service");

            container.Register(Component.For <IClockServiceCallback>()
                               .ImplementedBy <ClockCallback>()
                               .LifestyleTransient());

            container.Register(Component.For <IClockService>()
                               //.AsWcfClient(new DefaultClientModel
                               //{
                               //  Endpoint = WcfEndpoint.BoundTo(Binding.WS_DUAL_HTTP).At(endpoint)
                               //})
                               .AsWcfClient(new DuplexClientModel
            {
                Endpoint = WcfEndpoint.BoundTo(Binding.WS_DUAL_HTTP).At(endpoint)
            }.Callback(container.Resolve <IClockServiceCallback>()))
                               .LifestyleTransient());
        }
Exemple #3
0
        public void CanCreateServiceHostAndOpenHostWithRelativeEndpoints()
        {
            using (new WindsorContainer()
                   .AddFacility <WcfFacility>(f => f.CloseTimeout = TimeSpan.Zero)
                   .Register(Component.For <Operations>()
                             .DependsOn(new { number = 42 })
                             .AsWcfService(new DefaultServiceModel()
                                           .AddBaseAddresses(
                                               "net.tcp://localhost/Operations",
                                               "http://localhost:27198/UsingWindsor.svc")
                                           .AddEndpoints(
                                               WcfEndpoint.ForContract <IOperations>()
                                               .BoundTo(new NetTcpBinding {
                PortSharingEnabled = true
            }),
                                               WcfEndpoint.ForContract <IOperationsEx>()
                                               .BoundTo(new BasicHttpBinding())
                                               .At("Extended")
                                               )
                                           )
                             ))
            {
                var client = ChannelFactory <IOperations> .CreateChannel(
                    new NetTcpBinding { PortSharingEnabled = true }, new EndpointAddress("net.tcp://localhost/Operations"));

                Assert.AreEqual(42, client.GetValueFromConstructor());

                var clientEx = ChannelFactory <IOperationsEx> .CreateChannel(
                    new BasicHttpBinding(), new EndpointAddress("http://localhost:27198/UsingWindsor.svc/Extended"));

                clientEx.Backup(new Dictionary <string, object>());
            }
        }
Exemple #4
0
        public void CanOpenServiceHostsWithServicesDependingOnOpenGenerics()
        {
            using (var container = new WindsorContainer()
                                   .AddFacility <WcfFacility>(f =>
            {
                //f.Services.OpenServiceHostsEagerly = true;
                f.DefaultBinding = new NetTcpBinding {
                    PortSharingEnabled = true
                };
                f.CloseTimeout = TimeSpan.Zero;
            })
                                   .Register(
                       Component.For(typeof(IDecorator <>)).ImplementedBy(typeof(Decorator <>)),
                       Component.For <IServiceGenericDependency>().ImplementedBy <ServiceGenericDependency>().LifeStyle.Transient
                       .AsWcfService(new DefaultServiceModel().AddEndpoints(
                                         WcfEndpoint.BoundTo(new NetTcpBinding())
                                         .At("net.tcp://localhost/Operations")
                                         )
                                     ),
                       Component.For <IServiceNoDependencies>().UsingFactoryMethod(() => new ServiceNoDependencies())
                       ))
            {
                var client = ChannelFactory <IServiceGenericDependency> .CreateChannel(
                    new NetTcpBinding(), new EndpointAddress("net.tcp://localhost/Operations"));

                client.DoSomething();
            }
        }
Exemple #5
0
        /// <summary>
        /// The on startup.
        /// </summary>
        /// <param name="e">
        /// The e.
        /// </param>
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            var container = DynamicContainer.Instance;

            container.AddFacility <WcfFacility>();

            container.Register(
                Component.For <IHandlingReportService>()
                .Named("handlingReportServiceClient")
                .LifeStyle.Transient
                .ActAs(DefaultClientModel
                       .On(WcfEndpoint.BoundTo(new BasicHttpBinding())
                           .At(new Uri("http://127.0.0.1:8089/HandlingReportServiceFacade"))
                           ))
                .LifeStyle.Transient);

            var viewModel = container.Resolve <HandlingReportViewModel>();

            var registerAppWindow = new RegisterAppWindow {
                DataContext = viewModel
            };

            registerAppWindow.Show();
        }
Exemple #6
0
        public void CanModifyRequestsAndResponses()
        {
            using (new WindsorContainer()
                   .AddFacility <WcfFacility>(f => f.CloseTimeout = TimeSpan.Zero)
                   .Register(
                       Component.For <MessageLifecycleBehavior>(),
                       Component.For <IOperations>()
                       .ImplementedBy <Operations>()
                       .DependsOn(new { number = 42 })
                       .AsWcfService(new DefaultServiceModel().AddEndpoints(
                                         WcfEndpoint.BoundTo(new NetTcpBinding {
                PortSharingEnabled = true
            })
                                         .At("net.tcp://localhost/Operations")
                                         .AddExtensions(new ReplaceOperationsResult("100")))
                                     )
                       ))
            {
                var client = ChannelFactory <IOperations> .CreateChannel(
                    new NetTcpBinding { PortSharingEnabled = true },
                    new EndpointAddress("net.tcp://localhost/Operations"));

                Assert.AreEqual(100, client.GetValueFromConstructor());
            }
        }
Exemple #7
0
        public void CanPubishMEXEndpointsUsingCustomAddress()
        {
            using (new WindsorContainer()
                   .AddFacility <WcfFacility>(f => f.CloseTimeout = TimeSpan.Zero)
                   .Register(Component.For <Operations>()
                             .DependsOn(new { number = 42 })
                             .AsWcfService(new DefaultServiceModel()
                                           .AddBaseAddresses(
                                               "net.tcp://localhost/Operations",
                                               "http://localhost:27198/UsingWindsor.svc")
                                           .AddEndpoints(
                                               WcfEndpoint.ForContract <IOperations>()
                                               .BoundTo(new NetTcpBinding {
                PortSharingEnabled = true
            })
                                               )
                                           .PublishMetadata(mex => mex.EnableHttpGet().AtAddress("tellMeAboutYourSelf"))
                                           )
                             ))
            {
                var tcpMextClient = new MetadataExchangeClient(new EndpointAddress("net.tcp://localhost/Operations/tellMeAboutYourSelf"));
                var tcpMetadata   = tcpMextClient.GetMetadata();
                Assert.IsNotNull(tcpMetadata);

                var httpMextClient = new MetadataExchangeClient(new EndpointAddress("http://localhost:27198/UsingWindsor.svc?wsdl"));
                var httpMetadata   = httpMextClient.GetMetadata();
                Assert.IsNotNull(httpMetadata);
            }
        }
Exemple #8
0
        public void WillApplyInstanceBehaviors()
        {
            CallCountServiceBehavior.CallCount = 0;

            using (new WindsorContainer()
                   .AddFacility <WcfFacility>(f => f.CloseTimeout = TimeSpan.Zero)
                   .Register(
                       Component.For <IOperations>().ImplementedBy <Operations>()
                       .DependsOn(new { number = 42 })
                       .AsWcfService(new DefaultServiceModel()
                                     .AddEndpoints(
                                         WcfEndpoint.BoundTo(new NetTcpBinding {
                PortSharingEnabled = true
            })
                                         .At("net.tcp://localhost/Operations"))
                                     .AddExtensions(new CallCountServiceBehavior(),
                                                    new UnitOfworkEndPointBehavior())
                                     )
                       ))
            {
                var client = ChannelFactory <IOperations> .CreateChannel(
                    new NetTcpBinding { PortSharingEnabled = true }, new EndpointAddress("net.tcp://localhost/Operations"));

                bool unitOfWorkIsInitialized_DuringCall = client.UnitOfWorkIsInitialized();
                Assert.IsTrue(unitOfWorkIsInitialized_DuringCall);
                Assert.IsFalse(UnitOfWork.initialized, "Should be false after call");
                Assert.AreEqual(1, CallCountServiceBehavior.CallCount);
            }
        }
Exemple #9
0
        public void WillNotApplyErrorHandlersToServicesIfExplicit()
        {
            using (RegisterLoggingFacility(new WindsorContainer())
                   .AddFacility <WcfFacility>(f => f.CloseTimeout = TimeSpan.Zero)
                   .Register(
                       Component.For <ErrorLogger>()
                       .Attribute("scope").Eq(WcfExtensionScope.Explicit),
                       Component.For <IOperationsEx>().ImplementedBy <Operations>()
                       .DependsOn(new { number = 42 })
                       .AsWcfService(new DefaultServiceModel().AddEndpoints(
                                         WcfEndpoint.BoundTo(new NetTcpBinding {
                PortSharingEnabled = true
            })
                                         .At("net.tcp://localhost/Operations"))
                                     )
                       ))
            {
                var client = ChannelFactory <IOperationsEx> .CreateChannel(
                    new NetTcpBinding { PortSharingEnabled = true }, new EndpointAddress("net.tcp://localhost/Operations"));

                try
                {
                    client.ThrowException();
                    Assert.Fail("Should have raised an exception");
                }
                catch
                {
                    CollectionAssert.IsEmpty(memoryAppender.GetEvents());
                }
            }
        }
 public void Can_Apply_PrincipalPermissionModeAuthorization()
 {
     using (IWindsorContainer container = Container)
     {
         container.Register(
             Component.For <PrincipalPermissionModeAuthorization>()
             .DependsOn(new { principalPermissionMode = PrincipalPermissionMode.Custom })
             .Attribute(WcfConstants.ExtensionScopeKey).Eq(WcfExtensionScope.Services),
             Component.For <IOperations>()
             .ImplementedBy <Operations>()
             .LifeStyle.Transient
             .AsWcfService(
                 new DefaultServiceModel()
                 .AddEndpoints(WcfEndpoint
                               .BoundTo(new NetTcpBinding {
             PortSharingEnabled = true
         })
                               .At("net.tcp://localhost/Operations"))));
         WcfFacility wcfFacility = container.Kernel.GetFacilities().OfType <WcfFacility>().Single();
         ServiceHost host        = wcfFacility.Services.ManagedServiceHosts.Single();
         ServiceAuthorizationBehavior serviceAuthorizationBehavior = host.Description.Behaviors.OfType <ServiceAuthorizationBehavior>().SingleOrDefault();
         Assert.IsNotNull(serviceAuthorizationBehavior);
         Assert.AreEqual(PrincipalPermissionMode.Custom, serviceAuthorizationBehavior.PrincipalPermissionMode);
     }
 }
Exemple #11
0
        public void RegisterServices(IWindsorContainer container)
        {
            var ipaddress = IpFinder.GetLocalIpAddress();

            string baseAddress = $"http://{ipaddress}:8097/services/";


            container.Register(
                Component.For <IBookService>().ImplementedBy <BookServiceApplication>()
                .AsWcfService(new DefaultServiceModel()
                              .AddEndpoints(WcfEndpoint.ForContract(typeof(IBookService)).BoundTo(new WSHttpBinding
            {
                //PortSharingEnabled = true,
                MaxReceivedMessageSize = int.MaxValue,
                ReceiveTimeout         = new TimeSpan(0, 0, 2, 0, 0),
                CloseTimeout           = new TimeSpan(0, 0, 0, 60, 0),
                Security = new WSHttpSecurity {
                    Mode = SecurityMode.None
                }
            }))
                              .PublishMetadata(c => c.EnableHttpGet())
                              .AddBaseAddresses(new Uri(baseAddress + "books"))).LifestylePerWcfOperation());

            _logger.Info($"Server endpoint on : {baseAddress}books");
        }
Exemple #12
0
        public void SetUp()
        {
            windsorContainer = new WindsorContainer()
                               .AddFacility <WcfFacility>(f => f.CloseTimeout = TimeSpan.Zero)
                               .Register(
                Component.For <ServiceHostListener>(),
                Component.For <CollectingInterceptor>(),
                Component.For <UnitOfworkEndPointBehavior>(),
                Component.For <NetDataContractFormatBehavior>(),
                Component.For <IOne>().ImplementedBy <One>().LifeStyle.PerWcfSession()
                .Interceptors(InterceptorReference.ForType <CollectingInterceptor>()).Anywhere,
                Component.For <ITwo>().ImplementedBy <Two>().LifestylePerWcfSession()
                .Interceptors(InterceptorReference.ForType <CollectingInterceptor>()).Anywhere,
                Component.For <IServiceWithSession>().ImplementedBy <ServiceWithSession>().LifeStyle.Transient
                .Named("Operations")
                .AsWcfService(new DefaultServiceModel().AddEndpoints(
                                  WcfEndpoint.BoundTo(new NetTcpBinding {
                PortSharingEnabled = true
            })
                                  .At("net.tcp://localhost/Operations")
                                  )
                              )
                );

            client = CreateClient();
        }
 public void Can_Apply_Throttling()
 {
     using (IWindsorContainer container = Container)
     {
         container.Register(
             Component.For <ServiceThrottling>()
             .DependsOn(
                 new
         {
             maxConcurrentCalls     = 1,
             maxConcurrentSessions  = 2,
             maxConcurrentInstances = 3
         })
             .Attribute(WcfConstants.ExtensionScopeKey).Eq(WcfExtensionScope.Services),
             Component.For <IOperations>()
             .ImplementedBy <Operations>()
             .LifeStyle.Transient
             .AsWcfService(
                 new DefaultServiceModel()
                 .AddEndpoints(WcfEndpoint
                               .BoundTo(new NetTcpBinding {
             PortSharingEnabled = true
         })
                               .At("net.tcp://localhost/Operations"))));
         WcfFacility wcfFacility = container.Kernel.GetFacilities().OfType <WcfFacility>().Single();
         ServiceHost host        = wcfFacility.Services.ManagedServiceHosts.Single();
         ServiceThrottlingBehavior servicebehavior = host.Description.Behaviors.OfType <ServiceThrottlingBehavior>().SingleOrDefault();
         Assert.IsNotNull(servicebehavior);
         Assert.AreEqual(1, servicebehavior.MaxConcurrentCalls);
         Assert.AreEqual(2, servicebehavior.MaxConcurrentSessions);
         Assert.AreEqual(3, servicebehavior.MaxConcurrentInstances);
     }
 }
Exemple #14
0
        private void PrepareIocContainer()
        {
            var container = new WindsorContainer();

            container.AddFacility <WcfFacility>();

            var netTcpBinding = new NetTcpBinding
            {
                PortSharingEnabled = true,
                Security           = new NetTcpSecurity {
                    Mode = SecurityMode.None
                },
                MaxBufferSize          = 67108864,
                MaxReceivedMessageSize = 67108864,
                TransferMode           = TransferMode.Streamed,
                ReceiveTimeout         = new TimeSpan(0, 30, 0),
                SendTimeout            = new TimeSpan(0, 30, 0)
            };

            container.Register(Component.For(typeof(IParaService))
                               .AsWcfClient(new DefaultClientModel
            {
                Endpoint = WcfEndpoint.BoundTo(netTcpBinding)
                           .At(string.Format("{0}{1}", ConfigurationManager.AppSettings["ParaServiceBaseAddress"], "ParaService"))
            }).LifestylePerWebRequest());

            container.Register(Classes.FromThisAssembly()
                               .BasedOn <IController>()
                               .LifestyleTransient());

            ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory(container.Kernel));
        }
        public void TestInitialize()
        {
            windsorContainer = new WindsorContainer()
                               .AddFacility <WcfFacility>(f => f.CloseTimeout = TimeSpan.Zero)
                               .Register(
                Component.For <ServiceHostListener>(),
                Component.For <LoggingInterceptor>(),
                Component.For <CallCountServiceBehavior>(),
                Component.For <UnitOfworkEndPointBehavior>(),
                Component.For <NetDataContractFormatBehavior>(),
                Component.For <IOperations>().ImplementedBy <Operations>()
                .Named("Operations")
                .Interceptors(InterceptorReference.ForType <LoggingInterceptor>()).Anywhere
                .DependsOn(new { number = 42 })
                .AsWcfService(new DefaultServiceModel().AddEndpoints(
                                  WcfEndpoint.BoundTo(new NetTcpBinding {
                PortSharingEnabled = true
            })
                                  .At("net.tcp://localhost/Operations")
                                  )
                              )
                );

            LoggingInterceptor.Calls.Clear();
            CallCountServiceBehavior.CallCount = 0;

            client = ChannelFactory <IOperations> .CreateChannel(
                new NetTcpBinding { PortSharingEnabled = true }, new EndpointAddress("net.tcp://localhost/Operations"));
        }
Exemple #16
0
        public void WillApplyServiceAwareExtensions()
        {
            using (new WindsorContainer()
                   .AddFacility <WcfFacility>(f => f.CloseTimeout = TimeSpan.Zero)
                   .Register(
                       Component.For <ServiceHostListener>(),
                       Component.For <IOperations>().ImplementedBy <Operations>()
                       .DependsOn(new { number = 42 })
                       .AsWcfService(new DefaultServiceModel().AddEndpoints(
                                         WcfEndpoint.BoundTo(new NetTcpBinding {
                PortSharingEnabled = true
            })
                                         .At("net.tcp://localhost/Operations2")
                                         ))
                       ))
            {
                Assert.IsTrue(ServiceHostListener.CreatedCalled);
                Assert.IsTrue(ServiceHostListener.OpeningCalled);
                Assert.IsTrue(ServiceHostListener.OpenedCalled);
                client.GetValueFromConstructor();
                Assert.IsFalse(ServiceHostListener.ClosingCalled);
                Assert.IsFalse(ServiceHostListener.ClosedCalled);
            }

            Assert.IsTrue(ServiceHostListener.ClosingCalled);
            Assert.IsTrue(ServiceHostListener.ClosedCalled);
        }
Exemple #17
0
        public void WillApplyServiceScopedBehaviorsToMultipleEndpoints()
        {
            using (new WindsorContainer()
                   .AddFacility <WcfFacility>(f => f.CloseTimeout = TimeSpan.Zero)
                   .Register(
                       Component.For <DummyContractBehavior>()
                       .Attribute("scope").Eq(WcfExtensionScope.Services),
                       Component.For <IOperations>().ImplementedBy <Operations>()
                       .DependsOn(new { number = 42 })
                       .AsWcfService(new DefaultServiceModel()
                                     .AddEndpoints(
                                         WcfEndpoint.BoundTo(new NetTcpBinding {
                PortSharingEnabled = true
            })
                                         .At("net.tcp://localhost/Operations"),
                                         WcfEndpoint.BoundTo(new BasicHttpBinding())
                                         .At("http://localhost/Operations")
                                         )
                                     )
                       ))
            {
                var client = ChannelFactory <IOperations> .CreateChannel(
                    new NetTcpBinding { PortSharingEnabled = true }, new EndpointAddress("net.tcp://localhost/Operations"));

                Assert.AreEqual(42, client.GetValueFromConstructor());
            }
        }
Exemple #18
0
 public static void TestSetup()
 {
     if (!Process.GetProcesses().Any(x => x.ProcessName.Contains("Rik.CodeCamp.Host")))
     {
         var paths      = TestContext.CurrentContext.TestDirectory.Split('\\');
         var testsIndex = paths.Select((path, i) => new { path, i }).First(x => x.path.Equals("Tests")).i;
         var hostPath   = $@"{string.Join(@"\", paths.Take(testsIndex))}\Src\Hosts\Rik.CodeCamp.Host\bin\Debug\Rik.CodeCamp.Host.exe";
         _process = Process.Start(hostPath);
         Task.Delay(2000).Wait(); //I don't have enough time to do better than a timer right now :-/
     }
     if (Container != null)
     {
         return;
     }
     Container = new WindsorContainer();
     Container.Kernel.AddFacility <TypedFactoryFacility>();
     Container.Kernel.AddFacility <WcfFacility>();
     _clientBinding = new BasicHttpBinding
     {
         Security =
         {
             Mode      = BasicHttpSecurityMode.None,
             Transport = { ClientCredentialType = HttpClientCredentialType.None },
             Message   = { ClientCredentialType = BasicHttpMessageCredentialType.Certificate }
         }
     };
     Container.Register(Component.For <IBarContract>()
                        .AsWcfClient(new DefaultClientModel
     {
         Endpoint = WcfEndpoint.BoundTo(_clientBinding).At("http://localhost/BarContract")
     }).LifestyleTransient());
 }
Exemple #19
0
        public void WillApplyExplcitScopedServiceBehaviors()
        {
            CallCountServiceBehavior.CallCount = 0;

            using (new WindsorContainer()
                   .AddFacility <WcfFacility>(f => f.CloseTimeout = TimeSpan.Zero)
                   .Register(
                       Component.For <CallCountServiceBehavior>()
                       .Attribute("scope").Eq(WcfExtensionScope.Explicit),
                       Component.For <IOperations>().ImplementedBy <Operations>()
                       .DependsOn(new { number = 42 })
                       .AsWcfService(new DefaultServiceModel()
                                     .AddEndpoints(
                                         WcfEndpoint.BoundTo(new NetTcpBinding {
                PortSharingEnabled = true
            })
                                         .At("net.tcp://localhost/Operations"))
                                     .AddExtensions(typeof(CallCountServiceBehavior))
                                     )
                       ))
            {
                var client = ChannelFactory <IOperations> .CreateChannel(
                    new NetTcpBinding { PortSharingEnabled = true }, new EndpointAddress("net.tcp://localhost/Operations"));

                Assert.AreEqual(42, client.GetValueFromConstructor());
                Assert.AreEqual(1, CallCountServiceBehavior.CallCount);
            }
        }
        public void Install(IWindsorContainer container, IConfigurationStore store)
        {
            string serviceHostUrl = ConfigurationManager.AppSettings.Get("ServiceUrl");

            container.Register(
                Component.For <ISimpleService>()
                .ImplementedBy <SimpleService>()

                .LifeStyle.PerWcfOperation()
                .AsWcfService(new DefaultServiceModel()
                              .AddEndpoints(WcfEndpoint.BoundTo(new NetTcpBinding()
            {
                MaxReceivedMessageSize = Int32.MaxValue,
                ReaderQuotas           =
                    new System.Xml.XmlDictionaryReaderQuotas()
                {
                    MaxStringContentLength = Int32.MaxValue
                },
                PortSharingEnabled = true,
                Security           = new NetTcpSecurity
                {
                    Mode      = SecurityMode.None,
                    Transport = new TcpTransportSecurity
                    {
                        ClientCredentialType =
                            TcpClientCredentialType.None,
                        ProtectionLevel =
                            System.Net.Security.ProtectionLevel.None,
                    }
                }
            }
                                                                ).At(serviceHostUrl))
                              .PublishMetadata()));
        }
Exemple #21
0
        public void WillApplyErrorHandlersToServices()
        {
            using (RegisterLoggingFacility(new WindsorContainer())
                   .AddFacility <WcfFacility>(f => f.CloseTimeout = TimeSpan.Zero)
                   .Register(
                       Component.For <ErrorLogger>(),
                       Component.For <IOperationsEx>().ImplementedBy <Operations>()
                       .DependsOn(new { number = 42 })
                       .AsWcfService(new DefaultServiceModel().AddEndpoints(
                                         WcfEndpoint.BoundTo(new NetTcpBinding {
                PortSharingEnabled = true
            })
                                         .At("net.tcp://localhost/Operations"))
                                     )
                       ))
            {
                var client = ChannelFactory <IOperationsEx> .CreateChannel(
                    new NetTcpBinding { PortSharingEnabled = true }, new EndpointAddress("net.tcp://localhost/Operations"));

                try
                {
                    client.ThrowException();
                    Assert.Fail("Should have raised an exception");
                }
                catch
                {
                    foreach (var log in memoryAppender.GetEvents())
                    {
                        Assert.AreEqual("An error has occurred", log.RenderedMessage);
                        Assert.AreEqual("Oh No!", log.ExceptionObject.Message);
                    }
                }
            }
        }
        public static void Main()
        {
            //var helloServiceModel = new DefaultServiceModel(WcfEndpoint.BoundTo(new NetTcpBinding()).At("net.tcp://localhost:9101/hello"));//.AddExtensions(new GlobalExceptionHandlerBehaviour(typeof(GlobalExceptionHandler)));

            var throttlingBehavior = new ServiceThrottlingBehavior {
                MaxConcurrentCalls = Environment.ProcessorCount * 16, MaxConcurrentSessions = (Environment.ProcessorCount * 16) + (Environment.ProcessorCount * 100), MaxConcurrentInstances = Environment.ProcessorCount * 100
            };


            var helloServiceModel = new DefaultServiceModel(WcfEndpoint.BoundTo(new NetTcpBinding()).At("net.tcp://localhost:9101/hello")).AddExtensions(new GlobalExceptionHandlerBehaviour(typeof(GlobalExceptionHandler)), throttlingBehavior);

            helloServiceModel.OnCreated(host => {
                host.Authorization.PrincipalPermissionMode       = PrincipalPermissionMode.Custom;
                host.Authorization.ExternalAuthorizationPolicies = new System.Collections.ObjectModel.ReadOnlyCollection <System.IdentityModel.Policy.IAuthorizationPolicy>(new List <IAuthorizationPolicy>()
                {
                    new CustomAuthorizationPolicy()
                });


                //var od = host.Description.Endpoints[0].Contract.Operations.Find("Handle");
                //var serializerBehavior = od.Behaviors.Find<DataContractSerializerOperationBehavior>();

                //if (serializerBehavior == null)
                //{
                //    serializerBehavior = new DataContractSerializerOperationBehavior(od);
                //    od.Behaviors.Add(serializerBehavior);
                //}

                //serializerBehavior.DataContractResolver = new SharedTypeResolver();
            });



            var windsorContainer = new WindsorContainer().AddFacility <WcfFacility>();

            windsorContainer.Register(
                Component.For <LoggingCallContextInitializer>(),
                Component.For <LoggingBehavior>(),
                Component.For <IConsoleService>().ImplementedBy <ConsoleService>().AsWcfService(new DefaultServiceModel(WcfEndpoint.BoundTo(new NetTcpBinding()).At("net.tcp://localhost:9101/console"))),
                Component.For <IRequestHandlerService>().ImplementedBy <RequestHandlerService>().AsWcfService(new DefaultServiceModel(WcfEndpoint.BoundTo(new NetTcpBinding()).At("net.tcp://localhost:9101/requestHandler"))),
                Component.For <IHelloService>().ImplementedBy <HelloService>().AsWcfService(helloServiceModel)

                );

            var hostFactory        = new DefaultServiceHostFactory(windsorContainer.Kernel);
            var helloHost          = hostFactory.CreateServiceHost <IHelloService>();
            var consoleHost        = hostFactory.CreateServiceHost <IConsoleService>();
            var requestHandlerHost = hostFactory.CreateServiceHost <IRequestHandlerService>();

            try
            {
                Console.ReadLine();
            }
            finally
            {
                helloHost.Close();
                consoleHost.Close();
                requestHandlerHost.Close();
            }
        }
Exemple #23
0
        public void CanCaptureRequestsAndResponsesAtServiceLevel()
        {
            using (RegisterLoggingFacility(new WindsorContainer())
                   .AddFacility <WcfFacility>(f => f.CloseTimeout = TimeSpan.Zero)
                   .Register(
                       Component.For <LogMessageEndpointBehavior>()
                       .Attribute("scope").Eq(WcfExtensionScope.Explicit)
                       .Named("logMessageBehavior"),
                       Component.For <IOperations>()
                       .ImplementedBy <Operations>()
                       .DependsOn(new { number = 42 })
                       .AsWcfService(new DefaultServiceModel().AddEndpoints(
                                         WcfEndpoint.BoundTo(new NetTcpBinding {
                PortSharingEnabled = true
            })
                                         .At("net.tcp://localhost/Operations"))
                                     .LogMessages()
                                     )
                       ))
            {
                var client = ChannelFactory <IOperations> .CreateChannel(
                    new NetTcpBinding { PortSharingEnabled = true }, new EndpointAddress("net.tcp://localhost/Operations"));

                Assert.AreEqual(42, client.GetValueFromConstructor());
                Assert.AreEqual(4, memoryAppender.GetEvents().Length);
            }
        }
Exemple #24
0
        public static void Initialize()
        {
            Container = new WindsorContainer();

            Container.AddFacility <WcfFacility>();

            Container.Register(
                AllTypes.FromAssemblyNamed("DogmaticWcf.Server.Services")
                .Pick().If(type => type.GetInterfaces().Any(i => i.IsDefined(typeof(ServiceContractAttribute), true)))
                .Configure(configurer => configurer
                           .Named(configurer.Implementation.Name)
                           .LifeStyle.PerWcfOperation()
                           .AsWcfService(
                               new DefaultServiceModel()
                               .AddEndpoints(
                                   WcfEndpoint.BoundTo(new NetTcpBinding {
                PortSharingEnabled = true
            }).At(string.Format("net.tcp://localhost:6969/{0}", configurer.Implementation.Name)),
                                   WcfEndpoint.BoundTo(new NetNamedPipeBinding()).At(string.Format("net.pipe://localhost/{0}", configurer.Implementation.Name)))
                               .PublishMetadata()
                               )
                           )
                .WithService.Select((type, baseTypes) => type.GetInterfaces().Where(i => i.IsDefined(typeof(ServiceContractAttribute), true)))
                );
        }
Exemple #25
0
        public void CanCreateServiceHostWithAspNetCompatibility()
        {
            var captureServiceHost = new CaptureServiceHost();

            using (new WindsorContainer()
                   .AddFacility <WcfFacility>(f =>
            {
                f.CloseTimeout = TimeSpan.Zero;
                f.Services.AspNetCompatibility = AspNetCompatibilityRequirementsMode.Allowed;
            })
                   .Register(
                       Component.For <CaptureServiceHost>().Instance(captureServiceHost),
                       Component.For <IOperations>()
                       .ImplementedBy <Operations>()
                       .DependsOn(new { number = 42 })
                       .AsWcfService(new DefaultServiceModel().AddEndpoints(
                                         WcfEndpoint.BoundTo(new NetTcpBinding {
                PortSharingEnabled = true
            })
                                         .At("net.tcp://localhost/Operations"))
                                     )
                       ))
            {
                var client = ChannelFactory <IOperations> .CreateChannel(
                    new NetTcpBinding { PortSharingEnabled = true }, new EndpointAddress("net.tcp://localhost/Operations"));

                Assert.AreEqual(42, client.GetValueFromConstructor());

                AspNetCompatibilityRequirementsAttribute aspNetCompat =
                    captureServiceHost.ServiceHost.Description.Behaviors.Find <AspNetCompatibilityRequirementsAttribute>();
                Assert.IsNotNull(aspNetCompat);
                Assert.AreEqual(AspNetCompatibilityRequirementsMode.Allowed, aspNetCompat.RequirementsMode);
            }
        }
Exemple #26
0
        public void CanCreateServiceHostAndOpenHostUsingDefaultBinding()
        {
            using (new WindsorContainer()
                   .AddFacility <WcfFacility>(f =>
            {
                f.DefaultBinding = new NetTcpBinding {
                    PortSharingEnabled = true
                };
                f.CloseTimeout = TimeSpan.Zero;
            }
                                              )
                   .Register(Component.For <Operations>()
                             .DependsOn(new { number = 42 })
                             .AsWcfService(new DefaultServiceModel().AddEndpoints(
                                               WcfEndpoint.ForContract <IOperations>()
                                               .At("net.tcp://localhost/Operations")
                                               )
                                           )))
            {
                var client = ChannelFactory <IOperations> .CreateChannel(
                    new NetTcpBinding { PortSharingEnabled = true }, new EndpointAddress("net.tcp://localhost/Operations"));

                Assert.AreEqual(42, client.GetValueFromConstructor());
            }
        }
Exemple #27
0
 public void Install(IWindsorContainer container, IConfigurationStore store)
 {
     container.Register(Component.For <IParaService>().ImplementedBy <ParaService>()
                        .Interceptors <ExceptionInterceptor>().LifeStyle.Singleton
                        .AsWcfService(new DefaultServiceModel().AddEndpoints(WcfEndpoint.BoundTo(ConfigurationHelper.NetTcpBinding)
                                                                             .At(string.Format("{0}{1}", ConfigurationHelper.BaseAddress, "ParaService")))
                                      .PublishMetadata()));
 }
Exemple #28
0
        private IServerManager remote;                              // The remote server manager proxy

        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="serverEP">The <see cref="WcfEndpoint" /> for the server manager instance.</param>
        public ServerManager(WcfEndpoint serverEP)
        {
            if (serverEP == null)
            {
                throw new ArgumentNullException("serverEP");
            }

            this.serverEP = serverEP;
        }
Exemple #29
0
 public Configurator()
 {
     _container.AddFacility <WcfFacility>()
     .Register(
         Component
         .For <IMosquitoCallbackChannel>()
         .AsWcfClient(WcfEndpoint.FromConfiguration("NetTcpBinding_IMosquitoCallbackChannel"))
         );
 }
 public void Install(IWindsorContainer container, IConfigurationStore store)
 {
     container
     .AddFacility <WcfFacility>()
     .Register(Component.For <IAssetService>().AsWcfClient(
                   WcfEndpoint
                   .BoundTo(new WSHttpBinding())
                   .At("http://localhost:3203/AssetService.svc")));
 }