[英]How to get wcf communiction ONLY over Https
我想擁有一個WCF服務,所有請求均得到確認,授權並僅通過https發送。 我為SLL生成了證書。 為了進行開發,我使用ISS Express。 同樣在web.config中,我將任何http選項設置為false。 但是仍然在生成的WSDL中,當我使用WCFStorm檢查服務方法時,它仍然使用http://localhost:1947
而不是我聲明的https://localhost:44300
。 我需要更改以確保所有通信都將通過https進行? 這是我的web.config文件:
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="secureBinding">
<security mode="Message">
<message clientCredentialType="UserName" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<services>
<service name="AF.Services.AFService" behaviorConfiguration="AFServiceBehavior">
<endpoint address="AFService.svc"
binding="wsHttpBinding"
contract="AF.Common.Services.IAFService" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="AFServiceBehavior">
<serviceCredentials>
<serviceCertificate findValue="AFCert"
x509FindType="FindBySubjectName" storeLocation="LocalMachine"
storeName="My" />
<userNameAuthentication
userNamePasswordValidationMode="Custom"
customUserNamePasswordValidatorType="AF.Services.UserValidator, AF.Services" />
</serviceCredentials>
<serviceMetadata httpsGetEnabled="true" httpGetEnabled="false" />
<!-- TODO zmienić przed deployem!!-->
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<directoryBrowse enabled="true" />
</system.webServer>
僅可通過44300 https端口訪問描述如何使用該服務的網頁。
在“使用配置”部分中查看“ 如何:使用傳輸安全性和郵件憑據 ”,您似乎在綁定配置中需要以下安全設置:
<security mode="TransportWithMessageCredential">
<message clientCredentialType="UserName" />
</security>
因此,您完整的綁定配置將如下所示:
<wsHttpBinding>
<binding name="secureBinding">
<security mode="TransportWithMessageCredential">
<message clientCredentialType="UserName" />
</security>
</binding>
</wsHttpBinding>
還要注意,實際上並沒有將定義的綁定分配給端點,因此當前您正在獲得wsHttpBinding
的默認值(安全模式的默認值為“ Message”)。 您可以通過endpoint
元素上的bindingConfiguration
屬性分配上面的綁定配置:
<services>
<service name="AF.Services.AFService" behaviorConfiguration="AFServiceBehavior">
<endpoint address="AFService.svc"
binding="wsHttpBinding"
bindingConfiguration="secureBinding"
contract="AF.Common.Services.IAFService" />
</service>
</services>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.