gpt4 book ai didi

c# - WCF 命名管道错误 : The pipe has been ended. (109, 0x6d)

转载 作者:太空宇宙 更新时间:2023-11-03 13:26:14 24 4
gpt4 key购买 nike

我看过其他关于“管道已结束。(109, 0x6d)”的帖子,但没有一个能解决我的问题。我有一个相对简单的设置基于此博客:http://tech.pro/tutorial/855/wcf-tutorial-basic-interprocess-communication

我觉得我非常关注它,只是删除了 HTTP 绑定(bind)。

这是服务器代码:

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); 时我可能会收到错误消息?测试仅在同一台机器上以不同进程运行的两个控制台应用程序之间进行。

框架 4.0 顺便说一句。

谢谢!

编辑这是服务接口(interface)和实现:

[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 });
}
}

最佳答案

好的。这是调用代码向客户端传递具有无效字符的地址的问题。仅此而已。

关于c# - WCF 命名管道错误 : The pipe has been ended. (109, 0x6d),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22334514/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com