title: Setting up NTLM Authentication with WCF to Sharepoint Web Services
body: <p>I have been having a lot of difficulty setting up my WCF service to talk to Sharepoint Web services, specifically I am trying to use the Lists.asmx and Copy.asmx services.  </p>
  
  <p>I got it working using an http link to sharepoint for development, but now we need to switch to an HTTPS link.  I got the web reference setup and updated for this link, but when it tries to call a service (ex: GetListItems) it errors out with the following error: 
  The request failed with HTTP status 401: Unauthorized.</p>
  
  <p>I then tried to see what type of authentication our Sharepoint Server uses, which turns out to be NTLM.  I then tried to configure out web.config file for this.  Here is the entire web.config file:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;configuration&gt;
      &lt;configSections&gt;
          &lt;sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"&gt;
              &lt;section name="InventoryService.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/&gt;
          &lt;/sectionGroup&gt;
      &lt;/configSections&gt;
      &lt;appSettings/&gt;
      &lt;connectionStrings/&gt;
      &lt;system.web&gt;
          &lt;compilation debug="true" targetFramework="4.0"&gt;
          &lt;/compilation&gt;
          &lt;!--
          The &lt;authentication&gt; section enables configuration 
          of the security authentication mode used by 
          ASP.NET to identify an incoming user. 
      --&gt;
          &lt;authentication mode="Windows"/&gt;
          &lt;!--
          The &lt;customErrors&gt; section enables configuration 
          of what to do if/when an unhandled error occurs 
          during the execution of a request. Specifically, 
          it enables developers to configure html error pages 
          to be displayed in place of a error stack trace.
  
          &lt;customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm"&gt;
           &lt;error statusCode="403" redirect="NoAccess.htm" /&gt;
           &lt;error statusCode="404" redirect="FileNotFound.htm" /&gt;
          &lt;/customErrors&gt;
      --&gt;
          &lt;pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/&gt;&lt;/system.web&gt;
      &lt;!-- 
        The system.webServer section is required for running ASP.NET AJAX under Internet
        Information Services 7.0.  It is not necessary for previous version of IIS.
    --&gt;
      &lt;system.serviceModel&gt;
          &lt;bindings&gt;
     &lt;basicHttpBinding&gt;
      &lt;binding name="NewBinding0"&gt;
       &lt;security mode="TransportCredentialOnly"&gt;
        &lt;transport clientCredentialType="Ntlm" proxyCredentialType="None" /&gt;
       &lt;/security&gt;
      &lt;/binding&gt;
     &lt;/basicHttpBinding&gt;
    &lt;/bindings&gt;
    &lt;services&gt;
     &lt;service behaviorConfiguration="InventoryService.Service1Behavior"
      name="InventoryService.InventoryService"&gt;
      &lt;endpoint address="" binding="basicHttpBinding" bindingConfiguration="NewBinding0"
       contract="InventoryService.IInventoryService"&gt;
       &lt;identity&gt;
        &lt;dns value="localhost" /&gt;
       &lt;/identity&gt;
      &lt;/endpoint&gt;
      &lt;endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /&gt;
     &lt;/service&gt;
    &lt;/services&gt;
          &lt;behaviors&gt;
              &lt;serviceBehaviors&gt;
                  &lt;behavior name="InventoryService.Service1Behavior"&gt;
                      &lt;!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment --&gt;
                      &lt;serviceMetadata httpGetEnabled="true"/&gt;
                      &lt;!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information --&gt;
                      &lt;serviceDebug includeExceptionDetailInFaults="true"/&gt;
                  &lt;/behavior&gt;
              &lt;/serviceBehaviors&gt;
          &lt;/behaviors&gt;
      &lt;/system.serviceModel&gt;
      &lt;applicationSettings&gt;
          &lt;InventoryService.Properties.Settings&gt;
     &lt;setting name="InventoryService_WSCopy_Copy" serializeAs="String"&gt;
      &lt;value&gt;http://site/_vti_bin/Copy.asmx&lt;/value&gt;
     &lt;/setting&gt;
     &lt;setting name="InventoryService_SharepointLists_Lists" serializeAs="String"&gt;
      &lt;value&gt;https://site/_vti_bin/Lists.asmx&lt;/value&gt;
     &lt;/setting&gt;
    &lt;/InventoryService.Properties.Settings&gt;
      &lt;/applicationSettings&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>If anyone has a clue if I setup this config file correctly for NTLM, that would be really helpful.</p>
  
  <p>If this is setup correctly, then I guess I will move on to the next question about if I setup the credentials correctly:</p>
  
  <pre><code>inventoryList = new SharepointLists.Lists();
  inventoryList.Url = "https://fullsiteurl/_vti_bin/Lists.asmx";
  inventoryList.Credentials = new System.Net.NetworkCredential("user", "pass", "domain");
  </code></pre>
  
  <p>If someone could go over this, that would also be very helpful.</p>
  
  <p>Again I know that the config file is pretty long and I highly appreciate it if you go through it let me know if I setup NTLM authentication correctly.  </p>
  
  <p>If all this checks out ok, then I have no idea where to start on getting the HTTPS link with sharepoint working (The existing HTTP link to sharepoint is still accessible for the time being, until I can get the service working with the HTTPS link).</p>