RandomEngy
RandomEngy

Reputation: 15413

What might cause EndpointNotFoundException on local WCF named pipes?

I've got a system set up to let a worker process do some job and am coordinating with named pipes between the GUI process and the worker process. I kick off the worker process here:

this.pipeGuidString = Guid.NewGuid().ToString();
var startInfo = new ProcessStartInfo(
  "VidCoderWorker.exe",
  Process.GetCurrentProcess().Id.ToString(CultureInfo.InvariantCulture) + " " + this.pipeGuidString);
startInfo.RedirectStandardOutput = true;
startInfo.UseShellExecute = false;
startInfo.CreateNoWindow = true;
this.worker = Process.Start(startInfo);

// When the process writes out a line, its pipe server is ready and can be contacted for
// work. Reading line blocks until this happens.
this.logger.Log("Worker ready: " + this.worker.StandardOutput.ReadLine());
  bool connectionSucceeded = false;

this.logger.Log("Connecting to process " + this.worker.Id + " on pipe " + this.pipeGuidString);

var binding = new NetNamedPipeBinding
  {
    OpenTimeout = TimeSpan.FromSeconds(10),
    CloseTimeout = TimeSpan.FromSeconds(10),
    SendTimeout = TimeSpan.FromSeconds(10),
    ReceiveTimeout = TimeSpan.FromSeconds(10)
  };

this.pipeFactory = new DuplexChannelFactory<IHandBrakeEncoder>(
  this,
  binding,
  new EndpointAddress("net.pipe://localhost/" + pipeGuid + "/VidCoder"));

this.channel = this.pipeFactory.CreateChannel();
this.channel.Ping();

Then inside the worker process:

host = new ServiceHost(
  typeof (HandBrakeEncoder),
  new Uri[]
    {
      new Uri("net.pipe://localhost/" + PipeGuidString)
    });

host.AddServiceEndpoint(
  typeof (IHandBrakeEncoder),
  new NetNamedPipeBinding(),
  "VidCoder");

host.Open();

encodeComplete = new ManualResetEventSlim(false);
Console.WriteLine("Service state is " + host.State + " on pipe " + PipeGuidString);
encodeComplete.Wait();

host.Close();

It works fine for most people (including me) 100% of the time. But one user reports that the host process always gets an EndpointNotFoundException when trying to connect to the worker process, even with a log that indicates that the GUID was the same on both sides and the state was Opened on the worker process.

I figure that he must have something different with his system that's causing the failure and am wondering what that could be.

Any other ideas about why this would be happening? I read some stuff about local vs global named pipes but since I'm communicating locally and spawning the process locally it didn't seem like it should be an issue.

(edit2) User was surprisingly able to get a WCF trace: http://engy.us/misc/TracesWithNetPipeStarted.svclog

(edit3) It apparently works when running the host process as Administrator. Could it be that in this case some part of the pipe communication was requiring those privileges? How can I set up the pipe channel so that it never needs admin?

Upvotes: 2

Views: 6266

Answers (2)

MonteChristo
MonteChristo

Reputation: 597

I can confirm that having installed Garmin Express interferes with Named Pipes. For instance, trying to run unit tests in VS in non-admin mode causes the test runner to hang. Uninstalling Garmin Express resolves the issue.

Upvotes: 0

Chris Dickson
Chris Dickson

Reputation: 12135

Take a look at this SOA question and answer, which explains in detail how a WCF NetNamedPipeBinding service which is local to a particular session might be blocked by an unrelated application which is published globally, if the latter's service URL is chosen carelessly.

This seems quite a plausible explanation for the situation you describe.

Upvotes: 3

Related Questions