在WAS中承载WCF服务

http://foreversky12.iteye.com/blog/2308499


假设IIS站点下已有Class1.svc文件和Web.config文件,如下图:

在WAS中承载WCF服务

在WAS中承载WCF服务



1、在控制面板的 ‘启用或关闭windows功能’ 中勾选图中红色标记

在WAS中承载WCF服务


2、下一步我们需要添加绑定到Web站点,如上图中的ww站点,我们将向ww站点添加TCP协议作为实例,开始->所有程序->附件->右键以管理员身份运行命令行工具 ,执行如下命令 
    3.C:\Windows\system32\inetsrv> appcmd.exe set site "ww" -+bindings.[protocol='net.tcp',bindingInformation='808:*'] 
这个命令向ww站点添加了net.tcp的绑定,808:*表示此ww站点的端口号。

Web.config文件内容:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <!-- 部署服务库项目时,必须将配置文件的内容添加到
 主机的 app.config 文件中。System.Configuration 不支持库的配置文件。 -->
  <system.serviceModel>
    <bindings>
      <netTcpBinding>
        <binding name="NewBinding0" portSharingEnabled="true" />
      </netTcpBinding>
    </bindings>
    <services>
      <service behaviorConfiguration="serviceBehavior1" name="WcfServiceLibrary8.Service1">
        <endpoint address="" binding="netTcpBinding"
          bindingConfiguration="NewBinding0" contract="WcfServiceLibrary8.IService1" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="serviceBehavior1">
          <!-- 为避免泄漏元数据信息,
          请在部署前将以下值设置为 false -->
          <serviceMetadata httpGetEnabled="True" httpsGetEnabled="True"/>
          <!-- 要接收故障异常详细信息以进行调试,
          请将以下值设置为 true。在部署前设置为 false 
          以避免泄漏异常信息 -->
          <serviceDebug includeExceptionDetailInFaults="False" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


除了使用《添加服务引用》的方式生产客户端代理,还可以使用cmd的方式:

在WAS中承载WCF服务

参数:/out:表示输出到哪个路径下。/config:表示配置文件输出到哪个路径下 。后面的net.tcp://。。。。表示公布的元数据终结点的服务端地址