同一域下asp.net mvc和php的双重使用
我有一个场景,我们有一个客户有一个 Linux 托管的 php 应用程序 (joomla),他们希望与为“姐妹”站点创建的一些后端 asp.net mvc 功能集成。基本上,mvc 站点具有价格和库存可用性方法,(在姐妹站点中)填充下拉列表和页面上的其他“订单”样式信息。我的任务是查看集成选项,以允许 php 站点将此信息用作“服务”。 (一如既往,这些人正在考虑拥有成本、维护成本等,所以这是他们的首选路线)
有没有人做过类似的事情并取得成功?我想(很像姊妹网站)将使用大量的 ajax 来按需填充页面的某些部分。因此,这可能会影响您的任何建议。此外,所调用的方法最终会填充相同的数据库,因此跨不同平台关联 ID 不会出现问题。
如果可能的话,我真的不想走任何“iframe”类型的路线,但现实可能表明这是一种选择。我可能(天真地)想象我可以直接从 php 应用程序调用 mvc 函数,并传递某种“会话”变量进行身份验证。
相当高的要求还是相当直接??
欢呼
吉姆
[编辑] - 虽然由于 joomla 网站的现有结构而不太可能实现,但使用 openID 帐户是否有助于将两个网站“粘合”在一起?
另外,发现这篇小文章“可能”在某种程度上符合我的想法: http://www.jeffancel.com/archive/2009/04/ 05/70.aspx
I've got a scenario where we have a customer who has a linux hosted php app (joomla) that they wish to integrate with some back-end asp.net mvc functionality that was created for a 'sister' site. Basically, the mvc site has prices and stock availability methods which (in the sister site) populates dropdown lists and other 'order' style info on the pages. I've been tasked with looking at the integration options to allow the php site to use this info as a 'service'. (as ever, these guys are looking at cost of ownership, maintenence etc, so this is their preferred route)
Has anyone done anything similar with success?? I'd imagine (much like the sister site) liberal doses of ajax will be employed in order to populate portions of the page on demand. So this may have a bearing on any suggestions that you may have. Also, the methods that are being called ultimately end up populating the same database, so there are no issues with correlating the ID's across the different platforms.
I don't really want to go down any 'iframe' type route if at all possible, tho' reality may dictate this as being an option. I'm possibly (naively) imagining that i could simply invoke the mvc functions directly from the php app with some sort of 'session' variable being passed for authentication.
pretty tall order or pretty straightfwd??
cheers
jim
[edit] - tho highly unlikely to be implemented due to the existing structure of the joomla site, would the use of an openID account help to 'glue' the two sites together??
also, found this little article that 'may' go some way twds what I'm thinking of:
http://www.jeffancel.com/archive/2009/04/05/70.aspx
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果身份验证是一个因素,您可以使用 API KEY 告诉 .net 应用程序您是谁,而且他们还可以添加仅允许使用某些资源的过滤器。在 PHP 中,您可以通过多种方式使用 .net 服务,正如我已经做过多次的那样。如果您从服务器端(实际的 PHP)调用,那么您会希望它们以 xml 或 json 的形式公开您正在使用的数据;所以你可以在 PHP 中解析它并按照你想要的方式使用它。我可以建议以下几种方法:
1.) Ajax 或请求到您的 PHP 应用程序,该应用程序又使用 PHP 来使用您姊妹站点的服务;在最坏的情况下,您可能必须直接解析 html,尽管我建议让他们使用 RESTful 服务打开 XML 或 JSON 对象(如果您不介意在您的代码中添加几个方法,这是一个相当简单的修改)控制器)。
2.) Ajax 使用 jsonp 请求从您正在通信的站点获取 html 小部件。这也需要姊妹网站做一些工作,但这是非常可行的。如果您走这条路线,那么他们必须进行我在那篇文章中提到的跨域更改(尽管那是 .net mvc 1.0)。
最后,它归结为您选择的具体要求。我个人选择路线 1,并使用服务器端的大部分服务,因为它可以抽象 API 密钥等内容以及我不希望用户看到的其他内容。由于各个浏览器的行为不同(即与 firefox 等相比),从 PHP 处理 XML 也比从 javascript 更容易。
If authentication is a factor, you could use an API KEY to tell the .net application who you are, also, they can add filters that would only allow consumption from certain resources. From PHP, there are a couple ways that you can consume .net services as I have done it several times. If you call from the server side (actual PHP), then you would want them to expose the data you are consuming in xml or json; so you can parse it in PHP and use it the way you want to. Here are a couple routes I can suggest:
1.) Ajax or request into your PHP application, which in turn uses PHP to consume the services from your sister site; in worst case scenario, you may have to parse html directly, though I would suggest having them open up the XML or JSON object using a RESTful service (this is a fairly easy modification if you don't mind adding a couple of methods in your controller).
2.) Ajax using a jsonp request to grab an html widget from the site that you are communicating with. This would require some work by the sister site as well, but it is very doable. If you go this route, then they must make the cross domain changes that I mentioned in that post (though that is .net mvc 1.0).
In the end, it boils down to your specific requirements as to what you would choose. I personally choose route 1 and consume most services from the server side as it can abstract things such as API-Keys and other things I don't want the users to see. It is also easier to deal with XML from PHP rather than javascript because of the individual browser behaviors (ie versus firefox et al.).
最好的办法是创建 ASP.NET Web 服务或 WCF 服务来提供您所需的信息。然后您可以从您的 php 站点使用这些服务。如果您已经拥有提供数据的类和方法,那么将它们公开为 Web 服务真的很容易。
You best bet is to create asp.net web services or wcf services that provide the info you need. You can then consume these services from your php site. If you already have classes and methods that provide the data then it is really easy to just expose them as web services.