Calling web service with current users credentials from SharePoint

点点圈 提交于 2019-12-11 16:52:55

问题


When I run this C# code from my vs2010 client it works authenticating as me.

However if I deploy the code to a sharePoint page on a webserver I get an authentication error from the web service.

I understand this some double hop issue and I need to impersonate. maybe the code is calling the web service as the SharePoint service user.

Any easy way around this beyond hard coding credentials?

Uri uri = new Uri("http://tempuri.org/"); 
ICredentials credentials = CredentialCache.DefaultCredentials; 
NetworkCredential credential = credentials.GetCredential(uri, "Basic"); 
Service service = new Service("https://xxx/Exchange.asmx", credential);

Someone suggested using windowsidentity class with impersonate, but not sure how to plug that in.

Thanks.


回答1:


If you are trusted to use the application pool identity to interact with your remote web service then you can use this technique:

http://mindsharpblogs.com/todd/archive/2005/05/03/467.html



来源:https://stackoverflow.com/questions/7183859/calling-web-service-with-current-users-credentials-from-sharepoint

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!