【发布时间】:2010-09-10 00:36:52
【问题描述】:
我有一个 Web 服务,它在 WSE 3.0 中使用带有 X.509 证书的消息层安全性。该服务使用 X509v3 策略对 soapheader 中的各种元素进行签名。
我需要对证书进行一些自定义检查,因此我尝试实现自定义 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>`
(顺便说一句,stackoverflow 上的一种 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);
我暂时停留在 .NET 2.0 (VS2005),所以我认为 WCF 是不可能的,否则互操作性不是问题,因为我将控制系统中的客户端和服务。
【问题讨论】:
标签: c# web-services certificate x509