473,395 Members | 1,418 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Web Service with base class

I have a bunch of web services that are used to return data. All of the
methods access a DB to get the data. Ideally I would like to have them
inherit from a base class that takes care of the DB connection and
exception logging.

By default in VS.NET all web service classes inherit from
System.Web.Services.WebService. My understanding is that the main
benefit of this is you get access to the Application and Session
objects. But a web service does not need to inherit from this class to
work. VS.NET generates code that overrides the Dispose method of this
inhertited class so I can not even compile without inheriting.

So as I see it I could
A) Figure out how to make my web service classes work without
inheriting from System.Web.Services.WebService and then inherit from a
base class that takes care of DB connections and logging.

B) Use Microsoft's Data Access Application Block to take care of DB
connection and paramter caching and find another way to deal with
logging.

Anyone have any recommendations? Is there another way to do this? How
can I achieve A)

Thanks in advance,
Rupert

Nov 23 '05 #1
6 3968
On 26 Jan 2005 17:25:28 -0800, ru*********@hotmail.com wrote:
I have a bunch of web services that are used to return data. All of the
methods access a DB to get the data. Ideally I would like to have them
inherit from a base class that takes care of the DB connection and
exception logging.

By default in VS.NET all web service classes inherit from
System.Web.Services.WebService. My understanding is that the main
benefit of this is you get access to the Application and Session
objects. But a web service does not need to inherit from this class to
work. VS.NET generates code that overrides the Dispose method of this
inhertited class so I can not even compile without inheriting.

So as I see it I could
A) Figure out how to make my web service classes work without
inheriting from System.Web.Services.WebService and then inherit from a
base class that takes care of DB connections and logging.

B) Use Microsoft's Data Access Application Block to take care of DB
connection and paramter caching and find another way to deal with
logging.

Anyone have any recommendations? Is there another way to do this? How
can I achieve A)


I recommend you pursue B. An object should know how to do one thing, and
do it well. The webservice class should know how to process and respond to
webservice requests. That's it. If you need to access a database, then
you should have another class or set of classes that know how to do that,
and they should do it well. If you need to do some logic processing on the
data after it is retrieved from the database and before the webservice
returns it to the caller, then that should be in another class that just
knows how to do the business logic processing.
--
Tom Porterfield
Nov 23 '05 #2
HG
Hi

I would go for option 2, too.

But use the business delegate pattern wthin the webMethod.
That way you can delgate your call to another class (interface, maybe).

I have done this with an interface as the delegate and a factory that
instatiates the correct instance of class which supports delegate interface.
Gives you the opportunity to change the actual implementation class while
still using the same interface to your delegate.

Regards

Henrik
http://websolver.blogspot.com

<ru*********@hotmail.com> skrev i en meddelelse
news:11*********************@z14g2000cwz.googlegro ups.com...
I have a bunch of web services that are used to return data. All of the
methods access a DB to get the data. Ideally I would like to have them
inherit from a base class that takes care of the DB connection and
exception logging.

By default in VS.NET all web service classes inherit from
System.Web.Services.WebService. My understanding is that the main
benefit of this is you get access to the Application and Session
objects. But a web service does not need to inherit from this class to
work. VS.NET generates code that overrides the Dispose method of this
inhertited class so I can not even compile without inheriting.

So as I see it I could
A) Figure out how to make my web service classes work without
inheriting from System.Web.Services.WebService and then inherit from a
base class that takes care of DB connections and logging.

B) Use Microsoft's Data Access Application Block to take care of DB
connection and paramter caching and find another way to deal with
logging.

Anyone have any recommendations? Is there another way to do this? How
can I achieve A)

Thanks in advance,
Rupert

Nov 23 '05 #3
Hello ru*********@hotmail.com,
As I see it you need all web services to use the same database code via
inheritance [0]. Not a bad thing, but you will see the impact of that decision
when the data access methods change. All the services will potentially need
to change purely because of the fact they are inherited. Consider the option
B you suggested (composition) [0]. Use DAAB if you add a 'non-breaking' change
to DAAB or alter the implementation you dont need to recompile all your services,
just replace your DAAB assembly.

the example is in java but its an oo concept ;)
[0] - http://www.javaworld.com/javaworld/j...echniques.html
HTH
Regards,
Dilip Krishnan
MCAD, MCSD.net
dkrishnan at geniant dot com
http://www.geniant.com
I have a bunch of web services that are used to return data. All of
the methods access a DB to get the data. Ideally I would like to have
them inherit from a base class that takes care of the DB connection
and exception logging.

By default in VS.NET all web service classes inherit from
System.Web.Services.WebService. My understanding is that the main
benefit of this is you get access to the Application and Session
objects. But a web service does not need to inherit from this class to
work. VS.NET generates code that overrides the Dispose method of this
inhertited class so I can not even compile without inheriting.

So as I see it I could
A) Figure out how to make my web service classes work without
inheriting from System.Web.Services.WebService and then inherit from a
base class that takes care of DB connections and logging.
B) Use Microsoft's Data Access Application Block to take care of DB
connection and paramter caching and find another way to deal with
logging.

