WCF命名管道错误:管道已结束.(109 0 x6d)
本文关键字:管道 结束 x6d 错误 WCF | 更新日期: 2023-09-27 17:49:38
我看了其他处理"管道已结束"的帖子。(109, 0x6d)但是没有一个能解决我的问题。我有一个基于这个博客的相对简单的设置:http://tech.pro/tutorial/855/wcf-tutorial-basic-interprocess-communication
我觉得我非常密切地遵循它,只是删除了HTTP绑定。
服务器代码:
public class InterProcessServer : IInterProcessServer
{
private ServiceHost _host = null;
public event EventHandler<CommandLineArgsEventArgs> CommandLineArgsReceived;
protected InterProcessServer(Uri serverAddress, string serviceName)
{
IPassCommandLineArgs passArgs = null;
passArgs = CreatePassCommandLineArgs();
passArgs.CommandLineArgsReceived += new EventHandler<CommandLineArgsEventArgs> passArgs_CommandLineArgsReceived);
_host = new ServiceHost(passArgs, new Uri[] { serverAddress });
_host.AddServiceEndpoint(typeof(IPassCommandLineArgs), new NetNamedPipeBinding(), serviceName);
_host.Open();
}
public static IInterProcessServer CreateInterProcessServer(Uri serverAddress, string serviceName)
{
return new InterProcessServer(serverAddress, serviceName);
}
public void Dispose()
{
try
{
_host.Close();
}
catch { }
}
private void passArgs_CommandLineArgsReceived(object sender, CommandLineArgsEventArgs e)
{
EventHandler<CommandLineArgsEventArgs> handler = CommandLineArgsReceived;
if (handler != null)
handler(sender, e);
}
protected virtual IPassCommandLineArgs CreatePassCommandLineArgs()
{
return new PassCommandLineArgs();
}
}
下面是客户端代码:
public class InterProcessClient : IInterProcessClient
{
private IPassCommandLineArgs _pipeProxy = null;
private ChannelFactory<IPassCommandLineArgs> _pipeFactory = null;
protected InterProcessClient(Uri serviceAddress)
{
_pipeFactory = new ChannelFactory<IPassCommandLineArgs>(new NetNamedPipeBinding(), new EndpointAddress(serviceAddress));
_pipeProxy = _pipeFactory.CreateChannel();
}
public static IInterProcessClient CreateInterProcessClient(Uri serviceAddress)
{
return new InterProcessClient(serviceAddress);
}
public void SendArgs(string[] args)
{
_pipeProxy.PassArgs(args);
}
public void Dispose()
{
try
{
if (_pipeFactory != null)
_pipeFactory.Close();
}
catch { }
}
}
我已经确保客户端连接的地址是正确的。谁能提供一个想法,为什么我可能会得到错误时,从客户端调用_pipeProxy.PassArgs(args);
?测试只是在同一台机器上运行在不同进程中的两个控制台应用程序之间进行。
Framework 4.0 btw.
谢谢!
EDIT以下是服务接口和实现:
[ServiceContract]
public interface IPassCommandLineArgs
{
event EventHandler<CommandLineArgsEventArgs> CommandLineArgsReceived;
[OperationContract]
void PassArgs(string[] args);
}
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
public class PassCommandLineArgs : IPassCommandLineArgs
{
public event EventHandler<CommandLineArgsEventArgs> CommandLineArgsReceived;
public void PassArgs(string[] args)
{
EventHandler<CommandLineArgsEventArgs> hander = CommandLineArgsReceived;
if (hander != null)
hander(this, new CommandLineArgsEventArgs() { Args = args });
}
}
OK。这是调用代码将具有无效字符的地址传递给客户端的问题。仅此而已。