Пример #1
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();
        }
Пример #2
0
        /// <summary>
        /// Register a WCF client proxy for the given service interface with the IOC. The service
        /// will be contacted at the given URI.
        /// </summary>
        /// <remarks>
        /// <para>
        /// To register different endpoint behaviours the behaviour must be added to the clientModel (not the endpoint directly like the service registration).
        /// Adding the endpoint behaviours directly to the endpoint will not invoke the endpoint behaviours.
        /// </para>
        /// </remarks>
        /// <typeparam name="T">service interface</typeparam>
        /// <param name="k">IoC kernel to register to</param>
        /// <param name="uri">service URI</param>
        /// <param name="streamed">true if streaming must be supported</param>
        /// <param name="maxMsg">maximum message size supported</param>
        /// <param name="sendTimeout">WCF proxy timeout to send a message</param>
        /// <param name="receiveTimeout">WCF proxy timeout to receive a message</param>
        /// <param name="useExternalEndpointBehaviour">Optional: Flag to add external endpoint behaviour (<c>true</c>) or the default endpoint behaviour. Default: false</param>

        public void RegisterWCFClientProxy <T>(string uri, bool streamed, int maxMsg, TimeSpan sendTimeout, TimeSpan receiveTimeout, bool useExternalEndpointBehaviour) where T : class
        {
            var endPoint = GetEndpoint(uri, streamed, maxMsg, sendTimeout, receiveTimeout);

            try
            {
                var clientModel = new DefaultClientModel()
                {
                    Endpoint = endPoint.At(uri)
                };
                clientModel = clientModel.WithoutAsyncCapability();
                var endpointBehaviour = this.CreateEndpointBehaviour(useExternalEndpointBehaviour);
                clientModel.AddExtensions(endpointBehaviour);

                Kernel.Register(Component
                                .For <T>()
                                .LifeStyle.Transient
                                .AsWcfClient(clientModel)
                                );

                Logger.InfoFormat("WCF CLIENT proxy registered at [{0}]: Endpoint-Behaviour-Count: {1}, Use-External-EndpointBehaviour = '{2}.'", uri, clientModel.Extensions.Count(), useExternalEndpointBehaviour.ToString());
            }
            catch (Exception ex)
            {
                var msg = string.Format("Error: WCF client proxy registration failed at address = [{0}], useExternalEndpointBehaviour = '{1}', Ex='{2}'", uri, useExternalEndpointBehaviour.ToString(), ex.ToString());
                Logger.Fatal(msg);
                IoCSetup.ShutdownAndExit(msg, 1);
            }
        }
Пример #3
0
        private static void RegisterComponents(IWindsorContainer container)
        {
            container.Register(
                AllTypes.Pick()
                //Scan repository assembly for domain model interfaces implementation
                .FromAssemblyNamed("NDDDSample.Persistence.NHibernate")
                .WithService.FirstNonGenericCoreInterface("NDDDSample.Domain.Model"));

            container.AddComponent("bookingInterface",
                                   Type.GetType("NDDDSample.Application.IBookingService, NDDDSample.Application"),
                                   Type.GetType("NDDDSample.Application.Impl.BookingService, NDDDSample.Application"));

            container.AddComponent("routingService",
                                   Type.GetType("NDDDSample.Domain.Service.IRoutingService, NDDDSample.Domain"),
                                   Type.GetType("NDDDSample.Infrastructure.ExternalRouting.ExternalRoutingService, NDDDSample.Infrastructure.ExternalRouting"));

            container.AddFacility <WcfFacility>();

            container.Register(
                Component.For <MessageLifecycleBehavior>(),
                Component.For <UnitOfWorkBehavior>(),
                Component
                .For <IBookingServiceFacade>()
                .ImplementedBy <BookingServiceFacade>()
                .Named("BookingService")
                .LifeStyle.Transient
                .ActAs(new DefaultServiceModel()
                       .AddEndpoints(WcfEndpoint
                                     .BoundTo(new NetTcpBinding())
                                     //.At("net.tcp://localhost:8081/BookingServiceFacade")
                                     .At(String.Format("net.tcp://{0}/BookingServiceFacade", bookingRemoteServiceWorkerRoleEndpoint))
                                     // adds this message action to this endpoint
                                     .AddExtensions(new LifestyleMessageAction()
                                                    )
                                     ))
                );

            container.Register(
                Component
                .For <IGraphTraversalService>()
                .Named("pathfinderRemoteFacade")
                .LifeStyle.Transient
                .ActAs(DefaultClientModel
                       .On(WcfEndpoint.BoundTo(new NetTcpBinding())
                           .At(String.Format("net.tcp://{0}/GraphTraversalService", pathfinderRemoteServiceWorkerRoleEndpoint))
                           ))
                .LifeStyle.Transient);
        }
