sharepoint-2010 - SharePoint 2010 自定义 WCF 服务 - Windows 和 FBA 身份验证

标签 sharepoint-2010 forms-authentication wcf-security windows-authentication

我有 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/

相关文章:

c# - 通过 SOAP 使用 SharePoint Web 服务进行 Windows 身份验证

sharepoint - 无法删除内容类型

jquery - 在 SharePoint 2010 中如何使用 jQuery 为所有 <a> 标记添加目标 ="_blank"

visual-studio-2010 - 如何防止 VS2010 自动将新的 SharePoint 模块添加到随机功能

c# - 当他/她的用户名被另一个用户更改时如何强制注销用户?

forms-authentication - 对 umbraco 站点的所有请求都重定向到登录页面

c# - 以编程方式使用证书身份验证配置 WCF 服务客户端

authentication - 在子文件夹或虚拟目录上禁用表单例份验证

.net - 使用 WCF 模拟和 net.tcp 绑定(bind)访问 web.config 设置

使用客户端证书的 WCF 服务需要在 IIS 中进行匿名访问,因此实际上不起作用?