【问题标题】:Can't connect to NetTcpBinding WCF service due to "There was no endpoint listening" error由于“没有端点监听”错误,无法连接到 NetTcpBinding WCF 服务
【发布时间】:2012-02-18 02:08:46
【问题描述】:

你们能指出我在这里缺少什么吗?

我有两个示例项目。两个控制台应用程序(.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的小sn-p

  [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 异常,它说:“在 net.tcp://localhost:9000/WcfServiceLibrary/svc 上没有可以接受消息的端点侦听。这通常是由不正确的地址或 SOAP 操作。有关更多详细信息,请参阅 InnerException(如果存在)。"

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

谢谢!

【问题讨论】:

    标签: c# wcf wcf-binding nettcpbinding


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-17
      • 2011-07-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多