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 226877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:33:07+00:00 2026-05-11T19:33:07+00:00

I have 2 objects to create that are identical except for that they refer

  • 0

I have 2 objects to create that are identical except for that they refer to my dev and test WCF services. Basically, these are the object for the service itself, and the object for a DTO created by the WCF data-contract.

In my test client, I create either the 2 objects related to the dev WCF service, or the 2 objects related to the test WCF service. I then apply identical logic to both to test my service contract, etc.

What is the best way to structure this using OO principles, preferably without having to write the logic twice?

For reference, here are the objects I’m creating. The first set is from “ASRServiceClient”. The second set comes from “ASRTestServiceClient”.

 ASRService.ASRServiceClient svc = new ASRService.ASRServiceClient();
 ASRService.ASRItem tr1 = new ASRService.ASRItem();
  • 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-11T19:33:07+00:00Added an answer on May 11, 2026 at 7:33 pm

    Why do you need to modify the code in your client based on which service you’re connecting to? Wouldn’t you just be able to have 2 different .config files? One that contains connection for dev service and one that contains connection for test service? Just switch out .config files based on test/dev mode.

    Of course, the contract for your service would be an interface and both dev and test versions of the service use that same contract interface, but that didn’t seem to be what you were asking.

    Edit:

    Extract a ServiceContract Interface for your service if you haven’t already done so. Both your dev and test services should implement the interface. Something like this:

    [ServiceContract(Namespace="http://stackoverflow.com/questions/965977")]
    public interface IASRService
    {
        [OperationContract]
        ASRItem GetASRItem();
    }
    

    Your app.config (or web.config) file for your client should contain something like this where {namespace} is the namespace location of your interface. If you wanted to keep them both in a single .config file, this will work.

    <system.serviceModel>
      <client>
        <endpoint name="ASRService" address="http://yourserver.com/ASRService" 
                  contract="{namespace}.IASRService" binding="basicHttpBinding"/>
        <endpoint name="ASRServiceTest" address="http://localhost/ASRService" 
                  contract="{namespace}.IASRService" binding="basicHttpBinding"/>
      </client>
    </system.serviceModel>
    

    Code in your client that uses the services would look like this. Specify the name of the configuration in the ChannelFactory constructor.

    ChannelFactory<IASRService> cf = new ChannelFactory<IASRService>("ASRService");
    IASRService proxy = cf.CreateChannel();
    
    ASRItem DevServiceItem = proxy.GetASRItem;
    

    OR

    ChannelFactory<IASRService> cfTest = new ChannelFactory<IASRService>("ASRServiceTest");
    IASRService proxyTest = cfTest.CreateChannel();
    
    ASRItem TestServiceItem = proxyTest.GetASRItem;
    

    Since the type of either proxy is always IASRService, the code you have that manipulates the objects only needs to know about that Interface type. It shouldn’t care which version of the service generated the object.

    Also, I would recommend the book Learning WCF by Michele Leroux Bustamante. Great examples on how to do all this stuff!

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

Sidebar

Ask A Question

Stats

  • Questions 123k
  • Answers 123k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You should be able to fake this by using a… May 12, 2026 at 12:54 am
  • Editorial Team
    Editorial Team added an answer the TCP binding uses the binary message encoder by default,… May 12, 2026 at 12:54 am
  • Editorial Team
    Editorial Team added an answer Use this official guide: http://wiki.eclipse.org/Getting_started_with_CDT_development May 12, 2026 at 12:54 am

Related Questions

My program that I am writing's purpose arose with this issue: There are two
(Django 1.x, Python 2.6.x) I have models to the tune of: class Animal(models.Model): pass
I'm trying setup a generic sort of web of related objects. Let say I
If I implement an interface on a base class will it be inherited by

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.