2011-06-03 68 views
2

我有一個運行WCF Net Tcp綁定服務的Windows服務。所有綁定和端點信息均以編程方式設置。從基於SharePoint的聲明中調用Net Tcp WCF服務

_host.AddServiceEndpoint(typeof(IService), new NetTcpBinding(), serviceName); 

在SharePoint中,我使用一個通道工廠訪問該服務:

var channelFactory = new ChannelFactory<IService>(
    new NetTcpBinding(), 
    new EndpointAddress(new Uri(connectionUrl)) 
); 
return channelFactory.CreateChannel(); 

此代碼運行正常使用SharePoint 2007。現在,我們正在改善我們的SharePoint網站2010年新形式的基於聲明身份未發送客戶端憑據。我得到這個錯誤。

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. 

有誰知道我可以如何讓Channel Factory發送應用程序池的憑據?現在我已經通過使用RunWithElevatedPrivileges解決了我的問題,但我並不真的熱衷於這樣做,除非我沒有任何其他選擇。

回答

2

我們解決了它使用這種方法:

using(WindowsIdentity.Impersonate(IntPtr.Zero)) 
{ 
    var result = channel.ServiceMethod(); 
} 

這在我看來是更好然後不必要提升使用RunWithElevatedPrivileges的SharePoint憑據。