6

的SharePoint 2010配置爲聲明爲基礎的認證與外部用戶都的Windows基於表單的身份驗證(FBA)。我還需要開發自定義WCF服務。問題是我想將Windows憑據傳遞到WCF服務中;但是,我似乎無法獲得傳遞到服務的Windows憑據。我的自定義WCF服務似乎使用匿名身份驗證(必須在IIS中啓用以顯示FBA登錄屏幕)。SharePoint 2010的自定義WCF服務 - Windows和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()); 
    } 

我對IIS安全性有點不熟悉當涉及到聲明並嘗試使用Windows和FBA時設置/配置。我對WCF配置的安全性也缺乏經驗。我通常開發內部應用程序,並讓Visual Studio決定使用什麼,因爲安全性很少關注。

回答

0

我想我想出了答案。關鍵是要創建一個web.config文件並將其部署在與.svc文件相同的文件夾中。 web.config文件需要指定綁定使用「wsHttpBinding」而不是「basicHttpBinding」。我還刪除了.svc聲明中的Factory屬性和類中的BasicHttpBindingServiceMetadataExchangeEndpoint屬性。

+5

你可以發佈完整的web.config文件作爲解決方案嗎?我遇到了與WCF和2010基於聲明的身份驗證類似的問題。 – 2011-08-26 16:06:37