使用WCF的basicHttpBinding进行Windows身份验证

使用WCF的basicHttpBinding进行Windows身份验证,wcf,proxy,service,Wcf,Proxy,Service,在过去的两个小时里,我对这一点非常恼火:( 各位 我正在尝试从控制台应用程序访问SharePoint OOTB列表web服务。IIS中的SharePoint网站已设置为集成Windows身份验证模式,并且已禁用匿名访问 现在在客户端,我所做的如下 try { BasicHttpBinding bind = new BasicHttpBinding(); bind.Security.Mode = BasicHttpSecurityMode.TransportCr

在过去的两个小时里,我对这一点非常恼火:(

各位

我正在尝试从控制台应用程序访问SharePoint OOTB列表web服务。IIS中的SharePoint网站已设置为集成Windows身份验证模式,并且已禁用匿名访问

现在在客户端,我所做的如下

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,这会引发异常“HTTP请求未经客户端身份验证方案“协商”授权。从服务器接收的身份验证标头为“NTLM”

我真的很想做一些类似于我们在旧的NET2.0时代所做的事情

serviceProxy.Credentials = new NetworkCredentials("username","password","domain");
在新的代理类中实现这种凭证处理的最简单方法是什么

(顺便说一句,您已经注意到,我使用的是代码中的绑定/端点everything而不是配置文件,这是对我的应用程序的限制。请不要告诉我要更改它,因为这是不可能的)


有人能帮我吗?非常感谢。

IIRC当您在绑定中指定kerberos(windows)时,当web服务器尝试故障恢复到ntlm时,就会发生这种情况

您应该能够更改这行代码

bind.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;

如果需要kerberos才能工作,则需要确保web服务器上的服务与active directory中服务原则名称的相同帐户下运行

如果要指定凭据,请使用通道工厂创建客户端,并在打开通道之前,在通道工厂的凭据属性上设置适当的凭据。 例如:

var cf = new ChannelFactory<IServiceInterface>(
    bind, endpoint);
cf.Credentials.UserName.UserName = "domain\\someuser";
cf.Credentials.UserName.Password = "password";
var cf=新通道工厂(
绑定(端点);
cf.Credentials.UserName.UserName=“域\\someuser”;
cf.Credentials.UserName.Password=“Password”;

FYI:由于ASMXWCF而更改了主题,因此代理类当然不同。生成的代理似乎还具有允许您执行相同操作的凭据属性。您好,非常感谢您的建议。很遗憾,它不起作用。:(你可以在上面看到我对chris.w.mclean的评论,了解我的问题以及我面临的例外情况。
var cf = new ChannelFactory<IServiceInterface>(
    bind, endpoint);
cf.Credentials.UserName.UserName = "domain\\someuser";
cf.Credentials.UserName.Password = "password";