简体   繁体   English

如何让 Azure 中的 API 与服务通信?

[英]How can I make my API in Azure communicate with a service?

Disclaimer: I have zero experience with Azure, or any cloud solutions whatsoever, so I may be asking a stupid question;免责声明:我对 Azure 或任何云解决方案的经验为零,所以我可能会问一个愚蠢的问题; I have, however, been given this task at work, so I have to do it.然而,我在工作中被赋予了这项任务,所以我必须这样做。

My problem is as follows: I have a REST API project written in .NET Core.我的问题如下:我有一个用 .NET Core 编写的 REST API 项目。 It is hosted as an App Service on Azure.它在 Azure 上作为应用服务托管。 Some endpoints in the API have to communicate with a service (a MS Orleans service) and send some data to it. API 中的某些端点必须与服务(MS Orleans 服务)通信并向其发送一些数据。 Said service is also hosted on Azure as an App Service on the same Resource Group.所述服务还作为同一资源组上的应用服务托管在 Azure 上。 The way this solution has been developed is that the API knows the IP address of the service, and tries to connect with the service using said IP address.该解决方案的开发方式是 API 知道服务的 IP 地址,并尝试使用该 IP 地址与服务连接。 It works locally, but when I deploy it on Azure, I get exceptions.它在本地工作,但是当我在 Azure 上部署它时,我遇到了异常。 I tried changing the IP address to the inbound address provided by Azure, but it didn't work either.我尝试将 IP 地址更改为 Azure 提供的入站地址,但它也不起作用。 I'm getting the following error:我收到以下错误:

Error message错误信息

What should I do to make the services communicate?我应该怎么做才能使服务通信? I will thankful for any tips.我会感谢任何提示。

If we would like to connect with Silo from Azure Web App, we need to assign both Azure Web App and the worker role hosting the Silo to an Azure Virtual Network.如果我们想从 Azure Web App 连接 Silo,我们需要将 Azure Web App 和托管 Silo 的辅助角色分配到 Azure 虚拟网络。

Refer to MS Docs to understand about Azure Websites Virtual Network Integration.请参阅MS 文档以了解 Azure 网站虚拟网络集成。

we can assign the cloud service to the virtual network by modifying the ServiceConfiguration file.我们可以通过修改ServiceConfiguration文件将云服务分配给虚拟网络。

<NetworkConfiguration>
  <VirtualNetworkSite name="virtual-network-name" />
  <AddressAssignments>
    <InstanceAddress roleName="role-name">
      <Subnets>
        <Subnet name="subnet-name" />
      </Subnets>
    </InstanceAddress>
  </AddressAssignments>
</NetworkConfiguration>

Also make sure the Silo endpoints are configured.还要确保已配置 Silo 端点。

<Endpoints>
  <InternalEndpoint name="OrleansSiloEndpoint" protocol="tcp" port="11111" />
  <InternalEndpoint name="OrleansProxyEndpoint" protocol="tcp" port="30000" />
</Endpoints>

If the Web App is having difficulty connecting to the Silo: • Make sure you have at least two roles, or two instances of one role in your Azure Cloud Service, or the InternalEndpoint firewall rules may not be generated.如果Web 应用程序无法连接到Silo: • 确保您在Azure 云服务中至少有两个角色或一个角色的两个实例,否则可能不会生成InternalEndpoint 防火墙规则。 • Check that both the Web App and the Silo are using the same ClusterId and ServiceId. • 检查Web App 和Silo 是否使用相同的ClusterId 和ServiceId。 • Make sure the network security group is set up to allow internal virtual network connections. • 确保网络安全组设置为允许内部虚拟网络连接。 If you haven't got one you can create and assign one easily using the following PowerShell:如果您还没有,您可以使用以下 PowerShell 轻松创建和分配一个:

New-AzureNetworkSecurityGroup -Name "Default" -Location "North Europe"
Get-AzureNetworkSecurityGroup -Name "Default" | Set-AzureNetworkSecurityGroupToSubnet -VirtualNetworkName "virtual-network-name" -SubnetName "subnet-name"

Refer to Orleans docs for more info有关更多信息,请参阅奥尔良文档

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

相关问题 如何与 Kronos API 通信? - How can I communicate with the Kronos API? .Net客户端可以与azure signalR服务通信吗? - Can .Net Client communicate with azure signalR service? 如何为 Azure 应用服务 API 添加授权 header? - How can I add the authorization header for Azure App Service API? 如何使用服务类让我的 web-api 与我的控制器一起工作? - How do I make my web-api work with my controller using service class? 如何使用 C# 以编程方式与 Azure 服务总线通信 - How to Communicate with Azure Service Bus Programmatically using C# 如何在我的C#应用​​程序中管理Azure API管理服务 - How to manage Azure API management service in my C# application How can I restrict my Azure Web App API access to only my Xamarin.Forms app? - How can I restrict my Azure Web App API access to only my Xamarin.Forms app? azure 是否提供/提供任何 api 或任何我可以将自定义域添加到我的应用程序服务的方式? - Do azure provide/offer any api or any way from which i can add custom domain to my app service? 如何确保无需计时器即可在Android应用程序中使用Azure移动服务? - How do I make sure I can use Azure Mobile Services in my Android app without a Timer? 我应该如何设计我的tcp服务器程序,使`IHostedService相互通信 - How should I design my tcp server program to make `IHostedService`s communicate with each other
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM