WcfFacility Hello World

WcfFacility is one facilities of Castle Windsor facilities that helps you ignoring adding service reference by Visual Studio. With WcfFacility you can ease server and client service management. Before starting this sample I searched for and found a good starting point here. Unfortunately this sample was usng .svc file. As I didn’t want to use .svc file I wrote my own hello world sample with Wcf Facility:

Service code:

        public static void StartService()
        {
            var windsorContainer = new WindsorContainer()
                .AddFacility<WcfFacility>()
                .Register(Component.For<IDateService>()
                    .ImplementedBy<DateService>()
                    .DependsOn(new { number = 42 })
                    .AsWcfService(new DefaultServiceModel().AddEndpoints(
                            WcfEndpoint.BoundTo(new NetTcpBinding { PortSharingEnabled = true })
                                .At(“net.tcp://localhost:8063/DateService”)
                               ).PublishMetadata()
                ));
        }

Client Code:

        public static string InvokeWcfService()
        {
            var container = new WindsorContainer().AddFacility<WcfFacility>();

            container.Register(Component
                .For<IDateService>()
                .AsWcfClient(DefaultClientModel
                .On(WcfEndpoint.BoundTo(new NetTcpBinding())
                .At(“net.tcp://localhost:8063/DateService”)))
                .LifeStyle.Transient
                );

            var dateService = container.Resolve<IDateService>();
            string message = dateService.SaySomething(“123”);

            return message;
        }

Complete sample source code be downloaded here.

دیدگاهتان را بنویسید

نشانی ایمیل شما منتشر نخواهد شد. بخش‌های موردنیاز علامت‌گذاری شده‌اند *