多个 Azure 移动应用程序之间的通信?通过 HttpClient 或其他选项? (.Net-后端)

Communication between multiple Azure Mobile Apps? Via HttpClient or different options? (.Net-Backend)

简化场景:

欧盟一个 Azure 移动应用 "ServiceManagement"(包括数据库)

两个 Azure 移动应用程序,相同的代码,一个在欧洲 "ServiceEU",一个在美国 "ServiceUS"(每个都有自己的独立数据库)

客户登录 ServiceManagement,选择他希望在哪个区域托管他的数据。客户购买服务选项->付款记录、选择的选项等保存在ServiceManagement中。

现在 ServiceManagement 连接到 ServiceEU 或 ServiceUS 并告诉它为客户创建相应的服务计划。超出客户购买服务选项的时间,服务之间将没有通信。

除了 HttpClient 之外,是否还有其他选项来处理 Azure 移动应用程序 "ServiceManagement" 和 "ServiceEU" 或 "ServiceUS" 之间的通信?

我当前的代码似乎可以工作,但我找不到任何 resources/documentation 用于此类情况。所以我不确定是否有更好的选择。

/// <summary>
/// Hosted in ServiceManagement
/// </summary>
/// <returns></returns>
[HttpGet]
[ActionName("completeRemote")]
[ResponseType(typeof(String))]
public async Task<string> completeRemote()
{

    HttpClient client = new HttpClient();
    client.DefaultRequestHeaders.Add("ZUMO-API-VERSION", "2.0.0");

    //Calling completeAll from different Azure Mobile App "<url>"
    var res = await client.GetAsync("https://<url>/api/Test/completeAll");
    res.EnsureSuccessStatusCode();
    var str = await res.Content.ReadAsStringAsync();
    str = JsonConvert.DeserializeObject<String>(str);

    //verify request completed
    //Do something with str

    return str;
}

请记住,这是一个非常简化的概念

您可以使用 Azure 服务总线(或托管您自己的服务总线)

Depend on Azure Service Bus when you need highly reliable cloud messaging service between applications and services, even when one or more is offline.

关于维基百科上的企业服务总线:

An enterprise service bus (ESB) implements a communication system between mutually interacting software applications in a service-oriented architecture (SOA).

...

As it implements a software architecture for distributed computing, it therefore also implements a special variant of the more general client-server model. Whereas in general any application using ESB can behave as server or client in turns.

Are there any other options besides HttpClient to handle the communication between the Azure Mobile App "ServiceManagement" and "ServiceEU" or "ServiceUS"?

据我所知,C# 移动应用程序后端是一个 Web api。通常我们会使用httpclient向webapi应用程序发送请求得到结果

如果您不想使用httpclient,您可以使用azure 移动客户端SDK。

写代码很容易

您可以从 Nuget 包安装它。

Install-Package Microsoft.Azure.Mobile.Client

下面是示例代码,希望能给大家一些提示:

注意:它仍然会向移动应用程序后台发送请求。

    public static async Task<string> GetApplicationToken()
    {
        var clientUri = $"https://your-mobile-app-id.azurewebsites.net";

        var client = new MobileServiceClient(clientUri);
        var response = await client.InvokeApiAsync<string>("/api/values", HttpMethod.Get, null);
        return response;
    }