gpt4 book ai didi

wcf - 使用 Net.TCP 托管 WCF 服务

转载 作者:行者123 更新时间:2023-12-04 05:09:05 25 4
gpt4 key购买 nike

我对此完全陌生,并尝试使用 net.tcp 绑定(bind)托管最简单的 WCF 服务
我有 Windows 7 Professional 和 IIS7 并启用了非 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 绑定(bind)呢?我添加了“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网站并添加绑定(bind)net.tcp 808:*
    然后我修改我的 web.config 以使 WCF 服务看起来像这样。 (只是更改了端点上的绑定(bind))
    <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 绑定(bind)创建我的第一个 WCF 服务吗?

    最佳答案

    正如 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



    从命令行尝试启动它。

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

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

    关于wcf - 使用 Net.TCP 托管 WCF 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6627329/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com