ASP.NET MVC API 或 WCF API

发布于 2024-11-04 01:22:07 字数 308 浏览 7 评论 0原文

我正在开发一个 ASP.NET MVC 3 应用程序。我需要这个应用程序来使用我也需要实现的 API。该 API 应该可以从 ASP.NET MVC 控制器操作和 Ajax 获得。现在使用 ASP.NET MVC 制作 API 非常容易,但是是否可以从其他 ASP.NET MVC 网站操作中使用它?我想 WCF 非常容易使用,因为它只是一个服务引用。

该 API 的其他用户可能是 Windows Phone 和 iPhone。

更新:

许多人只将 API 视为消费数据的地方,但是您想要执行命令或执行操作(例如添加客户或更改 foo)的部分又如何呢?

I'm developing an ASP.NET MVC 3 application. I need this application to make use of an API I also need to implement. The API should both be available from ASP.NET MVC controller actions and Ajax. Now it is quite easy to make an API using ASP.NET MVC, but is it possible to use this from other ASP.NET MVC website actions? I guess the WCF is quite easy to use as it is just a service reference.

Other users of the API could be Windows Phone and iPhone.

Update:

Many only sees the API as a place where you consume data, but what about the part where you want to execute commands or do stuff, like add customer or change foo?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

悍妇囚夫 2024-11-11 01:22:07

您可能想查看我们在 PDC 上发布的新 WCF Web API。我们最近发布了重大升级。 WCF Web API 专门设计用于允许您以纯 HTTP 方式向一系列客户端公开 API。它是轻量级的,提供了一个很好的配置故事(没有配置文件)并且也更容易测试。

您可以在 wcf.codeplex.com 下载这些位。它包含各种示例,还有一组可帮助您入门的 NuGet 包。在 NuGet 上搜索 webapi.all

You may want to check our new WCF web API that was announced at PDC. We recently released a big upgrade. WCF Web API is designed specifically for allowing you to expose APIs to a range of clients in a pure HTTP manner. It is lightweight, offers a nice configuration story (no configuration files) and also is much easier to test.

You can download the bits at wcf.codeplex.com. It includes various samples, and there is also a set of NuGet packs for getting you started. Search for webapi.all on NuGet.

画离情绘悲伤 2024-11-11 01:22:07

我喜欢使用 RESTful 控制器操作来实现此目的。您可以返回 JSON 并在您自己的站点上使用 JavaScript 进行调用。其他网站几乎肯定会理解 JSON,因此他们能够很轻松地使用您的 API。这比沉重的 WCF 层更容易编写和测试。

查看此问题,了解 MVC 的一些 REST 框架示例:

ASP.NET MVC REST 框架

The way I like to do this is with RESTful controller actions. You can return JSON and use your calls with JavaScript on your own site. Other websites would almost certainly understand JSON and so they'd be able to consume your API pretty easily. This is much easier to write and test than a heavy WCF layer.

Check out this question for some example REST frameworks for MVC:

ASP.NET MVC REST frameworks

孤独患者 2024-11-11 01:22:07

完成数据馈送的较新方法之一是使用 OData。 Scott Hanselman 在 为 StackOverflow 创建 OData API(包括 XML 和 JSON)中对其进行了精彩的介绍30 分钟

它甚至允许您将 LINQ 查询放入您的 URL 中以准确检索您需要的数据。

One of the newer ways of accomplishing data feeds is using OData. Scott Hanselman has a great introduction to it in Creating an OData API for StackOverflow including XML and JSON in 30 minutes.

It allows you to even throw LINQ queries into your URLs to retrieve exactly the data you need.

仅此而已 2024-11-11 01:22:07

我上次使用 WCF JSON 绑定时真的很糟糕。 WCF 还附带了各种关于流的疯狂规则以及如何对所有内容使用 [MessageBody] 属性。

这对我来说是真正的皮塔饼。


我知道我以前回答过类似的问题:

当今在 .NET 中实现 RESTful 架构的最佳方法是什么?

WCF JSON binding was really terrible last time I used it. WCF also comes with all sorts of crazy rules about streams and how you have to use [MessageBody] attributes for everything.

It was a real PITA to me.


I knew I've answered something like this before:

What is the best way to implement a RESTful architecture in .NET today?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文