WCF异常:无法加载配置中指定的X.509证书身份,如何解决?

时间:2012-05-03 05:14:48

标签: c# wcf wcf-security endpoint

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

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

当我使用一个带有一个接口IFileManager的端点时,它工作正常,然后在我创建另一个接口ITaskManager并添加了一个新端点后,该服务停止工作。它让我在TaskManager端点上停止,并在FileManager端点上出现错误:

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>

1 个答案:

答案 0 :(得分:0)

看起来你已将身份置于错误的终点。将其移至端点地址=&#34; TaskManagerEndpoint&#34;元素不在mex下。

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