<p>I have a webservice that that uses message layer security with X.509 certificates in WSE 3.0. The service uses a X509v3 policy to sign various elements in the soapheader.</p>

<p>I need to do some custom checks on the certificates so I've tried to implement a custom X509SecurityTokenManager and added a section in web.config.</p>

<p>When I call the service with my Wseproxy I would expect a error (NotImplementedException) but the call goes trough and, in the example below, "foo" is printed at the console.</p>

<p>The question is: What have missed? The binarySecurityTokenManager type in web.config matches the full classname of RDI.Server.X509TokenManager. X509TokenManager inherits from 
X509SecurityTokenManager (altough methods are just stubs).</p>

<pre><code>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");
    }
}
}
</code></pre>

<p>The first few lines of my web.config, edited for brevity</p>

<pre><code>&lt;?xml version="1.0"?&gt;
  &lt;configuration&gt;&lt;configSections&gt;&lt;section name="microsoft.web.services3" type="..." /&gt;
  &lt;/configSections&gt;
  &lt;microsoft.web.services3&gt;
    &lt;policy fileName="wse3policyCache.config" /&gt;
    &lt;security&gt;
      &lt;binarySecurityTokenManager&gt;
        &lt;add type="RDI.Server.X509TokenManager" valueType="http://docs.oasis-open.org/..." /&gt;
      &lt;/binarySecurityTokenManager&gt;
    &lt;/security&gt;
  &lt;/microsoft.web.services3&gt;`
</code></pre>

<p>(Btw, how do one format xml nicely here at stackoverflow?)</p>

<pre><code>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);
</code></pre>

<p>I'm stuck at .NET 2.0 (VS2005) for the time being so I presume WCF is out of the question, otherwise interoperability isn't a problem, as I will have control of both clients and services in the system.</p>

[{'answer_id': 81630, 'author': 'Kieran Benton', 'author_id': 5777, 'author_profile': 'https://Stackoverflow.com/users/5777', 'pm_score': 0, 'selected': False, 'text': "<p>Not particular constructive advice I know, but if I was you I'd get off WSE3.0 as soon as possible. We did some work with trying to get it to interoperate with WCF and a Java client earlier this year and it was an obsolute KNIGHTMARE.</p>\n\n<p>WCF on the other hand is practically sane and the documentation on areas like this is pretty good. Is that  an option for you?</p>\n"}, {'answer_id': 92102, 'author': 'Carl-Johan', 'author_id': 15406, 'author_profile': 'https://Stackoverflow.com/users/15406', 'pm_score': 1, 'selected': False, 'text': '<p>The problem was located elsewhere. My serverproject was an web-app and some options wasn\'t available for web-apps just for web-sites. So I made a small web-site project and compared web.configs and noticed that some lines diffed.</p>\n\n<p>These lines was in the website web.config but not in my other projekt</p>\n\n<pre><code>  &lt;soapServerProtocolFactory type="Microsoft.Web.Services3.WseProtocolFactory, Microsoft.Web.Services3, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /&gt;\n  &lt;soapExtensionImporterTypes&gt;\n    &lt;add type="Microsoft.Web.Services3.Description.WseExtensionImporter, Microsoft.Web.Services3, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /&gt;\n  &lt;/soapExtensionImporterTypes&gt;\n</code></pre>\n\n<p>After I added those lines i got the expected error.</p>\n'}]
['https://Stackoverflow.com/questions/81295', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/15406/']