【问题标题】:No endpoint listening at net.pipenet.pipe 没有端点监听
【发布时间】:2014-06-23 23:32:26
【问题描述】:

我收到以下错误:

没有端点监听 net.pipe://localhost/ServiceModelSamples/service 可以接受 信息。这通常是由不正确的地址或 SOAP 操作引起的。 有关详细信息,请参阅 InnerException(如果存在)。

我正在从另一个 WCF 调用调用 Windows 服务内的 WCF 自托管服务,如下所示。

                   _host = new ServiceHost(typeof(CalculatorService),
            new Uri[] { new Uri("net.pipe://localhost/PINSenderService") });

        _host.AddServiceEndpoint(typeof(ICalculator),
                new NetNamedPipeBinding(),
                "");

        _host.Open();

        ChannelFactory<ICalculator> factory = new ChannelFactory<ICalculator>(
            new NetNamedPipeBinding(NetNamedPipeSecurityMode.None),
            new EndpointAddress("net.pipe://localhost/PINSenderService"));
        ICalculator proxy = factory.CreateChannel();
        proxy.SendPin(pin);
        ((IClientChannel)proxy).Close();
        factory.Close();

自托管 WCF 服务

 namespace PINSender
 {

    // Define a service contract.    

    public interface ICalculator
    {
        [OperationContract]
        void SendPin(string pin);
    }

    // Implement the ICalculator service contract in a service class.
    public class CalculatorService : ICalculator
    {
        // Implement the ICalculator methods.
        public void  SendPin(string pin)
        {
        }
    }

    public class CalculatorWindowsService : ServiceBase
    {
        public ServiceHost serviceHost = null;
        public CalculatorWindowsService()
        {
            // Name the Windows Service
            ServiceName = "PINSenderService";
        }

        public static void Main()
        {
            ServiceBase.Run(new CalculatorWindowsService());
        }

        // Start the Windows service.
        protected override void OnStart(string[] args)
        {
            if (serviceHost != null)
            {
                serviceHost.Close();
            }

            // Create a ServiceHost for the CalculatorService type and 
            // provide the base address.
            serviceHost = new ServiceHost(typeof(CalculatorService));

            // Open the ServiceHostBase to create listeners and start 
            // listening for messages.
            serviceHost.Open();
        }

        protected override void OnStop()
        {
            if (serviceHost != null)
            {
                serviceHost.Close();
                serviceHost = null;
            }
        }
    }

    // Provide the ProjectInstaller class which allows 
    // the service to be installed by the Installutil.exe tool
    [RunInstaller(true)]
    public class ProjectInstaller : Installer
    {
        private ServiceProcessInstaller process;
        private ServiceInstaller service;

        public ProjectInstaller()
        {
            process = new ServiceProcessInstaller();
            process.Account = ServiceAccount.LocalSystem;
            service = new ServiceInstaller();
            service.ServiceName = "PINSenderService";
            Installers.Add(process);
            Installers.Add(service);
        }
     }

}

App.Config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
  <service name="PINSender.CalculatorService"
           behaviorConfiguration="CalculatorServiceBehavior">
    <host>
      <baseAddresses>            
        <add baseAddress="net.pipe://localhost/PINSenderService"/>
      </baseAddresses>
    </host>

    <endpoint address=""
              binding="netNamedPipeBinding"
              contract="PINSender.ICalculator" />        
    <endpoint address="mex"
              binding="mexNamedPipeBinding"
              contract="IMetadataExchange" />                
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="CalculatorServiceBehavior">
      <serviceMetadata httpGetEnabled="False"  />
      <serviceDebug includeExceptionDetailInFaults="False"/>
    </behavior>
  </serviceBehaviors>
  </behaviors>
 </system.serviceModel>
</configuration>

【问题讨论】:

    标签: c# wcf windows-services named-pipes


    【解决方案1】:
    • 确保将IIS 配置为使用Windows Process Activation Service(WAS):

      1. 从“开始”菜单中,选择“控制面板”。
      2. 选择程序,然后选择程序和功能,或在经典视图中, 选择Programs and Features。
      3. 点击Turn Windows Features on or off。
      4. 在功能摘要下,单击添加功能。
      5. 展开Microsoft .NET Framework 3.0(or 3.5) 节点并检查 Windows Communication Foundation Non-HTTP Activation feature。
    • 确保 Net.Pipe Listener Adapter 服务正在运行:

      1. 转到run 并打开Services.msc
      2. 确保Net.Pipe Listener Adapter 服务正在运行。

    在您的 App.config 中,您已将 baseAddress 与 http 一起使用,请尝试将其更改为 net.pipe:

      <baseAddresses>
        <add baseAddress="net.pipe://localhost/ServiceModelSamples/service"/>
      </baseAddresses>
    

    更多详情请参阅NetNamedPipeBinding。

    更新:

    您需要在endpoint 中添加bindingConfiguration,例如:

    <endpoint address=""
                  binding="netNamedPipeBinding"
                  contract="Microsoft.ServiceModel.Samples.ICalculator" 
                  bindingConfiguration="Binding1" /> 
    

    并添加实际的bindingConfiguration 喜欢:

        <bindings>
      <!-- 
            Following is the expanded configuration section for a NetNamedPipeBinding.
            Each property is configured with the default value.
         -->
      <netNamedPipeBinding>
        <binding name="Binding1" 
                 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="65536">
          <security mode="Transport">
            <transport protectionLevel="EncryptAndSign" />
          </security>
        </binding>
      </netNamedPipeBinding>
    </bindings>
    

    【讨论】:

    • @Pranv 谢谢我已经仔细检查了这两个选项在我的机器上都可以正常工作。可能还有其他问题。
    • @HammadBukhari,更新答案。
    • @Pranv,如果我更新 App.Config 以使用您建议的代码,它会在我启动服务时给我错误。 "本地计算机上的服务启动然后停止。如果某些服务没有被其他服务或程序使用,它们会自动停止"
    • 这里是来自事件日志的错误跟踪“服务无法启动。System.InvalidOperationException: 找不到与绑定 WSHttpBinding 的端点的方案 http 匹配的基地址。注册的基地址方案是 [net.管道]。"
    • 谢谢@PranavSingh :) 你拯救了我的一天! :)
    【解决方案2】:

    我弹出了同样的错误。我在 Windows 8.1 上从 Visual Studio 2013 运行。我的解决方案是以管理员身份运行 Visual Studio。

    【讨论】:

      【解决方案3】:

      我还在 windows Server 2012 上运行 Visual Studio 2013,它与 8.1 基本相同,以管理员身份重新启动它也解决了我的问题。

      希望对你有帮助!

      【讨论】:

        【解决方案4】:

        我遇到了这个问题,因为我使用的是older tutorial,并尝试以编程方式进行配置。

        我缺少的部分是提供元数据端点 (thank you, this post!)。

        ServiceMetadataBehavior serviceMetadataBehavior = 
            host.Description.Behaviors.Find<ServiceMetadataBehavior>();
        
        if (serviceMetadataBehavior == null)
        {
            serviceMetadataBehavior = new ServiceMetadataBehavior();
            host.Description.Behaviors.Add(serviceMetadataBehavior);
        }
        
        host.AddServiceEndpoint(
            typeof(IMetadataExchange), 
            MetadataExchangeBindings.CreateMexNamedPipeBinding(), 
            "net.pipe://localhost/PipeReverse/mex"
        );
        

        【讨论】:

          猜你喜欢
          • 2010-11-17
          • 1970-01-01
          • 1970-01-01
          • 2013-04-07
          • 2014-12-05
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多