Пример #4
0
        private static void AddCustomRepositoriesTo(IWindsorContainer container)
        {
            container.Register(
                AllTypes.Pick()
                //Scan repository assembly for domain model interfaces implementation
                .FromAssemblyNamed("NDDDSample.Persistence.NHibernate")
                .WithService.FirstNonGenericCoreInterface("NDDDSample.Domain.Model"));

            container.AddFacility <WcfFacility>();

            container.Register(
                Component.For <MessageLifecycleBehavior>(),
                Component.For <IBookingServiceFacade>()
                .Named("bookingServiceFacade")
                .LifeStyle.Transient
                .ActAs(DefaultClientModel
                       .On(WcfEndpoint.BoundTo(new NetTcpBinding())
                           .At(String.Format("net.tcp://{0}/BookingServiceFacade", bookingRemoteServiceWorkerRoleEndpoint))
                           )));
        }
Пример #5
0
        private static WindsorContainer GetContainer()
        {
            var container = new WindsorContainer();

            container.Kernel.AddFacility <WcfFacility>();

            var helloClient = new DefaultClientModel
            {
                Endpoint = WcfEndpoint.BoundTo(new NetTcpBinding())
                           .At("net.tcp://localhost:9101/hello").AddExtensions(new SharedTypeResolver())
            };

            helloClient.OnChannelCreated((factory, channel) => {
                //var od = factory.Endpoint.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();
            });


            container.Register(Component.For <IHelloService>()
                               .AsWcfClient(helloClient));
            container.Register(Component.For <IRequestHandlerService>()
                               .AsWcfClient(new DefaultClientModel
            {
                Endpoint = WcfEndpoint.BoundTo(new NetTcpBinding())
                           .At("net.tcp://localhost:9101/requestHandler")
            }));
            container.Register(Classes.FromThisAssembly().BasedOn(typeof(Form)).LifestyleTransient());
            return(container);
        }
        public override IWcfClientModel GetClientModel(params object[] extensions)
        {
            IWcfEndpoint endpoint =
                WcfEndpoint
                .ForContract <T>()
                .BoundTo(Binding)
                .At(Address)
                .AddExtensions(extensions);

            DefaultClientModel clientModel = new DefaultClientModel(endpoint);

            if (OpenOnDemand)
            {
                clientModel.OpenOnDemand();
            }

            if (!AsyncCapability)
            {
                clientModel.WithoutAsyncCapability();
            }

            return(clientModel);
        }
Пример #7
0
        private static WindsorContainer GetContainer()
        {
            var container = new WindsorContainer();
            container.Kernel.AddFacility<WcfFacility>();

            var helloClient = new DefaultClientModel
                                   {
                                       Endpoint = WcfEndpoint.BoundTo(new NetTcpBinding())
                                           .At("net.tcp://localhost:9101/hello").AddExtensions(new SharedTypeResolver())
                                   };

            helloClient.OnChannelCreated((factory, channel) => {

                //var od = factory.Endpoint.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();
            });

            container.Register(Component.For<IHelloService>()
                                   .AsWcfClient(helloClient));
            container.Register(Component.For<IRequestHandlerService>()
                                   .AsWcfClient(new DefaultClientModel
                                   {
                                       Endpoint = WcfEndpoint.BoundTo(new NetTcpBinding())
                                           .At("net.tcp://localhost:9101/requestHandler")
                                   }));
            container.Register(Classes.FromThisAssembly().BasedOn(typeof(Form)).LifestyleTransient());
            return container;
        }
Пример #8
0
        public void Install(IWindsorContainer container, IConfigurationStore store)
        {
            container.Register(Component.For<IProvider>().ImplementedBy<Provider>());
            //.LifeStyle.Singleton
            //.LifeStyle.PerWcfSession()

            var clientModel = new DefaultClientModel(WcfEndpoint.ForContract<IRemoteFacade>()
                                                                .BoundTo(new WSHttpBinding())
                                                                .At("http://localhost:1080/Zen/RemoteFacade"));
                                                                //.At("http://localhost:8080/Zen/RemoteFacadeSvc"));

            container.AddFacility<WcfFacility>().Register(WcfClient.ForChannels(clientModel).Configure(null));

            /* register the svcs
            container.AddFacility<WcfFacility>() //<-- let Castle create the client proxies
                .Register(
                Component.For<IProvider>().ImplementedBy<Provider>(),
                Component.For<IRemoteFacade>()//.ImplementedBy<RemoteFacadeSvc>()
                         .AsWcfClient(new DefaultClientModel(WcfEndpoint
                            .ForContract<IRemoteFacade>()
                            .BoundTo(new WSHttpBinding())
                            .At("http://127.0.0.1:1080/Zen"))));
             */
        }
		public void CanProxyChannelFactoriesForAsyncSupport()
		{
			var model = new DefaultClientModel()
				{
					Endpoint = WcfEndpoint
						.BoundTo(new NetTcpBinding { PortSharingEnabled = true })
						.At("net.tcp://localhost/Operations")
				};
			var asyncBuilder = new AsynChannelFactoryBuilder<DefaultClientModel>(new ProxyGenerator());
			var channelFactory = asyncBuilder.CreateChannelFactory<ChannelFactory<IOperations>>(
				model, new NetTcpBinding(), "net.tcp://localhost/Operations");

			var client = channelFactory.CreateChannel();
			Assert.AreEqual(42, client.GetValueFromConstructor());
			((ICommunicationObject)client).Close();
		}