<? xml version = "1.0 " encoding = "utf-8 " ?>
< configuration >
< system.ServiceModel >
<!-- services 元素包含應用中駐留的所有service 的配置要求 -->
< services >
<!-- 每個服務的配置
屬性說明:
name - 指定這個service 配置是針對的那個服務, 爲一個實現了某些Contract 的服務類的完全限定名
( 名稱空間. 類型名),ServiceHost 載入一個服務後,會到配置文件中的<services> 下找有沒有
name 屬性跟服務匹配的<service> 的配置
behaviorConfiguration - 指定在<serviceBehaviors> 下的一個<behavior> 的name, 這個特定<behavior>
給這個service 制定了一些行爲, 比如服務是否允許身份模擬 -->
< service name = " 名稱空間. 類型名 " behaviorConfiguration = "behavior 名 ">
< host >
< baseAddresses >
<!-- 在此可以定義每種傳輸協議的baseAddress ,用於跟使用同樣傳輸協議Endpoint 定義的相對地
址組成完整的地址,但是每種傳輸協議只能定義一個baseAddress 。HTTP 的baseAddress 同時是service
對外發布服務說明頁面的URL -->
< add baseAddress = "http://address " />
</ baseAddresses >
< timeouts ></ timeouts >
</ host >
<!-- 每個服務可以有多個Endpoint ,下面<endpoint> 元素對每個Endpoint 分別進行配置
屬性說明:
address - 指定這個Endpoint 對外的URI, 這個URI 可以是個絕對地址,也可以是個相對於baseAddress 的
相對地址。如果此屬性爲空,則這個Endpoint 的地址就是baseAddress
binding - 指定這個Endpoint 使用的binding ,這個banding 可以是系統預定義的9 個binding 之一,
比如是basicHttpBinding ,也可以是自定義的customBinding 。binding 決定了通訊的類型、
安全、如何編碼、是否基於session 、是否基於事務等等
contract - 指定這個Endpoint 對應的Contract 的全限定名( 名稱空間. 類型名) ,這個Contract 應該被
service 元素的name 指定的那個service 實現
bindingConfiguration - 指定一個binding 的配置名稱,跟<bindings> 下面同類<binding> 的name 匹配
behaviorConfiguration - 指定這個endpoint 的behavior ,指向<behaviors> 下的同樣配置名稱的<endpointBehaviors>
name - Endpoint 的名稱,可選屬性,每個Contract 都可以有多個Endpoint ,但是每個Contract 對應的
多個Endpoint 名必須是唯一的 -->
< endpoint address = "URI " binding = "basicHttpBinding " contract = "Contract 全限定名 " bindingConfiguration = "binding 名 " behaviorConfiguration = "String " name = "">
<!-- 用戶定義的xml 元素集合,一般用作SOAP 的header 內容 -->
< headers >
<!-- 任何xml 內容 -->
</ headers >
</ endpoint >
</ service >
</ services >
< bindings >
<!-- 指定一個或多個系統預定義的binding ,比如<basicHttpBinding> ,當然也可以指定自定義的customBinding ,
然後在某個指定的binding 下建立一個或多個配置,以便被Endpoint 來使用這些配置 -->
< basicHttpBinding >
<!-- 某一類的binding 的下面可能有多個配置,binding 元素的name 屬性標識某個binding -->
< binding name = "binding 名 ">
</ binding >
</ basicHttpBinding >
</ bindings >
<!-- 定義service 和Endpiont 行爲 -->
< behaviors >
<!-- 定義service 的行爲 -->
< serviceBehaviors >
<!-- 一個或多個系統提供的或定製的behavior 元素
屬性說明:
name - 一個behavior 唯一標識,<service> 元素下<endpoint> 的behaviorConfiguration 屬性指向這個name -->
< behavior name = " 此Behavior 名稱 ">
<!-- 指定service 元數據發佈和相關信息
屬性說明:
httpGetEnabled - bool 類型的值,表示是否允許通過HTTP 的get 方法獲取sevice 的WSDL 元數據
httpGetUrl - 如果httpGetEnabled 爲true ,這個屬性指示使用哪個URL 地址發佈服務的WSDL ,
如果這個屬性沒有設置,則使用服務的HTTP 類型的baseAddress 後面加上?WSDL -->
< serviceMetadata httpGetEnabled = "true " httpGetUrl = "http://URI:port/address " />
<!-- 指定驗證服務端的憑據 -->
< serviceCredentials >
<!-- 指定服務端的證書
屬性說明:
storeName - 證書的存儲區,可能值爲:AddressBook ,AuthRoot ,CertificateAuthority
Disallowed ,My ,Root ,TrustedPeople ,TrustedPublisher
storeLocation - 證書存儲位置,可能值爲:CurrentUser ,LocalMachine
x509FindType - 查找證書的方式,可能的值:FindBySubjectName ,FindByThumbPrint ,FindByIssuerName......
findValue - 對應查找方式的要查找證書的值 -->
< serviceCertificate storeName = " 存儲區 " storeLocation = " 存儲位置 " x509FindType = "FindBySubjectName " findValue = "server1 " />
</ serviceCredentials >
</ behavior >
</ serviceBehaviors >
<!-- 定義Endpiont 的行爲 -->
< endpointBehaviors >
<!-- 一個或多個系統提供的或定製的behavior 元素
屬性說明:
name - 一個behavior 唯一標識,<client> 元素下<endpoint> 的behaviorConfiguration 屬性指向這個name -->
< behavior name = " 此Behavior 名稱 ">
<!-- 指定客戶端的憑據 -->
< clientCredentials >
<!-- 指定客戶端的證書
屬性說明:
storeName - 證書的存儲區,可能值爲:AddressBook ,AuthRoot ,CertificateAuthority
Disallowed ,My ,Root ,TrustedPeople ,TrustedPublisher
storeLocation - 證書存儲位置,可能值爲:CurrentUser ,LocalMachine
x509FindType - 查找證書的方式,可能的值:FindBySubjectName ,FindByThumbPrint ,FindByIssuerName......
findValue - 對應查找方式的要查找證書的值 -->
< clientCertificate storeName = " 存儲區 " storeLocation = " 存儲位置 " x509FindType = "FindBySubjectName " findValue = "Client1 " />
< serviceCertificate >
< authentication certificateValidationMode = "None " />
</ serviceCertificate >
</ clientCredentials >
</ behavior >
</ endpointBehaviors >
</ behaviors >
<!-- 包含客戶端跟服務端連接使用到的Endpoint 的配置 -->
< client >
<!-- 每個客戶端Endpoint 設置
屬性說明:
address - 對應到服務端這個Endpoint 的address
binding - 指定這個Endpoint 使用的binding ,這個banding 可以是系統預定義的9 個binding 之一,
比如是basicHttpBinding
contract - 指定這個Endpoint 對應的Contract 的全限定名( 名稱空間. 類型名)
name - Endpoint 的配置名,客戶端代理類的構造方法中的endpointConfigurationName 對應到這個name
bindingConfiguration - 指定客戶端binding 的具體設置,指向<bindings> 元素下同類型binding 的name
behaviorConfiguration - 指定這個endpoint 的behavior ,指向<behaviors> 下的同樣配置名稱的<endpointBehaviors> -->
< endpoint address = "URI " binding = "basicHttpBinding " bindingConfiguration = "binding 名 " behaviorConfiguration = "String " contract = "Contract 全限定名 " name = "endpoint 配置名 " >
<!-- 用於客戶端驗證服務端身份, 可選以下一種方式驗證服務端 -->
< identity >
< userPrincipalName ></ userPrincipalName >
< servicePrincipalName ></ servicePrincipalName >
<!-- 如果客戶端驗證是windows, 這裏指定DNS 名; 如果是Certificate ,這裏指定證書subject name -->
< dns ></ dns >
< rsa ></ rsa >
<!-- 指定服務端證書的公鑰
屬性說明:
encodedValue - 服務端證書的公鑰的base64 編碼,用於加密用戶名和密碼 -->
< certificate encodedValue = ""></ certificate >
<!-- 用戶指定在客戶端證書存儲區內的服務端證書
屬性說明:
storeName - 證書的存儲區,可能值爲:AddressBook ,AuthRoot ,CertificateAuthority
Disallowed ,My ,Root ,TrustedPeople ,TrustedPublisher
storeLocation - 證書存儲位置,可能值爲:CurrentUser ,LocalMachine
x509FindType - 查找證書的方式,可能的值:FindBySubjectName ,FindByThumbPrint ,FindByIssuerName......
findValue - 對應查找方式的要查找證書的值 -->
< certificateReference storeName = " 存儲區 " storeLocation = " 存儲位置 " x509FindType = "FindBySubjectName " findValue = "Client1 " />
</ identity >
</ endpoint >
</ client >
</ system.ServiceModel >
</ configuration >
from:http://www.cnblogs.com/chnking/archive/2008/01/23/1049353.html auhtor:chnking