PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, October 20, 2022

[FIXED] how to WCF dynamic DataMember?

 October 20, 2022     datacontract, datamember, json, wcf     No comments   

Issue

example: a Customer class have 100 data member(id, name, age, address...etc) to be serialization to JSON.

In Config file such as Web.config, can set a output list to serialize JSON ouptut.

If output only id and name, then JSON only have id and name.

My Question: Can support dynamic DataMember in a DataContract ?


Solution

You mean optional datamembers, I guess so, check this question Surely you'll have to have null values for the ones you dont want to send over the wire. Another, more dirtier, solution would be to use a dictionary as a datamember and have the fields you want to send as elements there. There may be type conversion issues, but maybe it serves you better.

Edit:

You probably want to go with a dictioray serialized as an associative array en js, as this question specifies. Check the answers and the links in there. That should get you going. But still I'd go with optional datamembers since it's more of a "contract" thing. Other than that a better description of what you want to do will help.



Answered By - Carlos Grappa
Answer Checked By - Clifford M. (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing