由于错误"There was no endpoint listening"无法连接到 NetTcpBinding WCF 服务



你们能指出我遗漏了什么吗?

我有两个样本项目。两个控制台应用程序(.Net 3.5)。这里是"服务器"端:

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();
    }
}

不确定它是否重要,但这里是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);
  }

最后是客户端

    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);
        }
    }

客户端失败,出现System.ServiceModel.EndpointNotFoundException异常,该异常显示:"没有端点在网络上侦听。tcp://localhost:9000/WcfServiceLibrary/svc可以接受这个消息的。这通常是由不正确的地址或SOAP操作引起的。有关更多详细信息,请参见InnerException(如果存在)。"

这是对使用命名管道的生产代码的修改,我想将其转换为Tcp传输。

谢谢!

我不小心在服务器的端点定义中留下了k.WinSvcEndpointName。这就是问题所在。

最新更新