Why does my WCF client throw a SOAP negotiation error?

If you use the Microsoft MSDN sample code to generate a WCF client, you will generally get a SOAP negotiation failure when the client tries to connect to the WCF service. This is because the WCF sample uses the Microsoft SVCUTIL.EXE command line utility to generate the app.config XML. Sadly, there is a problem with the generated XML - it contains an identity field like this:

<identity>
   <userPrincipalName value="r_moore@somedomain.com" />
</identity>

Which severely limits the accounts which can connect to the WCF service... to errrr... one. If you run your WCF service as a console app under your user account this won't be a problem. But when you move the WCF service to the kind of place you might expect to find it - inside a Windows Service - then it will fail because the service is now running under LocalSystem. Simply remove this identity field and the client will connect to your service without a problem. At least mine did.