The HTTP request is unauthorized with client authentication scheme 'Ntlm' The authentication header received from the server was 'NTLM'

后端 未结 10 2251
滥情空心
滥情空心 2020-12-01 00:21

I know there\'s a lot of questions on SO similar to this, but I couldn\'t find one for this particular issue.

A couple of points, first:

  • I have n
10条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-01 00:27

    After many answers that did not work, I finally found a solution when Anonymous access is Disabled on the IIS server. Our server is using Windows authentication, not Kerberos. This is thanks to this blog posting.

    No changes were made to web.config.

    On the server side, the .SVC file in the ISAPI folder uses MultipleBaseAddressBasicHttpBindingServiceHostFactory

    The class attributes of the service are:

    [BasicHttpBindingServiceMetadataExchangeEndpointAttribute]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
    public class InvoiceServices : IInvoiceServices
    {
    ...
    }
    

    On the client side, the key that made it work was the http binding security attributes:

    EndpointAddress endpoint =
      new EndpointAddress(new Uri("http://SharePointserver/_vti_bin/InvoiceServices.svc"));
    BasicHttpBinding httpBinding = new BasicHttpBinding();
    httpBinding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
    httpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Ntlm;
    InvoiceServicesClient myClient = new InvoiceServicesClient(httpBinding, endpoint);
    myClient.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation; 
    
    (call service)
    

    I hope this works for you!

提交回复
热议问题