When developing for WCF, I find situations in which I need to manually host the WCF services. (“Manually” == “not from within Visual Studio”). Sometimes I have to go back and forth between different services, etc. The command I really wanted was to be able to “just host from here.” So, I created a simple PowerShell script that does just that.
WCF-HostMe starts in the current directory and looks for a service to host. It simply looks for a config file (matching *.[exe|dll].config) and assumes that the config file’s name-matching exe or dll is the service. After formatting and building the parameter values, it launches the service using WcfSvcHost.exe.
Again, this is a simplistic approach and really only works well for development and testing purposes. Obviously this is not a good approach for production environments.
###### WCF-HostMe.ps1 # Hosts a WCF service using WCF Service Host (WcfSvcHost.exe) for testing purposes. # How it works: # Beginning in current dir, recursively searches for *.exe.config or *.dll.config # Assuming the .config file is asso'd with the WCF service, launches WCFSvcHost # using the service's and config's paths # # History: # 3/16/2012, J Burnett Created ##### # Find .config file # TODO: handle multiple search results # TODO: detect assembly is not hostable? (not WCF, WF) $configPath = (gci . -include *.exe.config, *.dll.config -recurse).VersionInfo.FileName # Build WCFSvcHost param inputs - the full paths of service & config $serviceArg = (" /service:""" + $configPath -replace '.config','') + """ " $configArg = " /config:""$configPath"" " # Launch WCFSvcHost to host the service echo '' echo "Attempting to host $serviceArg as WCF Service..." start-process WcfSvcHost.exe -ArgumentList ($serviceArg + " /config:""$configPath"" ") echo '' ### Copyright & Disclaimer ##### # This software is provided "as is"; there are no warranties of any kind. This software # may not work correctly and/or reliably in some environments. In no event shall # AltaModa Technologies, LLC, its personnel, associates or contibutors be liable for # ANY damages resulting from the use of this software. #####