我在 .NET 3.5 中使用 WCF 我正在使用命名管道但不断收到错误
在 net.pipe://localhost/Test 上没有侦听端点可以接受消息。这通常是由不正确的地址或 SOAP 操作引起的。
我按照教程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();
Run Code Online (Sandbox Code Playgroud)
服务器:
serviceHost = new ServiceHost(typeof(Test), new Uri("net.pipe://localhost"));
serviceHost.AddServiceEndpoint(typeof(ITest), new NetNamedPipeBinding(), "test");
File.Create(@"C:\test.txt");
serviceHost.Open();
Run Code Online (Sandbox Code Playgroud)
谢谢
在服务器端,创建 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();
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4316 次 |
最近记录: |