如何在N层数据应用程序中将API2/Rest用作数据层. [英] How to use API2/Rest as data tier in N-Tier Data Application.

查看:90
本文介绍了如何在N层数据应用程序中将API2/Rest用作数据层.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

我想创建一个桌面C#Forms程序,该程序是使用本文档概述的体系结构调用Web API的客户端 步行.我也阅读了这篇文章 这里

I would like to create a desktop C# Forms program that is a client calling a Web API using the architecture as outlined in this walkthtough.  I also read this article here

我不确定在哪里编写调用Web API的请求.

I'm not sure of where to code the requests to call the Web API.

任何人都可以解释为使该体系结构适用于为其数据调用Web API的客户端工作所需的哪些改变?

Can anyone explain what I would have to change to make this architecture work for a client calling a Web API for it's data?

这是我目前用于从Web API获取数据的代码:

This is the code that I currently use to get data from the Web API:

        private readonly RestClient _client;
        private readonly string _url = "http://www.somewebsite.com/";
        _client = new RestClient(_url);
        var request = new RestRequest("/Api/GetAllCustomers", Method.GET) { RequestFormat = DataFormat.Json };
        request.RootElement = "data";
        var response = _client.Execute<List<Customer>>(request);
        if (response.Data == null)
            throw new Exception(response.ErrorMessage);
        return Response.data;

我们将不胜感激任何帮助.

Any help would be gratefully appreciated.

谢谢,
托尼

Thanks,
Tony

停止世界,我想下车! ......生活与等待风暴过去无关……与学习在雨中跳舞有关.

Stop The World, I want To Get Off! ........... Life Isn't About Waiting For The Storm To Pass ... It's About Learning To Dance In The Rain.

推荐答案

您的示例教程不是很好,因为它向您展示了如何使用对基于Web的解决方案不利的数据集和数据表,因为它们太慢了.使用自定义对象.

Your example tutorial is not very good, because it is showing you how to use dataset and datatable which are bad for Web based solutions as they are too slow. But your code presented seems to be using a custom object.

http://lauteikkehn.blogspot.com/2012/03/datatable-vs-list .html

https://dzone.com/articles/reasons-move-datatables

应该通过层发送的是DTO或DTO.在一个集合中.

What should be sent through the tiers is a DTO or DTO(s)  in a collection.

https://en.wikipedia.org/wiki/Data_transfer_object

如果您要谈论的是典型的n层,则它由UI表示,业务逻辑和数据访问层组成.

If you are talking typical n-tier then it consist of UI presentation, business logic and data access tiers.

任何服务(例如WCF Web或非Web服务,Web API或旧版ASMX Web服务)通常位于业务和数据访问层之间.

Any service such as a WCF Web or non Web service, Web API or legacy ASMX Web service typically sits between the business and data access tiers.

我也会扔掉它.

http://www.codeproject.com/Articles /228214/了解用户界面设计模式-MVC-MVP的基本知识

http://www.codeproject.com/Articles/14660/WinForms-Model-View -演示者

http://www.codeproject.com/Articles /383153/The-Model-View-Controller-MVC-Pattern-with-Csharp

http://polymorphicpodcast.com/shows/mv-patterns/

http://www.dofactory.com/products/net-design-pattern-framework


这篇关于如何在N层数据应用程序中将API2/Rest用作数据层.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