namespace Infrastructure.WCF { using System; using System.ServiceModel; using Castle.Facilities.WcfIntegration; using Castle.MicroKernel.Registration; using Castle.Windsor; using NUnit.Framework; [TestFixture] public class DefaultServiceHostFactoryTestCase { [Test] public void CanCreateServer() { var container = new WindsorContainer(). AddFacility("wcf", new WcfFacility()); container.Register( Component.For(). ImplementedBy(). ActAs( new DefaultServiceModel().Hosted(). AddEndpoints( WcfEndpoint. ForContract(typeof(IEmailService)). BoundTo(new NetTcpBinding()). At("net.tcp://localhost:3456/EmailService") ) ) ); DefaultServiceHostFactory.RegisterContainer(container.Kernel); var hostFactory = new DefaultServiceHostFactory(container.Kernel); using(var host = hostFactory.CreateServiceHost(typeof(IEmailService).AssemblyQualifiedName, new Uri[0])) { Assert.IsNotNull(host); host.Open(); var newContainer = new WindsorContainer().Register(Component.For() .CustomDependencies(new { clientModel = new DefaultClientModel(WcfEndpoint .BoundTo(new NetTcpBinding()) .At("net.tcp://localhost:3456/EmailService") ) }) ); IEmailService client = newContainer.Resolve(); client.SendMessage("Test"); } } [ServiceContract] public interface IEmailService { [OperationContract] void SendMessage(string message); } public class DefaultEmailService : IEmailService { private ConsoleMessageSender sender; public DefaultEmailService(ConsoleMessageSender sender) { this.sender = sender; } public void SendMessage(string message) { sender.Send(message); } } public class ConsoleMessageSender { public void Send(string message) { Console.WriteLine(message); } } } }