简体   繁体   English

在现有WCF应用程序(IIS)中托管一个ASP.net MVC 4站点

[英]Host an ASP.net MVC 4 site inside existing WCF application (IIS)

My company provides a large scale SOAP application with .Net WCF. 我公司通过.Net WCF提供了一个大型SOAP应用程序。 Inside this existing WCF application we now need to host an Asp.net MVC 4 (or 5) website. 现在,在这个现有的WCF应用程序内部,我们需要托管一个Asp.net MVC 4(或5)网站。 This means we need some kind of routing, that URIs of a specific kind are completely redirected to the Asp-Subcomponent and processed as if it was a separate application. 这意味着我们需要某种路由,将特定类型的URI完全重定向到Asp-Subcomponent并像对待单独的应用程序一样进行处理。

Searching for this issue I only find solutions where you do it the other way round - for sure the routing inside Asp MVC towards a WCF subcomponent would be quite easy and straight-forward. 在搜索此问题时,我只能找到在其他方面可以找到解决方案的解决方案-确保Asp MVC内向WCF子组件的路由将非常容易且直接。 However, this is not possible in our case. 但是,在我们的情况下这是不可能的。 The WCF contains a lot of security hooks we can not (and absolutely do not want to) transfer into the Asp component. WCF包含许多我们无法(绝对不希望)转移到Asp组件中的安全性挂钩。 On the other hand, dividing it into two separate applications and let IIS do the routing is also no possible solution, since our application as a vast bunch of dependencies with other software packages of our company which we do not want to maintain twice in separate apps. 另一方面,将其分为两个单独的应用程序并让IIS执行路由也是不可能的解决方案,因为我们的应用程序与我们公司的其他软件包存在大量依赖关系,因此我们不想在单独的应用程序中维护两次。

The existing WCF component is hosted as a separate web application inside a IIS 7.5 with a .NET 4.0 application pool. 现有的WCF组件在带有.NET 4.0应用程序池的IIS 7.5中作为独立的Web应用程序托管。

Is there any reasonable way of sub-routing from WCF to Asp.net MVC? 有没有从WCF到Asp.net MVC的子路由的合理方法?

This approach sounds like it is going to cause you and your company more issues than it is worth. 听起来这种方法将给您和您的公司带来更多的问题,而不是值得的。 I see that you've mentioned that splitting it into two separate components is impossible, however I would consider it for a few reasons. 我看到您提到过将其分为两个单独的组件是不可能的,但是出于某些原因,我会考虑使用它。

  1. Authentication and Authorization in WCF and MVC differ considerably, I would refactor these this code into a library that wasn't dependent on each technology and then write a WCF and MVC abstraction for each application. WCF和MVC中的身份验证和授权有很大的不同,我会将这些代码重构为一个不依赖于每种技术的库,然后为每个应用程序编写WCF和MVC抽象。 That was you get reuse but also have two components that understand the underlying technology 那是您可以重用,但也有两个了解底层技术的组件

  2. Routing WCF doesn't understand routes, it only has a sinlge entry point. 路由 WCF不了解路由,它只有一个入口。 Decision making of which method to be called it embedded in the payload of the message. 决定将哪种方法嵌入消息的有效负载中。 MVC on the other hand routes based on the url. 另一方面,MVC基于url进行路由。

  3. Deploying Updates to the MVC site will require WCF Service updates and vice ce versa 更新部署到MVC站点将需要WCF服务更新,反之亦然

These are just some off the top of my head. 这些只是我头上的一些东西。 It just seems overly complicated and hacky to do it this way. 这样做似乎过于复杂和棘手 I'd consider two applications hosted separately in IIS with common logic extracted into common class libraries that allow for reuse. 我会考虑将两个应用程序分别托管在IIS中,并将通用逻辑提取到允许重用的通用类库中。

I suggest you give WCF Services and ASP.NET a thorough read. 我建议您仔细阅读WCF服务和ASP.NET

You are going to find it extremely difficult (or at least pioneering) to get WCF to sit between IIS and ASP.NET. 您将发现让WCF 位于 IIS和ASP.NET 之间极其困难(或至少是开创性的)。 They are designed to work side by side, or independently. 它们被设计为并排或独立工作。

Given it's pretty straightforward to have WCF and ASP.NET/MVC use the same underlying authentication system (eg Forms Auth), your main objection to architecting it right seems to be the "vast bunch of dependencies with other software packages of our company which we do not want to maintain twice in separate apps". 既然让WCF和ASP.NET/MVC使用相同的基础身份验证系统(例如Forms Auth)非常简单,那么您对其构架的主要反对意见似乎是“与我们公司其他软件包的大量依赖关系,不想在单独的应用程序中维护两次”。

Again solving that seems to be a pretty straightforward bit of refactoring. 再次解决这似乎是重构的一个非常简单的过程。 Your task would be just to extract out all the WCF specific code from the business logic, then put the business logic into a separate class library to be shared between WCF and MVC apps. 您的任务只是从业务逻辑中提取所有WCF特定代码,然后将业务逻辑放入单独的类库中,以在WCF和MVC应用程序之间共享。 To me there is no other sensible approach to solving your problem than this. 对我来说,没有什么比这更明智的方法来解决您的问题了。 Any other approach is probably going to leave you even more of a mess than the (monolithic sounding) WCF app you have currently. 与您当前拥有的(整体听起来)WCF应用程序相比,任何其他方法都可能给您带来更多混乱。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM