0

It's been a long time since I worked with SOAP so my question might be trivial but I just wasn't able to find a satisfying answer so far!

Anyways here's what's going on:

  • I got access to a system via SOAP endpoints (Dev, Test and Prod)
  • I used svcutil to create proxy classes (they are almost identical, only few lines difference)
  • I created an interface for my SOAP operations and implemented one class for each environment (Dev/Test/Prod)

Now I do like that I have separate classes since we might do logging or whatever in a different manner in production environment, however the business logic is pretty much the same but reusing the code doesn't seem feasable... even though the generated classes are the same, they live in different namespaces and I don't really want to touch generated code!

If they used REST it wouldn't be a problem but I'm having trouble to solve this problem gracefully with SOAP. How would you approach this?

EDIT: I am aware that the obvious simple solution would be to generate proxy class only once and use them for all the environments. However I'm not sure if that's the right approach since the different endpoints might change (although I would prefer of course if the API provider would make sure they're always identical but not sure if that's always possible in real life scenarios!)

LazarQt
  • 1
  • 1
  • If they *were* different, what use would they be? – Caleth Nov 07 '22 at 11:19
  • Are you developing a different piece of software for all three environments? Or three variants of the same software which correspond to the three API endpoints, Or do you develop one software which can be configured to switch between the three endpoints? – Doc Brown Nov 07 '22 at 15:37
  • ... and I am not a SOAP expert. For a noob like me, can you please explain some details why for a REST API this would not be a problem, but for a SOAP API it is? – Doc Brown Nov 07 '22 at 15:38
  • Can you use `partial` classes? Usually the way you get around the "I don't really want to use generated code" problem is to create a partial class whose name matches the generated class. – Robert Harvey Nov 07 '22 at 16:35
  • @RobertHarvey: it sounds like the OP had to change the namespace in the generated code (though I am not sure, question is missing too many details and lacks an example). Partial classes don't seem to be the right tool for that. – Doc Brown Nov 07 '22 at 17:30
  • 2
    "implemented one class for each environment (Dev/Test/Prod)" That is almost certainly not the right approach. You should be able to use a single class for all the environments. You can set the URL transparently via configuration, or set the URL with [runtime logic](https://stackoverflow.com/questions/5036308/dynamically-switch-wcf-web-service-reference-url-path-through-config-file) (that would probably read configuration). – John Wu Nov 08 '22 at 00:02
  • @Caleth I assume one use would be to test new endpoints (or changes) in dev environment before prod is updated. – LazarQt Nov 08 '22 at 08:12
  • @DocBrown I'm developing software that can be configured to switch between endpoints. For REST API it's easier because I'm not bound to the contract provided by proxy classes, I just send a serialized payload. – LazarQt Nov 08 '22 at 08:13
  • @RobertHarvey They are already partial but in different namespaces. – LazarQt Nov 08 '22 at 08:13
  • @JohnWu This is what I initially wanted to do but after proxy class generation I tried to find a different approach because the proxy classes are not EXACTLY the same. Altough that might not be best practice for an API provider in which case I should just inform them about it I guess and hope that their goal is to provide endpoints that match. – LazarQt Nov 08 '22 at 08:13
  • 1
    If you're pulling WSDL files from prod vs test vs dev and they are different, they may be on different builds. You should ask your service provider which one you should be using. In most cases you should pull it from production, since that is guaranteed to be supported. Just build the one proxy from the agreed location and use that one. If there are environmental/compatibility issues that is a process issue, not something to be solved in your code. In most cases. – John Wu Nov 08 '22 at 08:36
  • Is the namespace really important? Is there a hard technical problem for doing what John Wu wrote in the former comment: using the proxy classes from PROD when connecting to DEV or TEST (assumes the APIs for all 3 environments are essentially the same)? – Doc Brown Nov 08 '22 at 09:17
  • @JohnWu Makes sense to me, thank you. I know it seems very obvious and I feel silly for asking I just wasn't sure if that's something that SOAP endpoints usually do (for example: Have separate fields for different environments for whatever reason so I have to make sure to send the appropriate proxy class object) – LazarQt Nov 08 '22 at 11:36
  • @DocBrown No it's not important, it's just the approach I used to initially differentiate between the three environments. I thought I'd rather ask a silly question here first and THEN reach out to the service provider, because that's what stackoverflow & co. is for right, not embarrassing yourself in front of colleagues? Right? – LazarQt Nov 08 '22 at 11:38

0 Answers0