c# - 无法在服务结构中使用 DNS 与服务通信

标签 c# asp.net-core azure-service-fabric

我正在尝试让无状态服务向另一个服务发送值,只是为了通过在服务结构中使用 DNS 服务来实现服务之间的通信。我已经用 postman 测试了这两个应用程序,它们工作正常。我正在关注 this tutorial这样做似乎很简单。

DNS 服务已启用: DNS-service is running

无状态服务有一个 DNS 名称: enter image description here DNS 名称在 ApplicationManifest.xml 中配置

<Service Name="SocketService" 
 ServiceDnsName="SocketService.TimeSeriesActorApplication" 
 ServicePackageActivationMode="ExclusiveProcess">
    <StatelessService ServiceTypeName="SocketServiceType" 
     InstanceCount="[SocketService_InstanceCount]">
       <SingletonPartition />
   </StatelessService>
</Service>

然后我尝试向该服务发送一个 http get,就像在教程中一样。

using (var client = new HttpClient())
{
 client.BaseAddress = new Uri("http://socketservice.timeseriesactorapplication:8712/api/");
 var response = await client.GetAsync("values");
}

但我得到一个异常(exception):

WebException: The remote name could not be resolved: 'socketservice.timeseriesactorapplication'

当我按照教程建议使用端口 8080 时,以及当我使用我在 ServiceManifest.xml 中指定的端口时,都会发生这种情况。

<Endpoints>
  <Endpoint Protocol="http" Name="ServiceEndpoint" Type="Input" Port="8712" />
</Endpoints>

我在这里错过了什么?

更新: 使用 localhost 而不是 dns-name 也可以正常工作。

Github 上的问题:Unable to resolve service DNS name #332

最佳答案

我看到您正在运行服务结构 5.6.210。最近的 5.6.220 版本 ( https://blogs.msdn.microsoft.com/azureservicefabric/2017/06/20/release-of-sdk-2-6-220-and-runtime-5-6-220-refresh-for-windows/ ) 包含一些针对 DNS 服务的修复。请注意,即使我运行的是 5.6.220,我也注意到 DNS 名称解析似乎并不总是在我的本地机器上部署后立即开始工作(我必须重新部署或等待几分钟)。如果您在本地运行,您可以在终端窗口中测试名称解析 - 只需 ping 您服务的 DNS 名称即可。

关于c# - 无法在服务结构中使用 DNS 与服务通信,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44723374/

相关文章:

azure - 如何将持续运行的应用程序部署到 Azure Service Fabric?

azure - 如何一致且成功地将 Azure Service Fabric 应用程序部署到本地群集?

Azure Service Fabric - 可以通过一个公共(public) IP 地址拥有多种节点类型吗?

c# - CHM-Help C# 的打开子页面

c# - 将父类(super class)转换为特定的派生类型

authentication - Azure AD 身份验证redirect_uri 在 Linux 托管 (Cloud Foundry) ASP.NET Core 2.2 应用程序上不使用 https

.net - VS 2015 中未解决 Microsoft.NETCORE.app 依赖关系

c# - 键入时缺少 Visual Studio 2013 智能感知快速信息

c# - 使用 Oxyplot 和 Xamarin 的堆积柱形图

c# - 无法加载文件或程序集 'System.Private.ServiceModel,版本 = 4.1.2.4