简体   繁体   中英

WCF service named pipe failure

I've searched thoroughly, and found several answers to this problem, but none of them apply.

I have a .NET 4.0 WCF service hosted by windows services using a named pipe endpoint. This is set to start automatically on boot. I have a client that consumes the service.

When the server is rebooted, the service will start normally, but the client will get the following error:

1: There was no endpoint listening at net.pipe://localhost/WCFSQLService/ that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.

2: The pipe endpoint 'net.pipe://localhost/WCFSQLService/' could not be found on your local machine.

If the client and service are both restarted, the problem resolves itself.

As others have pointed out, both the Net.Pipe Listener Adapter is running and the WCF Non-HTTP Activation is checked:

net.pipe侦听器适配器

wcf非http激活

We've even tried setting the service to delayed start, but no joy. One would assume it was something wrong with the endpoint or config or normal WCF stuff, but when the service and client are both restarted everything works. Additionally, this only happens on 1 machine. If necessary I can provide endpoint information and code.

Client:

NetNamedPipeBinding binding = new NetNamedPipeBinding();
EndpointAddress endpoint = new EndpointAddress(endpointAddress);
ChannelFactory<IWCFSQLService> channel = new ChannelFactory<IWCFSQLService>(binding, endpoint);
IWCFSQLService client = channel.CreateChannel();
// do client calls
channel.Close();

Host

  class Program
  {
    static void Main(string[] args)
    {
      ServiceBase[] servicesToRun = new ServiceBase[] 
        {
          new WinServiceHost(), 
        };


      ServiceBase.Run(servicesToRun);
    }
  }



  public class WinServiceHost : ServiceBase
  {
    private readonly ServiceManager serviceManager = new ServiceManager();

    protected override void OnStart(string[] args)
    {
      base.OnStart(args);

      serviceManager.OpenHost<MyService>();
    }

    protected override void OnStop()
    {
      base.OnStop();

      serviceManager.CloseAll();
    }
  }

  public class ServiceManager
  {
    private readonly List<ServiceHost> serviceHosts = new List<ServiceHost>();

    public void CloseAll()
    {
      foreach (ServiceHost serviceHost in serviceHosts)
      {
        serviceHost.Close();
      }
    }

    public void OpenHost<T>()
    {
      Type type = typeof(T);
      ServiceHost serviceHost = new ServiceHost(type);
      serviceHost.Open();
      serviceHosts.Add(serviceHost);
    }
  }

config

  <system.serviceModel>
    <services>
      <service behaviorConfiguration="behaviorConfig" name="MyService">
        <endpoint address="" binding="netNamedPipeBinding" bindingConfiguration="clientNamedPipeBinding"
                  contract="IMyService">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <host>
          <baseAddresses>
            <add baseAddress="net.pipe://localhost/MyService" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <bindings>
      <netNamedPipeBinding>
        <binding name="clientNamedPipeBinding">
          <readerQuotas maxArrayLength="65536" maxBytesPerRead="65536" />
        </binding>
      </netNamedPipeBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="behaviorConfig">
          <serviceMetadata httpGetEnabled="false" httpGetUrl="" />
          <serviceDebug includeExceptionDetailInFaults="true" />
          <serviceSecurityAudit auditLogLocation="Application" suppressAuditFailure="true" serviceAuthorizationAuditLevel="Failure" messageAuthenticationAuditLevel="SuccessOrFailure" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

Maybe the server is killing the named pipe? Try to re-open the channel on the client periodically until it recovers maybe.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM