技术开发 频道

详解在IIS中配置并运行WCF服务

  确认服务已经运行

  8. 在Windows的开始菜单中选择Start | Run菜单项。

  9. 输入http://localhost/DerivativesCalculator/Service.svc。

  10. 按Enter键。

  11. 浏览器会启动并显示如图所示的Service Information页面。


显示在Internet Explorer 7中的Service Information页面

  12. 完成之后,关闭Internet Explorer。

  ·运行客户程序来使用运行在IIS中的服务

  我们可以用同一个客户程序来调用运行在IIS中的服务。当然服务所在的终结点的位置与先前我们在客户程序中配置的终结点的位置不同,因此需要修改。

  配置客户程序

  1. 回到Visual Studio,在Solution Explorer的Client项目中右键单击app.config文件并选择Open菜单项。

  2. 将文件中的endpoint的address attribute改成下面的地址:


<?xml version="1.0" encoding="utf-8"?>
<configuration>
  
<system.serviceModel>
    
<bindings>
    . . .      
    
</bindings>
    
<client>
      
<endpoint address="http://localhost/DerivativesCalculator/Service.svc"
                binding
="basicHttpBinding"
                bindingConfiguration
="BasicHttpBinding_IDerivativesCalculator"
                contract
="IDerivativesCalculator"
                name
="DerivativesCalculatorConfiguration" />
    
</client>
  
</system.serviceModel>
</configuration>

     3. 选择Build | Build Solution菜单项。

  运行客户程序

  4. 在Solution Explorer中右键单击Client项目并选择Debug | Start new instance菜单项。

  5. 在刚打开的Client.EXE命令行窗口中按Enter键。

  客户程序从运行在IIS中的Derivatives Calculator服务获得了一个衍生产品的估计价格,这和我们上一次调用运行在命令行应用程序中的服务完全相同。

  6. 在Client.EXE命令行窗口中按Enter键来关闭客户程序。

0
相关文章