Guest User

Untitled

a guest
Jun 22nd, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.30 KB | None | 0 0
  1. public class WCallUpdate : NotificationData
  2. {
  3. private string m_from = "";
  4. [DataMember]
  5. public string From
  6. {
  7. get { return m_from; }
  8. set { m_from = value; }
  9. }
  10. private WCall m_wCall = new WCall();
  11. [DataMember]
  12. public WCall Call
  13. {
  14. get { return m_wCall; }
  15. set { m_wCall = value; }
  16. }
  17. }
  18.  
  19. /// <summary>
  20. /// Basic class used in the notification service
  21. /// </summary>
  22. [DataContract]
  23. public class NotificationData
  24. {
  25. }
  26.  
  27. /// <summary>
  28. /// Enum containing all the events used in the application
  29. /// </summary>
  30. [DataContract]
  31. public enum NotificationTypeKey
  32. {
  33. [EnumMember]
  34. Default = 0,
  35. [EnumMember]
  36. IWorkQueueServiceAttributionAddedEvent = 1,
  37. [EnumMember]
  38. IWorkQueueServiceAttributionUpdatedEvent = 2,
  39. [EnumMember]
  40. IWorkQueueServiceAttributionRemovedEvent = 3,
  41. }
  42.  
  43. #region Create Message
  44. /// <summary>
  45. /// Creates a memoryStream from a notificationData
  46. /// note: we insert also the notificationTypeKey at the beginning of the
  47. /// stream in order to treat the memoryStream correctly on the client side
  48. /// </summary>
  49. /// <param name="notificationTypeKey"></param>
  50. /// <param name="notificationData"></param>
  51. /// <returns></returns>
  52. public MemoryStream CreateMessage(NotificationTypeKey notificationTypeKey, NotificationData notificationData)
  53. {
  54. MemoryStream stream = new MemoryStream();
  55. BinaryFormatter formatter = new BinaryFormatter();
  56. try
  57. {
  58. formatter.Serialize(stream, notificationTypeKey);
  59. formatter.Serialize(stream, notificationData);
  60. }
  61. catch (Exception ex)
  62. {
  63. Logger.Exception(ex);
  64. }
  65. return stream;
  66. }
  67. #endregion
  68.  
  69. WCallUpdate m_wCallUpdate = new WCallUpdate();
  70. NotificationTypeKey m_notificationTypeKey = new NotificationTypeKey.Default;
  71. CreateMessage(notificationTypeKey , wCallUpdate );
  72.  
  73. System.Runtime.Serialization.SerializationException: Type 'Xxx.DataContracts.WCall' in Assembly 'Xxx.DataContract, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable.
  74. at System.Runtime.Serialization.FormatterServices.InternalGetSerializableMembers(RuntimeType type)
  75. at System.Runtime.Serialization.FormatterServices.GetSerializableMembers(Type type, StreamingContext context)
  76. at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitMemberInfo()
  77. at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter)
  78. at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.Serialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter)
  79. at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Write(WriteObjectInfo objectInfo, NameInfo memberNameInfo, NameInfo typeNameInfo)
  80. at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck)
  81. at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck)
  82. at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph)
  83. at Xxx.Notification.NotificationMessageFactory.CreateMessage(NotificationTypeKey notificationTypeKey, NotificationData notificationData) in Xxx.NotificationNotificationCenter.cs:line 36
  84.  
  85. #region NotificationData
  86. /// <summary>
  87. /// Basic class used in the notification service
  88. /// </summary>
  89. [Serializable]
  90. [DataContract]
  91. public class NotificationData
  92. {
  93. }
  94. #endregion
  95.  
  96. [Serializable]
  97. public class WCallUpdate : NotificationData
  98. {
  99. private string m_from = "";
  100. [DataMember]
  101. public string From
  102. {
  103. get { return m_from; }
  104. set { m_from = value; }
  105. }
  106. private WCall m_wCall = new WCall();
  107. [DataMember]
  108. public WCall Call
  109. {
  110. get { return m_wCall; }
  111. set { m_wCall = value; }
  112. }
  113. }
  114.  
  115. #region DataContractSerializer
  116. /// <summary>
  117. /// Creates a Data Contract Serializer for the provided type. The type must be marked with
  118. /// the data contract attribute to be serialized successfully.
  119. /// </summary>
  120. /// <typeparam name="T">The type to be serialized</typeparam>
  121. /// <returns>A data contract serializer</returns>
  122. public static DataContractSerializer CreateDataContractSerializer<T>() where T : class
  123. {
  124. DataContractSerializer serializer = new DataContractSerializer(typeof(T));
  125. return serializer;
  126. }
  127. #endregion
  128.  
  129. AA D1=new AA(); //Derived type
  130. BB D2=new BB(); //Derived type
  131. CC D3=new CC(); //Derived type
  132. X D4=new X(); //Base Class
  133.  
  134. XList<X> AllData=new XList<X>();
  135. AllData.Add(D1);
  136. AllData.Add(D2);
  137. AllData.Add(D3);
  138. AllData.Add(D4);
  139. // -----------------------------------
  140. AllData.Save(@"C:TempDemo.xml");
  141. // -----------------------------------
  142. // Retrieve data from XML file
  143. // -----------------------------------
  144. XList<X> AllData=new XList<X>();
  145. AllData.Open(@"C:TempDemo.xml");
  146. // -----------------------------------
Add Comment
Please, Sign In to add comment