Search code examples
.netvb.netweb-servicesproxy-classes

Extending web service proxy classes


I need to add functionality to my web service calls so object translation and automatic retries are done and abstracted away.

I would usually override the base class to add the extra functionality, but as the proxy methods aren't over-ridable I can't keep the method names the same. The only other option I can think of to do it this way is to use the 'Shadows' keyword to achieve what I want. Now I don't like the idea of shadows as it isn't particularly OOP, but in this case it seems to make a neat solution.

What other methods do people use to add functionality to their web service proxy classes without modifying the generated classes?


Solution

  • You can use the Composition over Inheritance principle to achieve this. E.g. write a wrapper around your Web Service to obtain the desired functionality.

    Update: code sample

    interface IWebService
    {
        void DoStuff();
    }
    
    public class MyProxyClass
    {
        IWebService service;
    
        public void DoStuff()
        {
            //do more stuff
            service.DoStuff();
        }
    }