祝你有美好的一天需要帮助
错误 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;
}