No configuration Wcf host and client

Using Exception in Wcf should be very caucious, as I blogged before, wcf exception should be marked as Serializable, and implement all 4 ctor from base exception class. An unit-test for each exception might be overkill, but it’s worth to try.

In-proc wcf host is neat for this purpose, by using channel Factory, client side doesn’t need configuration either.

    public class MyDataNotFoundExceptionSpecs
        private readonly ServiceHost _host;
        private const string _url = "net.tcp://localhost:9000/TestException";

        public MyDataNotFoundExceptionSpecs()
            _host = new ServiceHost(typeof(TestService));

                new NetTcpBinding(), _url);
            Console.WriteLine("wcf service started.");

            private ChannelFactory<ITestService> channelFactory;
            public void SetupChannelFacotry()
                channelFactory = new ChannelFactory<ITestService>(
                   new NetTcpBinding(),
                   new EndpointAddress(_url));               
            public void CleanUpChannelFacotry()
        public void should_passed_to_client()
            ITestService proxy = channelFactory.CreateChannel();




    public class TestService : ITestService
        public void Ping(string user)
            throw new FaultException<MyDataNotFoundException>(new MyDataNotFoundException());

    public interface ITestService
        void Ping(string user);


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s