SoapCore.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. //
  2. // System.Runtime.Remoting.Channels.SoapCore.cs
  3. //
  4. // Author: Lluis Sanchez Gual ([email protected])
  5. //
  6. // 2003 (C) Copyright, Novell, Inc.
  7. //
  8. using System.Collections;
  9. using System.Runtime.Remoting.Messaging;
  10. using System.Runtime.Serialization;
  11. using System.Runtime.Serialization.Formatters;
  12. using System.Runtime.Serialization.Formatters.Soap;
  13. namespace System.Runtime.Remoting.Channels
  14. {
  15. internal class SoapCore
  16. {
  17. SoapFormatter _serializationFormatter;
  18. SoapFormatter _deserializationFormatter;
  19. bool _includeVersions = true;
  20. bool _strictBinding = false;
  21. #if NET_1_1
  22. TypeFilterLevel _filterLevel = TypeFilterLevel.Low;
  23. #endif
  24. public static SoapCore DefaultInstance = new SoapCore ();
  25. public SoapCore (object owner, IDictionary properties, string[] allowedProperties)
  26. {
  27. foreach(DictionaryEntry property in properties)
  28. {
  29. string key = (string) property.Key;
  30. if (Array.IndexOf (allowedProperties, key) == -1)
  31. throw new RemotingException (owner.GetType().Name + " does not recognize '" + key + "' configuration property");
  32. switch (key)
  33. {
  34. case "includeVersions":
  35. _includeVersions = Convert.ToBoolean (property.Value);
  36. break;
  37. case "strictBinding":
  38. _strictBinding = Convert.ToBoolean (property.Value);
  39. break;
  40. #if NET_1_1
  41. case "typeFilterLevel":
  42. if (property.Value is TypeFilterLevel)
  43. _filterLevel = (TypeFilterLevel) property.Value;
  44. else {
  45. string s = (string) property.Value;
  46. _filterLevel = (TypeFilterLevel) Enum.Parse (typeof(TypeFilterLevel), s);
  47. }
  48. break;
  49. #endif
  50. }
  51. }
  52. Init ();
  53. }
  54. public SoapCore ()
  55. {
  56. Init ();
  57. }
  58. public void Init ()
  59. {
  60. RemotingSurrogateSelector surrogateSelector = new RemotingSurrogateSelector ();
  61. StreamingContext context = new StreamingContext (StreamingContextStates.Remoting, null);
  62. _serializationFormatter = CreateFormatter (surrogateSelector, context);
  63. _deserializationFormatter = CreateFormatter (null, context);
  64. #if NET_1_1
  65. _serializationFormatter.FilterLevel = _filterLevel;
  66. _deserializationFormatter.FilterLevel = _filterLevel;
  67. #endif
  68. }
  69. SoapFormatter CreateFormatter (ISurrogateSelector selector, StreamingContext context)
  70. {
  71. SoapFormatter fm = new SoapFormatter (selector, context);
  72. if (!_includeVersions)
  73. fm.AssemblyFormat = FormatterAssemblyStyle.Simple;
  74. if (!_strictBinding)
  75. fm.Binder = ChannelCore.SimpleBinder;
  76. return fm;
  77. }
  78. public SoapFormatter GetSafeDeserializer ()
  79. {
  80. StreamingContext context = new StreamingContext (StreamingContextStates.Remoting, null);
  81. return CreateFormatter (null, context);
  82. }
  83. public SoapFormatter Serializer
  84. {
  85. get { return _serializationFormatter; }
  86. }
  87. public SoapFormatter Deserializer
  88. {
  89. get { return _deserializationFormatter; }
  90. }
  91. }
  92. }