在.NET 4中用IIS部署WCF就這么簡單

作者: dudu  來源: 博客園  發布時間: 2011-01-21 15:05  閱讀: 4915 次  推薦: 0   原文鏈接   [收藏]  

  在.NET 3.5中,我們需要這樣做:

  1. 添加一個HelloService.svc文件,添加ServiceHost標記,在Service中添加WCF服務實現的名稱,比如:

 
<%@ ServiceHost Language="C#" Debug="false" Service="CNBlogs.Service.Impl.HelloService"%>

  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中增加下面兩個屬性即可:

 
<add relativeAddress="HelloService.svc" service="CNBlogs.Service.Impl.HelloService"/>

  這樣配置后,就可以正常調用WCF服務。

  如果需要通過SvcUtil.exe生成客戶端代理,只需在serviceBehaviors中添加:

 
<behavior>
<serviceMetadata httpGetEnabled="true"/>
</behavior>

  推薦閱讀:A Developer's Introduction to Windows Communication Foundation 4

0
2
 
標簽:.NET 4 WCF IIS
 
 

文章列表

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 大師兄 的頭像
    大師兄

    IT工程師數位筆記本

    大師兄 發表在 痞客邦 留言(0) 人氣()