title: CRM 2011 SecurityNegotiationException trying to access web services
body: <p>Getting an unexpected error when trying to connect to CRM 2011 web service. Here's the background:</p>
  
  <p>Connection String (with sensitive info removed): <code>"ServiceUri=https://crmdomain.com/OrgName/XRMServices/2011/Organization.svc; Url=https://crmdomain.com/OrgName; Username=appusername; Password=hidden"/&gt;</code></p>
  
  <p><strong>Creating the connection as follows:</strong></p>
  
  <ol>
  <li>Parse conn string into CRMConnection: <code>var conn = Microsoft.Xrm.Client.CrmConnection.Parse(connString);</code> (at this point, the properties in the <code>CrmConnection</code> object look correct, including ClientCredentials)</li>
  <li>Create org proxy: <code>var orgProxy = new OrganizationServiceProxy(conn.ServiceUri, conn.HomeRealmUri, conn.ClientCredentials, conn.DeviceCredentials);</code></li>
  <li>Create data context: <code>var context = new MyContext(orgProxy);</code></li>
  </ol>
  
  <p><strong>At this point, when retrieving any data from <code>context</code>, the following WCF exception occurs:</strong></p>
  
  <p>System.ServiceModel.Security.SecurityNegotiationException occurred
    Message=<strong>The caller was not authenticated by the service.</strong>
    Source=mscorlib
    StackTrace:
      Server stack trace: 
         at System.ServiceModel.Security.IssuanceTokenProviderBase'1.DoNegotiation(TimeSpan timeout)
         at System.ServiceModel.Security.SspiNegotiationTokenProvider.OnOpen(TimeSpan timeout)
         at System.ServiceModel.Security.WrapperSecurityCommunicationObject.OnOpen(TimeSpan timeout)</p>
  
  <p>... and so on.</p>
  
  <p>The <strong>InnerException</strong> shows <code>IsSenderFault=True</code> and <code>IsPredefinedFault=True</code>.</p>
  
  <p>What's going on here?</p>