简体   繁体   English

服务结构同一服务上的多个WCF端点

[英]Service fabric multiple WCF endpoints on same service

I am trying to create 2 endpoints for a service: net.tcp and http. 我想创建2个端点服务:的net.tcp和HTTP。 Both endpoints will have the same endpoint name. 两个端点将具有相同的端点名称。 How to do it in Service fabric ? 如何在Service fabric中做到这一点?

It is easy to define it in App config when not running in SF, this way: 这是很容易在应用程序配置来定义它,当在SF,这种方式不运行:

<service behaviorConfiguration="DefaultBehavior" name="ContractImplementation">
        <endpoint address="net.tcp://localhost:6000/ContractName" binding="netTcpBinding" bindingConfiguration="netTcpBinding" contract="ContractName" />
        <endpoint address="http://localhost:6001/ContractName" binding="basicHttpBinding" bindingConfiguration="httpBinding" contract="ContractName" />
</service>

When running in SF, I create a listener by creating WcfCommunictionListener object. 在SF中运行时,我通过创建WcfCommunictionListener对象来创建侦听器。 I can't create another one with different binding, as it complains the endpoint name is already in use. 我无法创建具有不同绑定的另一个,因为它抱怨端点名称已在使用中。

As described in the docs here : 如在文档中描述在这里

When creating multiple listeners for a service, each listener must be given a unique name. 为服务创建多个侦听器时,必须为每个侦听器指定一个唯一的名称。

The endpoint names must have different names, and you can handle the loading in the logic that create the listener, you should create one listener for each endpoint and pass the name of each of then; 端点名称必须具有不同的名称,并且您可以在创建侦听器的逻辑中处理加载,应该为每个端点创建一个侦听器并传递每个侦听器的名称;

Something like this: 像这样:

protected override IEnumerable<ServiceReplicaListener> CreateServiceReplicaListeners()
{
    return new[]
    {
        new ServiceReplicaListener(context =>
          new WcfCommunicationListener<ICalculator>(
              wcfServiceObject:this,
              serviceContext:context,
              endpointResourceName: "WcfServiceEndpoint1",
              listenerBinding: WcfUtility.CreateTcpListenerBinding()
          )
        ),
        new ServiceReplicaListener(context =>
          new WcfCommunicationListener<ICalculator>(
              wcfServiceObject:this,
              serviceContext:context,
              endpointResourceName: "WcfServiceEndpoint2",
              listenerBinding: WcfUtility.CreateTcpListenerBinding()
          )
       )
   };
}

For more information on how to use WcfCommunicationListener check here 有关如何使用WcfCommunicationListener更多信息,请在此处检查

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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