Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6778867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:19:03+00:00 2026-05-26T16:19:03+00:00

I’m attempting to put a web service wrapper around several third-party web services. For

  • 0

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:

  1. OrderService
  2. AddressService

Both of these services have the same object defined in different namespaces:

  1. OrderService.AuthenticationParameters
  2. 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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T16:19:04+00:00Added an answer on May 26, 2026 at 4:19 pm

    There are quite a few solutions to this.

    • Have your service proxy classes implement your own interface to expose the methods, and then simply use reflection to build a type.
    • Wrap both services in another class that exposes the methods and has a reference to both services, then simply provide a switching argument to determine which to use.
    • Abstract the use of a service via your own interface and have classes coded against each service explicitly (see below).

    Or if you want to play with dynamic and duck typing, this seemed to work:

    namespace ConsoleApplication42
    {
        class Program
        {
            static void Main(string[] args)
            {
                Type t1 = Type.GetType("ProviderOne.AuthService");
    
                dynamic service = Activator.CreateInstance(t1);
    
                Console.WriteLine(service.GetUsername());
    
                Type t2 = Type.GetType("ProviderTwo.AuthService");
    
                service = Activator.CreateInstance(t2);
                Console.WriteLine(service.GetUsername());
    
                Console.Read();
            }
        }
    }
    
    namespace ProviderOne
    {
        public class AuthService
        {
            public string GetUsername()
            {
                return "Adam";
            }
        }
    }
    
    namespace ProviderTwo
    {
        public class AuthService
        {
            public string GetUsername()
            {
                return "Houldsworth";
            }
        }
    }
    

    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.

    interface IGetUsername
    {
        string GetUsername();
    }
    
    class UsernameViaProviderOne : IGetUsername
    {
        public string GetUsername()
        {
            return new ProviderOne.AuthService().GetUsername();
        }
    }
    
    class UsernameViaProviderTwo : IGetUsername
    {
        public string GetUsername()
        {
            return new ProviderTwo.AuthService().GetUsername();
        }
    }
    

    Then the decision is firmly in your client code and removes the need for reflection/dynamic typing:

    IGetUsername usernameProvider = null;
    
    if (UseProviderOne)
        usernameProvider = new UsernameViaProviderOne();
    
    ...
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string
I am trying to loop through a bunch of documents I have to put

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.