gpt4 book ai didi

azure - 在 Xamarin 中与服务器通信的最佳方式?

转载 作者:行者123 更新时间:2023-12-02 08:07:07 25 4
gpt4 key购买 nike

我对 Xamarin 和移动开发完全陌生。我的第一个问题是架构方面的,使用现有的 Rest api 与移动客户端传输数据是否是一个好的做法。

我挖了google、Xamarin Azure云文档,但没有找到满意的文章。此外,我们还有一个 ember 前端应用程序,它使用来自 Azure 的 REST api。

如果此信息不够,请向我询问,如果重复,请随时使用正确的链接将其标记为重复。谢谢大家,请帮忙并分享您的宝贵经验。

谢谢

我浏览过的几个链接

https://azure.microsoft.com/en-us/documentation/learning-paths/appservice-mobileapps/

http://www.davevoyles.com/asp-net-web-api-vs-azure-mobile-services/

https://azure.microsoft.com/en-us/blog/azure-mobile-services-why-should-asp-net-developers-care/

http://weblogs.asp.net/scottgu/azure-virtual-machine-machine-learning-iot-event-ingestion-mobile-sql-redis-sdk-improvements

https://azure.microsoft.com/en-us/documentation/articles/app-service-mobile-value-prop/

https://azure.microsoft.com/en-us/documentation/articles/app-service-mobile-ios-get-started/

https://azure.microsoft.com/en-us/documentation/articles/partner-xamarin-mobile-services-ios-get-started/

最佳答案

如果您只想使用现有服务器 REST API,明显的步骤是在 Xamarin 中构建 REST 客户端。忘记 Xamarin 或任何相关的 Azure 移动服务客户端,因为这需要更改服务器代码。

关于如何构建REST客户端,有多种选择,但我推荐Refit作为更简单、更快捷的方法。例如,您在一个简单的接口(interface)中声明 REST 方法:

public interface IGitHubApi
{
[Get("/users/{user}")]
Task<User> GetUser(string user);
}

神奇之处在于,所有必需的代码都将在编译时生成,因此您可以专注于 API 方法而不是实现本身,并在几分钟(而不是几小时或几天)内构建您的客户端。然后您可以像这样使用该界面:

var gitHubApi = RestService.For<IGitHubApi>("https://api.github.com");
var octocat = await gitHubApi.GetUser("octocat");

不使用 Azure 移动服务客户端的缺点是,如果您需要任何离线/在线同步,则必须自己进行。但根据我的经验,客户端-服务器数据同步是一种边缘情况,在绝大多数应用程序中根本不需要。

关于azure - 在 Xamarin 中与服务器通信的最佳方式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37126793/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com