views:

761

answers:

3

I am currently doing a CRUD project for school and basically they want us to have this kind of structure (3 projects):

  • Class Library
    • Contains all the Data Access logic (Retrieving the data from the database with either Linq of standard ADO.Net)
  • Web Service
    • Having a reference to the Class Library and offering [WebMethod]s that access the methods from the Class Library
  • ASP.Net Website
    • Having a Service Reference to the Web Service and using the WebMethods to retrieve the data

Which basically means that we cannot access the Class Library directly from the Website:

Website
       \
        \
         Web Service
                    \
                     \
                      Class Library


Now of course there are multiple solutions to choose from as to provide abstraction in the Web Service to seperate for example methods that retrieve the Articles and methods to retrieve the Categories (which are two different entiries and have two seperate classes in the Class Libary):

  • I can either do one webservice which will have all the methods (GetAllArticles, GetAllCategories, GetArticleByID etc...) and the Website only makes a reference to this one web service. But ofcourse this will result in having All the methods in a single class (ie a single web service)
  • Or I can create multiple web services (Articles.asmx, Categories.asmx etc...) and reference all of them from the website and then call the one I need depending on what data I need to retrieve.

But I mean for me, the above solutions are not really ideal because if I have the first solution, I will have a ton of methods all in one class (no abstraction whatsoever) and in the second solution, I will have to reference about 10 different web services from the website (one for Articles, one for Categories etc...)

At school they told us to use the Web Service (or Web Services) to access the class library, and then retrieve the data from the class library using the Webmethods...but both solutions I mentioned earlier on seem a bit dodgy.


So people, can you please suggest to me a better way of how I might go about in implementing this structure?

+3  A: 

In your example you suggested one service for Articles and one service for Categories. That may of course be just an example, but in that case it would not make sense to separate them, because it would be quite likely and common to have queries and/or routines which make use of both Category data and Article data.

With that in mind, it usually makes the most sense to group routines by the degree to which they are related to one another. If you can separate all your possible routines into, say, three clean groups with little to no overlap, then it makes sense to have three services. If you cannot cleanly separate any of your routines, you should limit yourself to one web service.

But regarding your statement "No abstraction" being a downside of one web service - that isn't necessarily true. You can always create layers of abstraction behind the web service, so that the service class itself is simply a facade with many thin method calls that reach into bulkier logic elsewhere.

In the end, the only approach which truly matters because it's the only approach which works is this: take the simplest approach possible, only build what you need to build in as few layers as you can; only add complexity when you reach a problem which cannot be solved in a better way than by adding that complexity. It is always easier to add complexity than to take it away.

Rex M
+1, because I agree that layers of abstraction go behind the web service (into the DAL in this example, as there's no separate business logic layer).
Pawel Krakowiak
Thanks for the advice. I now have multiple classes in the web services that abstract the logic for artists, albums etc...and the web service is just a facade for all those methods
Andreas Grech
A: 

I would put all the webmethods into the same class. The webmethods should only be wrappers around you business classes plus whatever input validation and authorisation you need.

Since web services are generally used by mahcines and not humans there is no pressing need for a hierarchy. It can become a burden to manage the URLs and web server if you create a webmethod class per business class.

If you are planning on using the HTML page that browsers automatically generate to call your web services as your main user interface you need to be a little bit careful. For example you won't be able to rely on SOAP headers if you need to authenticate requests.

sipwiz
A: 

Why not use ADO.Net Data Service?

staceyw