WCF 异常:无法加载配置中指定的 X.509 证书标识,如何修复它

本文关键字:证书 标识 何修复 异常 加载 配置 WCF | 更新日期: 2023-09-27 18:33:04

我有一个WCF服务库,有两个接口:FileManager和TaskManager。

我想将这些接口的两个端点合并到一个服务中。

当我将一个端点与一个接口IFileManager一起使用时,它运行良好,然后在我ITaskManager另一个接口并添加新端点后,服务停止工作。 它给了我在任务管理器端点上停止,并在文件管理器端点上出现错误:

System.InvalidOperationException: Cannot load the X.509 certificate identity specified in the configuration.

如何解决?

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
  <compilation debug="true" />
</system.web>
<!-- When deploying the service library project, the content of the config file must be added to the host's app.config file. System.Configuration does not support config files for libraries. -->
 <system.serviceModel>
   <diagnostics wmiProviderEnabled="false" />
   <bindings>
  <netTcpBinding>
    <binding name="TcpBindingRule" maxBufferPoolSize="2097152" maxBufferSize="2097152"
      maxReceivedMessageSize="2097152" />
  </netTcpBinding>
</bindings>
<services>
  <service behaviorConfiguration="Service1Behavior" name="WcfServiceLibrary1.FileManagerService">
    <clear />
    <endpoint address="FileManagerEndpoint" binding="netTcpBinding"
      bindingConfiguration="TcpBindingRule" name="FileManagerEndpoint"
      contract="WcfServiceLibrary1.IFileManager" listenUriMode="Explicit">
      <identity>
        <dns value="" />
        <certificateReference x509FindType="FindBySubjectDistinguishedName" />
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange"
      listenUriMode="Explicit">
      <identity>
        <certificateReference storeName="My" storeLocation="LocalMachine"
          x509FindType="FindBySubjectDistinguishedName" />
      </identity>
    </endpoint>
    <endpoint address="TaskManagerEndpoint" binding="netTcpBinding"
      bindingConfiguration="" name="TaskManagerEndpoint" contract="WcfServiceLibrary1.ITaskManager">
      <identity>
        <dns value="" />
      </identity>
    </endpoint>
    <host>
      <baseAddresses>
        <add baseAddress="net.tcp://Markor:1991/filemanager" />
      </baseAddresses>
    </host>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="Service1Behavior">
      <serviceMetadata httpGetEnabled="false" />
      <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
  </serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>

WCF 异常:无法加载配置中指定的 X.509 证书标识,如何修复它

看起来你把身份放在了错误的终点下。将其移动到终结点地址="任务管理器终结点"元素下,而不是在 mex 下。

 <endpoint address="TaskManagerEndpoint" binding="netTcpBinding"
      bindingConfiguration="" name="TaskManagerEndpoint" contract="WcfServiceLibrary1.ITaskManager">
      <identity>
        <dns value="" />
        <certificateReference storeName="My" storeLocation="LocalMachine" x509FindType="FindBySubjectDistinguishedName" />
      </identity>
    </endpoint>