2011-05-19 43 views
1

下面的代碼:「對象只包含密鑰對的公共一半,還必須提供私鑰。」使用2層。質子交換膜的與X509&MS Services3.Security

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("[email protected]"," "); 
      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,權威性,是我的公開證書和signCert,SOAP,是我的私有證書,但我真的很不確定。我從一種(Web服務)食譜中獲取代碼... Web服務表示他們沒有查看密碼。

的錯誤信息是:
"Object contains only the public half of a key pair. A private key must also be provided."

回答

2

您需要.pem文件轉換成一個.pfx爲.NET Framework,以便能夠使用它。 .pfx將包含公鑰和私鑰。您可以使用OpenSSL將ADP發送給您的.pem文件轉換爲.pfx文件。

http://www.openssl.org/

mutualCert是用於連接到ADP SSL證書signCert用於你的SOAP/Web服務調用

我一直在努力的inerface與ADP數月,我仍然有問題。

希望這會有所幫助 -Doug