Aug 6, 2010

WCF in one day

I just started learning WCF yesterday. While I know I’m far from knowing all the power of this technology I did get the basics of what I needed working in that one day.  I have a project that will split between two computers on a closed network. The data collection hardware and associated libraries will all sit on a headless PC that will be rack mounted. The native code for the libraries is C++. The GUI will sit on a laptop connected over Ethernet and that application will be written in C#. It occurred to me that instead of sending TCP based string commands back and forth (and all the associated runtime error checking)  I could use WCF to directly invoke methods on the data collection PC, and benefit from compile time checking.  While I’ll probably end up writing some C++/CLI code, I thought I might be able to manage all the intranet communication in C# and leverage all the nice IDE tools. I found some great screencasts on channel nine that got me 90% of the way there. [ 1 ] However, once I took what I learned there and tried modifying things I started running into a lot of security/permission problems. I really should have picked up and read a book, but just by exploring around in the WCF editor I was able to determine how to suppress all the security and get clients to access the service from both the same computer and from another computer on the intranet. The host computer was running Windows 7 and the final client was running XP. Worked like a charm, now  I wish I had WCF for my embedded platform.

Below is a screencast summary of what I did from soup-to-nuts. It takes about 15 minutes (so I get to exploit the new YouTube extended time limit). I create everything from scratch and show all the changes I made via the WCF editor to get things working, including a mistake I made regarding instance management and how to correct it.

Here’s the snippet from the MDSN docs on the magic permissions that get set when using the WCF Host. I’ve included the relevant portion here below the screencast.

 

Auto Hosting of the Service and Client

When you are first getting started the fact that Visual Studio auto hosts the service and auto launches a test client is very convenient. Once you start adding more projects to your solution and you want to test self hosting or hosting in a service the auto launched hosting will get in the way. Luckily they are easy to turn off.

image

Using Service Host without Administrator privilege

To enable users without administrator privilege to develop WCF services, an ACL (Access Control List) is created for the namespace "http://+:8731/Design_Time_Addresses" during the installation of Visual Studio. The ACL is set to (UI), which includes all interactive users logged on to the machine. Administrators can add or remove users from this ACL, or open additional ports.This ACL enables users to use the WCF Service Auto Host (wcfSvcHost.exe) without granting them administrator privileges.

You can modify access using the netsh.exe tool in Windows Vista under the elevated administrator account. The following is an example of using netsh.exe.

netsh http add urlacl url=http://+:8001/MyService user=<domain>\<user>
[ 1 ] I must admit these screencasts are an effective marketing tool –the next time I tackle a new technology I think it would be prudent to buy  a month of PluralSight training ($99) instead of a book.

About Me

My photo
Tod Gentille (@todgentille) is now a Curriculum Director for Pluralsight. He's been programming professionally since well before you were born and was a software consultant for most of his career. He's also a father, husband, drummer, and windsurfer. He wants to be a guitar player but he just hasn't got the chops for it.