Scenario: I have an existing https ASP.NET site to which I'm going to be adding some new remote services. The services provide calculations that need to be callable both via AJAX methods on the site, and via a .NET开发者_如何学Go desktop application.
I had been using ASP.NET WebServices (marked with the ScriptService attribute) to accomplish this. I just recently discovered WCF.
From my understanding, it seems the major thing a WCF Service would offer over a plain old .NET Web Service in this instance is the ability to connect over various other communication channels like Message Queue and COM+ down the line. I don't ever see that happening with this project.
So tell me, why else should I consider WCF?
WCF offers a very customisable platform; just about any part of the WCF stack can be replaced with your own custom components. Changing the communication protocol is just the tip of the iceberg. This design makes it possible to accomplish things you wouldn't easily be able to with ASP.NET Web Services.
For example, I recently wrote an auditing component which listens to request-reply transmissions on a WCF service or client, and writes them all to an auditing database. WCF provides extension points for message interceptors to access messages and perform operations on them whilst they are still XML. As such, I've written around only 100 lines of code to accomplish what I wanted.
A supporting reason to use WCF is the tools. Out of the box, WCF provides better tools for testing, configuring and diagnosing services. In addition to this, being the go-to solution for services in .NET, there are now many tools and utilities specifically targeting the WCF platform.
WCF replaces ASP.NET Web Services entirely. I recommend all new work in .NET services should be done in WCF where at all possible. Whether you should migrate existing projects to WCF is another matter, where the benefits of WCF need to outweigh the cost of replacing a functioning solution.
Even if you're not currently planning on adding different Service Endpoints, you shouldn't rule it out as a possibility. You never know what somebody might need down the road.
That said, if the .NET Web Service is meeting your needs and you don't need the additional benefits that WCF adds (easy endpoint swapping, more tightly integrated standard security, etc.) then don't both with it.
If your code is working and getting the job done, there's really no point in investing time in a new technology just to say you use it. Wait to investigate WCF until you really need a feature it offers.
精彩评论