e-r*_*ock 6 forms-authentication windows-authentication wcf-security sharepoint-2010
我为基于声明的身份验证配置了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服务...
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());
}
Run Code Online (Sandbox Code Playgroud)
对于声明并尝试同时使用Windows和FBA,我对IIS安全设置/配置缺乏经验.对于安全性的WCF配置,我也缺乏经验.我经常开发内部商务应用程序,让Visual Studio决定使用什么,因为安全性很少受到关注.
我想我找到了答案。关键是创建一个 web.config 文件并将其部署在与 .svc 文件相同的文件夹中。web.config 文件需要指定绑定使用“ wsHttpBinding ”而不是“ basicHttpBinding ”。我还删除了 .svc 声明中的 Factory 属性和类上的 BasicHttpBindingServiceMetadataExchangeEndpoint 属性。
| 归档时间: |
|
| 查看次数: |
4638 次 |
| 最近记录: |