Anyone have any recommendations? Is there another way to do this? How
can I achieve A)

Thanks in advance,
Rupert

Nov 23 '05 #4
HG
Or even better...You composition is an Interface.

That way you can change the underlying implementation of the class

Regards

Henrik
http://websolver.blogspot.com

"Dilip Krishnan" <dk*******@NOSPAM.geniant.com> skrev i en meddelelse
news:22**********************@msnews.microsoft.com ...
Hello ru*********@hotmail.com,
As I see it you need all web services to use the same database code via inheritance [0]. Not a bad thing, but you will see the impact of that decision when the data access methods change. All the services will potentially need to change purely because of the fact they are inherited. Consider the option B you suggested (composition) [0]. Use DAAB if you add a 'non-breaking' change to DAAB or alter the implementation you dont need to recompile all your services, just replace your DAAB assembly.

the example is in java but its an oo concept ;)
[0] - http://www.javaworld.com/javaworld/j...echniques.html
HTH
Regards,
Dilip Krishnan
MCAD, MCSD.net
dkrishnan at geniant dot com
http://www.geniant.com
I have a bunch of web services that are used to return data. All of
the methods access a DB to get the data. Ideally I would like to have
them inherit from a base class that takes care of the DB connection
and exception logging.

By default in VS.NET all web service classes inherit from
System.Web.Services.WebService. My understanding is that the main
benefit of this is you get access to the Application and Session
objects. But a web service does not need to inherit from this class to
work. VS.NET generates code that overrides the Dispose method of this
inhertited class so I can not even compile without inheriting.

So as I see it I could
A) Figure out how to make my web service classes work without
inheriting from System.Web.Services.WebService and then inherit from a
base class that takes care of DB connections and logging.
B) Use Microsoft's Data Access Application Block to take care of DB
connection and paramter caching and find another way to deal with
logging.

Anyone have any recommendations? Is there another way to do this? How
can I achieve A)

Thanks in advance,
Rupert


Nov 23 '05 #5
Hello HG,
Or even better...You composition is an Interface.


IMO If the idea is to reuse code that that wouldnt make sense. then
every class has to implement this interface. In general you need to seperate
layers of responsibility, so the rule of is, if your class is a math web
service. Any authentication function of that service should be in a seperate
'helper' class implementation (with its own inheritance heirarchy i.e. IAuthentication
interface WindowsAuthentication Implementation etc) and the service should
be composed of these 'helpers' That way your service can chance independent
of the authentication mechanism. Makes sense?

HTH
Regards,
Dilip Krishnan
MCAD, MCSD.net
dkrishnan at geniant dot com
http://www.geniant.com

Nov 23 '05 #6
Thank you all for your replies.I am new to the OO world and these
replies are helpful. I am not familiar with the business delegate
pattern but I will look into it.

I had read articles such as this
http://www.c-sharpcorner.com/Tutoria...3TierAppPA.asp
but of course this was no written with the DAL being web services
(client choice) in mind.
Rupert

Nov 23 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: PatrickSA | last post by:
Hi, Am new to web services, so apologies for the basic nature of the question - and apologies in advance if this is the wrong newsgroup. We're building a new web service and I'm looking around...
3
by: Jeremy S. | last post by:
On my dev machine (XP/Pro with VS.NET 2003) I have been developing a Windows Service and installing it on the local machine by opening the Visual Studio Command Prompt and then executing . Now I...
2
by: Fan Wang | last post by:
Hi All, I wrote a windows service with C# as below. But I can't install it with installutil.exe. I got an error message " Exception occurred while initializing the installation:...
3
by: Marty McDonald | last post by:
Using Visual Studio.Net... I have two classes, one derives from the other. My web service accepts the base class as input, it returns the derived class as the return value. When I set a web...
2
by: letibal | last post by:
Hello, I have written a windows service and created an installer for it. The service runs under the system accounts. When started, it launches a GUI. By default, the InteractiveProcess property...
3
by: dr | last post by:
I created a basic service using VS2005. Add OnPowerEvent method as detailed on MSDN and return false to a PowerBroadcastStatus.QuerySuspend notification. The service also has set...
6
by: dotNeter | last post by:
The services, talked here, are things used in IServiceContainer, IServiceProvider, etc. In my opinion, everything can be a service, and a service is generally used for providing specific features...
3
by: Jeremy Chapman | last post by:
I've writtin a very simple web service in axis which returns an array of classes. I consume it in a .net app. When receiving the response, my .net app generates an error "Cannot assign object...
0
by: =?Utf-8?B?QW5keSBZdQ==?= | last post by:
Hi, I'm trying to return exceptions from a WCF Service using FaultExceptions. I got the service compiled and running. But I get an error while adding a service reference to it. The error reads: "...
0
by: =?Utf-8?B?U2ltb25EZXY=?= | last post by:
Hi All I would like to install the same Windows Service project on the same server under different names, one for each customer. I have been able to do it but I would like an expert opinion as...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.