1

祝你有美好的一天需要帮助

错误 1“Microsoft.Web.Services3.Security.SendSecurityFilter”不包含采用 0 个参数的构造函数

公共类SecurityManager:SendSecurityFilter {公共覆盖无效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);
    }

公共 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;
    }
4

1 回答 1

1

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

10.10.4 默认构造函数

如果类不包含实例构造函数声明,则会自动提供默认实例构造函数。该默认构造函数只是调用直接基类的无参数构造函数。

但是 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)
{
}
于 2015-02-04T13:50:11.333 回答