WCF netTcpBinding hosted on IIS7.5 Stops Working

2019-03-30 22:17发布

问题:

I have a simple .NET 4 WCF service which I have hosted locally on IIS7.5. Initially I had it hosted using httpBinding which worked fine. Then I switched it to netTcpBinding, which after changing the web.config file accordingly was also working fine. However today it has decided to stop working. I cannot connect to the service using the test client at all, getting:

URI: net.tcp://localhost/case/service.svc/mex Metadata contains a reference that cannot be resolved: 'net.tcp://localhost/case/service.svc/mex'. The message could not be dispatched because the service at the endpoint address 'net.tcp://localhost/case/service.svc/mex' is unavailable for the protocol of the address.

I have checked that the non-http activation service is (still) installed; the net tcp listener service is running; net.tcp is in the list of enabled protocols for the site; I have run servicemodelreg.exe -ia; I have also re-run aspnet_regiis.exe -i; and finally I have checked the net.tcp binding is on the site.

If I run netstat I can see something is listening on the port, but I cannot connect to it.

This is driving me nuts, as this morning it was working fine (as it was last week) and now it's just not.

EDIT: If I access the service in IE then I can see it's throwing the following exception:

Could not find a base address that matches scheme net.tcp for the endpoint with binding NetTcpBinding. Registered base address schemes are [http].

But looking in the web.config file that doesn't seem to be the case:

<services>
  <service behaviorConfiguration="ServiceBehavior" name="[REMOVED].[REMOVED]">
    <endpoint binding="netTcpBinding" bindingConfiguration="PortSharingBinding" contract="[REMOVED].[REMOVED]" />
    <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
  </service>
</services>

<bindings>
  <netTcpBinding>
    <binding name="PortSharingBinding" portSharingEnabled="true">
      <security mode="None"/>
    </binding>
    <binding name="mexTcpBinding" portSharingEnabled="true">
      <security mode="None" />
    </binding>
  </netTcpBinding>
</bindings>

回答1:

OK, finally solved it. I had enabled net.tcp protocol at the site level, but it was not enabled at the application level. I guess it must have been before, and I think I might of created a new application after changing the project name earlier and obviously forgot to set the protocol on the application - doh!

So the final checklist for hosting a WCF net.tcp service on IIS is:

  1. Ensure the WCF Non-HTTP Activation service is installed
  2. Ensure the Net.Tcp Listener Service and Net.Tcp Port Sharing Service are both running
  3. Add net.tcp to the enabled protocols for the site and the application (to access the Advanced Settings option from IIS Manager you must have an http binding present)
  4. Run servicemodelreg.exe -ia to register WCF elements with IIS
  5. Run aspnet_regiis.exe -i to ensure .NET is setup correctly with IIS
  6. Add net.tcp binding to the site


回答2:

Have you checked that port sharing is enabled?

see http://msdn.microsoft.com/en-us/library/ms734772.aspx

EDIT - For WAS there is another service needed:

besides the NetTcpPortSharing the service NetTcpActivator is needed too...

see http://msdn.microsoft.com/en-us/magazine/cc163357.aspx