简体   繁体   English

我们为WCF服务使用SOAP和REST端点。 ASP.NET Web API对我们意味着什么?

[英]We use both SOAP and REST endpoints for our WCF services. What will the ASP.NET Web API mean to us?

On our services, we configure several endpoints, allowing us to publish the same interfaces to SOAP 1.1 and 1.2 clients and HTTP clients consuming either XML or JSON. 在我们的服务上,我们配置了多个端点,从而使我们可以向使用XML或JSON的SOAP 1.1和1.2客户端以及HTTP客户端发布相同的接口。 Now that the WCF REST team has been merged into the ASP.NET team to create the Web API stuff, what will this mean for us in the future? 现在,WCF REST团队已合并到ASP.NET团队中,以创建Web API东西,这对我们未来意味着什么? Will it still be supported to expose WCF interfaces as XML/JSON services? 将WCF接口公开为XML / JSON服务是否仍受支持? Should we move the REST endpoints to the Web API framework? 我们是否应该将REST端点移至Web API框架? Will this be the last shift of the MS REST stack? 这将是MS REST堆栈的最后转变吗?

Good question. 好问题。 I don't work for Microsoft and I don't have any inside information but my understanding is that WCF will be able to expose XML and JSON forever. 我不在Microsoft工作,也没有任何内部信息,但是我的理解是WCF将能够永远公开XML和JSON。 In fact if you are merely exposing JSON or XML endpoints you are not doing REST. 实际上,如果您仅公开JSON或XML端点,那么您就没有进行REST。 The real question is do you use the HTTP verbs (DELETE, PUT, POST, GET) as part of your API or you are simply exposing methods that are equivalent to your SOAP methods. 真正的问题是,您是将HTTP动词(DELETE,PUT,POST,GET)用作API的一部分,还是只是公开与SOAP方法等效的方法。 If you are using the HTTP verbs it may be a good long-term strategy to migrate the REST part to WebAPI. 如果您使用的是HTTP动词,那么将REST部分迁移到WebAPI可能是一个很好的长期策略。 If you are not then you can happily use WCF (go ahead tell your cusomers you are using REST for marketing reasons, to marketing people it's just a buzzword anyway). 如果不是,那么您可以快乐地使用WCF(继续告诉您的客户,您出于市场营销的原因而使用REST,无论如何向人们推销都是一个流行语)。

If you are using the HTTP verbs it is not that hard to have both WCF and WebAPI. 如果您使用的是HTTP动词,则同时拥有WCF和WebAPI并不难。 All you need to do is remove all logic from the service itself and expose it as a business layer methods. 您需要做的就是从服务本身中删除所有逻辑,并将其作为业务层方法公开。 Then both kids of services can use these methods, call them in the appropriate way and shape the results. 然后,服务的两个孩子都可以使用这些方法,以适当的方式调用它们并确定结果。

To answer this, you need to have a little history on the ASP.NET Web API. 要回答这个问题,您需要对ASP.NET Web API有一些了解。

Initially the ASP.NET Web API it was the WCF Web API , a project on Codeplex extending WCF to make it easier to support a REST-style service. 最初的ASP.NET Web API是WCF Web API ,它是Codeplex上的一个项目,用于扩展WCF,以使其更易于支持REST风格的服务。 WCF was entirely built on SOAP as its core messaging type, so using HTTP as anything other than a transport-layer protocol required a different approach, with a different set of attributes and generally didn't mesh well with the rest of the framework. WCF完全基于SOAP作为其核心消息传递类型而构建,因此将HTTP用作传输层协议以外的其他任何东西都需要使用不同的方法,具有不同的属性集,并且通常与框架的其余部分不能很好地结合。

The WCF Web API was extending the WCF framework in all the ways required to support HTTP as an application-level transport mechanism. WCF Web API正在以支持HTTP作为应用程序级传输机制所需的所有方式扩展WCF框架。 It was introducing request routing based on the resource URI, dynamic formatting according to the Accept headers and the other things which were previously missing from WCF. 它引入了基于资源URI的请求路由,根据Accept标头的动态格式设置以及WCF以前缺少的其他功能。

However, it became clear during its development that these technologies already existed within .NET, in the MVC stack. 但是,很明显,在开发过程中,这些技术已经存在于.NET中的MVC堆栈中。 Thus, the decision was made that rather than having two competing sets of technologies, they move the work over to the ASP.NET MVC team, and the ASP.NET Web API was born. 因此,他们决定,他们将工作移交给ASP.NET MVC团队,而不是拥有两套相互竞争的技术,从而诞生了ASP.NET Web API


If you are doing a REST-style service, the ASP.NET Web API is much better suited to your needs than the WCF framework. 如果您要进行REST风格的服务,则ASP.NET Web API比WCF框架更适合您的需求。 The WCF team will not be progressing their support for the REST-style architecture; WCF团队将不会继续支持REST风格的体系结构。 these features of the WCF framework are effectively subsumed by the Web API, where it finds a much more natural fit . Web API有效地包含了WCF框架的这些功能,在Web API中,WAPI框架找到了更为自然的契合度

Should you re-write your services to use the new Web API? 您是否应该重新编写服务以使用新的Web API? Well, the REST features of WCF aren't going to suddenly stop working. 好吧,WCF的REST功能不会突然停止工作。 You should only consider the move if it gives you some features you're after (like dynamic content-format selection), or if you're looking to continually develop your API (as the Web API is significantly easier to use than WCF). 仅当此举为您提供了一些您需要的功能(例如动态内容格式选择),或者您正在寻求不断开发API(因为Web API比WCF明显更易于使用)时,才应考虑此举。

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

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