使用Net.TCP托管WCF服务

Mar*_*tin 8 wcf nettcpbinding

我是全新的,并尝试使用net.tcp绑定托管最简单的WCF服务我有Windows 7 Professional和IIS7并启用了NON 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>
Run Code Online (Sandbox Code Playgroud)

到现在为止还挺好.但那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>
Run Code Online (Sandbox Code Playgroud)

然后我去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>
Run Code Online (Sandbox Code Playgroud)

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

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

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

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

Pet*_* K. 13

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

netstat/an | 找/我"808"

它应该显示:

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

如果服务正常运行.

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

sc启动NetTcpActivator

从命令行到ttry启动它.

在此之前,请确保已安装非HTTP激活窗口组件.

还要检查服务是否实际运行. 我有一个问题,他们不一定会在重启后启动.


Toc*_*cco 7

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

看见