使用Net.TCP承载WCF服务

8

我完全是新手,想使用net.tcp绑定托管最简单的WCF服务。我有Windows 7专业版和IIS7,并启用了非HTTP激活。

  • 我在vs2010中开始一个新的WCF服务应用程序项目并编译它。仅此而已!
  • 我删除了所有的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:* 然后,我修改了WCF服务的web.config,使其如下所示(仅更改了端点上的绑定)

<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错误代码10061:无法建立连接,因为目标计算机积极拒绝.. 127.0.0.1:808

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

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

3个回答

13

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

netstat /an | find /i "808 "

如果正确运行,它应该显示:

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

要启动服务,请在命令行中输入以下命令:

sc start NetTcpActivator

如果服务尚未启动,则可以使用此命令启动它。

即使在此之前,请确保已安装非HTTP激活的Windows组件

还要检查服务是否正在运行。如果您遇到类似于在重新启动后无法启动问题,请检查一下。


7
在IIS上启用net.tcp绑定以处理808端口的请求。 在IIS管理器/绑定中进行检查。 查看详情

非常感谢!我一整天都在努力解决这个问题 :) - Martin

0

我曾经遇到过同样的错误信息,解决方法是不仅在站点上创建TCP绑定,如下所示:

IIS Site Bindings

同时在高级设置中启用net.tcp协议:

enter image description here


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接