为什么我们在WCF中使用证书

时间:2014-09-21 11:54:37

标签: wcf ssl certificate

我正在研究大学管理系统,我正在制作WCF服务.... 我的要求是通过互联网保护我的网络服务(WCF),因为有人告诉我使用证书,但我不知道如何使用证书     我也实现了Https协议,我正在使用WshttpBinding

这是我的Web.config文件: -

<?xml version="1.0"?>
<configuration>

     <system.diagnostics>
    <sources>
      <source name="System.ServiceModel.MessageLogging" switchValue="Warning,ActivityTracing">
        <listeners>
          <add type="System.Diagnostics.DefaultTraceListener" name="Default">
            <filter type="" />
          </add>
          <add name="ServiceModelMessageLoggingListener">
            <filter type="" />
          </add>
        </listeners>
      </source>
      <source propagateActivity="true" name="System.ServiceModel" switchValue="Warning,ActivityTracing">
        <listeners>
          <add type="System.Diagnostics.DefaultTraceListener" name="Default">
            <filter type="" />
          </add>
          <add name="ServiceModelTraceListener">
            <filter type="" />
          </add>
        </listeners>
      </source>
    </sources>
    <sharedListeners>
      <add initializeData="d:\khurram\projectalahsaan2014\alahsaan\dal\web_messages.svclog"
        type="System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
        name="ServiceModelMessageLoggingListener" traceOutputOptions="Timestamp">
        <filter type="" />
      </add>
      <add initializeData="d:\khurram\projectalahsaan2014\alahsaan\dal\web_tracelog.svclog"
        type="System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
        name="ServiceModelTraceListener" traceOutputOptions="Timestamp">
        <filter type="" />
      </add>
    </sharedListeners>
    <trace autoflush="true" />
  </system.diagnostics>
  <connectionStrings>
    <add name="DAL.Properties.Settings.ConStr" connectionString="Data Source=.\SQL2012;Initial Catalog=AlAhsaan2014;Integrated Security=True" providerName="System.Data.SqlClient" />
  </connectionStrings>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
    <!--<httpRuntime maxRequestLength="2147483647" executionTimeout="3600" enable="true" />-->
    <!--2147483647-->
    <sessionState mode="InProc" cookieless="true" timeout="20"> </sessionState>
  </system.web>
  <system.serviceModel>
    <diagnostics>
      <messageLogging logEntireMessage="true"
                      logMalformedMessages="true"
                      logMessagesAtTransportLevel="true" />
    </diagnostics>
    <bindings>
      <wsHttpBinding>
        <binding name="secureWsHttpBinding"
                 maxBufferPoolSize="2147483647"
                 maxReceivedMessageSize="524288000"  
                 messageEncoding="Mtom"> <!--500MB Download-->
          <readerQuotas maxArrayLength="1572864"/>  <!--1.5MB Upload-->
          <security mode="Transport">
            <transport clientCredentialType="None"/>
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
    <protocolMapping>
      <remove scheme="https"/>
      <add scheme="https" binding="wsHttpBinding" bindingConfiguration="secureWsHttpBinding"/>
    </protocolMapping>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpsGetEnabled="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>
    <services>
      <service name="DAL.AlahsaanDSL">
        <endpoint address="" binding="wsHttpBinding" bindingConfiguration="secureWsHttpBinding"
          contract="DAL.IAlahsaanDSL" />
        <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
      </service>
    </services>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

</configuration>

我的问题是: -

  1. 证书的机制是什么?
  2. 如何使用证书?
  3. 证书是否提供(PKI)(公钥基础设施)?

0 个答案:

没有答案