在.NET 4中用IIS部署WCF就这么简单

来源:互联网 发布:php david sklar pdf 编辑:程序博客网 时间:2024/04/30 10:51

在.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

* New Features of WCF 4.0

原创粉丝点击