我为基于声明的身份验证配置了SharePoint 2010,同时为外部用户提供Windows和基于表单的身份验证(FBA).我还需要开发自定义WCF服务.问题是我希望Windows凭据传递到WCF服务; 但是,我似乎无法将Windows凭据传递到服务中.我的自定义WCF服务似乎使用匿名身份验证(必须在IIS中启用才能显示FBA登录屏幕).
我试图遵循的示例可以在http://msdn.microsoft.com/en-us/library/ff521581.aspx找到.
WCF服务部署到_vti_bin(ISAPI文件夹).
这是.svc文件的代码
<%@ ServiceHost Language="C#" Debug="true"
Service="MyCompany.CustomerPortal.SharePoint.UI.ISAPI.MyCompany.Services.LibraryManagers.LibraryUploader, $SharePoint.Project.AssemblyFullName$"
Factory="Microsoft.SharePoint.Client.Services.MultipleBaseAddressBasicHttpBindingServiceHostFactory, Microsoft.SharePoint.Client.ServerRuntime, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"
CodeBehind="LibraryUploader.svc.cs" %>
Run Code Online (Sandbox Code Playgroud)
这是.svc文件背后的代码
[ServiceContract]
public interface ILibraryUploader
{
[OperationContract]
string SiteName(); }
[BasicHttpBindingServiceMetadataExchangeEndpoint]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
public class LibraryUploader : ILibraryUploader
{
//just try to return site title right now…
public string SiteName()
{
WindowsIdentity identity = ServiceSecurityContext.Current.WindowsIdentity;
ClaimsIdentity claimsIdentity = new ClaimsIdentity(identity);
return SPContext.Current.Web.Title;
}
}
Run Code Online (Sandbox Code Playgroud)
我刚刚测试它的WCF测试客户端(WPF app)使用以下代码来调用WCF服务... …
forms-authentication windows-authentication wcf-security sharepoint-2010