【发布时间】:2011-06-24 05:39:20
【问题描述】:
我已为 基于声明的身份验证 配置了 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" %>
这是 .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;
}
}
我刚刚测试的 WCF 测试客户端(WPF 应用程序)使用以下代码调用 WCF 服务...
private void Button1Click(object sender, RoutedEventArgs e)
{
BasicHttpBinding binding = new BasicHttpBinding();
binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Ntlm;
EndpointAddress endpoint =
new EndpointAddress(
"http://dev.portal.data-image.local/_vti_bin/MyCompany.Services/LibraryManagers/LibraryUploader.svc");
LibraryUploaderClient libraryUploader = new LibraryUploaderClient(binding, endpoint);
libraryUploader.ClientCredentials.Windows.AllowedImpersonationLevel =
System.Security.Principal.TokenImpersonationLevel.Impersonation;
MessageBox.Show(libraryUploader.SiteName());
}
在声明和尝试同时使用 Windows 和 FBA 时,我对 IIS 安全设置/配置有些缺乏经验。在涉及安全性的 WCF 配置时,我也缺乏经验。我通常开发内部商业应用程序并让 Visual Studio 决定使用什么,因为安全性很少受到关注。
【问题讨论】:
标签: sharepoint-2010 forms-authentication wcf-security windows-authentication