[英]role of service element in web.config file for a WCF
WCF的web.config文件中service元素的確切作用是什么? 我見過WCF服務在沒有服務元素的情況下可以完美運行的實例。
這是一個示例配置文件,我可以從&腳本后面的代碼(相同/不同的域)中調用其服務
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
</system.web>
<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true"/>
<!--Calling from different domain -->
<standardEndpoints>
<webScriptEndpoint>
<standardEndpoint name="" crossDomainScriptAccessEnabled="true">
</standardEndpoint>
</webScriptEndpoint>
</standardEndpoints>
<behaviors>
<endpointBehaviors>
<behavior name="EndPointBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
從WCF 4.0開始,該框架引入了默認端點,行為和綁定的概念。 這是為了簡化WCF的配置。 在您發布的配置文件中,沒有定義的端點或綁定,因此該服務將在服務文件的位置創建一個默認端點(即,如果您的服務文件位於C:\\inetpub\\wwwroot\\MyService\\MyService.svc
,IIS應用程序名為MyService
,它將為http://<servername>\\MyService\\MyService.svc
)。
現成的默認綁定是http
basicHttpBinding
。 因此,這為您提供了一個帶有basicHttpBinding
的默認終結點。 您仍然可以顯式定義端點和綁定,並且可以定義綁定並將其設置為該配置中使用該綁定的所有服務的默認設置(通過省略name
屬性),還可以更改用於在<system.serviceModel>
部分的<protocolMapping>
部分中給定的傳輸。 例如,如果您希望默認情況下將wsHttpBinding
用於所有http
請求,則可以執行以下操作:
<protocolMapping>
<add binding="wsHttpBinding" scheme="http"/>
</protocolMapping>
有一篇很好的文章涵蓋了這一點-Windows Communication Foundation 4的開發人員簡介 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.