Visual Studio regex replace for 7 year old issue...

Wed, Nov 13, 2019 2-minute read

I still work on a lot of old technology. Today I was updating one of my client’s systems that consumes a (3rd party) web service - the service was moving from -gasp- anonymous auth to requiring a username and password. (Sent in plain text over non-SSL, mind, but… baby steps. I’m guessing this was good enough to close an audit point.)

The original implementation used the old Visual Studio ‘Web Service reference' (for old style SOAP .asmx) which was replaced sometime later by ‘Service Reference' and intended for anything implementing the WCF protocol. The old style didn’t support the WSE security stuff, whereas the newer did.

I replaced the reference and, after a bit of jiggery pokery ( got it sort of working.

Except for then hitting an issue where the data back from the new service call was… missing. It was all there in a base objects, just not in the complex object as usual. It smelt like a deserialisation issue… and it was a deserialisation issue: (TL;DR - the WCF implementation expected the XML in the SOAP response to come back in a specific order. If it didn’t come back in the right order, it fell over. Obvious really. The fix is to remove the attributes that tell the XML deserialiser which order to expect things.)

The solution posted worked perfectly - even if it was written 7 years ago. To fix approx 7/8 year old code. Sigh. It’s a win, I guess.

But on a positive note, it did remind me that Find/Replace in Visual Studio supports regular expressions - so hunting for Order={n} throughout the Reference.cs was simple with Order=[0-9] (with use regular expressions ticked) - just Search/Replace through and fairly quickly things are back and working again.