使用SSL的IIS下WCF配置(CSDN手动迁移)

时间:2021-08-20 10:16:46

在WCF的WebConfig配置http绑定,并设置为使用传输安全性,如下所示

1     <bindings>
2       <basicHttpBinding>
3         <binding name="secureHttpBinding">
4           <security mode="Transport">
5             <transport clientCredentialType="None"/>
6           </security>
7         </binding>
8       </basicHttpBinding>
9     </bindings>

指定服务和服务终结点

1     <services>  
2       <service name="WCF.Service" >  
3         <endpoint contract="WCF.IService" address="" binding="basicHttpBinding" bindingConfiguration="secureHttpBinding"></endpoint>  
4         <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" /><!--这里为固定写法-->  
5       </service>  
6     </services> 

完整WebConfig如下:

 1 <?xml version="1.0" encoding="utf-8"?>  
 2 <configuration>  
 3   
 4   <system.web>  
 5     <compilation targetFramework="4.0" />  
 6   </system.web>  
 7   <system.serviceModel>  
 8   
 9     <bindings>  
10       <basicHttpBinding>  
11         <binding name="secureHttpBinding">  
12           <security mode="Transport">  
13             <transport clientCredentialType="None"/>  
14           </security>  
15         </binding>  
16       </basicHttpBinding>  
17     </bindings>  
18       
19     <services>  
20       <service name="WCF.Service" >  
21         <endpoint contract="WCF.IService" address="" binding="basicHttpBinding" bindingConfiguration="secureHttpBinding"></endpoint>  
22         <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" /><!--这里为固定写法-->  
23       </service>  
24     </services>  
25   
26     <behaviors>  
27       <serviceBehaviors>  
28         <behavior>  
29           <!-- 为避免泄漏元数据信息,请在部署前将以下值设置为 false -->  
30           <serviceMetadata httpsGetEnabled="true" />  
31           <!-- 要接收故障异常详细信息以进行调试,请将以下值设置为 true。在部署前设置为 false 以避免泄漏异常信息 -->  
32           <serviceDebug includeExceptionDetailInFaults="false" />  
33         </behavior>  
34       </serviceBehaviors>  
35     </behaviors>  
36       
37     <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />  
38   </system.serviceModel>  
39   <system.webServer>  
40     <modules runAllManagedModulesForAllRequests="true" />  
41     <!--  
42         若要在调试过程中浏览 Web 应用程序根目录,请将下面的值设置为 True。  
43         在部署之前将该值设置为 False 可避免泄露 Web 应用程序文件夹信息。  
44       -->  
45     <directoryBrowse enabled="true" />  
46   </system.webServer>  
47   
48 </configuration>