1

这是代码:

using ADPTest.com.adp.hrbws;
using System.Security.Cryptography.X509Certificates;
using Microsoft.Web.Services3.Security;
using Microsoft.Web.Services3.Security.Tokens;
using Microsoft.Web.Services3.Security.Cryptography;

namespace ADPTest
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create the web service proxy.
            HrbService proxy = new HrbService();

            // Add the Username token.
            UsernameToken usernameToken = new UsernameToken("user@ABC"," ");
            proxy.RequestSoapContext.Security.Tokens.Add(usernameToken);

            // Add the certificate for mutual SSL.
            X509Certificate2 mutualCert = new X509Certificate2 "I:\\auth.pem", " ");
            proxy.ClientCertificates.Add(mutualCert);

            // Sign the message using the signing certificate.
            X509Certificate2 signCert = new X509Certificate2("I:\\soap.pem", " ");
            X509SecurityToken signatureToken = new X509SecurityToken(signCert);
            MessageSignature signature = new MessageSignature(signatureToken);
            proxy.RequestSoapContext.Security.Elements.Add(signature);

我认为mutualCert,auth,是我的公共证书和signCert,SOAP,是我的私人证书,但我真的不确定。我从一种(网络服务)食谱中获取了代码......网络服务说他们不看密码。

错误信息是:

“对象仅包含密钥对的公共部分。还必须提供私钥。”

4

1 回答 1

2

您需要将 .pem 文件转换为 .pfx 以便 .Net 框架能够使用它。.pfx 将包含公钥和私钥。您可以使用 OpenSSL 将 ADP 发送给您的 .pem 文件转换为 .pfx 文件。

http://www.openssl.org/

mutualCert 是用于连接到 ADP 的 SSL 证书 signCert 用于您的 SOAP/Web 服务调用

几个月来我一直在研究 ADP 接口,但我仍然遇到问题。

希望这会有所帮助-道格

于 2011-08-03T13:41:16.273 回答