使用自签名证书来使用WCF服务

时间:2015-09-02 08:49:44

标签: wcf self-signed

当我执行消费应用程序时,它给出了以下异常: 无法激活请求的服务“https://localhost:53996/HistoricStatementsWS.HistoricStatements.svc”。

当我尝试将此路径输入chrome时,它说: URI'https://ws20.intra.local:53996/HistoricStatementsWS.HistoricStatements.svc'已经存在注册。

我不知道如何摆脱这些例外,到目前为止我已经通过了很多论坛。

SERVER-SIDE app.config

<system.web>
<compilation debug="true" />
<membership defaultProvider="ClientAuthenticationMembershipProvider">
  <providers>
    <add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" />
  </providers>
</membership>
<roleManager defaultProvider="ClientRoleProvider" enabled="true">
  <providers>
    <add name="ClientRoleProvider" type="System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" cacheTimeout="86400" />
  </providers>
</roleManager>
</system.web>
<system.serviceModel>
<bindings>
  <wsHttpBinding>
    <binding name="wsHttpEndpointBinding">
      <security mode="Transport">
        <transport clientCredentialType="Certificate" />
      </security>
    </binding>
  </wsHttpBinding>
</bindings>
<services>
  <service behaviorConfiguration="behaviourHttps" name="HistoricStatementsWS.HistoricStatements">
    <endpoint address="" binding="wsHttpBinding" bindingConfiguration="wsHttpEndpointBinding"
      name="wsHttpEndpoint" contract="HistoricStatementsWS.IHistoricStatements" />
    <endpoint address="HistoricStatementsWS.HistoricStatements.svc"
      binding="wsHttpBinding" bindingConfiguration="wsHttpEndpointBinding"
      name="mexEndpoint" contract="IMetadataExchange" />
    <host>
      <baseAddresses>
        <add baseAddress="https://localhost:53996/" />
      </baseAddresses>
    </host>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="behaviourHttps">
      <useRequestHeadersForMetadataAddress />
      <serviceMetadata httpGetEnabled="false" httpsGetEnabled="true"
        httpsGetUrl="https://localhost:53996/HistoricStatementsWS.HistoricStatements.svc"
        policyVersion="Policy15" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>

CLIENT-SIDE Webconfig

<configuration>
<configSections>
</configSections>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
<system.webServer>
<directoryBrowse enabled="true" showFlags="Date,Time,Extension,Size" />
</system.webServer>
<system.serviceModel>
<bindings>
  <wsHttpBinding>
    <binding name="wsHttpEndpoint">
      <security mode="Transport">
        <transport clientCredentialType="Certificate" />
      </security>
    </binding>
  </wsHttpBinding>
</bindings>
<client>
  <endpoint behaviorConfiguration="endpointBehavior" address="https://localhost:53996/HistoricStatementsWS.HistoricStatements.svc" binding="wsHttpBinding"
    bindingConfiguration="wsHttpEndpoint" contract="IHistoricStatements.IHistoricStatements"
    name="wsHttpEndpoint" />
</client>
<behaviors>
  <endpointBehaviors>
    <behavior name="endpointBehavior">
      <clientCredentials>
        <clientCertificate storeLocation="LocalMachine" storeName="My" findValue="00B192126A72D282D2" x509FindType="FindBySerialNumber"/>
        <serviceCertificate>
          <authentication certificateValidationMode="None" revocationMode="NoCheck" />
        </serviceCertificate>
      </clientCredentials>
    </behavior>
  </endpointBehaviors>
</behaviors>
</system.serviceModel>
</configuration>

0 个答案:

没有答案