5

I am working with some <gulp> legacy code written in .NET 3.5 using ASMX web services.

A windows service (call it FooService) is statically caching an ASMX proxy for a web service (call it BarWS) that it calls in response to client requests around 10-30 times an hour.

Being <gulp> legacy code it is for various reasons incredibly hard to test. I am in the process of breaking dependencies to make it testable and this static reference got me wondering. It's been years since I used ASMX and I recall the proxy is thread-safe - but I wondered if it could become unusuable in the same way that singleton/shared WCF proxies can when they develop an issue and become faulted.

Given the light use of this proxy (BarWS is called less than 30 times/hour), I am thinking it would far safer to create a fresh proxy on every call - but I'm just wondering if I would be making an unnecessary change. Anyone know?

P.S. I know WCF is better, but migration to WCF is too much change right now in this <gulp> legacy codebase.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
James World
  • 29,019
  • 9
  • 86
  • 120
  • 4
    `legacy` and `.NET 3.5`... woah... I feel old! :) – Sam B Feb 03 '11 at 15:08
  • 1
    What is the significance of *legacy code* that it's italicized twice? –  Feb 03 '11 at 15:30
  • 1
    @James: you don't have to change the service to WCF, but consider changing to use a "Service Reference" instead of a "Web Reference". – John Saunders Feb 03 '11 at 19:03
  • @James: you should also quote your `` if you're going to use them. – John Saunders Feb 03 '11 at 19:04
  • 1
    One definition of legacy code is code without tests, hence you can easily write legacy code in .NET 4.0 as well – flq Feb 03 '11 at 19:07
  • FYI:.NET 3.5 is far from "" legacy. It's still supported by microsoft. – capdragon Feb 03 '11 at 19:17
  • .Net 3.5 is pretty close to `` though, just not legacy ``. –  Feb 03 '11 at 20:13
  • 1
    To be fair, most of the legacy code was written in .NET 2.0 and subsequently recompiled later on. The italics emphasis is more that legacy is kind of slang for really REALLY bad untested code (see the seminal "Working with Legacy Code" by Michael Feathers which popularized this definition). Let's just say this proxy appears in a class that contains a method with 8000 lines of code... – James World Feb 03 '11 at 20:24

1 Answers1

5

Measure how long it takes to create a proxy. If it's a false optimization (I strongly suspect it is), then change it to instance based creation. It's generally good to avoid statics. Put it behind a factory, then at least you can still have singleton-type behaviour if you really wanted to, but this creational behaviour would then be masked and independent of the client.

Tim Lloyd
  • 37,954
  • 10
  • 100
  • 130
  • I'm 99% certain it's a false optimization... I like the factory idea a lot though - thanks. I'm voting this answer up, but not ticking it since it doesn't quite nail the question about the proxy instance's reusability after a failure. Thanks! – James World Feb 03 '11 at 20:27
  • @James Sure, I have no idea (can't remember) whether it is stateful. If it is, you obviously have an additional and bigger problem: is it thread-safe? – Tim Lloyd Feb 03 '11 at 20:52
  • MSDN docs claim it is thread-safe - but I've not tested this yet. It's quite tricky to test that and the behaviour under failure since the only implemenation of the service is (of course) a live production service (no WSDL, no source code :) ) No getting away from it, I'll have to reverse engineer a fake for it! – James World Feb 03 '11 at 21:26
  • @James If I remember correctly you can get the wsdl by tacking "?wsdl" onto the service URL. – Tim Lloyd Feb 03 '11 at 21:29
  • Nice idea... if only the web service on the server side didn't appear to be hand-cranked with a custom java implementation. :) – James World Feb 04 '11 at 09:34