使WCF服务支持HTTPS的设定方法 (服务器篇)

1,生成加密证书

    用VisualStudio 中 MakeCert.exe 的工具生成加密证书。

MakeCert.exe -sr localmachine -ss My -n CN=localhost,OU=https://localhost -sky exchange -pe -r localhost.cer

 

2,查看生成好的加密证书的『Thumbprint hash』

 

使WCF服务支持HTTPS的设定方法 (服务器篇)

 

3,用 httpcfg 命令将加密证书和SSL端口关联好。

    关联 httpcfg set ssl -i [ip]:[port] -h [thumbprint hash]

    解除关联 httpcfg delete ssl –i [ip]:[port]

C:\Documents and Settings\Administrator>httpcfg query ssl

C:\Documents and Settings\Administrator>httpcfg set ssl -i 0.0.0.0:10180 -h 59ab8e12f1dbf43060684932c1bb570874049c09
HttpSetServiceConfiguration completed with 0.

C:\Documents and Settings\Administrator>httpcfg query ssl
    IP                      : 0.0.0.0:10180
    Hash                    : 59ab8e12f1dbf43060684932c1bb57 874 49c 9
    Guid                    : {00000000-0000-0000-0000-000000000000}
    CertStoreName           : (null)
    CertCheckMode           : 0
    RevocationFreshnessTime : 0
    UrlRetrievalTimeout     : 0
    SslCtlIdentifier        : (null)
    SslCtlStoreName         : (null)
    Flags                   : 0
------------------------------------------------------------------------------

C:\Documents and Settings\Administrator>
 

 

4,用 httpcfg 命令设定 URLACL

C:\Documents and Settings\Administrator>httpcfg.exe set urlacl /u https://+:10184/webapp/sample1 /a "D:(A;;GX;;;NS)"
HttpSetServiceConfiguration completed with 0.

C:\Documents and Settings\Administrator>httpcfg.exe set urlacl /u https://+:10184/webapp/sample2 /a "D:(A;;GX;;;NS)"
HttpSetServiceConfiguration completed with 0.

C:\Documents and Settings\Administrator>httpcfg query urlacl
    URL : http://+:80/Temporary_Listen_Addresses/
    ACL : D:(A;;GX;;;WD)
------------------------------------------------------------------------------
    URL : https://+:10184/webapp/sample1/
    ACL : D:(A;;GX;;;NS)
------------------------------------------------------------------------------
    URL : https://+:10184/webapp/sample2/
    ACL : D:(A;;GX;;;NS)
------------------------------------------------------------------------------

C:\Documents and Settings\Administrator> 

 

 

5,修改WCF的配置文件

<system.serviceModel>

<bindings >
  <basicHttpBinding>
    <binding name ="myBasicBinding">
        <security mode ="Transport">
        <transport clientCredentialType="None"/>
        </security>
    </binding>
  </basicHttpBinding>
</bindings>

<services>
  <service name="net.dncsoft.sample1" behaviorConfiguration="sample1Behavior">
    <endpoint address="https://localhost:10184/webapp/sample1" 
                contract="net.dncsoft.Isample1"
                binding="basicHttpBinding" 
                bindingNamespace="http://www.dncsoft.net/2011/11/sample" 
                bindingConfiguration="myBasicBinding" />
    </service>
    <service name="net.dncsoft.sample2" behaviorConfiguration="sample2Behavior">
    <endpoint address="https://localhost:10184/webapp/sample2" 
                contract="net.dncsoft.Isample2"
                binding="basicHttpBinding"
                bindingNamespace="http://www.dncsoft.net/2011/11/sample" 
                bindingConfiguration="myBasicBinding" />
  </service>
</services>

<behaviors>
  <serviceBehaviors>
    <behavior name="sample1Behavior">
        <serviceMetadata httpsGetEnabled="true" httpGetEnabled="false" 
        httpsGetUrl="https://localhost:10184/webapp/sample1"/>
    </behavior>
    <behavior name="sample2Behavior">
        <serviceMetadata httpsGetEnabled="true" httpGetEnabled="false" 
        httpsGetUrl="https://localhost:10184/webapp/sample2"/>
    </behavior>
  </serviceBehaviors>
</behaviors>

</system.serviceModel>
 

 

 

 

 

你可能感兴趣的:(https)