user2939764
user2939764

Reputation: 15

Encrypt a SOAP Message Using an X.509 Certificate error

Have a nice day need a help from here i have securityManager Class which inherit on SendSecurityFilter class WSE3 but it returns error when it build it genarate this error please help me to solve this some one know about this class details.Thanks

Error 1 'Microsoft.Web.Services3.Security.SendSecurityFilter' does not contain a constructor that takes 0 arguments

public class SecurityManager : SendSecurityFilter { public override void SecureMessage(SoapEnvelope envelope, Security security) {

 // Get an X.509 certificate for signing the SOAP message.
        X509SecurityToken signatureToken = GetSecurityToken("CN=WSE2QuickStartClient");
        if (signatureToken == null)
        {
            throw new SecurityFault("Message Requirements could not be satisfied.");
        }

        // Add the X.509 certificate to the header.
        security.Tokens.Add(signatureToken);

        // Specify that the SOAP message is signed using this X.509
        // certifcate.
        MessageSignature sig = new MessageSignature(signatureToken);
        security.Elements.Add(sig);

        // Get an X.509 certificate for encrypting the SOAP message.
        X509SecurityToken encryptionToken = GetSecurityToken("CN=WSE2QuickStartServer");
        if (encryptionToken == null)
        {
            throw new SecurityFault("Message Requirements could not be satisfied.");
        }

        // Specify that the SOAP message is encrypted using 
        // this X.509 certificate.
        EncryptedData enc = new EncryptedData(encryptionToken);
        security.Elements.Add(enc);
    }

public X509SecurityToken GetSecurityToken(string subjectName) {

        X509SecurityToken securityToken = null;
        X509Store store = new X509Store(StoreName.My,
          StoreLocation.CurrentUser);
        store.Open(OpenFlags.ReadOnly);
        try
        {
            X509Certificate2Collection certs =
                store.Certificates.Find(X509FindType.FindBySubjectDistinguishedName,
                subjectName, false);

            X509Certificate2 cert;
            if (certs.Count == 1)
            {
                cert = certs[0];
                securityToken = new X509SecurityToken(cert);
            }
            else
                securityToken = null;
        }
        catch (Exception ex)
        {
            securityToken = null;
        }
        finally
        {
            if (store != null)
                store.Close();
        }
        return securityToken;
    }

Upvotes: 1

Views: 590

Answers (1)

knyu
knyu

Reputation: 996

The reason you getting this error is that base SendSecurityFilter class does not have default constructor that takes 0 arguments. And you did not implement any constructors for your SecurityManager class, so default one should be generated:

10.10.4 Default constructors

If a class contains no instance constructor declarations, a default instance constructor is automatically provided. That default constructor simply invokes the parameterless constructor of the direct base class.

But SendSecurityFilter does not have parameterless constructor to invoke from your SecurityManager class!

To fix this error you should implement one of that constructors or both of them:

//replace "public" with suitable modififier
public SecurityManager(string serviceActor, bool isClient) : base(serviceActor, isClient)
{
}

//replace "public" with suitable modififier
public SecurityManager(string serviceActor, bool isClient, string clientActor) : base(serviceActor, isClient, clientActor)
{
}

Upvotes: 1

Related Questions