A PowerShell Script to Assist WCF Service Hosting / Testing

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.
#####

ACS v2 Protocols & Tokens Matrix

Version 2 of Windows Azure’s Access Control Service (ACS) was released recently.  There seems to be some confusion flying about when it comes to which security tokens are provided by protocols or ACS mechanisms.  Here’s a quick matrix which we hope will clarify the situation:

  SWT SAML 1.1 SAML 2.0
OAuth 2.0

   
OAuth WRAP

   
SAML (SAMLP)    

WS-Federation

WS-Trust

So you can acquire a SAML 2.0 token using a SAML protocol (aka, SAMLP), but not SWT or SAML 1.1 tokens.

This matrix also draws attention to other issues:

  • SWT tokens are the most protocol agnostic. ACS supports rendering SWT tokens from all protocols except SAMLP.
  • SAML 1.1 are the most protocol specific.  If your application requires SAML 1.1, ACS has already made your protocol decision for you. (From a security token perspective, WS-Federation is a more complex special case of WS-Trust)

Good Explanation of Publishing Metadata for WCF

The blog post, Quick WCF Metadata Publication Walkthrough, is not new, but it give a good explanation of how metadata publication works with WCF.  In particular, it provides good understanding of interaction / dependencies of <baseAddresses />, <endpoint /> and <behavior />.  If you use it’s guidance and tinker around a bit, you’ll also get a good grasp on how you can do IMetadataExchange though HTTP, named pipes or TCP.