相关代码在独立的控制台应用程序中运行良好,而在 NSB 架构中尝试使其工作时出错。我试图在工作人员中测试相同的内容,并在测试控制台应用程序中独立进行测试。在任何一种情况下,它都会出错 - X509Certificate2 certificate = new X509Certificate2(filePath, "***key***UeUHFxS"); 异常消息是 - System.Security.Cryptography.CryptographicException: '系统找不到指定的文件。该代码由如图所示的代码和一个关联的 Activate 设备的帮助文件组成。但是,在用于初始化 X509Certificate2 的部分中,来自 pfx 文件路径和密钥的例外是。class Program{ static void Main(string[] args) { try { string filePath = Path.GetDirectoryName(System.AppDomain.CurrentDomain.BaseDirectory); filePath = Directory.GetParent(Directory.GetParent(filePath).FullName).FullName; filePath = Path.Combine(filePath, @"Cert\TestCompany-qa.partner.client.siriusxm.com.pfx"); X509Certificate2 certificate = new X509Certificate2(filePath, "****key****"); SoapMessageHelper soapHelper = new SoapMessageHelper(certificate, @"https://api-ext-test.siriusxm.com/SAT/UpdateDeviceSatRefresh/v_1"); var test = soapHelper.ActivateDevice(new ActivateDeviceRequest() { SourceName = "12493", ESN = "W26890HW", TimeStamp = DateTime.UtcNow, TrasanctionId = System.Guid.NewGuid().ToString() }); XmlDocument doc = new XmlDocument(); doc.LoadXml(test); foreach (XmlNode node in doc.DocumentElement.ChildNodes) { foreach (XmlNode locNode in node) { if (locNode.Name == "ns0:responseRefreshDevice") { string resultCode = locNode["ns0:resultCode"].InnerText; string errorCode = locNode["ns0:errorCode"].InnerText; string errorMessage = locNode["ns0:errorMessage"].InnerText; Console.WriteLine(resultCode + errorCode + errorMessage); } } }
2 回答
翻阅古今
TA贡献1780条经验 获得超5个赞
让我们尝试将您的构造函数修改为:
X509Certificate2 certificate = new X509Certificate2(filePath, key, X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.Exportable);
使用 MachineKeySet 作为 msdn 说:
“私钥存储在本地计算机存储中,而不是当前用户存储中。”
- 2 回答
- 0 关注
- 153 浏览
添加回答
举报
0/150
提交
取消