標籤:
在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>
使用SSL的IIS下WCF配置(CSDN手動遷移)