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.
UPD2:
User which run this code has appropriate permissions in SharePoint (actually console app runs under the same user as codebehind).