我看过其他帖子处理“管道已经结束。(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。
谢谢!
编辑以下是服务界面和实施:
[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 });
}
}
答案 0 :(得分:1)
行。这是调用代码传递到客户端具有无效字符的地址的问题。没什么。