views:

77

answers:

2

I need to create a service that:

  1. accepts HTTP requests (with query string or HTTP POST parameters)
  2. does some processing on the requests (checking if the request is valid, authentication etc.)
  3. reads data from a custom store (another HTTP call in our case)
  4. returns the result as custom XML (defined with XSD)

I'm trying to think of various MS technologies that could help me and how good they would be for this scenario (pretty standard one I guess).

The tasks above are relatively separate, this is what comes to mind:

HTTP front-end:

  • ASP.NET Web Forms
  • ASP.NET MVC (seems more appropriate here as I won't need server controls, view state etc.)
  • WCF? Don't know much about it or how well it would suit my task.

Custom logic on the server:

  • this will probably be a generic C# code in all cases (sometimes "plugged into" or called from MVC controllers or some equivalent place in other technologies)

Reading data from internal data stores:

As said, this is another HTTP server in our case. Options that come to mind:

  • Just read the data using something like WebClient
  • (Just theoretically) implement a LINQ provider
  • (Just even more theoretically) implement an EF provider

Output the data as custom XML:

  • Linq2XML
  • Serialization? Is it flexible enough?
  • Does WCF provide some tools for this?
  • Some "OXM" - Object/XML mapper if there is something like that for .NET

I may be wrong in many of my assumptions, this is just a quick list that comes to mind after a quick research.

Some general notes / questions:

  • Testing is important
  • Solution with a clear domain model would be much preferred over the one without
  • Can Entity Framework actually help somewhere in my scenario? If so, where and how?
  • Would WCF be an appropriate technology for this? I don't know much about it.
+1  A: 

ASP.NET MVC can return an XML result, in any flavor you like. ASP.NET MVC is specifically designed to be testable. Use whatever suits your temperament to generate the XML. URLs are mapped directly to a C# controller method that returns the XML to the user. The URL routing capability in ASP.NET MVC provides great flexibility in defining your URL structure and mapping that structure to controller methods. You can use Entity Framework to create your domain model and read from the data store.

WCF should be capable of this as well, if you just want to build the service without a UI. Here is a primer: http://msdn.microsoft.com/en-us/library/dd203052.aspx

The NerdDinner tutorial is the definitive primer for ASP.NET MVC.

More info on the Entity Framework here: http://msdn.microsoft.com/en-us/library/aa697427(VS.80).aspx

Robert Harvey
When you talk about EF and it being capable of reading from the data store, would I need to implement my own EF provider? Sounds like a big job all in itself...
Borek
What data store did you have in mind? EF supports [several popular databases.](http://en.wikipedia.org/wiki/ADO.NET_Entity_Framework#Entity_Framework_ADO.NET_providers)
Robert Harvey
The data is retrieved via HTTP calls.
Borek
So you retrieve the data from some service with HTTP, transform it with XSL (or something similar), and spit the transformed data out thru another service? Unless the data is highly structured or terribly intricate, I don't think you need an additional abstraction layer.
Robert Harvey
The data store, although it's accessed via HTTP, doesn't return XML so I need to do custom transformation.In a sense, I'd like to have a domain model which can "persist" via 2 formats/interfaces - one is our internal HTTP (but non-XML) service and the other one is the public XML.
Borek
You still haven't told me what the data store is, but if it's a database and you control it, I would wrap an ORM like the Entity Framework around it (if you haven't already done so), and use that to read the data to generate the XML.
Robert Harvey
It's not a relational database, it's a custom store and the only way to communicate with it is an internal HTTP service (theoretically, you could read a binary data somewhere from the disk, write a parser for it etc. but I don't want to get into it; an assumption here is the data accessible via HTTP in some custom format).
Borek
For reading the HTTP and consuming it in a meaningful way, I would look into something like the [HTML Agility Pack.](http://htmlagilitypack.codeplex.com/) Writing linq providers is not the simplest thing in the world, but instructions for doing it are [here](http://msdn.microsoft.com/en-us/library/bb546158.aspx) and [here](http://blogs.msdn.com/mattwar/pages/linq-links.aspx).
Robert Harvey
See also http://stackoverflow.com/questions/1223458/smart-way-of-parsing-and-using-website-data
Robert Harvey
+1  A: 

WCF with the REST style webHttpBinding does exactly that - check out the WCF REST Developer Center for a ton of intro articles, blog posts, videos, white papers and so forth.

Building on top of WCF REST, there's also WCF Data Services - formerly known as "Astoria" or ADO.NET Data Services - which offers a uniform access to your data models. It's been formalized into the Open Data Protocol (OData) and is being touted as the next big thing in data access from Microsoft - check it out, well worth a close look!

marc_s
WCF/REST looks *very* interesting from the whitepaper that is linked from the top of the page, thanks for that. However, I really need to be confident that it will solve my problems before I choose WCF - it's a complext technology and that is a handicap all by itself.
Borek
I know about OData and very much like where this is going. However, I'm not sure how easy / difficult is to implement the OData provider. Any idea? (Compared to, say that WCF solution you suggested or a simple ASP.NET MVC + XML Serialization?)
Borek
@Borek: WCF is a very mature, very capable technology. I don't see any danger in choosing it. It's REST support is excellent, and even if that doesn't work out - if you architect your app properly, you could swap out the REST part fairly easily - the URL's will always be the same, more or less...
marc_s
@Borek: WCF Data Services are very easy to implement: define a model (e.g. Linq-to-SQL or Entity Framework), create a WCF Data Service, set some access rules - you're done!
marc_s
From what I've seen WCF code is full of static calls (OperationContext.Something) which is potentially very problematic. There are ways around it, it's just something that a well-architected technology shouldn't do. Things like that make me wonder whether WCF won't actually hurt the overall productivity if I'll need to sort out such deficiencies. But overall, the technology looks like a perfect fit for what I'm looking for so I'm marking this as an answer, thanks.
Borek