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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:18:20+00:00 2026-06-13T05:18:20+00:00

at the project I am working on, we have a requirement to have a

  • 0

at the project I am working on, we have a requirement to have a DataContract that can contain some undefined JSON.

The DataMember is some JSON that makes sense to the client only. We want to allow the client to send us json we do not know about.

Example:

public class Contract
{
    [DataMember]
    public int clientId;
    [DataMember]
    public string json;
}

Obviously, having a contract defined like that would require the client to escape the json like this:

{
    "clientId":1,
    "json": "{\"test\":\"json\"}"
}

Obviously, this is not what we need. The json the client should sent us should look like this:

{
    "clientId":1,
    "json": {"test":"json"}
}

Possible solutions we investigated:

  1. use Stream as contract parameters for the request’s body. Works but puts the work on our side instead of using the framework.
  2. Defining “json” as a DynamicObject. Does not work. Was not able to get the property written properly.
  3. Using Newtonsoft library, change the default contract serializer in the WCF endpoint to serialize all inputs to a JObject. We mst also handle serialization on the request, and it causes problems in our application. We’d prefer to avoid this way.

Does anyone have a possible solution to this problem?

EDIT

The service offers rest json resources. It defines a single endpoint with webHttpBinding.
The operation is defined like this (stripped down for simplicity):

[WebInvoke(Method = "POST", UriTemplate = "...", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare)]
[OperationContract]
Stream Create(Contract c);

Also, the service is decorated with following attribute:

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]

Thank you.
JF

  • 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-06-13T05:18:21+00:00Added an answer on June 13, 2026 at 5:18 am

    WCF (as of 4.5) doesn’t support deserializing arbitrary JSON as part of a data contract. You’ll need to use another serializer which does that – JSON.NET is one which I personally like. To be able to change the serializer, you can use a different message formatter, and in the post at https://github.com/microsoftarchive/msdn-code-gallery-community-s-z/tree/master/Supporting%20different%20data%20and%20serialization%20formats%20in%20WCF I have a sample which does exactly that – replaces the default serialization used by WCF with JSON.NET.

    Notice that to receive arbitrary JSON using that library, you’ll need to change the type of the "json" property to the equivalent of arbitrary JSON in JSON.NET, JToken:

    public class Contract 
    { 
        [DataMember] 
        public int clientId; 
        [DataMember] 
        public Newtonsoft.Json.Linq.JToken json; 
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

On the project that I'm currently working I have a requirement to run a
I have a working project that Im amending, it crashes after trying to use
We have a requirement that every piece of code that makes it into production
I am working on my first NHibernate project, and have the following setup/requirement. I
For a JAVA project I am working on there is a requirement that I
I'm working on a project that needs Jasper reporting, I have used the code
As part of a project I'm working on we have a requirement to support
I am working on a project and I have a weird requirement. I have
I have a requirement for the project I'm working on right now which is
In a project I'm working on, there is a requirement to have exposed USB

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.