由于“没有端点侦听”,无法连接到 NetTcpBinding WCF 服务错误

发布于 2025-01-06 09:14:34 字数 2469 浏览 0 评论 0原文

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

我有两个示例项目。两个控制台应用程序(.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 异常,其中显示: < em>“在 net.tcp://localhost:9000/WcfServiceLibrary/svc 上没有监听可以接受消息的端点。这通常是由不正确的地址或 SOAP 操作引起的。请参阅 InnerException,如果存在,请了解更多详细信息。”

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

谢谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

流年里的时光 2025-01-13 09:14:34

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文