わかりました、これが私がこれをした方法です:
基本クラスを構築します
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;
}
}
サービス ファブリックに複数のサービスを追加すると...魅力的に機能します! :)