我已經構建了一個相當簡單的WCF服務,該服務在IIS 7.5實例上託管。我已經採取了必要措施來確保SSL證書啓用https。我已經解決了所有各種DNS設置,因此我現在可以在來自全世界的給定Https:// URL處打開我的WCF。目標是這樣的:對於將要發送數據到服務的大約5個客戶端的某種客戶端/服務器認證。什麼是保證這項服務的最佳方法?這一點非常簡單,只有一種方法。我相信web.config中會有一些變化以及代碼隱藏。示例非常感謝。支持HTTPS,IIS託管WCF服務,如何保護它?
這裏的web.config
<!-- language: lang-xml -->
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.serviceModel>
<services>
<service name="wcflistener.Service1">
<endpoint address=""
binding="basicHttpBinding"
bindingConfiguration="secureHttpBinding"
contract="wcflistener.IService1"/>
<endpoint address="mex"
binding="mexHttpsBinding"
contract="IMetadataExchange" />
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="secureHttpBinding">
<security mode="Transport">
<transport clientCredentialType="None"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" 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>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
而且非常簡單Service1.svc.cs
[DataContract]
public class Service1 : IService1
{
public void SampleMethod(DataTable table, string name)
{
//sample method logic here
}
}
我敢肯定,現在,用戶名/密碼就足夠了。我控制方程中的所有部分,託管IIS等等。此時任何事情都是可能的。讓我們去選項#2 –
添加一個鏈接,以執行用戶名/密碼認證的步驟 –
作品像一個魅力,謝謝。 –