c# - Choose 'using' namespace at runtime -


I have a web service client application that connects to the 3rd party web service. Third party has updated its web service, so now my client application fails with SOAP exceptions. Unfortunately, I can not just update my app to work with a new web service because some of my users will still be using the old web service. So basically I would like to be able to work with any version of the web service using a version of my client app.

Since the Visual Studio generates a bunch of code which I compile with a web reference added, I now have two files: an API generated for each version of a web service Both are really same, they are just the underlying SOAP messages that have changed. I have put these generated files in my own namespace to avoid collisions. So now I would like to be able to choose which namespace (based on configurable parameters) used in that order.

For example:

  OldVersionNamespace using (used wordpress); Using other NewVersionNamespace; Obviously, this will never work because there will be no way to compile the code which refers to the elements present in this namespace. Is there an easy way to deal with this issue? Maybe I can use reflection in order to do for me? 

The only thing I can think of is to actually copy / paste my existing code into two separate files, the only difference is that the namespace used on top is actually a very bad idea. , Though seems to be.

Apply a common interface to both sets of generated sections, it is very easy with partial types - you There is no need to change the generated class at all, just create a suitable interface and then the same type of file as the generated, say that they implement the interface.

You code for the interface, and choose which implementation to take to a single location based on a config file.

The addition benefit is that you can write unit tests against your code, you can joke out of the web service.


Comments