WCF Named Pipe Error: The pipe has been ended. (109, 0x6d)

牧云@^-^@ 提交于 2019-12-11 02:48:27

问题


I have looked at the other posts dealing with "The pipe has been ended. (109, 0x6d)" but none of them have solved my problem. I have a relatively simple setup bases off of this blog: http://tech.pro/tutorial/855/wcf-tutorial-basic-interprocess-communication

I feel like I follow it pretty closely, only removing the HTTP binding.

Here is the server code:

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

Here is the client code:

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 { }
    }
}

I have ensured that the address the client is connecting to is correct. Can anyone provide an idea why I might be getting the error when _pipeProxy.PassArgs(args); is called from the client? The test is just between two console apps on the same machine running in different processes.

Framework 4.0 btw.

Thanks!

EDIT Here is the service interface and implementation:

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

回答1:


OK. This was an issue of the calling code passing in an address that had an invalid character to the client. Nothing more.



来源:https://stackoverflow.com/questions/22334514/wcf-named-pipe-error-the-pipe-has-been-ended-109-0x6d

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!