title: WCF Named Pipe in Windows Service using App.Config
body: <p>I am frustrated. Okay, here is the error.</p>
  
  <blockquote>
    <p>There was no endpoint listening at net.pipe://localhost/MyIpcAppToService that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.</p>
  </blockquote>
  
  <p>I finally got the App.Config file working, at least no complaints.</p>
  
  <p>Current App.Config</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;configuration&gt;
      &lt;!-- When deploying the service library project, the content of the config file must be added to the host's 
    app.config file. System.Configuration does not support config files for libraries. --&gt;
      &lt;startup&gt;
          &lt;supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2"/&gt;
      &lt;/startup&gt;
      &lt;system.serviceModel&gt;
          &lt;services&gt;
              &lt;service behaviorConfiguration="MyServiceBehavior" name="MyService.Communication.IpcAppToService"&gt;
                  &lt;endpoint address="net.pipe://localhost/MyIpcAppToService" binding="wsDualHttpBinding" bindingConfiguration="MyAppToServiceEndpointBinding" contract="MyIpc.IIpcAppToService"/&gt;
                  &lt;endpoint address="mex" binding="mexHttpBinding" name="mex" contract="IMetadataExchange"/&gt;
                  &lt;host&gt;
                      &lt;baseAddresses&gt;
                          &lt;add baseAddress="http://localhost:8733/MyService/"/&gt;
                      &lt;/baseAddresses&gt;
                  &lt;/host&gt;
              &lt;/service&gt;
    &lt;/services&gt;
          &lt;behaviors&gt;
              &lt;serviceBehaviors&gt;
                  &lt;behavior name="MyServiceBehavior"&gt;
                      &lt;!-- To avoid disclosing metadata information, set the values below to false before deployment --&gt;
                      &lt;serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/&gt;
                      &lt;!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment  to avoid disclosing exception information --&gt;
                      &lt;serviceDebug includeExceptionDetailInFaults="true"/&gt;
                      &lt;dataContractSerializer maxItemsInObjectGraph="2147483647"/&gt;
                  &lt;/behavior&gt;
              &lt;/serviceBehaviors&gt;
          &lt;/behaviors&gt;
          &lt;protocolMapping&gt;
              &lt;add scheme="http" binding="wsHttpBinding" bindingConfiguration="MyAppToServiceEndpointBinding" /&gt;
          &lt;/protocolMapping&gt;
          &lt;bindings&gt;
              &lt;wsDualHttpBinding&gt;
                  &lt;!-- https://docs.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/wcf/wshttpbinding --&gt;
                  &lt;binding name="MyAppToServiceEndpointBinding"
                                   transactionFlow="true"
                                   sendTimeout="00:01:00"
                                   maxReceivedMessageSize="2147483647"
                                   messageEncoding="Mtom"&gt;
                  &lt;/binding&gt;
              &lt;/wsDualHttpBinding&gt;
          &lt;/bindings&gt;
          &lt;serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"&gt;
              &lt;baseAddressPrefixFilters&gt;
                  &lt;add prefix="http://localhost:8733"/&gt;
              &lt;/baseAddressPrefixFilters&gt;
          &lt;/serviceHostingEnvironment&gt;
      &lt;/system.serviceModel&gt;
      &lt;appSettings&gt;
          &lt;add key="countoffiles" value="7"/&gt;
          &lt;add key="logfilelocation" value="abc.txt"/&gt;
      &lt;/appSettings&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>I used to have:</p>
  
  <pre><code>&lt;endpoint address="http://localhost:8733/MyIpcAppToService" ...
  </code></pre>
  
  <p>and in the Windows Service <code>OnStart()</code> event:</p>
  
  <p>(this following code is now commented out, as of this question post, as the <code>App.config</code> file is supposed to start the named.pipe.)</p>
  
  <pre><code>public Boolean CreatePipeServer()
  {
      string eventText = $"My Service: CommAppToService::CreatePipeServer(IPC App to Service){Environment.NewLine}";
      try
      {
          if (null != this.ServiceParent.HostIpcAppToService)
              this.ServiceParent.HostIpcAppToService = null;
  
          string pipeBaseAddress = @"net.pipe://localhost/MyIpcAppToService";
          this.ServiceParent.HostIpcAppToService = new ServiceHost(typeof(IpcAppToService), new Uri(pipeBaseAddress));
          NetNamedPipeBinding pipeBinding = new NetNamedPipeBinding()
          {
              //ReceiveTimeout = new TimeSpan(0, 0, 0, 0, Constants.My_TimeoutMsSendReceive),
              //SendTimeout = new TimeSpan(0, 0, 0, 0, Constants.My_TimeoutMsSendReceive),
          };
          this.ServiceParent.HostIpcAppToService.AddServiceEndpoint(typeof(IIpcAppToService), pipeBinding, "MyIpcAppToService");
          this.ServiceParent.HostIpcAppToService.UnknownMessageReceived += HostIpcAppServer_UnknownMessageReceived;
          this.ServiceParent.HostIpcAppToService.Faulted += HostIpcAppServer_Faulted;
          this.ServiceParent.HostIpcAppToService.Closing += HostIpcAppServer_Closing;
          this.ServiceParent.HostIpcAppToService.Closed += HostIpcAppServer_Closed;
  
          this.IpcAppToService = new IpcAppToService();
          this.IpcAppToService.ApplyDispatchBehavior(this.ServiceParent.HostIpcAppToService);
          this.IpcAppToService.Validate(this.ServiceParent.HostIpcAppToService);
          this.ServiceParent.HostIpcAppToService.Open();
  
          return true;
      }
  </code></pre>
  
  <p>I read that the service will AUTOMATICALLY start services placed in the <code>App.Config</code> file, really the <code>MyExeName.exe.config</code> file. I kept looking at the code and saw that it was nearly identical, so I replaced the <code>http://</code> with <code>net.pipe://</code>.</p>
  
  <p>Sadly, old code, new code, in between code, all nothing. I keep receiving the same error.</p>
  
  <p>I use the following to connect to the service from my desktop application.</p>
  
  <pre><code>public static Boolean ConnectToService()
  {
      try
      {
          var callback = new IpcCallbackAppToService();
          var context = new InstanceContext(callback);
          var pipeFactory = new DuplexChannelFactory&lt;IIpcAppToService&gt;(context, new NetNamedPipeBinding(), new EndpointAddress("net.pipe://localhost/MyIpcAppToService"));
          Program.HostIpcAppToService = pipeFactory.CreateChannel();
          Program.HostIpcAppToService.Connect();
          CommAppToService.IsPipeAppToService = true;
  
          return true;
      }
  
      catch (Exception ex)
      {
          // Log the exception.
          Errors.LogException(ex);
      }
  
      return false;
  }
  </code></pre>
  
  <p>For whatever it is worth, here is:</p>
  
  <p>Interface</p>
  
  <pre><code>[ServiceContract(SessionMode = SessionMode.Allowed, CallbackContract = typeof(IIpcCallbackAppToService))]
  public interface IIpcAppToService
  {
      [OperationContract(IsOneWay = false)]
      [FaultContractAttribute(typeof(IpcAppToServiceFault))]
      UInt16 GetServiceId();
  
      ...
  }
  </code></pre>
  
  <p>Service:</p>
  
  <pre><code>[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
  public class IpcAppToService : IIpcAppToService, IErrorHandler
  {
      public static IIpcCallbackAppToService Callback { get; set; } = null;
  
      public void OpenCallback()
      {
          IpcAppToService.Callback = OperationContext.Current.GetCallbackChannel&lt;IIpcCallbackAppToService&gt;();
      }
  
      public void CloseCallback()
      {
          IpcAppToService.Callback = null;
      }
  
      public void SendMessage(string message)
      {
          //MessageBox.Show(message);
      }
  
      public UInt16 GetServiceId()
      {
          return Constants.My_Id_AppToService;
      }
  
      ...
  }
  </code></pre>
  
  <p><strong>Inner Exception</strong> from my desktop WinForms Application
  (Note, there were no further inner exceptions than this one.):</p>
  
  <blockquote>
    <p>"The pipe endpoint 'net.pipe://localhost/MyIpcAppToService' could not be found on your local machine."</p>
  </blockquote>
  
  <p>Why do I keep seeing this error?</p>
  
  <p><strong>UPDATE AFTER 1ST ANSWER</strong></p>
  
  <p>The direction that I would like to take is opposite of the answer, yet the same, namely that the service starts with the <code>App.config</code> and the <code>client</code> uses C# code.</p>
  
  <p>Sadly, I still get the same error.</p>
  
  <p><strong>Revised Server Side App.config</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;configuration&gt;
      &lt;!-- When deploying the service library project, the content of the config file must be added to the host's 
    app.config file. System.Configuration does not support config files for libraries. --&gt;
      &lt;startup&gt;
          &lt;supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2"/&gt;
      &lt;/startup&gt;
      &lt;system.serviceModel&gt;
          &lt;services&gt;
              &lt;service behaviorConfiguration="BehaviorMyService" name="MyService.Communication.IpcAppToService"&gt;
                  &lt;endpoint address="net.pipe://localhost/MyIpcAppToService"
                                      binding="netNamedPipeBinding"
                                      bindingConfiguration="EndpointBindingMyAppToService"
                                      contract="MyIpc.IIpcAppToService"
                                      /&gt;
                  &lt;endpoint address="mex" binding="mexHttpBinding" name="mex" contract="IMetadataExchange"/&gt;
                  &lt;host&gt;
                      &lt;baseAddresses&gt;
                          &lt;add baseAddress="http://localhost:8733/MyService/"/&gt;
                      &lt;/baseAddresses&gt;
                  &lt;/host&gt;
              &lt;/service&gt;
          &lt;/services&gt;
          &lt;behaviors&gt;
              &lt;serviceBehaviors&gt;
                  &lt;behavior name="BehaviorMyService"&gt;
                      &lt;!-- To avoid disclosing metadata information, set the values below to false before deployment --&gt;
                      &lt;serviceMetadata httpGetEnabled="true"
                                                       httpsGetEnabled="true"
                                                       /&gt;
                      &lt;!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment  to avoid disclosing exception information --&gt;
                      &lt;serviceDebug includeExceptionDetailInFaults="true"/&gt;
                      &lt;dataContractSerializer maxItemsInObjectGraph="2147483647"/&gt;
                  &lt;/behavior&gt;
              &lt;/serviceBehaviors&gt;
          &lt;/behaviors&gt;
          &lt;bindings&gt;
              &lt;netNamedPipeBinding&gt;
                  &lt;!-- https://docs.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/wcf/wshttpbinding --&gt;
                  &lt;binding name="EndpointBindingMyAppToService"
                                   closeTimeout="00:01:00"  
                                   openTimeout="00:01:00"   
                                   receiveTimeout="00:10:00"   
                                   sendTimeout="00:01:00"  
                                   transactionFlow="false"   
                                   transferMode="Buffered"   
                                   transactionProtocol="OleTransactions"  
                                   hostNameComparisonMode="StrongWildcard"   
                                   maxBufferPoolSize="524288"  
                                   maxBufferSize="65536"   
                                   maxConnections="10"   
                                   maxReceivedMessageSize="2147483647"
                                   &gt;
                      &lt;security mode="None"&gt;
                          &lt;transport protectionLevel="None" /&gt;
                      &lt;/security&gt;
                  &lt;/binding&gt;
              &lt;/netNamedPipeBinding&gt;
          &lt;/bindings&gt;
          &lt;serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"&gt;
              &lt;baseAddressPrefixFilters&gt;
                  &lt;add prefix="http://localhost:8733"/&gt;
              &lt;/baseAddressPrefixFilters&gt;
          &lt;/serviceHostingEnvironment&gt;
      &lt;/system.serviceModel&gt;
      &lt;appSettings&gt;
          &lt;add key="countoffiles" value="7"/&gt;
          &lt;add key="logfilelocation" value="abc.txt"/&gt;
      &lt;/appSettings&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p><strong>Revised Client Side C# Code:</strong></p>
  
  <pre><code>var callback = new IpcCallbackAppToService();
  InstanceContext context = new InstanceContext(callback);
  NetNamedPipeBinding binding = new NetNamedPipeBinding();
  binding.Security.Mode = NetNamedPipeSecurityMode.None;
  EndpointAddress endpointAddress = new EndpointAddress("net.pipe://localhost/MyIpcAppToService");
  var pipeFactory = new DuplexChannelFactory&lt;IIpcAppToService&gt;(context, binding, endpointAddress);
  Program.HostIpcAppToService = pipeFactory.CreateChannel();
  Program.HostIpcAppToService.Connect();
  CommAppToService.IsPipeAppToService = true;
  </code></pre>
  
  <p>The service throws no exceptions that I can detect, as the EventViewer is clean, just the OnStart() successfully completed message. I know that the system processes the <code>App.config</code> file, as previously when I had errors, the <code>Windows Event Viewer</code> would keep complaining, but not anymore.</p>
  
  <p>Here were some of the Microsoft docs that I used:</p>
  
  <p><a href="https://docs.microsoft.com/en-us/dotnet/framework/wcf/samples/netnamedpipebinding" rel="nofollow noreferrer">netNamedPipeBinding</a></p>
  
  <p><a href="https://docs.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/wcf/netnamedpipebinding" rel="nofollow noreferrer">netNamedPipeBinding2</a></p>
  
  <p>I did try <a href="https://ioninja.com/" rel="nofollow noreferrer">IO Ninja</a>, but specifying <code>\\.\pipe\MyIpcToService</code> for <code>File Stream</code>, <code>Pipe Listener</code>, and <code>Pipe Monitor</code>, but nothing shows there, even when I try to connect using my WinForms desktop application, which then throws the no pipe listener found exception.</p>
  
  <p>What can be the problem?</p>