我是调用WCF Web服务的小老鼠,所以希望这是一个简单的问题。当使用.NET 4 winform客户端调用Web服务时,如何将授权方案从匿名更改为NTLM?如何使用NTLM授权方案调用Web服务?
现在我收到异常:HTTP请求未经授权,客户端身份验证方案为“匿名”。从服务器收到的验证头是'NTLM'。
我的目标是构建一个小工具来帮助我监视TFS 2010的数据仓库和多维数据集。 TFS提供了一个WarehouseControlWebService Web服务。登录到服务器时,我可以在浏览器中通过“测试”模式调用该服务。不过,我试图从桌面远程调用相同的Web服务。我的用户帐户位于服务器上的本地管理员组中。
我创建了一个带有规范Button1和TextArea1的.NET 4 WinForm。然后我添加了一个服务引用到Web服务,并创造性地把它称为ServiceReference1:
Add Service Reference...
http://tfssvr:8080/tfs/TeamFoundation/Administration/v3.0/WarehouseControlService.asmx
这里是我的代码背后:
private void button1_Click(object sender, EventArgs e)
{
// Creating a proxy takes about 3-4 seconds
var dwSvc = new ServiceReference1.WarehouseControlWebServiceSoapClient();
// Invoking the method throws an MessageSecurityException
var dwStatus = dwSvc.GetProcessingStatus(null, null, null);
}
我越来越System.ServiceModel.Security.MessageSecurityException:
该HTTP请求未经授权,客户端身份验证方案为“匿名”。从服务器收到的验证头是'NTLM'。
我试着通过我传递凭据:
dwSvc.ClientCredentials.Windows.ClientCredential =
new System.Net.NetworkCredential("user", "pass", "domain");
,也...
dwSvc.ClientCredentials.Windows.ClientCredential =
CredentialCache.DefaultNetworkCredentials;
我涉水通过WCF文档,但...哦...男孩有那里很多。我希望这是一件容易的事情?
在此先感谢。
请参阅http://meta.stackexchange.com/questions/2950/should-hi-thanks -taglines-and-salutations-be-from-posts –