是否可以定义服务使用的网址而不是标准fabric:/AppName/ServiceName
?
我无法在应用程序级别找到这是否可配置。
答案 0 :(得分:0)
您可以从此处使用此uri构建器(ServiceUriBuilder.cs)类:https://github.com/Azure-Samples/service-fabric-dotnet-web-reference-app/blob/master/ReferenceApp/Common/ServiceUriBuilder.cs
对于无状态服务,您可以轻松获取代理:
var serviceUri = new ServiceUriBuilder(ServiceName);
var proxyFactory = new ServiceProxyFactory();
var svc = proxyFactory.CreateServiceProxy<IServiceName>(serviceUri.ToUri());
对于有状态服务,您必须指定分区。
var serviceUri = new ServiceUriBuilder(StatefulServiceName);
var proxyFactory = new ServiceProxyFactory();
//this is just a sample of partition 1 if you are using number partitioning.
var partition = new ServicePartitionKey(1);
var svc = proxyFactory.CreateServiceProxy<IStatefulServiceName>(serviceUri.ToUri(), partition);
答案 1 :(得分:0)
是,您可以将ApplicationManifest.xml
中的服务名称更改为从服务的类名中获取的名称以外的名称。
简短:只需将该服务name
中的ApplicationManifest.xml
属性更改为其他内容。
代码:如果我有此服务:
public interface IJustAnotherStatelessService : IService
{
Task<string> SayHelloAsync(string someValue);
}
internal sealed class JustAnotherStatelessService : StatelessService, IJustAnotherStatelessService
{
// Service implementation
}
在此Program.cs
注册:
ServiceRuntime.RegisterServiceAsync("JustAnotherStatelessServiceType",
context => new JustAnotherStatelessService(context)).GetAwaiter().GetResult();
在该服务的ServiceManifest.xml
中
<?xml version="1.0" encoding="utf-8"?>
<ServiceManifest ...>
<ServiceTypes>
<!-- This is the name of your ServiceType.
This name must match the string used in RegisterServiceType call in Program.cs. -->
<StatelessServiceType ServiceTypeName="JustAnotherStatelessServiceType" />
</ServiceTypes>
...
在ApplicationManifest.xml
中,您将获得建议的名称:
<ApplicationManifest ...>
<DefaultServices>
<Service Name="JustAnotherStatelessService">
<StatelessService ServiceTypeName="JustAnotherStatelessServiceType" InstanceCount="[JustAnotherStatelessService_InstanceCount]">
<SingletonPartition />
</StatelessService>
</Service>
</DefaultServices>
</ApplicationManifest>
这将为您提供Uri服务,如
fabric:/app_name/JustAnotherStatelessService
现在,继续更改应用程序清单中的名称:
<ApplicationManifest ...>
<DefaultServices>
<Service Name="AwesomeService">
<StatelessService ServiceTypeName="JustAnotherStatelessServiceType" InstanceCount="[JustAnotherStatelessService_InstanceCount]">
<SingletonPartition />
</StatelessService>
</Service>
</DefaultServices>
</ApplicationManifest>
您的服务现在回答
fabric:/app_name/AwesomeService