没有端点在net.pipe上监听

6

我遇到了以下错误:

没有终结点侦听 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>
4个回答

16
  • 确保已配置 IIS 使用 Windows Process Activation Service(WAS)

    1. 从开始菜单中选择控制面板。
    2. 选择程序,然后选择程序和功能,或在经典视图中选择 程序和功能
    3. 点击 打开或关闭 Windows 功能
    4. 在功能摘要下,点击添加功能。
    5. 展开 Microsoft .NET Framework 3.0(或 3.5) 节点并选中 Windows Communication Foundation 非 HTTP 激活功能
  • 确保 Net.Pipe Listener Adapter 服务正在运行:

    1. Win+R 打开运行对话框,输入 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 谢谢,我已经仔细检查了两个选项,在我的机器上都正常工作。可能还有其他问题。 - Hammad Bukhari
@HammadBukhari,答案已更新。 - Pranav Singh
@Pranv,如果我更新App.Config以使用您建议的代码,则在启动服务时会出现错误。 "本地计算机上的服务已启动,然后停止。某些服务会自动停止,如果它们未被其他服务或程序使用"。 - Hammad Bukhari
以下是来自事件日志的错误跟踪:"无法启动服务。System.InvalidOperationException: 无法找到与绑定WSHttpBinding的端点匹配的基地址方案http。已注册的基地址方案为[net.pipe]。" - Hammad Bukhari
1
谢谢@PranavSingh :) 你救了我的一天! :) - Lokesh
显示剩余7条评论

3

我也遇到了同样的错误。我使用的是Windows 8.1上的Visual Studio 2013。对我而言解决方案是以管理员身份运行Visual Studio。


0

我遇到了这个问题,因为我使用的是旧教程,并尝试进行编程配置。

我缺少的部分是提供元数据终点(谢谢您,这篇文章!)。

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"
);

0

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

希望能对你有所帮助!


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接