我已经使用最新WIF SDK(适用于.NET 4.0)附带的被动和活动案例的项目模板成功创建了一个可用的自定义STS.一切都按预期工作.
我现在正在尝试将我的Web应用程序和服务升级到.NET 4.5,包括我的自定义STS.我已经能够将Microsoft.IdentityModel.xxx中的所有命名空间/类映射到框架中内置的新命名空间/类,但有一个例外--WSTrustServiceHostFactory.
该类似乎不再存在,我无法弄清楚如何替换它提供的功能.即,从以下链接:http: //msdn.microsoft.com/en-us/library/microsoft.identitymodel.protocols.wstrust.wstrustservicehostfactory
<%@ServiceHostLanguage="C#"Debug="true"Service="XXX.XXX.MyActiveSTSConfiguration"Factory="Microsoft.IdentityModel.Protocols.WSTrust.WSTrustServiceHostFactory"%>
Run Code Online (Sandbox Code Playgroud)
升级到4.5后,我的被动STS目前正在工作.我需要找到一个使用4.5框架实例化活动SecurityTokenService的适当/推荐方法(理想情况下,对于SDK项目模板中的大多数配置使用web.config).任何建议表示赞赏.
一旦我弄清楚了一些事情,事实证明这很简单.
服务主机标记:
<%@ ServiceHost Language="C#" Debug="true" Service="XXX.XXX.MyActiveSTSConfiguration" Factory="XXX.XXX.CustomWSTrustServiceHostFactory" %>
Run Code Online (Sandbox Code Playgroud)
这是我的自定义工厂类实现.关键是,由于您不能再使用WSTrustServiceFactory为您创建WSTrustServiceHost,您必须在CreateServiceHost方法覆盖中自己显式创建一个.
public class CustomWSTrustServiceHostFactory
: ServiceHostFactory {
/// <summary>
/// Initializes a new instance of the <see cref="CustomWSTrustServiceHostFactory"/> class.
/// </summary>
public CustomWSTrustServiceHostFactory()
: base() { }
/// <summary>
/// Creates and configures a <see cref="WSTrustServiceHost"/> with a specific base address.
/// </summary>
/// <param name="serviceType">Specifies the type of service to host (ignored).</param>
/// <param name="baseAddresses">The <see cref="T:Uri"/> array that contains the base addresses for the service.</param>
/// <returns>A <see cref="WSTrustServiceHost"/> with a specific base address.</returns>
protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses) {
var config = new PortalActiveSTSConfiguration();
var host = new WSTrustServiceHost(config, baseAddresses);
//var host = base.CreateServiceHost(serviceType, baseAddresses);
var serviceBehavior = host.Description.Behaviors.Find<ServiceBehaviorAttribute>();
serviceBehavior.AddressFilterMode = AddressFilterMode.Any;
return host;
}
/// <summary>
/// Creates and configures a <see cref="WSTrustServiceHost"/> with a specific base address.
/// </summary>
/// <param name="constructorString">The constructor string (ignored).</param>
/// <param name="baseAddresses">The <see cref="T:Uri"/> array that contains the base addresses for the service.</param>
/// <returns></returns>
public override ServiceHostBase CreateServiceHost(string constructorString, Uri[] baseAddresses) {
var config = new PortalActiveSTSConfiguration();
var host = new WSTrustServiceHost(config, baseAddresses);
//var host = base.CreateServiceHost(constructorString, baseAddresses);
var serviceBehavior = host.Description.Behaviors.Find<ServiceBehaviorAttribute>();
serviceBehavior.AddressFilterMode = AddressFilterMode.Any;
return host;
}
}
Run Code Online (Sandbox Code Playgroud)
自定义服务配置类实现(基本上是WIF 4.0 STS模板附带的):
public class MyActiveSTSConfiguration
: SecurityTokenServiceConfiguration {
public MyActiveSTSConfiguration()
: base(
WebConfigurationManager.AppSettings[ISSUER_NAME],
new X509SigningCredentials(
CertificateUtil.GetCertificate(
StoreName.My, StoreLocation.LocalMachine, X509FindType.FindByThumbprint,
WebConfigurationManager.AppSettings[SIGNING_CERTIFICATE_THUMBPRINT],
true)
)
) {
this.SecurityTokenService = typeof(MyActiveSTS);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1980 次 |
| 最近记录: |