我在 .NET 3.5 中使用 WCF 我正在使用命名管道但不断收到错误



我遵循了教程 http://www.switchonthecode.com/tutorials/wcf-tutorial-basic-interprocess-communication 但问题仍然存在。客户端和服务器上的端点是相同的(我检查了拼写等)。此项目没有配置文件,但配置在代码中。

编辑:代码(客户端):

  ChannelFactory<ITest> pipeFactory =
    new ChannelFactory<ITest>(
    new NetNamedPipeBinding(),
    new EndpointAddress(
    "net.pipe://localhost/test"));

       ITest test= pipeFactory.CreateChannel();

            test.doStuff();

服务器:
        serviceHost = new ServiceHost(typeof(Test), new Uri("net.pipe://localhost"));

        serviceHost.AddServiceEndpoint(typeof(ITest), new NetNamedPipeBinding(), "test");

        File.Create(@"C:\test.txt");

        serviceHost.Open();

谢谢

最佳答案

在服务器端,创建 ServiceHost 实例时不要包含基地址。相反,在添加服务端点时提供完全限定的端点地址:

serviceHost = new ServiceHost(typeof(Test));
serviceHost.AddServiceEndpoint(typeof(ITest), new NetNamedPipeBinding(), new EndpointAddress("net.pipe://localhost/test"));
File.Create(@"C:\\test.txt");
serviceHost.Open();

关于c# - 带有命名管道的 WCF 错误 "no endpoint listening",我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5881823/

10-12 12:49
查看更多