title: sharepoint 2013 wcf service The HTTP request is unauthorized
body: <p>I'm using wcf service hosted on iis7 over https and when i call service in windows 8 app it returns error</p>
  
  <p>"The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'NTLM'."</p>
  
  <p>this service web.config</p>
  
  <pre><code>&lt;configuration&gt;
  &lt;system.serviceModel&gt;
  &lt;services&gt;
    &lt;service behaviorConfiguration="CellStorageServiceBehavior" name="Microsoft.SharePoint.SoapServer.CellStorages"&gt;
      &lt;endpoint address="CellStorageService" binding="basicHttpBinding"
        bindingConfiguration="StreamBinding" contract="MOL.Service.ISAPI.MOL.IServiceHosted" /&gt;
      &lt;endpoint address="CellStorageServiceBasic" binding="basicHttpBinding"
        bindingConfiguration="StreamBindingBasic" contract="MOL.Service.ISAPI.MOL.IServiceHosted" /&gt;
      &lt;endpoint address="CellStorageServiceDigest" binding="basicHttpBinding"
        bindingConfiguration="StreamBindingDigest" contract="MOL.Service.ISAPI.MOL.IServiceHosted" /&gt;
      &lt;endpoint address="CellStorageServiceNtlm" binding="basicHttpBinding"
        bindingConfiguration="StreamBindingNtlm" contract="MOL.Service.ISAPI.MOL.IServiceHosted" /&gt;
    &lt;/service&gt;
    &lt;service behaviorConfiguration="CellStorageServiceHttpsBehavior" name="Microsoft.SharePoint.SoapServer.CellStoragesHttps"&gt;
      &lt;endpoint address="CellStorageService" binding="basicHttpBinding"
                bindingConfiguration="StreamBindingHttps" contract="MOL.Service.ISAPI.MOL.IServiceHosted" /&gt;
  
      &lt;endpoint address="CellStorageServiceBasic" binding="basicHttpBinding"
               bindingConfiguration="StreamBindingHttpsBasic" contract="MOL.Service.ISAPI.MOL.IServiceHosted" /&gt;
  
      &lt;endpoint address="CellStorageServiceDigest" binding="basicHttpBinding"
               bindingConfiguration="StreamBindingHttpsDigest" contract="MOL.Service.ISAPI.MOL.IServiceHosted" /&gt;
  
      &lt;endpoint address="CellStorageServiceNtlm" binding="basicHttpBinding"
                bindingConfiguration="StreamBindingHttpsNtlm" contract="MOL.Service.ISAPI.MOL.IServiceHosted" /&gt;
    &lt;/service&gt;
    &lt;service behaviorConfiguration="ClaimProviderWebServiceBehavior" name="Microsoft.SharePoint.SoapServer.SPClaimProviderWebService"&gt;
      &lt;endpoint address=""
                binding="basicHttpBinding"
                bindingConfiguration="TextStreamBindingNoSecurity"
                bindingNamespace="http://schemas.microsoft.com/sharepoint/claims/"
                behaviorConfiguration="HttpBinding.LargeDataEndpointBehavior"
                contract="MOL.Service.ISAPI.MOL.IServiceHosted" /&gt;
    &lt;/service&gt;
    &lt;service behaviorConfiguration="HttpsClaimProviderWebServiceBehavior" name="Microsoft.SharePoint.SoapServer.SPClaimProviderWebServiceHttps"&gt;
      &lt;endpoint address=""
                binding="basicHttpBinding"
                bindingConfiguration="TextStreamBindingHttpsNoSecurity"
                bindingNamespace="http://schemas.microsoft.com/sharepoint/claims/"
                behaviorConfiguration="HttpBinding.LargeDataEndpointBehavior"
                contract="MOL.Service.ISAPI.MOL.IServiceHosted" /&gt;
    &lt;/service&gt;
  &lt;/services&gt;
  &lt;protocolMapping&gt;
    &lt;add scheme="https" binding="webHttpBinding" bindingConfiguration="StreamBindingHttps" /&gt;
    &lt;add scheme="http" binding="webHttpBinding" bindingConfiguration="StreamBinding" /&gt;
  &lt;/protocolMapping&gt;
  &lt;bindings&gt;
    &lt;webHttpBinding&gt;
      &lt;binding name="webHttpBindingWithJsonP"
             crossDomainScriptAccessEnabled="true" /&gt;
    &lt;/webHttpBinding&gt;
    &lt;basicHttpBinding&gt;
      &lt;binding name="StreamBinding" closeTimeout="00:01:00" openTimeout="00:01:00"
        receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="true"
        maxBufferSize="4194304" maxReceivedMessageSize="4194304" messageEncoding="Mtom"
        transferMode="StreamedResponse"&gt;
        &lt;security mode="TransportCredentialOnly"&gt;
          &lt;transport clientCredentialType="Windows"/&gt;
        &lt;/security&gt;
      &lt;/binding&gt;
      &lt;binding name="StreamBindingBasic" closeTimeout="00:01:00" openTimeout="00:01:00"
        receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="true"
        maxBufferSize="4194304" maxReceivedMessageSize="4194304" messageEncoding="Mtom"
        transferMode="StreamedResponse"&gt;
        &lt;security mode="TransportCredentialOnly"&gt;
          &lt;transport clientCredentialType="Basic"/&gt;
        &lt;/security&gt;
      &lt;/binding&gt;
      &lt;binding name="StreamBindingDigest" closeTimeout="00:01:00" openTimeout="00:01:00"
        receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="true"
        maxBufferSize="4194304" maxReceivedMessageSize="4194304" messageEncoding="Mtom"
        transferMode="StreamedResponse"&gt;
        &lt;security mode="TransportCredentialOnly"&gt;
          &lt;transport clientCredentialType="Digest"/&gt;
        &lt;/security&gt;
      &lt;/binding&gt;
      &lt;binding name="StreamBindingNtlm" closeTimeout="00:01:00" openTimeout="00:01:00"
        receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="true"
        maxBufferSize="4194304" maxReceivedMessageSize="4194304" messageEncoding="Mtom"
        transferMode="StreamedResponse"&gt;
        &lt;security mode="TransportCredentialOnly"&gt;
          &lt;transport clientCredentialType="Ntlm"/&gt;
          &lt;message clientCredentialType="UserName" algorithmSuite="Default" /&gt;
        &lt;/security&gt;
      &lt;/binding&gt;
      &lt;binding name="TextStreamBindingNoSecurity" closeTimeout="00:01:00" openTimeout="00:01:00"
        receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="true"
        maxBufferSize="4194304" maxReceivedMessageSize="4194304" messageEncoding="Text"
        transferMode="StreamedResponse"&gt;
      &lt;/binding&gt;
      &lt;binding name="StreamBindingHttps" closeTimeout="00:01:00" openTimeout="00:01:00"
        receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="true"
        maxBufferSize="4194304" maxReceivedMessageSize="4194304" messageEncoding="Mtom"
        transferMode="StreamedResponse"&gt;
        &lt;security mode="Transport"&gt;
          &lt;transport clientCredentialType="Windows"/&gt;
        &lt;/security&gt;
      &lt;/binding&gt;
      &lt;binding name="StreamBindingHttpsBasic" closeTimeout="00:01:00" openTimeout="00:01:00"
        receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="true"
        maxBufferSize="4194304" maxReceivedMessageSize="4194304" messageEncoding="Mtom"
        transferMode="StreamedResponse"&gt;
        &lt;security mode="Transport"&gt;
          &lt;transport clientCredentialType="Basic"/&gt;
        &lt;/security&gt;
      &lt;/binding&gt;
      &lt;binding name="StreamBindingHttpsDigest" closeTimeout="00:01:00" openTimeout="00:01:00"
        receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="true"
        maxBufferSize="4194304" maxReceivedMessageSize="4194304" messageEncoding="Mtom"
        transferMode="StreamedResponse"&gt;
        &lt;security mode="Transport"&gt;
          &lt;transport clientCredentialType="Digest"/&gt;
        &lt;/security&gt;
      &lt;/binding&gt;
      &lt;binding name="StreamBindingHttpsNtlm" closeTimeout="00:01:00" openTimeout="00:01:00"
        receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="true"
        maxBufferSize="4194304" maxReceivedMessageSize="4194304" messageEncoding="Mtom"
        transferMode="StreamedResponse"&gt;
        &lt;security mode="Transport"&gt;
          &lt;transport clientCredentialType="Ntlm"/&gt;
          &lt;message clientCredentialType="UserName" algorithmSuite="Default" /&gt;
        &lt;/security&gt;
      &lt;/binding&gt;
      &lt;binding name="TextStreamBindingHttpsNoSecurity" closeTimeout="00:01:00" openTimeout="00:01:00"
        receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="true"
        maxBufferSize="4194304" maxReceivedMessageSize="4194304" messageEncoding="Text"
        transferMode="StreamedResponse"&gt;
        &lt;security mode="Transport"&gt;
          &lt;transport clientCredentialType="None"/&gt;
        &lt;/security&gt;
      &lt;/binding&gt;
      &lt;binding name="mexHttpBinding"&gt;
        &lt;security mode="TransportCredentialOnly"&gt;
          &lt;transport clientCredentialType="Windows" proxyCredentialType="Windows"/&gt;
        &lt;/security&gt;
      &lt;/binding&gt;
      &lt;binding name="mexNtlmHttpBinding"&gt;
        &lt;security mode="TransportCredentialOnly"&gt;
          &lt;transport clientCredentialType="Ntlm" proxyCredentialType="Ntlm"/&gt;
        &lt;/security&gt;
      &lt;/binding&gt;
    &lt;/basicHttpBinding&gt;
  &lt;/bindings&gt;
  &lt;!--For debugging purposes set the includeExceptionDetailInFaults attribute to true--&gt;
  &lt;behaviors&gt;
    &lt;serviceBehaviors&gt;
      &lt;behavior name="CellStorageServiceBehavior"&gt;
        &lt;serviceMetadata httpGetEnabled="true" /&gt;
  
        &lt;serviceDebug includeExceptionDetailInFaults="true" /&gt;
  
      &lt;/behavior&gt;
      &lt;behavior name="CellStorageServiceHttpsBehavior"&gt;
        &lt;serviceMetadata httpsGetEnabled="true" /&gt;
  
        &lt;serviceDebug includeExceptionDetailInFaults="true" /&gt;
      &lt;/behavior&gt;
      &lt;behavior name="ClaimProviderWebServiceBehavior" &gt;
        &lt;serviceMetadata httpGetEnabled="true" /&gt;
        &lt;serviceDebug includeExceptionDetailInFaults="false" /&gt;
      &lt;/behavior&gt;
      &lt;behavior name="HttpsClaimProviderWebServiceBehavior" &gt;
        &lt;serviceMetadata httpsGetEnabled="true" /&gt;
        &lt;serviceDebug includeExceptionDetailInFaults="false" /&gt;
      &lt;/behavior&gt;
    &lt;/serviceBehaviors&gt;
    &lt;endpointBehaviors&gt;
      &lt;behavior name="HttpBinding.LargeDataEndpointBehavior"&gt;
        &lt;dataContractSerializer maxItemsInObjectGraph="2147483647" /&gt;
      &lt;/behavior&gt;
    &lt;/endpointBehaviors&gt;
  &lt;/behaviors&gt;
  </code></pre>
  
  <p>
  </p>
  
  <p>and this way to call service from windows 8 app</p>
  
  <pre><code>private async void ConfigureHttpsProxy()
      {
          try
          {
              SecurityBindingElement securityElement = SecurityBindingElement.CreateUserNameOverTransportBindingElement();
              HttpsTransportBindingElement httpsTransport = new HttpsTransportBindingElement();
              httpsTransport.AuthenticationScheme = System.Net.AuthenticationSchemes.Ntlm;
  
              CustomBinding binding = new CustomBinding(securityElement, httpsTransport);
              binding.Name = "StreamBindingHttps";
  
              EndpointAddress remoteAddress = new EndpointAddress(addressHttps);
  
              var client = new ServiceHosted.ServiceHostedClient(binding, remoteAddress);
              client.ClientCredentials.UserName.UserName = "UserName";
  
              client.ClientCredentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
  
              var result = await client.GetUserAsync("ahmed", "123456");
  
              var x = result.DepartmentName;
          }
          catch { }          
      }
  </code></pre>