I am quite annoyed with this one for last 2 hours :(
Folks,
I am trying to access a SharePoint OOTB List web service from a Console application. My SharePoint site in IIS is set to Integrated Windows Auth mode, and anonymous access is disabled.
Now at client side what I am doing is as follows
try
{
BasicHttpBinding bind = new BasicHttpBinding();
bind.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
bind.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
EndpointAddress endpoint = new EndpointAddress("http://abc:37379/_vti_bin/lists.asmx");
ServiceReference1.ListsSoapClient listService
= new ConsoleApplication1.ServiceReference1.ListsSoapClient(bind, endpoint);
var elm = listService.GetListItems("Tasks", null, null, null, "10", null, @"06dc3b48-a55e-4db8-8511-acbaf9748e15");
}
catch (Exception ex){
Console.WriteLine("Message:\n" + ex.Message + "\nDetail:\n" +
ex.ToString() + "\nStackTrace:\n" + ex.StackTrace); }
Boom, this raises the exception "The HTTP request is unauthorized with client authentication scheme 'Negotiate'. The authentication header received from the server was 'NTLM'."
I really wanted to do something like following what we used to do in old net 2.0 days
serviceProxy.Credentials = new NetworkCredentials("username","password","domain");
What is the easiest way to achieve this kind of credential handling in new proxy classes??
(BTW as you have already noticed I am using the Binding /endpoint everything inside code rather a config file, this is a restriction for my app. please don't tell me to change this-its not possible).
Can anyone help me with this?? It would be greatly appreciated.