none
Initializing data contract type as singleton or static RRS feed

  • Question

  • Hello,

    I have a data contract that has values that never changes.  It is actually the header that identifies my financial institution to our vendor.

    It is something like this:

    Header_Type header= new Header_Type();
    header.Version= "myVersion";

    Client_Info client= new Client_Info();
    client.ID= "myID";
    client.Database= "myDatabase";

    header.Client= client;

    None of the header information changes in any operation calls.  For efficiency, I was considering initializing either a static variable or Singleton and setting the value when my service started and then using it in all future operations.

    Is there a downside to doing this?  And, if not, would it be better to use a static variable or a Singleton?

    Thanks much!!!!


    • Edited by Hiline1961 Monday, March 9, 2015 5:34 PM
    Monday, March 9, 2015 5:34 PM

Answers

  • Try using NetDataContractSerializer-
    The NetDataContractSerializer differs from the DataContractSerializer in one important way: the NetDataContractSerializer includes CLR type information in the serialized XML, whereas the DataContractSerializer does not. Therefore, the NetDataContractSerializer can be used only if both the serializing and deserializing ends share the same CLR types.
    The serializer can serialize types to which either the DataContractAttribute or SerializableAttribute attribute has been applied. It also serializes types that implement ISerializable.

    Windows Phone/Windows Store

    Tuesday, March 10, 2015 6:55 AM

All replies

  • Try using NetDataContractSerializer-
    The NetDataContractSerializer differs from the DataContractSerializer in one important way: the NetDataContractSerializer includes CLR type information in the serialized XML, whereas the DataContractSerializer does not. Therefore, the NetDataContractSerializer can be used only if both the serializing and deserializing ends share the same CLR types.
    The serializer can serialize types to which either the DataContractAttribute or SerializableAttribute attribute has been applied. It also serializes types that implement ISerializable.

    Windows Phone/Windows Store

    Tuesday, March 10, 2015 6:55 AM
  • Thank you!
    Monday, March 16, 2015 2:59 PM