我正在尝试使用以下配置托管我的服务。
<system.serviceModel>
<services>
<service name="Test.MyService" behaviorConfiguration="MyServiceBehavior">
<!-- Service Endpoints -->
<endpoint address="MyTestService" binding="wsHttpBinding" bindingConfiguration="WebserviceHttpBinding" contract="Test.IMyService"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<bindings>
<wsHttpBinding>
<binding name="WebserviceHttpBinding">
<security mode="Message">
<message clientCredentialType="UserName" negotiateServiceCredential="false"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceBehavior">
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="Test.CredentialValidator, Test"/>
<serviceCertificate findValue="RPKey" x509FindType="FindBySubjectName" storeLocation="LocalMachine" storeName="My"/>
</serviceCredentials>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
当我调试这个服务时,我没有问题。我用这个网站在IIS中托管了这个服务。当我从IIS浏览这个服务时,我得到以下异常。
应用程序。
密钥集不存在
在执行过程中发生
当前web请求。请检查
错误及其来源
异常详细信息:
System.Security.Cryptography.CryptographyException异常:
源错误:
生成了未处理的异常
在电流执行过程中
web请求。关于
可以使用异常来识别
堆栈跟踪:
[CryptographicException:密钥集不存在
]
System.Security.Cryptography.Utils.CreateProvHandle(CspParameters,Boolean randomKeyContainer)+369
System.Security.Cryptography.rsacyptoserviceprovider.GetKeyPair()+85
System.Security.Cryptography.RSACryptoServiceProvider..ctor(Int32 dwKeySize,CspParameters,Boolean useDefaultKeySize)+280
System.Security.Cryptography.X509Certificates.X509Certificate2.get_PrivateKey()+468
[ArgumentException:证书'CN=RPKey'必须具有能够进行密钥交换的私钥。进程必须具有私钥的访问权限。]
System.ServiceModel.Security.SecurityUtils.EnsureCertificateCanDoKeyExchange(X509Certificate2证书)+15832031
System.ServiceModel.Security.ServiceCredentialsSecurityTokenManager.CreateServerX509TokenProvider()+45
System.ServiceModel.Security.ServiceCredentialsSecurityTokenManager.CreateLocalSecurityTokenProvider(RecipientServiceModelSecurityTokenRequirement recipientRequirement)+73
System.ServiceModel.Security.ServiceCredentialsSecurityTokenManager.CreateSecurityTokenProvider(SecurityTokenRequirement要求)+65
System.ServiceModel.Security.SymmetricSecurityProtocolFactory.OnOpen(TimeSpan超时)+15334232
System.ServiceModel.Security.WrapperSecurityCommunicationObject.OnOpen(TimeSpan超时)+23
System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan超时)+563
System.ServiceModel.Security.SecurityListenerSettingsLifetimeManager.Open(TimeSpan超时)+101
1.OnOpen(TimeSpan timeout) +203
System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) +563
System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen(TimeSpan timeout) +87
System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) +563
System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout) +110
System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) +563
System.ServiceModel.Security.SecuritySessionSecurityTokenAuthenticator.OnOpen(TimeSpan timeout) +149
System.ServiceModel.Security.WrapperSecurityCommunicationObject.OnOpen(TimeSpan timeout) +23
System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) +563
System.ServiceModel.Security.SecurityUtils.OpenCommunicationObject(ICommunicationObject obj, TimeSpan timeout) +24
System.ServiceModel.Security.SecuritySessionServerSettings.OnOpen(TimeSpan timeout) +878
System.ServiceModel.Security.WrapperSecurityCommunicationObject.OnOpen(TimeSpan timeout) +23
System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) +563
System.ServiceModel.Security.SecurityListenerSettingsLifetimeManager.Open(TimeSpan timeout) +153
System.ServiceModel.Channels.SecurityChannelListener
System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan超时)+563
System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan超时)+563
System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan超时)+110
System.ServiceModel.HostingManager.ActivateService(字符串normalizedVirtualPath)+135
System.ServiceModel.HostingManager.ensurereserviceavailable(字符串normalizedVirtualPath)+654
[ServiceActivationException:由于编译期间出现异常,无法激活服务'/AtlasServices/service.svc'。异常消息是:证书“CN=RPKey”必须具有能够进行密钥交换的私钥。进程必须具有私钥的访问权限..]
System.ServiceModel.Activation.hostedHTTPPrequestAsyncResult.End(IAsyncResult结果)+15623609
System.ServiceModel.Activation.HostedHTTPPrequestAsyncResult.ExecuteSynchronous(HttpApplication上下文,布尔流上下文)+265
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()+80
System.Web.HttpApplication.ExecuteStep(IExecutionStep步骤,布尔值&同步完成)+171