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

來源:互聯網
上載者:User

標籤:blog   http   os   io   ar   strong   檔案   div   cti   

在.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> 轉載出處:http://www.cnblogs.com/dudu/archive/2011/01/18/1938490.html

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.