rafale
rafale

Reputation: 1735

Can I use netTcpBinding for WCF services hosted outside of IIS?

My WCF service is being hosted as a Windows managed service, so I'm unsure of whether or not I can still use the netTcpBinding. I've tried following a couple of guides at MSDN, but for some reason my service always fails to start whenever I do the switch from basicHttpBinding. Perhaps there are additional steps that services outside of the IIS are required to undergo?

Upvotes: 3

Views: 1533

Answers (2)

Alex Aza
Alex Aza

Reputation: 78537

Yes you can host WCF service with netTcpBinding outside of IIS, in Windows service or even Console Application if you want to.

Here is config file sample:

<system.serviceModel>
  <behaviors>
    <serviceBehaviors>
      <behavior name="ServiceBehavior">
        <serviceMetadata />
        <serviceDebug includeExceptionDetailInFaults="true" />
      </behavior>
    </serviceBehaviors>
  </behaviors>
  <services>
    <service behaviorConfiguration="ServiceBehavior"
             name="XX.XX.Service">
      <endpoint address=""
                binding="netTcpBinding"
                bindingConfiguration="BindingConfiguration"
                contract="XX.XX..IService" />
      <endpoint address="mex"
                binding="mexTcpBinding"
                contract="IMetadataExchange" />
      <host>
        <baseAddresses>
          <add baseAddress="net.tcp://localhost:8731/XXService" />
        </baseAddresses>
      </host>
    </service>
  </services>
  <bindings>
    <netTcpBinding>
      <binding
        name="BindingConfiguration">
        <security mode="None" />
      </binding>
    </netTcpBinding>
  </bindings>
</system.serviceModel>

[Edit]

Problems with your config file:

  • base address is http instead of net.tcp
  • metadata endpoint is mexHttpBinding instead of metTcpBinding
  • security - by default windows authorization will be used, if test communication between to boxes, you might have permission problem. I suggest to start with security mode None and then adjust security when everything else works.
  • you don't need to specify httpGetEnabled for service behavior
  • if the port that you are going to use is already in use, you will not be able to start service

Upvotes: 4

Kirk Broadhurst
Kirk Broadhurst

Reputation: 28738

You absolutely can, and I'd go so far as to say you should.

Here's your problem:

<services>
   <service name="Server.FileService" ...
      <host>
         <baseAddresses>
            <add baseAddress="http://localhost:8000/Test/file"/>
         </baseAddresses>
      </host>
      <endpoint address="" binding="netTcpBinding" contract="Server.IFile" />
      <endpoint address="mex" binding="mexHttpBinding" ...

The net.tcp address must have a net.tcp:// prefix, not a http:// prefix.

I don't normally use baseAddress so can't give advice on that. I'd remove baseAddress and instead use

      <endpoint address="net.tcp://localhost:8001/Test/file" ..

(note that I would also choose another port over 8000)

Upvotes: 2

Related Questions