消费ASP.NET MVC的操作方法 [英] Consuming ASP.NET MVC action methods

查看:106
本文介绍了消费ASP.NET MVC的操作方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前的情况:一个ASP.NET MVC的网站有多个控制器和行动方法和观点,从而允许将食谱

current situation: an ASP.NET MVC web site with a number of controllers and action methods, and views to allow adding recipes.

现在,我要创建一个WPF应用程序充当UI添加配方(相同的网站)。

Now, I have to create a WPF application that acts as a UI to add recipes (same as the web site).

我的问题是:我可以使用ASP.NET MVC网站揭露了由WPF应用程序消耗的服务操作(以及如何才能做到这一点)?或者我应该更好地创造为专用WCF服务,并有WPF和ASP.NET MVC的网站使用这些服务?

My question is: can I use ASP.NET MVC site to expose service operations that are consumed by the WPF application (and how can this be done)? Or should I better create dedicated WCF services for that, and have the WPF AND the ASP.NET MVC site consume these services?

谢谢,
路德维希

Thanks, Ludwig

推荐答案

我已经成功地使用MVC控制器和行动服务从浏览器中以HTML的意见,以及外部应用程序。它的工作原理很好,但因为它代表你需要的工具一点点:

I have successfully used MVC controllers and actions to service both HTML views from the browser, as well as external applications. It works well, but as it stands you'd need a little bit of tooling:


  1. 我有一个动作的过滤器,返回从客户端请求的格式的行动所产生的模型(通过检查接受头,寻找任一应用程序/ JSON或文本/ XML)。所以,我可以序列生成的模型JSON或XML(I preFER JSON)。

  2. 您需要找到或创建您的客户端应用程序中创建WebRequests到你的行动简单的API,然后处理结果。我创建了一个简单的API,可以POST或GET,然后任何反序列化生成的JSON到(使用JSON.NET)的对象。有REST客户端API在那里,你可以使用这个。

但是,你可以避开一些这种额外的工具,如果你去了WCF-REST路线。更重要的是,我想看看ASP.NET MVC 4的功能的WebAPI(这是我将迁移到)。

However, you could avoid some of this extra tooling if you go the WCF-REST route. Better yet, I'd look into ASP.NET MVC 4's WebApi feature (which is what I will be migrating to).

有关的记录,我认为WCF是强大的,但我们的组织已经厌倦的是多么复杂,把所有的旋钮和打所有的交换机以获得工作的权利,并设置方便地从一个安装到其他。 MVC,在另一方面,只是工作......因为我们已经用它来服务我们的HTML视图,它是一个真正的喜悦,只需要添加一些额外的code把它处理服务电话,太。只是个人的preference,当然了。

For the record, I think WCF is powerful, but our organization has grown tired of how complicated it can be to turn all the knobs and hit all the switches to get it working right, and set up easily from one install to the other. MVC, on the other hand, just works... and since we already use it to service our HTML views, it's a real joy to only have to add a little extra code to have it handle service calls, too. Just a personal preference, of course.

这篇关于消费ASP.NET MVC的操作方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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