【问题标题】:NetTcp AND HTTP binding in WCFWCF 中的 NetTcp 和 HTTP 绑定
【发布时间】:2015-03-19 19:39:55
【问题描述】:

我已经摆弄了两天,试图让我的 TCP 端点在我的 Wcf 应用程序中工作。

我在 IIS8(不是 IIS Express)中托管了我的 Wcf 应用程序,将网站配置为启用在端口 808 上侦听的 net.tcp 协议。

但是无论我做什么,我都无法到达 TCP 端点。 HTTP 端点正在按预期工作。

这是我的 Web.config:

    <configuration>
  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5"/>
  </system.web>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="DefaultHttpBinding" />
      </basicHttpBinding>
      <netTcpBinding>
        <binding name="DefaultTCPBinding" portSharingEnabled="true">
          <security mode="None"/>
        </binding>
      </netTcpBinding>
    </bindings>
    <services>
      <service behaviorConfiguration="SimplBehavior" name="SimplWCF.WcfService">
        <endpoint address="mextcp" binding="mexTcpBinding" contract="IMetadataExchange"/>
        <endpoint address="local" binding="netTcpBinding" contract="SimplWCF.IWcfService" bindingConfiguration="DefaultTCPBinding" name="localTcpBinding"/>
        <!-- Used for connecting the service to CMS-->
        <endpoint address="mexhttp" binding="mexHttpBinding" contract="IMetadataExchange"/>
        <endpoint address="public" binding="basicHttpBinding" contract="SimplWCF.IWcfService" bindingConfiguration="DefaultHttpBinding" name="publicHttpBinding"/>
        <!-- Used for connecting the webpages to the service-->
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:50356/SimplWCF/" />
            <add baseAddress="net.tcp://localhost:808/SimplWCF/"/>
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="SimplBehavior">
          <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="false" httpsGetEnabled="false"/>
          <!-- 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="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <protocolMapping>
      <add binding="basicHttpsBinding" scheme="https" />
      <add binding="basicHttpBinding" scheme="http"/>
      <add binding="netTcpBinding" scheme="net.tcp"/>
    </protocolMapping>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <!--
        To browse web app root directory during debugging, set the value below to true.
        Set to false before deployment to avoid disclosing web app folder information.
      -->
    <directoryBrowse enabled="true"/>
  </system.webServer>

</configuration>

我知道 HTTP 端点不能与 httpGetEnabled="false" 一起正常工作,但现在我只需要我的 TCP 端点就可以工作。

当我尝试在 Visual Studio 中的另一个项目中添加服务引用(在命名空间中作为我的 WCF)时,我会这样编写 URL:

net.tcp://localhost:808/SimplWCF/WcfService.svc

  • 但我不能 100% 确定这是正确的做法。

希望有人可以帮助我。

【问题讨论】:

  • 我在某处读到 TCP 端点的地址必须是“VirtualDirectoryPath + SvcFile + 端点配置中指定的相对地址” - 所以我的 TCP 端点将位于“net.tcp:// localhost:808/SimplWCF/WcfService.svc/local”,但这也不起作用..

标签: c# asp.net wcf http tcp


【解决方案1】:

我终于让它工作了! 我删除了 TCP 端点中的相对地址,所以我的配置现在看起来像这样:`

<services>
      <service behaviorConfiguration="SimplBehavior" name="SimplWCF.WcfService">
        <endpoint address="mextcp" binding="mexTcpBinding" contract="IMetadataExchange"/>
        <endpoint address="" binding="netTcpBinding" contract="SimplWCF.IWcfService" bindingConfiguration="DefaultTCPBinding" name="localTcpBinding"/>
        <!-- Used for connecting the service to CMS-->
        <endpoint address="mexhttp" binding="mexHttpBinding" contract="IMetadataExchange"/>
        <endpoint address="public" binding="basicHttpBinding" contract="SimplWCF.IWcfService" bindingConfiguration="DefaultHttpBinding" name="publicHttpBinding"/>
        <!-- Used for connecting the webpages to the service-->
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:50356/SimplWCF/" />
            <add baseAddress="net.tcp://localhost:808/SimplWCF/"/>
          </baseAddresses>
        </host>
      </service>
    </services>

感谢您的宝贵时间!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-12-08
    • 1970-01-01
    • 2011-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-20
    相关资源
    最近更新 更多