ASMX Web Service - Intercept every call and alter parameter

Viewed 250

I have a couple of different asmx web services that I need to extend with a certain behaviour. I need to be able to access the passed in parameters and change them in certain conditions.

I tried to implement a SoapExtensionAttribute but that didn't work. My SoapExtension was never called and I believe the reason behind that is that I can't configure it on the client side because I don't have access there.

Is there a way to hook into the web service calls and change the parameters before the method is executed? I really don't want to put the same code in the beginning of every web service method...

Here an example of what I would have to do if I don't find a better solution:

[WebService(Namespace="MyWebServices", Description="MyWebService")]
public class MyWebService : System.Web.Services.WebService
{
    ...

    [WebMethod]
    public string MyWebServiceMethod1(string parameter)
    {
        ChangeParameter(parameter);

        return "Hello this is my WebService";
    }

    [WebMethod]
    public string MyWebServiceMethod2(string parameter, string parameter2)
    {
        ChangeParameter(parameter);
        ChangeParameter(parameter2);

        return "Hello this is my WebService";
    }

    ...
}
0 Answers
Related