Calling Net Tcp WCF Service from Claims based SharePoint
I have a windows service that runs a WCF Net Tcp binding service. All binding and endpoint information is set programmatically.
_host.AddServiceEndpoint(typeof(IService), new NetTcpBinding(), serviceName);
In sharepoint I am accessing this service using a channel factory:
var channelFactory = new ChannelFactory<IService>(
new NetTcpBinding(),
new EndpointAddress(new Uri(connectionUrl))
);
return channelFactory.CreateChannel();
This code ran fine using SharePoint 2007. Now that we are upgradin开发者_高级运维g our SharePoint site to 2010 the new forms based claims identity is not sending client credentials. I get this error.
System.IdentityModel.Tokens.SecurityTokenValidationException, System.IdentityModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
The service does not allow you to log on anonymously.
Does anyone know how I can get the Channel Factory to send the application pool's credentials? Right now I have solved my issue by using RunWithElevatedPrivileges but I'm not really keen on doing that unless I do not have any other choice.
We solved it using this approach:
using(WindowsIdentity.Impersonate(IntPtr.Zero))
{
var result = channel.ServiceMethod();
}
This in my opinion is better then needlessly elevating SharePoint credentials using RunWithElevatedPrivileges.
精彩评论