Click here to Skip to main content
15,881,600 members

WCF serialization for an object with more than one member with same object

impeham asked:

Open original thread
example:
C#
[DataContract]
public class TestObject
{
    [DataMember]
    public string Member1 { get; set; }

    [DataMember]
    public int Member2 { get; set; }

}

[DataContract]
public class TestClass
{
    [DataMember]
    public TestObject MyObject1 { get; set; }

    [DataMember]
    public TestObject MyObject2 { get; set; }
}

TestClass test = new TestClass();

test.MyObject1 = new TestObject();
test.MyObject1.Member1 = "First";
test.MyObject1.Member2 = 100;
test.MyObject2 = test.MyObject1;

The question is - if i send "test" object to a wcf service's method, will the serialization of Member1 and Member2 be doubled (the data will be serialized both for Member1 and Member2 even though they are the same object)?

If this is the case, is there a way to avoid this (serialize the data in MyObject1 once and set MyObject2 to point to the same object in the service side)?
Tags: C#, WCF, Serialization

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900