首页 \ 问答 \ ASP.NET MVC和提供第三方API(ASP.NET MVC and Providing Third-Party API)

ASP.NET MVC和提供第三方API(ASP.NET MVC and Providing Third-Party API)

我正在开发一个网络应用程序。 这更像是一个业务线应用程序,而不是一个网站。 我正在使用ASP.NET MVC,SQL Server 2008,我已经购买了LLBLGen。 我需要向第三方提供某种API。 例如,如果这是一个医疗应用程序,第三方可能需要CRUD患者,检索复杂的报告,参与某些类型的工作流程等。

在没有进入宇航员架构路线的情况下,使用MVC执行此操作的最佳方法是什么。 我需要一个完整的“Web服务”类型层,还是可以在MVC中重用我的控制器? 通过MVC暴露这种API是否有意义? 最理想的是,我需要一个涉及最少量代码重用的解决方案。 我已经找到了一些关于使用MVC做REST的东西,但是其中一些是相当模糊的,我不确定它是否有意义。 我需要一个合理的API,但我不需要遵循REST宗教的所有原则或类似的东西。 除了为网站提供HTML前端之外,我还需要某种API,无论是REST,SOAP还是其他。

另外,处理URL有哪些选择? 并非应用程序中的所有内容都映射到site / products / product-id之类的内容。 其中一些涉及参与复杂的工作流程等。


I'm developing a web app. This is more of a line-of-business app rather than a web site. I'm using ASP.NET MVC, SQL Server 2008, and I've purchased LLBLGen. I need to provide an some sort of API to third parties. For instance, if this was a medical app, third parties might need to CRUD patients, retrieve complex reports, engage certain kinds of workflows, etc.

What is the best way to do this with MVC without going to the architecture astronaut route. Do I need a whole "web service" type layer or can I re-use my controllers in MVC? Does it make sense to have this kind of API exposed through MVC? Optimally, I need a solution that involves the least amount of code repitition. I've found some stuff on doing REST with MVC but some of it is rather ambiguous and I'm not sure if it makes sense. I need a reasonable API but I'm not required to follow all the tenets of the REST religion or anything like that. I just need some sort of API in addition to providing the HTML front-end to the site, be it REST, SOAP, whatever.

Also, what are some options for dealing with URLs? Not everything in the app maps to something like site/products/product-id. Some of it involves engaging complex workflows, etc.


原文:https://stackoverflow.com/questions/2008218
更新时间:2021-09-14 15:09

最满意答案

我会说建立一些FTP空间,或一个WebDAV共享。 如果你不能这样做,那么我会上传一个(或少量)zip文件中的图像,而不是试图处理数百个独特的上传文件,这将非常耗时,因为浏览器只会选择一个文件一次在一个文件上传对话框(即你不能只选择一个完整的目录上传)。

为什么不在这个例子中使用PHP:

在PHP中编写简单的文件上传处理程序非常简单,但如果您想要处理非常大的上传,则需要谨慎处理文件大小上传限制,脚本执行时间限制和内存限制。 第一次安装可能有点令人沮丧。

如果它是一个你想要处理的多GB文件,那么HTTP上传并不是你想要的方式(基于,如果你必须问为什么,让它按你想要的方式工作可能会让你感到非常沮丧) )。

在Mac OS上有几个优秀的FTP客户端,没有理由相信Web浏览器是比FTP客户端更好的传输文件的方法。

关于进度条支持:

在PHP中当前进度条的支持是非常有限的(目前只通过第三方模块有点毛),但我相信有一个计划将模块包含在标准发行版中。 googling for uploadprogress.so应该给出一些相关的结果。

在回答小绿林:

我使用了这个扩展http://pecl.php.net/package/uploadprogress (它至少与我已经安装的一个扩展相冲突 - 尽管我认为他们已经解决了这个问题),并编写了一个自定义JavaScript处理程序( http ://iaincollins.com/javascript/FileUploader.js )基于网络上的一些多个示例,努力融入每一个的最佳实例。 例如,使用一个不可见的iframe来透明地返回上传进度,创建一个DHTML文件上传对话框,并通过使它变得透明并将其覆盖在我自己的控件之上来取代基于浏览器的丑陋浏览器上传控件(所以它仍然是可点击的,因为你不能从JavaScript调用文件上传对话框,尽管您可以获取已上传文件的名称)。 正确地获得CSS样式对于此特别重要 - 它非常适合浏览器。

我写的JS很可悲,非常具体情况,但它可能有一些有用的元素 - 对不起,我没有任何公开的东西可以链接到它,因为它是为私人界面创建的。

我发现现在有一个用于uploadprogress的jQuery插件 - 它不会做所有事情,但这将是一个很好的开始: http : //nixbox.com/demos/jquery-uploadprogress.php ...我记得更好的例子其中包括一个处理多个文件上传的文件(通过对它们进行排队并按顺序执行 - 您仍然必须一次选择一个文件),但不幸的是我似乎找不到它们。

结论:

我会尽量避免麻烦,除非您有时间,否则请执行FTP空间或私人/点对点文件传输应用程序。

文件传输协议(顾名思义)是专门为大文件传输而设计的,因为它只需要很少的配置(不会遇到资源限制),所以您可以合理地期望客户端拥有FTP恢复支持,假设你的服务器确实如此(例如,如果下载失败,他们应该能够轻松地从停止的地方恢复它,而不是从头开始,因为它们必须处理基于PHP文件的HTTP上载)。

