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

    技术2025-02-07  46

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

     

    转自:http://www.cnblogs.com/dudu/archive/2011/01/18/1938490.html

    最新回复(0)