在IIS中使用wsHttpBinding托管WCF服务时出现问题
我正在尝试使用以下配置托管我的服务在IIS中使用wsHttpBinding托管WCF服务时出现问题,wcf,wcf-binding,wcf-security,Wcf,Wcf Binding,Wcf Security,我正在尝试使用以下配置托管我的服务 <system.serviceModel> <services> <service name="Test.MyService" behaviorConfiguration="MyServiceBehavior"> <!-- Service Endpoints --> <endpoint address="MyTestSe
<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浏览此服务时,出现以下异常
“/MyTestService”中的服务器错误
应用程序
键集不存在
描述:未处理的异常
在执行过程中发生
当前web请求。请检查
有关堆栈跟踪的详细信息,请参阅
错误及其来源
密码
例外情况详情:
System.Security.Cryptography.Cryptography异常:
键集不存在
源错误:
生成了一个未处理的异常
在执行当前
网络请求。有关
例外的来源和位置
可以使用异常来识别
堆栈跟踪如下
堆栈跟踪:
[加密异常:密钥集不存在
]
System.Security.Cryptography.Utils.CreateProvHandle(CspParameters,Boolean randomKeyContainer)+369
System.Security.Cryptography.Utils.GetKeyPairHelper(CspAlgorithmType keyType、CspParameters parameters、Boolean randomKeyContainer、Int32 dwKeySize、SafeProvHandle和SafeProvHandle、SafeKeyHandle和SafeKeyHandle)+151
System.Security.Cryptography.RSACryptoServiceProvider.GetKeyPair()+85
System.Security.Cryptography.RSACryptoServiceProvider..ctor(Int32 dwKeySize,CspParameters参数,布尔useDefaultKeySize)+280
System.Security.Cryptography.X509Certificates.X509Certificate2.get_PrivateKey()+468
System.ServiceModel.Security.SecurityUtils.EnsureCertificateCanDoKeyExchange(X509Certificate2 certificate)+85
[ArgumentException:证书'CN=RPKey'必须具有能够交换密钥的私钥。进程必须具有私钥的访问权限。]
System.ServiceModel.Security.SecurityUtils.EnsureCertificateCanDoKeyExchange(X509Certificate2 certificate)+15832031
System.ServiceModel.Security.ServiceCredentialSecurityTokenManager.CreateServerX509TokenProvider()+45
System.ServiceModel.Security.ServiceCredentialsSecurityTokenManager.CreateLocalSecurityTokenProvider(RecipientServiceModelSecurityTokenRequirement recipientRequirement)+73
System.ServiceModel.Security.ServiceCredentialsSecurityTokenManager.CreateSecurityTokenProvider(SecurityTokenRequirement要求)+65
System.ServiceModel.Security.SessionRenewSecurityTokenManager.CreateSecurityTokenProvider(SecurityTokenRequirement要求)+14
System.ServiceModel.Security.SymmetricSecurityProtocolFactory.OnOpen(TimeSpan超时)+15334232
System.ServiceModel.Security.WrapperSecurityCommunicationObject.OnOpen(TimeSpan超时)+23
System.ServiceModel.Channel.CommunicationObject.Open(TimeSpan超时)+563
System.ServiceModel.Security.SecurityListenerSettingsLifetimeManager.Open(TimeSpan超时)+101
System.ServiceModel.Channels.SecurityChannelListener1.OnOpen(TimeSpan超时)+203
System.ServiceModel.Channel.CommunicationObject.Open(TimeSpan超时)+563
System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen(TimeSpan超时)+87
System.ServiceModel.Channel.CommunicationObject.Open(TimeSpan超时)+563
System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan超时)+110
System.ServiceModel.Channel.CommunicationObject.Open(TimeSpan超时)+563
System.ServiceModel.Security.SecuritySessionSecurityTokenAuthenticator.OnOpen(TimeSpan超时)+149
System.ServiceModel.Security.WrapperSecurityCommunicationObject.OnOpen(TimeSpan超时)+23
System.ServiceModel.Channel.CommunicationObject.Open(TimeSpan超时)+563
System.ServiceModel.Security.SecurityUtils.OpenCommunicationObject(ICommunicationObject对象,TimeSpan超时)+24
System.ServiceModel.Security.SecuritySessionServerSettings.OnOpen(TimeSpan超时)+878
System.ServiceModel.Security.WrapperSecurityCommunicationObject.OnOpen(TimeSpan超时)+23
System.ServiceModel.Channel.CommunicationObject.Open(TimeSpan超时)+563
System.ServiceModel.Security.SecurityListenerSettingsLifetimeManager.Open(TimeSpan超时)+153
System.ServiceModel.Channel.SecurityChannel Listener
1.OnOpen(TimeSpan超时)+203
System.ServiceModel.Channel.CommunicationObject.Open(TimeSpan超时)+563
System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen(TimeSpan超时)+87
System.ServiceModel.Channel.CommunicationObject.Open(TimeSpan超时)+563
System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan超时)+110
System.ServiceModel.Channel.CommunicationObject.Open(TimeSpan超时)+563
System.ServiceModel.HostingManager.ActivateService(字符串规范化VirtualPath)+135
System.ServiceModel.HostingManager.EnsureServiceAvailable(字符串规范化VirtualPath)+654
[ServiceActivationException:由于编译期间出现异常,无法激活服务'/AtlasServices/service.svc'。异常消息是:证书'CN=RPKey'必须具有能够交换密钥的私钥。进程必须具有私钥的访问权限..]
System.ServiceModel.AsyncResult.End(IAsyncResult结果)+15700960
System.ServiceModel.Activation.HostedHttPrequesStatAsyncResult.End(IAsyncResult结果)+15623609
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.ExecuteSynchronous(HttpApplication上下文,布尔流上下文)+265
System.ServiceModel.Activation.HttpModule.ProcessRequest(对象发送方,EventArgs e)+227
System.Web.SyncEvent