在.NET 4中用IIS部署WCF就這么簡單
在.NET 3.5中,我們需要這樣做:
1. 添加一個HelloService.svc文件,添加ServiceHost標記,在Service中添加WCF服務實現的名稱,比如:
2. 在web.config/system.serviceModel/bindings/basicHttpBinding中添加一個binding。
3. 在web.config/system.serviceModel/behaviors/serviceBehaviors中添加一個behavior。
4. 在web.config/system.serviceModel/services中添加一個service,并且:
a) 設置behaviorConfiguration屬性。
b) 設置name屬性。
5. 在service下添加一個endpoint,并且:
a) 設置binding屬性。
b) 設置name屬性。
c) 設置contract屬性。
在.NET 4中,我們只要這樣做:
在web.config/system.serviceModel/serviceHostingEnvironment/serviceActivations中增加下面兩個屬性即可:
這樣配置后,就可以正常調用WCF服務。
如果需要通過SvcUtil.exe生成客戶端代理,只需在serviceBehaviors中添加:
<serviceMetadata httpGetEnabled="true"/>
</behavior>
推薦閱讀:A Developer's Introduction to Windows Communication Foundation 4