Wednesday, January 27, 2010

SMTP server for development purposes

Needed to test some code sending emails, but did not find the local SMTP sever on Windows 7.

Did a quick search and found this one.. sweet..

http://smtp4dev.codeplex.com/

Dummy SMTP server that sits in the system tray and does not deliver the received messages. The received messages can be quickly viewed, saved and the source/structure inspected. Useful for testing/debugging software that generates email.
Share:

Tuesday, January 19, 2010

WCF Client wrapper

The using statment and WCF are a bad combo.. Instead use the following class. With some lambda together with this class it's almost like a using statement.

 using System;
    using System;
    using System.ServiceModel;

    /// 
    /// Helper class for WCF clients
    /// 
    public class WcfClientUtils
    {
        /// 
        /// Execute actions against the client and aborts the client on a faulted state
        /// 
        /// Client type
        /// Client instance
        /// Actions to perform on instance
        /// 
        /// WcfClientUtils.Execute(new ServiceReference1.Service1Client(),
        ///     client =>
        ///     {
        ///         var returnData = client.HelloWorld());
        ///     });
        /// 
        public static void Execute(T client, Action action) where T : ICommunicationObject
        {
            try
            {
                //client.Open();
                action(client);
                client.Close();
            }
            catch (CommunicationException)
            {
                client.Abort();
                throw;
            }
            catch (TimeoutException)
            {
                client.Abort();
                throw;
            }
            catch (Exception)
            {
                if (client.State == CommunicationState.Faulted)
                {
                    client.Abort();
                }

                throw;
            }
        }
    }

And this is how you could use this class

WcfClientUtils.Execute(new ServiceReference1.Service1Client(),
    client =>
        {
            var returnData = client.HelloWorld());
});
Share: