简体   繁体   中英

NetTcp AND HTTP binding in WCF

I've been fiddling for two days now, trying to get my TCP endpoint working in my Wcf application.

I've hosted my Wcf app in IIS8 (NOT IIS Express), configured the website to enable net.tcp protocol listening on port 808.

But no matter what I do, I can't reach the TCP endpoint. The HTTP endpoint is working as intended.

Here's my 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>

I know that the HTTP endpoint doesn't work properly with httpGetEnabled="false" , but right now I just need my TCP endpoint to work.

When I try to add a service reference in another project in Visual Studio (in the namespace as my WCF) I write the URL like this:

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

  • But I'm not 100% sure this is the correct way of doing it.

Hope somebody can help me.

I finally got it working now! I removed the relative address in the TCP endpoint, so that my config now looks like this: `

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

Thank you for your time!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM