问题
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