views:

1743

answers:

7

Using a web service is often an excellent architectural approach. And, with the advent of WCF in .Net, it's getting even better.

But, in my experience, some people seem to think that web services should always be used in the data access layer for calls to the database. I don't think that web services are the universal solution.

I am thinking of smaller intranet applications with a few dozen users. The web app and its web service are deployed to one web server, not a web farm. There isn't going to be another web app in the future that can use this particular web service. It seems to me that the cost of calling the web service unnecessarily increases the burden on the web server. There is a performance hit to inter-process calls. Maintaining and debugging the code for the web app and the web service is more complicated. So is deployment. I just don't see the advantages of using a web service here.

One could test this by creating two versions of the web app, with and without the web service, and do stress testing, but I haven't done it.

Do you have an opinion on using web services for small-scale web app's? Any other occasions when web services are not a good architectural choice?

+3  A: 

If you are just coding a tiny (less than 50 users) web application for your intranet, a web service seems overkill. Especially if its primary function (providing a single point of access to many services) won't be used.

Jared
+1  A: 

For a small-scale web app (You have to ask the question, "Will it always remain small scale?" though) using web services, separate business layers, data layers, and so on and so forth can be overkill.

Before anyone shoots me, I do agree that separation of logic between layers along with unit tests, continuous integration, et al are bloody brilliant. In my current role I'd be utterly lost and rocking in the corner without them. However for a very small-scale web app being used to, for example, track contact numbers and addresses for a company of 36 employees, the cost/benefit analysis would suggest that all the "niceties" listed above would be overkill.

However... Remember to ask the question "Will it always remain small scale?" :-)

Rob
Web services don't help with the scaling (esp. when statefull they can be pain in the back to scale) - they help with integration.
ddimitrov
Yes they can be a pain, but to say they don't/can't help with scaling outwards is an utter fallacy. You can use them to distribute modules of business logic to separate hardware so your web server is calling on "n" machines to do work for it. As an example.
Rob
Sure you can... I just wouldn't use them because of this. There are a number of other ways to scale out that do not force you to publish an rigid interface and XML serialization (i.e. message queues, map-reduce, grids, tupple-spaces)
ddimitrov
+1  A: 

I agree that the use of a web service in a small scale web app adds a layer of complexity that does not seem justified. Most of my solutions, internet and intranet, 10-50 users, do not employ web services. I am glad others feel the same...I thought I was the only one.

MBoy
I also thought I was the only one. Good to know we're not alone.
DOK
+20  A: 

Web Services are an absolutely horrible choice for data access. It's a ton of overhead and complexity for almost zero benefit.

If your app is going to run on one machine, why deny it the ability to do in-process data access calls? I'm not talking about directly accessing the database from your UI code, I'm talking about abstracting your repositories away but still including their assemblies in your running web site.

There are cases where I'd recommend web services (and I'm assuming you mean SOAP) but that's mostly for interoperability.

The granularity of the services is also in question here. A service in the SOA sense will encapsulate an operation or a business process. Data access methods are only part of that process.

In other words:

  - someService.SaveOrder(order);  // <-- bad
    // some other code for shipping, charging, emailing, etc

  - someService.FulfillOrder(order);  //<-- better
    //the service encapsulates the entire process

Web services for the sake of web services is irresponsible programming.

Ben Scheirman
I couldn't agree more. My company's main project has a webapp talking to a web service talking to a persistence layer. Nothing else access the web service but the webapp. Removing the web service would remove a giant layer that adds no value. A change anywhere requires updating 3 places!
matt b
+4  A: 

Just because the tool generates a bunch of stubs doesn't mean it's a good use. WS-* excels in scenarios where you expose services to external parties. This means that each operation should be on the granularity of business process as opposed to data access.

The multitude of standards can be used to describe different facets of your contract in great detail and a (hypothetical) fully compliant WS stack can take away a lot of pain from the third party developers and even allow the fabled point and click integration a'la Yahoo Pipes. With good governance controls you can evolve your public interface and manage the backward compatibility as needed.

All this is next to impossible to be generated automatically. The C# stub generator knows only the physical interface of your class, but doesn't have any idea about the semantics involved. See this paper for more detailed discussion.

If you are building a web site, then build a web site. If you want asynchronous messaging inside your application, use MSMQ. If you want to expose data to internal clients, use POX. If you need efficient binary message format, check Google's Protocol Buffers or if you need RPC check Hessian for C# or DCOM.

Web services are a coarse grained integration solution. They are rigid, they are slower than alternatives, they take too much effort to do well (and when not done well are next to pointless).

To summarize: "When should a web service not be used?" - anytime you can get away without it

ddimitrov
+6  A: 

Nick Harrison, a brilliant developer in Charlotte, suggested these scenarios where using a web service makes sense:

  • On a Web farm, where there are multiple web servers hosting website(s), all pointing to web service(s) running on another web server. This allows for distributing the load over multiple servers.
  • Client/server, where Windows forms apps can call a web service.
  • Cross platform
  • Passing through a firewall
DOK
A: 

For a small scale web app I think that using web services is often quite a good idea, you can use it to easily decouple the web server from the data tier. With the straightofrward development requirements and great tooling I don't see the problem.

However don't use web services in the following scenarios:

  • When you must use Http as the transport and Xml serialization of your data and you need lots of different bits of data, synchronously and often. Whether REST or SOAP or WS-* you're going to suffer performance issues. The more calls you make the slower your system will be. If you want medium size chunks of data less frequently, asynchronously and you can use straight TcpIp (e.g. Wcf netTcpBinding) you'd be better off.
  • When you need to query and join data from your web service with other data sources, rather motivate for a data warehouse which can be populated with properly consolidated and rationalized data from across the enterprize

This is my experience, hope it helps.

Matthew