11/30/13

WCF Web Service Get Assembly Version

This is a simple snippet to show a simple way to display the current assembly version of a WCF Web Service.  We first need a helper class with a method that looks as follows: (class is excluded for brevity)

public static string GetVersion()
        {
            string version = string.Empty;
            var assembly = System.Reflection.Assembly.GetExecutingAssembly();
            if (assembly != null)
            {
                  version = assembly.GetName().Version.ToString();
            }

            return version;
        }

We now need to add a Web method to our web service that we can call to return the version number. I often like to add a Ping or Version web method to the web services to test basic client connectivity. The method just needs to call the helper class and return the string with the version information as follows:

public String Ping()
        {
            string version = RequestHelper.GetVersion();
            return version;
        }

When testing this web service, you can call this method to verify what current version is deployed.

I hope you find this helpful.