Re: Base WebService Page and Event?



"lucius" <lucius@xxxxxxxxxxxxxxxx> wrote in message news:jlj493p9vb9t1ifaqvpm9lgj4elunu75u6@xxxxxxxxxx

I have a multiple Framework 2.0 .asmx.cs that have a string input
property called "securityinput" on many WebMethods. Each .asmx.cs
inherits from a base class that inherits from WebService.

I would like to create a custom Event in the constructor of this base
class that would capture/inspect the "securityinput" stuff. Then all
existing child WebService pages, as well as new ones, could have their
security automatically handled without doing their own
security-related method calls within their web methods.

I am forced to evaluate this "securityinput" manually because the web
service lives in a very heterogenous environment and some callers
cannot do anything beyond add securityinput as a parameter.

Is this possible?

Well, sort of.

To generalize your question a little, what you've got is a set of web methods that need common processing before they execute their "real work". You don't want these methods to have to do any work in order to make this happen, yet you need to ensure that the security check always happens.

One of the GOF Design Patterns can be helpful here - the Template Method pattern. It's possible to define a base class with an Execute method. This method can perform all the common steps, then can call an abstract "ExecuteImplementation" method. This can have the code that is specific to each of the particular web methods.

Now, this does mean having a separate small class per web method, but can be worth it. I've implemented a production service this way, and use such a "service layer" to provide common handling of authentication, exception handling, etc.

The nice thing about this technique is that you get to vary the implementation by working with the class hierarchy.

I'll try to post an example of this tonight.
--
John Saunders [MVP]

.


Loading