我有一个Web服务,它使用WSE 3.0中的X.509证书的消息层安全性。该服务使用X509v3策略在soapheader中签署各种元素。自定义X509SecurityTokenManager被忽略
我需要对证书进行一些自定义检查,以便试图实现自定义X509SecurityTokenManager并在web.config中添加一个节。
当我使用我的Wseproxy调用服务时,我期望出现错误(NotImplementedException),但调用进入低谷,并且在下面的示例中,在控制台上将打印“foo”。
问题是:什么错过了? web.config中的binarySecurityTokenManager类型与RDI.Server.X509TokenManager的完整类名匹配。 X509TokenManager从 继承X509SecurityTokenManager(其他方法只是存根)。
using System;
using System.Xml;
using System.Security.Permissions;
using System.Security.Cryptography;
using Microsoft.Web.Services3;
using Microsoft.Web.Services3.Security.Tokens;
namespace RDI.Server
{
[SecurityPermissionAttribute(SecurityAction.Demand,Flags = SecurityPermissionFlag.UnmanagedCode)]
public class X509TokenManager : Microsoft.Web.Services3.Security.Tokens.X509SecurityTokenManager
{
public X509TokenManager() : base()
{
throw new NotImplementedException("Stub");
}
public X509TokenManager(XmlNodeList configData) : base(configData)
{
throw new NotImplementedException("Stub");
}
protected override void AuthenticateToken(X509SecurityToken token)
{
base.AuthenticateToken(token);
throw new NotImplementedException("Stub");
}
}
}
首先我的web.config,编辑为简洁的几行
<?xml version="1.0"?>
<configuration><configSections><section name="microsoft.web.services3" type="..." />
</configSections>
<microsoft.web.services3>
<policy fileName="wse3policyCache.config" />
<security>
<binarySecurityTokenManager>
<add type="RDI.Server.X509TokenManager" valueType="http://docs.oasis-open.org/..." />
</binarySecurityTokenManager>
</security>
</microsoft.web.services3>`
(顺便说一句,在如何很好地计算器这里做一个格式的XML?)
Administration.AdministrationWse test = new TestConnector.Administration.AdministrationWse();
X509Certificate2 cert = GetCert("RDIDemoUser2");
X509SecurityToken x509Token = new X509SecurityToken(cert);
test.SetPolicy("X509");
test.SetClientCredential(x509Token);
string message = test.Ping("foo");
Console.WriteLine(message);
我m暂时停留在.NET 2.0(VS2005),所以我认为WCF是不存在问题的,否则互操作性不是问题,因为我可以控制系统中的客户端和服务。