下面是我的场景:我有一个正在处理的SharePoint站点,它位于一个服务器场上。在这个站点中,我创建了一个HttpHandler,它使用位于不同服务器上的SharePoint搜索webservice。看起来是这样的:
-
我的网站所在的SharePoint Server A
-
对服务器B上的SharePoint搜索web服务具有服务引用
-
-
搜索服务所在的SharePoint服务器B
我的代码如下所示:
BasicHttpBinding binding = new BasicHttpBinding();
binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Ntlm;
QueryServiceSoapClient _queryService = new QueryServiceSoapClient(binding, new EndpointAddress("http://easearch.ea.com/_vti_bin/search.asmx"));
_queryService.ClientCredentials.Windows.AllowNtlm = true;
_queryService.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
_queryService.ClientCredentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
//_queryService.ClientCredentials.Windows.ClientCredential = new NetworkCredential("MyUsername", "MyPassword", "MyDomain"); //This is the only way it seems to work
//NetworkCredential userCredential = CredentialCache.DefaultCredentials.GetCredential(_queryService.Endpoint.ListenUri, "NTLM");
//_queryService.ClientCredentials.Windows.ClientCredential = userCredential;
string status = _queryService.Status();
客户端身份验证方案“Ntlm”。
来自服务器的是“NTLM”。
我已经尝试了上述代码的多种不同组合,只有当我直接提供凭据时,HttpHandler才起作用。有人有什么想法吗?
谢谢。