سؤال

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 });
    }
}
هل كانت مفيدة؟

المحلول

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

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top