我有 SharePoint 2010 为 配置基于声明的身份验证 两者都有 window 和 基于表单的身份验证 (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 决定使用什么,因为安全性很少受到关注。
最佳答案
我想我找到了答案。关键是创建一个 web.config 文件并部署在与 .svc 文件相同的文件夹中。 web.config 文件需要指定使用“ wsHttpBinding ”而不是“ basicHttpBinding ”的绑定(bind)。我还删除了 .svc 声明中的 Factory 属性和类上的 BasicHttpBindingServiceMetadataExchangeEndpoint 属性。
关于sharepoint-2010 - SharePoint 2010 自定义 WCF 服务 - Windows 和 FBA 身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4946971/