Procedural wrapping of web methods

R

Ralph Mack

Hello, all,

I have a web service that has a piece of code that really bothers me.
The web service has many methods (probably far too many really), all of
which have very different parameters. To do the real work of these
methods, I have them fan out to several classes underneath the web
service, each responsible for different areas. Thus, all of the web
service methods have basically the same structure:

* Each method has about four levels of nesting, involving:
* a mutex to serialize access.
* all of the protection code needed to ensure that an
appropriate SoapException is generated on any failure.
* allocating a database reference
* insurance that both the database reference and the lock are
safely released no matter what happens during the execution
of the method.

* In the middle of this deep nest, each method allocates an object to
use to perform the "real work" of the method and then calls a method on
that object that looks like the original method call.

* Different groups of methods within the service use different objects
to do the work, but all of these "real work" objects have a common
constructor "signature".

With the number of methods in the web service, all of this code gets
quite large but, aside from the selection of the object to allocate and
the invocation of the method, it is all tediously identical.

Now it seems to me that, with all the metadata tools like delegates,
BeginInvoke & EndInvoke, and reflection, it ought to be possible to
abstract all those nested layers into a single method and pass it the
class to create, the method to invoke, and the parameters to supply to
the relevant method.

I could do something ugly with an array-of-variant, but it might well
get as big as the current solution and it would be difficult to make it
typesafe. What I want to do is pick up the parameter list of the
original method and dump it into the relevant method with all of the
late binding checking that the CLR should provide to ensure that the
parameter set matches the parameter set of the method invoked.

With the right stuff in place, I should be able to reduce the code in
the web service class to about four lines per method, a substantial
improvement in maintenance and readability.

So I've got all of these tools in front of me, I think I mostly know how
to use them, but I can't seem to figure out how to put the pieces
together. Can somebody give me a hint?

Ralph
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top