不安全的 Internet 用戶端和服務
下面的插圖示範了一個公用的、不安全的 Windows Communication Foundation (WCF) 用戶端和服務的樣本。
| 特徵 |
說明 |
安全模式 |
無 |
傳輸 |
HTTP |
綁定 |
在代碼中使用 BasicHttpBinding,或在配置中使用 <basicHttpBinding> 元素。 |
互通性 |
與現有的 Web 服務用戶端和服務進行互操作 |
身分識別驗證 |
None |
完整性 |
None |
保密性 |
None |
服務
下面的代碼和配置將獨立運行。執行下列操作之一:
- 使用代碼(而不使用配置)建立獨立服務。
- 使用提供的配置建立服務,但不定義任何終結點。
代碼
下面的代碼示範如何建立不安全的終結點。預設情況下,BasicHttpBinding 將安全模式設定為 None。
服務配置
下面的代碼使用配置設定相同的終結點。
<?xml version="1.0" encoding="utf-8"?><configuration> <system.serviceModel> <behaviors /> <services> <service behaviorConfiguration="" name="ServiceModel.Calculator"> <endpoint address="http://localhost/Calculator" binding="basicHttpBinding" bindingConfiguration="Basic_Unsecured" name="BasicHttp_ICalculator" contract="ServiceModel.ICalculator" /> </service> </services> <bindings> <basicHttpBinding> <binding name="Basic_Unsecured" /> </basicHttpBinding> </bindings> <client /> </system.serviceModel></configuration>
用戶端
下面的代碼和配置將獨立運行。執行下列操作之一:
- 使用代碼(和用戶端代碼)建立獨立用戶端。
- 建立不定義任何端點位址的用戶端。而使用將配置名稱作為參數的用戶端建構函式。例如:
代碼
下面的代碼示範一個訪問不安全終結點的基本 WCF 用戶端。
用戶端配置
下面的代碼將配置用戶端。
<?xml version="1.0" encoding="utf-8"?><configuration> <system.serviceModel> <bindings> <basicHttpBinding> <binding name="BasicHttpBinding_ICalculator" > <security mode="None"> </security> </binding> </basicHttpBinding> </bindings> <client> <endpoint address="http://localhost/Calculator/Unsecured" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ICalculator" contract="ICalculator" name="BasicHttpBinding_ICalculator" /> </client> </system.serviceModel></configuration>