Skip to main content
2 of 3
some more info added
Sergei Sergeev
  • 11.6k
  • 5
  • 32
  • 49

SharePoint 2010 Query service authentication problem

I am struggling with calling search.asmx service from asp.net page. I've created proxy class using svcutil.exe and run request using following code:

var binding = new BasicHttpBinding();
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
binding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.None;
binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;
binding.Security.Transport.Realm = string.Empty;
binding.Security.Message.AlgorithmSuite = System.ServiceModel.Security.SecurityAlgorithmSuite.Default;
var service = new QueryServiceSoapClient(binding, new EndpointAddress("http://mysite/_vti_bin/search.asmx"));
service.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
var res = service.QueryEx(qXMLString);

Web application is set up using Kerberos authentication, I got exception

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

in method System.ServiceModel.Channels.HttpChannelUtilities.ValidateAuthentication
I've tried set up service.ClientCredentials.Windows.AllowNtlm = true; but error is the same.

What can be the cause of this problem?

Thanks in advance.

UPD:

I've tried above code to run in a console app, and all working fine, exception is thrown form asp.net codebehind only.

Sergei Sergeev
  • 11.6k
  • 5
  • 32
  • 49