Search code examples
wcfnet.tcp

No endpoint listening error on net.tcp


Service config

<service name="Services.MyService">
   <host>
      <baseAddresses>
         <add baseAddress="net.tcp://localhost:9000/Services/MyService/" />
      </baseAddresses>
    </host>
    <endpoint name="NetTcpService" 
        address="" 
        binding="netTcpBinding" 
        bindingConfiguration="TcpConfig"
        contract="Service.IMyService" />
    <endpoint 
        address="mex" 
        binding="mexTcpBinding" bindingConfiguration="TcpConfig" 
        contract="IMetadataExchange" />
  </service>

Client code:

var endPoint = new EndpointAddress("net.tcp://localhost:9000/Services/MyService/mex");
var binding = new NetTcpBinding { TransferMode = TransferMode.Streamed, SendTimeout = TimeSpan.MaxValue };
var channel = new ChannelFactory<IMyService>(binding, endPoint);
var proxy = channel.CreateChannel();

Error:

No Endpoint listening at "net.tcp://localhost/Services/MyService/mex"

tcp services are running, firewall is off. Not sure what's missing.


Solution

  • Your actual service is listening at net.tcp://localhost:9000/Services/MyService/ - so try to change your code to look like this:

    var endPoint = new EndpointAddress("net.tcp://localhost:9000/Services/MyService/");
    var binding = new NetTcpBinding { TransferMode = TransferMode.Buffered, SendTimeout = TimeSpan.MaxValue };
    var channel = new ChannelFactory<IMyService>(binding, endPoint);
    var proxy = channel.CreateChannel();
    

    Besides changing the address, also use TransferMode.Buffered (instead of Streamed) which is the default - I don't see any configuration in your server-side config that would indicate that you're using the streamed transfer mode.

    The address net.tcp://localhost:9000/Services/MyService/mex is the metadata exchange address - not your service. This endpoint is needed for your clients to be able to interrogate the service to learn about what kind of service method it offers, what parameters it expects and so forth - everything that's need to create the client-side proxy code. But this is NOT the service address where your actual service lives and responds to requests.