Thanks so much for posting this! Thanks to you and The Google I only lost about an hour :).
This was driving me crazy - I have two environments going, identical code in both, one worked fine, one got the 401 error for the call to GetUserProfileByName from my InfoPath from. Guess which environment I try to keep up to date with security ...