WCF Serializeable Entity and __BackingField

We have a third-party DLL that contains (among other things) our entities.
All attributes are marked with an attribute [Serializeable].

Now we need to create new WCF services that will expose some of these objects.
The problem is that since entites are not declared with attributes DataContractand DataMember, property names are added with __BackingField!

I know that using the DataContarct \ Member attributes will solve this problem, but given that I cannot modify a third-party DLL with objects, is there another workaround?

+5
source share
3 answers

, [Serializable], , , ( [Serializable] "" ). ( ), k_BackingField, .

, . ( svcutil, Add Service Reference) , , . _BackingField.

:

[Serializable]
public class MyType
{
    public string MyProp { get; set; }
}

[Serializable]
public class MyType
{
    private string <MyProp>k_BackingField;
    public string MyProp
    {
        [CompilerGenerated]
        get { return this.<MyProp>k_BackingField; }
        [CompilerGenerated]
        set { this.<MyProp>k_BackingField = value; }
    }
}
+5

, .

, , , .

:

  • . , , / .
  • .

SOA, , , XSD. , .

, .

, .

+1

You can use the XmlSerializerFormatAttribute to use the XmlSerializer instead of the DataContractSerializer in the service implementation.

It will work slower, but it should solve your problem.

+1
source

All Articles