WCF TCP共享服务启用服务无法启动

时间:2017-08-21 12:53:46

标签: c# wcf service tcp

简而言之,当我开始工作流程服务流程时,它会失败并返回:

  

本地计算机上的CS.Connector.Protean服务已启动,然后启动   停止。如果某些服务未被使用,则会自动停止   其他服务或计划

我从配置文件中的服务模型中删除属性 portSharingEnabled =" true" ,然后工作流程服务启动并按预期执行。然后我将该属性添加回配置中,并且工作进程服务不会再次启动。我在这篇文章的底部包含了服务模型配置。

Net.TCP共享服务正在运行,因此它应该拦截传入的net.TCP连接。

我已阅读此MSDN文章,但我必须在某处遗漏某些内容。

是不是可以使用mex端点而不使用端口共享绑定?我尝试添加绑定到mex终点,但仍然没有快乐。 :(

帮助!谢谢

<system.serviceModel>
    <bindings>
      <netTcpBinding>
        <binding name="TCPSecure" portSharingEnabled="true">
          <security mode="Message" />
        </binding>
      </netTcpBinding>
    </bindings>
    <services>
      <service name="Protean.Connector.ProteanConnector">
        <endpoint address="" binding="netTcpBinding" bindingConfiguration="TCPSecure" contract="Protean.Connector.IProteanConnector"></endpoint>
        <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="net.tcp://10.1.2.124:60000/ProteanConnector" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="">
          <serviceMetadata httpGetEnabled="false" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
  

更新!

  1. 我开始提供工作服务并通过测试证实了这一点。
  2. 我添加了属性端口共享,但服务无法启动。
  3. 我删除了mex端点,服务成功运行。已建立连接的应用程序能够成功使用该服务。
  4. 我添加了mex,并引用了仅启用了端口共享且服务无法启动的绑定。
  5. 我需要mex才能使IDE Visual Studio可以发现该服务。

    我认为现在的问题是,元数据交换的终点如何与端口共享属性一起工作?

      

    更新2

    MSDN Social Webpage Link

    此论坛告诉我将mex绑定从mexTcpBinding更改为netTcpBinging。我做了,服务运行了,但我现在无法在IDE中发现该服务。

    这是正确的解决方案路径吗?旅程还在继续。

    我开始认为我挖得越深,我就越有可能偶然发现一些政府的阴谋。 #HumourInDarkTimes #StrangerThings;)

1 个答案:

答案 0 :(得分:1)

  

解决方案

    var type = typeof(LoggingManager);

    using (var host = new ServiceHost(type))
    {

        /*
         * Work-around to the conflict between global port sharing and local port sharing 
         * caused by Net.Tcp Sharing Serivces and the default port exclusivity (hogging) of Metadata Exchange binding.
         */
        var mexBinding = new CustomBinding(MetadataExchangeBindings.CreateMexTcpBinding());
        mexBinding.Elements.Find<TcpTransportBindingElement>().PortSharingEnabled = true;
        host.AddServiceEndpoint(typeof(IMetadataExchange), mexBinding, "mex");

        host.Open();
        Console.WriteLine("Service started. Press [Enter] to exit.");
        Console.ReadLine();
        host.Close();
    }
  

解决方案描述

我阅读了一些文章,通过交换绑定mexTcpBinding for netTCPBinding建议解决方案,我发现这在我的实例中不起作用。

以上解决方案获取mexTCPBinding并将属性 PortSharingEnabled = true 添加到其中。这用于创建新的端点代码 - 并且传递给服务主机。最后,我从配置中删除了元交换端点,嘿-presto,它有效。

  

有用的链接