简体   繁体   中英

Can't connect to NetTcpBinding WCF service due to “There was no endpoint listening” error

Could you guys please point what I'm missing here ?

I have two sample projects. Both console applications (.Net 3.5). Here is "server" side:

class Program
{
    static void Main()
    {
        var baseAddresses = new Uri("net.tcp://localhost:9000/WcfServiceLibrary/svc");

        var host = new ServiceHost(typeof(UiWcfSession), baseAddresses);

        var reliableSession = new ReliableSessionBindingElement { Ordered = true, InactivityTimeout = TimeSpan.MaxValue };
        var binding = new CustomBinding(reliableSession, new TcpTransportBindingElement()) { ReceiveTimeout = TimeSpan.MaxValue };

        host.AddServiceEndpoint(typeof(IClientFulfillmentPipeService), binding, k.WinSvcEndpointName);
        host.Open();

        Thread.CurrentThread.Join();
    }
}

Not sure if it's important but here is small snippet of IClientFulfillmentPipeService

  [ServiceContract(CallbackContract = typeof (IClientFulfillmentPipeServiceCallbacks), SessionMode = SessionMode.Required)]
  public interface IClientFulfillmentPipeService
  {
    [OperationContract(IsOneWay = true)]
    void Initialize(int uiProcessId, string key);
  }


  [ServiceContract]
  public interface IClientFulfillmentPipeServiceCallbacks
  {
    [OperationContract(IsOneWay = true)]
    void ShowBalloonTip(int timeout, string tipTitle, string tipText, BalloonTipIcon tipIcon);
  }

and finally client

    private void OpenConnection()
    {

        try
        {
            var ep = new EndpointAddress("net.tcp://localhost:9000/WcfServiceLibrary/svc");

            var reliableSession = new ReliableSessionBindingElement {Ordered = true};

            Binding binding = new CustomBinding(reliableSession, new TcpTransportBindingElement());
            reliableSession.InactivityTimeout = TimeSpan.MaxValue;
            var pipeFactory = new DuplexChannelFactory<IClientFulfillmentPipeService>(this, binding, ep);
            commChannel = pipeFactory.CreateChannel();

            ((IChannel) commChannel).Open(OpenConnectionTimeout);
        }
        catch (Exception ex)
        {
            Log.ErrorFormat("The communication channel to the windows service could not be established.  {0}", ex.Message);
        }
    }

The client fails with System.ServiceModel.EndpointNotFoundException exception which says: "There was no endpoint listening at net.tcp://localhost:9000/WcfServiceLibrary/svc that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details."

This is modification of production code which is using named pipes and I want to convert it to Tcp transport.

Thanks!

I accidentally left k.WinSvcEndpointName in the endpoint definition in the server. That was the problem.

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