最好的方式来从.NET REST API使用JSON [英] Best Way To Consume JSON from REST API in .NET

查看:543
本文介绍了最好的方式来从.NET REST API使用JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作在C#.NET Web应用程序,我需要使用来自第三方REST服务(他们没有使用WCF)。我在使用Web服务调用的一个背景的,那里有一个WSDL提供和Visual Studio将建立所有的底层code,然后我准备好了。

I'm working on a .net web app in c# and I need to consume a REST service from a third party (they are not using WCF). I'm coming from a background of using web service calls where there was a WSDL available and Visual Studio would build all of the underlying code and then I am ready to go.

有没有工具或框架,可以在一定程度上模仿这种行为?据我所知,没有合同,没有办法的工具,知道会发生什么,但我想我可以继续通过向导,我提供参数做一个REST调用,然后帮助向导制定出响应的细节。在该过程结束时,我将有一组模拟类似于如何在Web服务的行为的REST API的对象。

Is there no tool or framework that can to some degree simulate this behavior? I understand that without a contract there is no way for a tool to know what to expect but I would think I could go through a wizard where I supply parameters to make a REST call and then help the wizard work out the details of the response. At the end of the process I would have a set of objects that model the REST API similar to how the web service behave.

我知道,REST和JSON有一些很大的优势,他们却缺乏一个标准的开箱合同,允许自动code一代好像倒退的真正一步。

I know that REST and JSON have some great advantages to them but the lack of a standard out of the box contract to allow automated code generation seems like a real step backwards.

我失去了一些东西明显的或者是在.NET中使用REST时的事务只是当前的状况如何?我真的需要写锅炉板code为每一个新的API?

Am I missing something obvious or is that just the current state of affairs when consuming REST in .NET? Do I really need to write boiler plate code for each new API?

推荐答案

您可以看一下使用 RestSharp 访问REST API 。我给了一个样本,其中包括一种方法,在使用AutoMapper从数据传输对象去域模型的<一个href="http://stackoverflow.com/questions/8481366/mvc3-convert-json-from-rest-service-to-model/8481490#8481490">this SO质疑。

You can look at using RestSharp to access the REST API. I gave a sample, including an approach at using AutoMapper to go from data transfer object to domain model on this SO question.

这篇关于最好的方式来从.NET REST API使用JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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