与Xamarin中的服务器通信的最佳方法?

问题描述 投票:1回答:1

我对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/

azure xamarin xamarin.ios xamarin.forms xamarin-studio
1个回答
2
投票

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

关于如何构建REST客户端,有多种选择,但是我建议Refit是一种更简便,更快捷的方法。 例如,您在一个简单的接口中声明了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移动服务客户端的缺点是,如果需要任何脱机/联机同步,则必须自己进行。 但以我的经验来看,客户端-服务器数据同步是一个极端情况,绝大多数应用程序根本不需要。

© www.soinside.com 2019 - 2024. All rights reserved.