简体   繁体   English

在SharePoint 2010 Web部件中模拟用户以调用WCF服务

[英]Impersonate User in SharePoint 2010 web part to call WCF service

I have a Web Part where I am trying to call a WCF Service as the current logged in user. 我有一个Web部件,我试图在其中调用WCF服务作为当前登录用户。 The Web Part work locally when debugging in Visual Studio 2013 - calling the external WCF service. 在Visual Studio 2013中调试时,Web部件在本地工作-调用外部WCF服务。 I have configured Kerberos for the WCF Service as well as the SharePoint site and fee like that is all correct. 我已经为WCF服务以及SharePoint网站配置了Kerberos,而这样做的费用都是正确的。 I can call the WCF Service correctly from another Kerberos enabled web app fine as well as from a console app. 我可以从另一个启用了Kerberos的Web应用程序以及从控制台应用程序正确调用WCF服务。

Now I'd like to roll this to a SharePoint farm. 现在,我想将此滚动到SharePoint服务器场。 However after I add the solution to the farm and activate the feature on the sharepoint site...I get an error when I try to add the web part to a page. 但是,在将解决方案添加到服务器场并激活共享点网站上的功能后,尝试将Web部件添加到页面时出现错误。 The error comes up in a box that says "The caller was not authenticated by the service.". 该错误出现在显示“呼叫者未通过服务验证”的框中。 The error comes from the actualy method call. 错误来自实际方法调用。

My web part code is as such: 我的Web部件代码是这样的:

WorksiteService.iWorksiteServiceClient wss = new WorksiteService.iWorksiteServiceClient("WSHttpBinding_iWorksiteService");
wss.ClientCredentials.Windows.ClientCredential =  System.Net.CredentialCache.DefaultNetworkCredentials;
wss.ClientCredentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation;
WorkSiteDocument[] wd = wss.GetDocumentsByAlias2("test");

The web.config in for the sharepoint site has this for the endpoint: 共享点站点中的web.config具有此端点:

<system.serviceModel>    
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />    
<bindings>      
<wsHttpBinding>        
<binding name="WSHttpBinding_iWorksiteService" />      
</wsHttpBinding>    
</bindings>    
<client>      
<endpoint address="http://myservicerd.xyz.com/WorkSiteService.svc" binding="wsHttpBinding"     bindingConfiguration="WSHttpBinding_iWorksiteService" contract="WorksiteService.iWorksiteService" name="WSHttpBinding_iWorksiteService">        
<identity>          
<servicePrincipalName value="myservicerd.xyz.com" />        
</identity>      
</endpoint>    
</client>  
</system.serviceModel>

Any ideas on why I get that error? 关于我为什么收到该错误的任何想法? I'm assuming I'm not getting the current user's credentials for some reason.There is nothing in the event or sharepoint logs of the sharepoint server or wcf server. 我假设由于某种原因我没有获得当前用户的凭据。共享点服务器或wcf服务器的事件或共享点日志中没有任何内容。 Any ideas on how I can troubleshoot this?Thank you for any assistance you can provide. 关于如何解决此问题的任何想法?感谢您提供的任何帮助。

I'm not a Sharepoint Expert, but from a Kerberos perspective I would suggest to check the delegation settings in Active Directory just as Marek suggested. 我不是Sharepoint专家,但从Kerberos的角度来看,我建议按照Marek的建议检查Active Directory中的委托设置。

In a double-hop scenario like this, the 'man' in the middle must be permitted to take on the identity of the client. 在像这样的双跳场景中,必须允许中间的“人”扮演客户的身份。

The question remains who the 'man' in the middle is, which depends on the IIS configuration. 问题仍然是中间的“人”是谁,这取决于IIS配置。 If the IIS is configured for kernel-mode authentication the middle identity is probably the computer account if the server IIS is installed on. 如果将IIS配置为用于内核模式身份验证,则在安装服务器IIS的情况下,中间身份可能是计算机帐户。

Otherwise I would assume that the identity that needs delegation rights should be the identity of the application pool the web part runs in. 否则,我将假定需要委派权限的身份应该是Web部件在其中运行的应用程序池的身份。

If you determined the identity, go to the appropriate Active Directory account (delegation tab) and select 'Account is trusted for delegation'. 如果确定了身份,请转到相应的Active Directory帐户(“代理”选项卡),然后选择“信任帐户可进行委派”。

Maybe this blog article can shed some light on this: http://tekaris.com/blog/2013/04/05/http-400-bad-request-kerberos-authentication-with-iis-2/ 也许这篇博客文章可以对此有所启发http : //tekaris.com/blog/2013/04/05/http-400-bad-request-kerberos-authentication-with-iis-2/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM