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

  • Home
  • SEARCH
  • 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 501039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:08:56+00:00 2026-05-13T06:08:56+00:00

I have a Windows WCF serivce and Web client. My service has one method

  • 0

I have a Windows WCF serivce and Web client. My service has one method

[OperationContract]
SubmitOrder(OrderInfo info)....

// class used to pass all relevant data
[DataContract]
class OrderInfo
{
 [DataMember]
 OrderType Type;
 // general order data
}

It was great until I have introduced new order types (controlled by OrderInfo.Type property). You can think of new order type as derived from general order (in terms of behaviour).
Each new order has some additional properties. What is the best approach to
implement this polymorphic behaviour of Order?

Currently I simply add new properties to OrderInfo class while adding new orders.

[DataContract]
class OrderInfo
{
 [DataMember]
 OrderType Type;
 // general order data

 // First custom order data
 // Second custom order data
 // TODO - add new properties for new orders
}

I don’t like it much cause it too straight. What if I change [DataContract] and the client
is not rebuilt?

What are my alternatives? I can of course implement inheritance and derive new [DataContract] class like MyCustomOrder1, but inheritance is not supported by serialization, I need to use [KnownTypes] which is forbidden due to some reasons.

  • 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-13T06:08:56+00:00Added an answer on May 13, 2026 at 6:08 am

    Off the top of my head and I’m not sure this is a great idea, but I think a way to do this would be to relax your contracts on the service side, e.g. use a MessageContract instead and accept ‘any’ content in the message. You can still distribute your datacontracts to your clients, so you have the benefit of programming your client against a model. On the service side, you then need to figure out what kind of content the message contains and act accordingly.

    I’m not sure about the details of how to implement this, but I’d start by looking at the Message class in WCF: http://msdn.microsoft.com/en-us/library/ms734675.aspx

    It boils down to using ‘untyped’ messages as explained here: http://geekswithblogs.net/claeyskurt/archive/2008/09/24/125430.aspx as previously discussed here: WCF and Anonymous Types


    A completely different way (and maybe cleaner?) to do this would be to use IExtensibleDataObject as explained in part 2 of this post http://geekswithblogs.net/claeyskurt/archive/2008/05/02/121848.aspx.


    edit: I was reading about data contract versioning and I thought of what could be a better solution

    If for whatever reason you can’t use KnownType, what you’re doing boils down to creating new versions of your contract. The easiest way to start would be to

    • create a single orderinfo contract with all the properties of the subtypes
    • add a ‘type’ property (a string, because you can’t just add new enumerations afterwards, this would be a breaking change)
    • make all the properties that were on the base class ‘required’
    • make all the properties that were on the subtypes ‘optional’
    • implement IExtensibleDataObject to be forward-compatible
    • in our service, use the type property to determine what kind of order it is and act accordingly

    Now, when you’re adding new types, add the new properties to the OrderInfo class, and as long as they are optional and the rest of the class doesn’t change, you’ll be backwards compatible with your clients who don’t have the new version of your contract yet. Yes, it could get messy on the client side, but you can always abstract this away behind some helper classes.

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

Sidebar

Ask A Question

Stats

  • Questions 276k
  • Answers 276k
  • 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 display:inline makes it behave as if it's just another item… May 13, 2026 at 2:43 pm
  • Editorial Team
    Editorial Team added an answer Some projects that require this sort of configuration, and face… May 13, 2026 at 2:43 pm
  • Editorial Team
    Editorial Team added an answer I think Hooked has the right answer, but I think… May 13, 2026 at 2:43 pm

Related Questions

I have a WCF service and am hosting it in a Windows Service. I
I have a web application that is talking to a WCF service hosted within
I have created a WCF service on my local machine. My local machine uses
I have a simple ASP.NET web app which uses a WCF Client to talk
We have a simple ASP.Net WCF Ajax enabled web service which is called via

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.