title: how to call web service using NTLM authorization scheme?
body: <p>I'm a noob to calling WCF web services, so am hoping this is an easy question. When calling a web service with .NET 4 winform client, how do I change the authorization scheme from Anonymous to NTLM?</p>
  
  <p>Right now I'm getting the exception: <em>The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'NTLM'</em>.</p>
  
  <p>My goal is to build a little tool to help me monitor TFS 2010's data warehouse and cube.  TFS provides a WarehouseControlWebService web service. I can call the service via Test mode in a browser when logged on to the server. However I'm trying to call the same web service remotely, from my desktop.  My user account is in the local Administrators group on the server.</p>
  
  <p>I've created a .NET 4 WinForm with the canonical Button1 and TextArea1.  I then added a service reference to the web service and creatively called it ServiceReference1:</p>
  
  <pre><code>Add Service Reference...
  http://tfssvr:8080/tfs/TeamFoundation/Administration/v3.0/WarehouseControlService.asmx
  </code></pre>
  
  <p>And here's my code behind:</p>
  
  <pre><code>private void button1_Click(object sender, EventArgs e)
  {
      // Creating a proxy takes about 3-4 seconds
      var dwSvc = new ServiceReference1.WarehouseControlWebServiceSoapClient();
  
      // Invoking the method throws an MessageSecurityException
      var dwStatus = dwSvc.GetProcessingStatus(null, null, null);
  }
  </code></pre>
  
  <p>I'm getting System.ServiceModel.Security.MessageSecurityException:</p>
  
  <p><em>The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'NTLM'</em>.</p>
  
  <p>I've tried passing my credentials via:</p>
  
  <pre><code>dwSvc.ClientCredentials.Windows.ClientCredential =
      new System.Net.NetworkCredential("user", "pass", "domain");
  </code></pre>
  
  <p>and also ...</p>
  
  <pre><code>dwSvc.ClientCredentials.Windows.ClientCredential =
      CredentialCache.DefaultNetworkCredentials;
  </code></pre>
  
  <p>I'm wading through the WCF documentation but ... oh boy ... there's a lot there. I'm hoping this is something easy??</p>
  
  <p>Thanks in advance.</p>