我创建了应该使用证书的wcf服务。我使用自签名证书的测试工作非常完美,但是当我尝试在服务器上运行它时,所有更改都会由CA生成证书。我使用CA生成了客户端和服务器证书,之后我将服务器证书导出到“受信任的人”文件夹。 (我将两个证书放到LocalMachine目录中)。此外,我已授予证书所有必要的权限。
当我运行客户端程序而我出现异常时会出现问题:
X.509证书CN = xxxx不在受信任的人员商店中。
这是我的服务器配置
<services>
<service behaviorConfiguration="MyServiceBehavior" name="PoswsService">
<endpoint address="http://xxxx/PoswsService.svc" binding="wsHttpBinding" bindingConfiguration="MyServiceBinding"
contract="IPoswsService" />
<endpoint address="http://xxxx/mex" binding="mexHttpBinding" name="MetadataBinding"
contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceBehavior">
<serviceCredentials>
<clientCertificate>
<authentication certificateValidationMode="PeerOrChainTrust" revocationMode="Online"/>
</clientCertificate>
<serviceCertificate findValue="xxxxxxxxxxxxxxxxxxxxx" storeLocation="LocalMachine"
storeName="My" x509FindType="FindBySerialNumber" />
</serviceCredentials>
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<wsHttpBinding>
<binding name="MyServiceBinding">
<security>
<message clientCredentialType="Certificate"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
</system.serviceModel>
这是客户端配置
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IPoswsService"
bypassProxyOnLocal="false" transactionFlow="false" >
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="" />
<message clientCredentialType="Certificate" negotiateServiceCredential="true"
algorithmSuite="Default" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://xxxx/PoswsService.svc"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IPoswsService"
contract="TestService.IPoswsService" name="WSHttpBinding_IPoswsService" behaviorConfiguration="CustomBehavior">
<identity>
<certificate encodedValue="long word" />
</identity>
</endpoint>
</client>
<behaviors>
<endpointBehaviors>
<behavior name="CustomBehavior">
<clientCredentials>
<clientCertificate findValue="xxxxxxxxxxxxxxxxxxx" x509FindType="FindBySerialNumber" storeLocation="CurrentUser" storeName="My"/>
<serviceCertificate>
<authentication certificateValidationMode="PeerTrust"/>
</serviceCertificate>
</clientCredentials>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
有人知道我的错误在哪里吗?
答案 0 :(得分:0)
答案 1 :(得分:-1)
我没有很多WCF经验,但通常,您希望将CA证书放在受信任的位置。客户端应该有自己的受信任位置,CA证书也需要去那里。如果这是一个生产服务,您将需要将certificateValidationMode更改为客户端和服务器的“ChainTrust”,这意味着它将信任链接到CA证书的证书。 “PeerTrust”意味着您只需将您想要信任的实际证书放在信任位置。这个page可能有助于您查看。