使用Net.TCP托管WCF服务

时间:2011-07-08 16:16:42

标签: wcf nettcpbinding

我对此非常陌生,并尝试使用net.tcp绑定托管最简单的WCF服务 我有Windows 7专业版和IIS7,并启用了NON http激活。

  • 我启动了一个新的WCF服务应用程序 在vs2010中项目并编译它。 打个招呼!
  • 我删除了所有的IIS 网站并添加一个名为WCFHost的新文件
  • 我打开WcfTestClient.exe并添加 http://localhost/Service1.svc应用程序找到它

Web.config看起来像这样(未触动)

 <system.serviceModel>
    <services>
      <service name="WcfService2.Service1" behaviorConfiguration="WcfService2.Service1Behavior">
        <endpoint address="" binding="wsHttpBinding" contract="WcfService2.IService1">
          <!-- 
              Upon deployment, the following identity element should be removed or replaced to reflect the 
              identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity 
              automatically.
          -->
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="WcfService2.Service1Behavior">
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

到目前为止,这么好。但那net.tcp绑定呢。我添加了“enabledProtocols”属性,因此我的applicationHost.config看起来像这样

       <site name="WCFHOST" id="3">
            <application path="/" applicationPool="WCFHOST" enabledProtocols="http,net.tcp,net.pipe,net.msmq">
                <virtualDirectory path="/" physicalPath="C:\Prosjekter\temp\TestService\TestService" />
            </application>
            <bindings>
                <binding protocol="net.tcp" bindingInformation="808:*" />
                <binding protocol="http" bindingInformation="*:80:" />
            </bindings>
        </site>

然后我去IIS WCFHost网站并添加绑定net.tcp 808:* 然后我修改我的web.config以使WCF服务看起来像这样。 (刚刚更改了端点上的绑定)

<system.serviceModel>
    <services>
      <service name="WcfService2.Service1" behaviorConfiguration="WcfService2.Service1Behavior">
        <!-- Service Endpoints -->
        <endpoint address="" binding="netTcpBinding" contract="WcfService2.IService1">
          <!-- 
              Upon deployment, the following identity element should be removed or replaced to reflect the 
              identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity 
              automatically.
          -->
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="WcfService2.Service1Behavior">
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
 </system.serviceModel>

当我现在尝试在我的WcfTestClient.exe中添加服务net.tcp:// localhost:808 / Service1.svc时出现错误

错误:无法从net.tcp://localhost/Service1.svc获取元数据 TCP-errorcode 10061:无法建立连接,因为目标计算机主动拒绝它.... 127.0.0.1:808

我的防火墙已关闭。 我见过一件事,但是......当使用netstat -a时,那里没有列出808端口..应该吗?

有人可以帮我创建我的第一个使用nettcp绑定的WCF服务吗?

2 个答案:

答案 0 :(得分:13)

正如Tocco所说,检查服务是否正在运行。您可以通过检查:

来完成此操作
  

netstat / an |找/我“808”

它应该显示:

  

TCP 0.0.0.0:808 0.0.0.0:0聆听
   TCP [::]:808 [::]:0 LISTENING

如果服务正常运行。

要启动它,如果它还没有工作,你可以发出:

  

sc start NetTcpActivator

从命令行到ttry启动它。

在此之前,请确保the non-HTTP activation windows components are installed

同时检查服务是否实际运行。 I had a problem where they would not necessarily start after a reboot.

答案 1 :(得分:7)

在IIS上为808上的请求启用了net.tcp绑定? 在IIS管理器/绑定上检查它。

See it