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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T03:34:59+00:00 2026-05-20T03:34:59+00:00

I have a fair amount of experience with the DataContractSerializer and handling custom type

  • 0

I have a fair amount of experience with the DataContractSerializer and handling custom type serialization using IDataContractSurrogate. Today, I have learned about the new DataContractResolver in .NET 4.0 which seems to provider a similar and more loosely coupled implementation of IDataContractSurrogate.

The problem I have is that I need to supply some custom de/serialization behavior that gets used by a call to Message.GetBody().

The Message payload in question has (among other things) an public read/write property that returns “object”. Contrived example:

public class MessageContents
{
   public int SomeValue { get; set; }
   public object SomeData { get; set; }
}
...
MessageContents entity = new MessageContents { SomeValue = 1, SomeData = new Whatever() };
Message entityMessage = Message.CreateMessage(
   MessageVersion.Soap12WSAddressing10,
   String.Format("{0}Request", operation),
   entity);
...
entityMessage.GetBody<MessageContents>()

The GetBody<>() call throws the normal “can’t deserialized unrecognized type ‘Whatever'” expection. When using the DataContractSerializer directly, I’ve had no problem solving the problem, but since GetBody<>() uses its own DataContractSerializer, how can I affect this deserialization behavior?

The reason I’m dealing with Messages directly is because the service interface in question is returning large amounts of streaming data and WCF requires me to form my operation contract with Message types.

I’ve tried adding a DataContractSerializerOperationBehavior behavior to my service interface (for each operation), but the registered DataContractResolver is never getting fired.

Anyone have any suggestions?

  • 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-20T03:35:00+00:00Added an answer on May 20, 2026 at 3:35 am

    You could use the Message.GetBody<T>(XmlObjectSerializer) method and pass a properly configured instance of the DataContractSerializer class:

    var knownTypes = new string[] { "Whatever" };
    var serializer = new DataContractSerializer(typeof(MessageContents), knownTypes);
    
    MessageContents contents = message.GetBody<MessageContents>(serializer);
    

    Related resources:

    • DataContractSerializer Constructor (Type, IEnumerable<Type>)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a fair amount of experience using MOQ, while I've recently have stumbled
I have a fair amount of JSP and JSF experience. Not so much with
I am fairly new to Perl programming, but I have a fair amount of
I have a custom workflow which requires a fair amount of setup before to
I know a fair amount about the current javascript engines. What techniques have arisen
Im using Doctrine2 and I have a fair amount of model Objects. All the
I'm using handlebars.js on a project and I'm starting to have a fair amount
First off, I'm new to DevExpress. I have done a fair amount of search
Hey everyone. I have a fair amount of experience developing iOS apps, but nothing
OK so I have read a fair amount about SQL Server's locking stuff, but

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.