0

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?

Tim Lloyd
  • 37,954
  • 10
  • 100
  • 130
Mr Shoubs
  • 14,629
  • 17
  • 68
  • 107
  • Are you using a Service Reference or a Web Reference? Service Reference gives you many more tools to do what you want. – John Saunders Jul 28 '11 at 15:17
  • Web Reference, our client base use .net 2. – Mr Shoubs Jul 28 '11 at 15:37
  • 1
    That's too bad. You should consider getting them up to .NET 3.5 - it's just .NET 2.0 Service Pack 2 plus some new assemblies - including WCF. You would be able to write some central code to do this sort of cross-cutting concern without having to write wrappers for ever operation. – John Saunders Jul 28 '11 at 17:00
  • I know, but getting 1000's of independent companies to upgrade is a lot of work. :( new customers must have .net 4 installed, so eventually... one day... :) – Mr Shoubs Jul 28 '11 at 17:04
  • 1
    Do you use an installer technology? You can make the .NET 3.5 redistributable be a dependency. Next time they upgrade your software, they get .NET 3.5. Alternatively, you could make this new feature (retries, etc.) be dependent on .NET 3.5, so if they don't want the new feature, they don't need .NET 3.5. But if they install the new feature, they get .NET 3.5. – John Saunders Jul 28 '11 at 17:07
  • We do for new installs, but to update we have our own updater tool as we had a lot of problems with proxies in the past. Also customers get a bit annoyed if we mess with anything that is installed on client machines :/ – Mr Shoubs Jul 28 '11 at 17:12
  • @JohnSaunders let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/1930/discussion-between-mr-shoubs-and-john-saunders) – Mr Shoubs Jul 28 '11 at 17:13
  • always wondered what that link did... – Mr Shoubs Jul 28 '11 at 17:14

1 Answers1

1

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();
    }
}
Bas
  • 26,772
  • 8
  • 53
  • 86