Custom Policy Assertion SOAP with Certificate c#

752 Views Asked by At

I have this code to add a X509Certificate to SOAP message and sign it:

//Convert X509Certificate (Config.clientCertificate) to X509Certifica2 to use later on security token.
X509Certificate2 certificate = new X509Certificate2(Config.clientCertificate);

//Create security token
X509SecurityToken certToken = new X509SecurityToken(certificate);

//Add WS-Security to proxy class client and sign message
webserviceClient.RequestSoapContext.Security.Tokens.Add(certToken);
webserviceClient.RequestSoapContext.Security.Elements.Add(new MessageSignature(certToken));

But Visual Studio displays a warning with this message:

SoapContext.Security is obsolete. Consider deriving from SendSecurityFilter or ReceiveSecurityFilter and creating a custom policy assertion that generates these filters.

I am using this assembly: Microsoft.Web.Services3 on a Windows dll project (not WCF).

Please, anyone could provide some help to implement a SendSecurityFilter and how to create a custom policy assertion using a client certificate?

I have found some tutorials on internet about this technique but all are with UsernameToken and I don't know how to translate it to use a X509Certificate.

It is working but I want to have an updated code without this warning.

Thank you very much. Best regards.

0

There are 0 best solutions below