I’m attempting to put a web service wrapper around several third-party web services. For the sake of this question, we’ll work with two of them:
- OrderService
- AddressService
Both of these services have the same object defined in different namespaces:
- OrderService.AuthenticationParameters
- AddressService.AuthenticationParameters
I was hoping to be able to create a single base class that would be able to detect/switch between namespaces. For example:
public abstract class BaseLogic
{
internal BaseLogic()
{
/* Initialize authParams */
//Switch out / detect namespace here
this.authParams = new OrderService.AuthenticationParameters();
this.authParams.accountName = "[MyAccountName]";
this.authParams.userName = "[MyUserName]";
this.authParams.password = "[MyPassword]";
}
}
I’ve seen several similar questions. Either they don’t apply to my situation, or I’m incapable of understanding them.
Question: Is what I’m trying to achieve possible? If it’s possible, am I over complicating things?
Additional Info: Eventally, there will be more than two services that share this common object. The vendor provides a separate service URL for each branch of functionality they provide.
There are quite a few solutions to this.
Or if you want to play with dynamic and duck typing, this seemed to work:
Bear in mind they all hinge on both services having the same signature.
As for the other services in future, it really depends. I’ve never really encountered a need to dynamically switch from one service to another to get slightly different behaviour in achieving the same thing.
Perhaps this should be driven from your app’s side? Instead of a service being chosen to suit, simply implement two versions of the class that has this changing behaviour – put a common interface on it, and decide which of your classes to use at runtime. The class itself will then be coded directly against one of the services.
Then the decision is firmly in your client code and removes the need for reflection/dynamic typing:
To labour the point, you could always get very SOA and create yet another service that your app talks to that aggregates the other two services. Then at least your client code doesn’t see the huge number of different services and talks to just one.