公钥错误WCF客户端

时间:2013-11-11 22:48:01

标签: wcf wcf-security x509

我正在开发WCF服务。它托管在IIS中并由SSL保护。我正在使用Soap11定制招标。我有一个私钥用于此服务,它在web.config文件中引用。我已从私钥导出公钥,并计划将此公钥提供给将调用此服务的供应商。

当我尝试使用客户端测试服务时。我收到以下错误。在我的客户端,我引用了公钥。我的客户端将请求发送到由私钥保护的服务。我检查了私钥以确保“你有一个与此证书对应的私钥。此外,我的IIS应用程序池在我的用户名下运行。我是计算机的管理员。

但是,当我尝试发送请求时,我收到错误“X.509证书中不存在私钥”。在客户端。可能导致此错误的原因是什么?

堆栈追踪:

System.NotSupportedException was caught
  HResult=-2146233067
  Message=The private key is not present in the X.509 certificate.
  Source=mscorlib
  StackTrace:
    Server stack trace: 
       at System.IdentityModel.Tokens.X509AsymmetricSecurityKey.GetSignatureFormatter(String algorithm)
       at System.IdentityModel.SignedXml.ComputeSignature(SecurityKey signingKey)
       at System.ServiceModel.Security.WSSecurityOneDotZeroSendSecurityHeader.CompletePrimarySignatureCore(SendSecurityHeaderElement[] signatureConfirmations, SecurityToken[] signedEndorsingTokens, SecurityToken[] signedTokens, SendSecurityHeaderElement[] basicTokens, Boolean isPrimarySignature)
       at System.ServiceModel.Security.SendSecurityHeader.CompleteSignature()
       at System.ServiceModel.Security.SendSecurityHeader.CompleteSecurityApplication()
       at System.ServiceModel.Security.SecurityAppliedMessage.OnWriteMessage(XmlDictionaryWriter writer)
       at System.ServiceModel.Channels.BufferedMessageWriter.WriteMessage(Message message, BufferManager bufferManager, Int32 initialOffset, Int32 maxSizeQuota)
       at System.ServiceModel.Channels.TextMessageEncoderFactory.TextMessageEncoder.WriteMessage(Message message, Int32 maxMessageSize, BufferManager bufferManager, Int32 messageOffset)
       at System.ServiceModel.Channels.HttpOutput.SerializeBufferedMessage(Message message)
       at System.ServiceModel.Channels.HttpOutput.Send(TimeSpan timeout)
       at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.SendRequest(Message message, TimeSpan timeout)
       at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
       at System.ServiceModel.Channels.SecurityChannelFactory`1.SecurityRequestChannel.Request(Message message, TimeSpan timeout)
       at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
       at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
       at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
       at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
    Exception rethrown at [0]: 
       at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
       at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
       at PaymentGatewayTestClient.Customer.ICustomerDetails.CustomerDetails(CustomerDetailRequest request)
       at PaymentGatewayTestClient.Customer.CustomerDetailsClient.CustomerDetails(CustomerDetailRequest request) in c:\temp\Test\PaymentGatewayTestClient\PaymentGatewayTestClient\Service References\Customer\Reference.cs:line 937
       at PaymentGatewayTestClient.Program.Main(String[] args) in c:\temp\Test\PaymentGatewayTestClient\PaymentGatewayTestClient\Program.cs:line 38
  InnerException: 

1 个答案:

答案 0 :(得分:0)

看起来服务器无法访问密钥的私有部分。您必须为运行应用程序池的用户授予私钥权限。

另见: PrivateKey trust permissions for local machine "Trusted roots" certificates