使用X.509证书错误加密SOAP消息

时间:2015-02-04 12:16:27

标签: asp.net-mvc wcf soap wse3.0 x509securitytokenmanager

有一个美好的一天需要帮助从这里我有安全管理器类继承SendSecurityFilter类WSE3但它在构建它时返回错误genarate这个错误请帮我解决这个有关这个类详细信息。谢谢

错误1'Microsoft.Web.Services3.Security.SendSecurityFilter'不包含带0参数的构造函数

公共类SecurityManager:SendSecurityFilter     {  public override void SecureMessage(SoapEnvelope信封,安全性安全性)    {

 // 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;
    }

1 个答案:

答案 0 :(得分:1)

您收到此错误的原因是base SendSecurityFilter类没有带0参数的默认构造函数。并且您没有为SecurityManager类实现任何构造函数,因此应该生成默认构造函数:

  

10.10.4 Default constructors

     

如果类不包含实例构造函数声明,则为默认值   实例构造函数自动提供。那个默认   构造函数只需调用direct的无参数构造函数   基类。

但是SendSecurityFilter没有从SecurityManager类调用的无参数构造函数!

要修复此错误,您应该实现其中一个构造函数或两者:

//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)
{
}