2016-11-30 4 views
0

WCFに基づく通常のWindowsサービスを使用している状況では、同じアドレス上の複数のリスナーをホストします。アドレスには接尾辞が追加されます(同じポート上のステートレスWCFサービスリスナー

など)。
http://localhost:9000/<listener1_name>/ 
http://localhost:9000/<listener2_name>/ 
http://localhost:9000/<listener3_name>/ 
http://localhost:9000/<listener4_name>/ 

しかし、私たちはサービスファブリックを使用してasuzeに移りたいので、これを段階的に取りたいと思います。 そして、このWindowsサービスをService Fabric環境に移行することです...

私がやっていないことは、同じポートをリッスンする多数のステートレスサービスをセットアップすることです異なる接尾辞付き。

私はEndPointPathSuffix属性がトリックを行うと思っていましたが、サービスの1つしか稼働しません。他の人は、港がすでに利用されていることを明確に述べている。これは働くことを望んだ

<Resources> 
    <Endpoints> 
    <Endpoint Name="WcfService1Endpoint" Protocol="tcp" Port="9000" PathSuffix="Service1ListenerName"/
    <Endpoints> 
</Resources> 

し、次に:

<Resources> 
    <Endpoints> 
    <Endpoint Name="WcfService2Endpoint" Protocol="tcp" Port="9000" PathSuffix="Service2ListenerName" /> 
    <Endpoints> 
</Resources> 

等等...

は私の状況を解決するための他の方法はありますか今私は全体の構造を変更する必要がありますか?

誰かがこれを解決しました。

ありがとうございます!

+1

ここに記載されている手順を実行しましたか? https://msdn.microsoft.com/en-us/library/ms734772(v=vs.110).aspx – LoekD

+0

アイデアありがとう。たとえそれが答えではなかったとしても、それは私が正しい方法で私を押し込んだ...私がまもなく使った解決策を投稿するかもしれない。 –

答えて

0

OK]をクリックして、ここで私はこれをしなかった方法です:

私は

public class StatelessServiceBase : StatelessService 
{ 
    . 
    . 
    . 

    protected ICommunicationListener CreateListener(StatelessServiceContext context, object service, string interfaceName, AuthenticationInspector inspector = null) 
    { 
     Uri baseUri = new Uri($"{Util.GetBaseServerAddress()}{service.GetType().Name}"); 
     ServiceHost serviceHost = new ServiceHost(service.GetType(), baseUri); 
     this.AddServiceEndpoint(serviceHost, service, interfaceName, inspector); 
     return new ServiceHostCommunicationListener(serviceHost, baseUri.AbsoluteUri); 
    } 

    private void AddServiceEndpoint(ServiceHost serviceHost, object service, string interfaceName, AuthenticationInspector inspector) 
    { 
     var binding = new WSHttpBinding(SecurityMode.None); 
     binding.SendTimeout = new TimeSpan(0, 10, 0); 
     binding.ReceiveTimeout = new TimeSpan(0, 10, 0); 
     binding.MaxBufferPoolSize = 2147483647; 
     binding.MaxReceivedMessageSize = 2147483647; 
     binding.ReaderQuotas = new System.Xml.XmlDictionaryReaderQuotas 
     { 
      MaxDepth = 2147483647, 
      MaxStringContentLength = 2147483647, 
      MaxArrayLength = 2147483647, 
      MaxBytesPerRead = 2147483647, 
      MaxNameTableCharCount = 2147483647 
     }; 

     if (inspector == null) 
     { 
      serviceHost.AddServiceEndpoint(service.GetType().GetInterface(interfaceName), binding, string.Empty); 
     } 
     else 
     { 
      serviceHost.AddServiceEndpoint(service.GetType().GetInterface(interfaceName), binding, string.Empty).Behaviors.Add(inspector); 
     } 
    } 
} 

基本クラスを構築し、私はステートレスなサービスクラスからCreateListenerと呼ば:

internal class MyStatelessService : StatelessServiceBase 
{ 
    public MyStatelessService(StatelessServiceContext context) 
     : base(context) 
    { 
    } 

    protected override IEnumerable<ServiceInstanceListener> CreateServiceInstanceListeners() 
    { 
     yield return new ServiceInstanceListener(context => 
       this.CreateListener(context, new MyService(), "IMyService", new AuthenticationInspector())); 
    } 
} 

そして、 Settings.xmlは次のようになります。

<?xml version="1.0" encoding="utf-8" ?> 
<Settings xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/2011/01/fabric"> 
    <Section Name="Configuration"> 
    <Parameter Name="BaseServerAddress" Value="http://localhost:9000/"/> 
    </Section> 
</Settings> 
リーダー機能と一緒に

public class Util 
{ 
    internal static string GetBaseServerAddress() 
    { 
     var configurationPackage = FabricRuntime.GetActivationContext().GetConfigurationPackageObject("Config"); 

     var baseServerAddress = 
      configurationPackage.Settings.Sections["Configuration"].Parameters["BaseServerAddress"]; 

     return baseServerAddress.Value; 
    } 
} 

が魅力のように作業する...サービスファブリックで複数のサービスを追加して! :)

関連する問題