尽管HTTP有能力处理上传文件,但它不够健壮,而且需要明确配置各种资源限制(在Web服务器和PHP中 - 如上所述),以便可以上传多GB文件。 即使使用WebDAV(使用HTTP服务器远程文件系统),它也是透明的,但它不像FTP那么健壮,主要是由于客户端实现的问题 - 特别是在Windows和Mac OS上传输超大文件时可能会出现问题,尽管对于小型(例如<500 MB)文件传输通常很好。

值得一提的是,HTML5规范将改进文件上传的处理方式 - 可以一次上传多个文件,并且可以将文件上传进度作为规范的一部分,但现在它不是真正的选择。


I would say set up some FTP space, or a WebDAV share. If you can't do that then I would upload the images in a single (or small number) of zip files, rather than trying to deal with hundreds of unique uploads, which would be very time consuming as browsers will only select a single file at a time in a file upload dialog (i.e. you can't just select an entire directory to upload).

Why not to use PHP in this instance:

Writing a simple file upload handler is easy in PHP but if you do want to handle very large uploads it's quite a bit tricker as you will need to be wary of file size upload limits, script excution time limits and memory limits. It can be a bit frustrating to setup the first time.

If it's a multi GB file you want to handle then an HTTP upload is not the way you want to go (based on, that if you have to ask why, getting it working as you want is probably going to be very frustrating process for you).

There are several excellent FTP clients on Mac OS, and there is no reason to trust a web browser to be better method of transferring files than an FTP Client.

Regarding progress bar support:

Currenly progress bar support is very limited in PHP (currently only via 3rd party modules which are a little hairy) though I belive there is a plan to include the module in the standard distribution. Googling for uploadprogress.so should give some relevant results.

In reply to littlegreen:

I used this extension http://pecl.php.net/package/uploadprogress (which managed to conflict with at least one extension I had installed already - although I think they have fixed that issue now) and wrote a custom javascript handler (http://iaincollins.com/javascript/FileUploader.js) based on some multiple examples on the web, in an effort to incorporate the best of each. e.g. Using an invisible iframe to return the upload progress transparently, creating a DHTML file upload dialog box and replacing the ugly browser based file upload control by making it transparent and overlaying it on top of my own control (so it was still clickable, as you can't invoke the file upload dialog from JavaScript, although you can get the name of the file that has been selected for upload). Getting the CSS styling right was particularly important for this - it's quite browser specific.

The JS I wrote is sadly very situation specific, but it might have some helpful elements - sorry I don't have anything public I can link to as it was created for a private interface.

I see there is a jQuery plugin for uploadprogress now - it doesn't do everything, but it would be a good start: http://nixbox.com/demos/jquery-uploadprogress.php ... I recall better examples being out there, including one that handled multiple file uploads (by queuing them and performing them sequentially - you still had to select one file at a time) but unfortunately I can't seem to find them.

Conclusion:

I would try and avoid the hassle and do something like FTP space or a private / peer to peer file transfer application unless you have the time.

File Transfer Protocol (as the name implies) is specifically designed for large file transfer and is a better option as it will need little configuration (you won't run into resource limits) and you can reasonably expect the client to have FTP resume support, assuming your server does (i.e. if the download stalls, they should be easily able to resume it from where they left off, rather than starting from scratch again as they would have to do with a PHP file based HTTP upload).

While HTTP has the ability to handle uploading files it's not as robust, and various resource limits (in the web server, and in PHP - as mentioned above) would need to be explicitly configured to make the uploading of a multi GB file possible. Even with WebDAV (using HTTP sever a remote file system) it's transparent but it tends not to be as robust as FTP, chiefly due to buggy client implementations - specifically there can be problems when transferring very large files on both Windows and Mac OS, although it's typically fine for small (e.g. <500 MB) file transfers.

As a side note, the HTML5 specification will improve how file uploads are handled - with the possibility to upload multiple files at once, and with file upload progress as part of the specification, but for now it's not really an option.

相关问答

更多
  • 我修正了我的错误,下面链接。 下面添加我的控制器。 render json: {success: true} 然后为好的上传脚本添加分块 chunking: { enabled: true } 然后修复它。 I fix above my error, link below. Add my controller below . render json: {success: true} Then for fine uploader script add chunking chunking: { ...
  • I have used all source code from below url: http://yuilibrary.com/yui/docs/uploader/uploader-multiple.html and to create instance the uploader. We need to just ...
  • 问题出在我正在使用的网络服务器上,它无法调用/执行php脚本。 The issue was with the webserver that i was using, It was unable to invoke/execute php script.
  • 从文档: 要在上传请求中发送的其他字段。 用于身份验证等。 包含名称和值道具的对象数组。 所以你的additionalField需要是: :additionalFields([{name: 'data', value: my_data_variable}], From the documentation: Additional fields to send along the upload request. Useful for authentication and so on. Array of Obje ...
  • 使用pluploader插件,它是一个很棒的插件,非常适合上传您可以轻松处理服务器端脚本的多个文件: 这是一个示例代码:

    Your browser doesn't have Flash, Silverlight or HTML5 support.