SoapCore.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. IDictionary _properties;
  22. #if NET_1_1
  23. TypeFilterLevel _filterLevel = TypeFilterLevel.Low;
  24. #endif
  25. public static SoapCore DefaultInstance = new SoapCore ();
  26. public SoapCore (object owner, IDictionary properties, string[] allowedProperties)
  27. {
  28. _properties = properties;
  29. foreach(DictionaryEntry property in properties)
  30. {
  31. string key = (string) property.Key;
  32. if (Array.IndexOf (allowedProperties, key) == -1)
  33. throw new RemotingException (owner.GetType().Name + " does not recognize '" + key + "' configuration property");
  34. switch (key)
  35. {
  36. case "includeVersions":
  37. _includeVersions = Convert.ToBoolean (property.Value);
  38. break;
  39. case "strictBinding":
  40. _strictBinding = Convert.ToBoolean (property.Value);
  41. break;
  42. #if NET_1_1
  43. case "typeFilterLevel":
  44. if (property.Value is TypeFilterLevel)
  45. _filterLevel = (TypeFilterLevel) property.Value;
  46. else {
  47. string s = (string) property.Value;
  48. _filterLevel = (TypeFilterLevel) Enum.Parse (typeof(TypeFilterLevel), s);
  49. }
  50. break;
  51. #endif
  52. }
  53. }
  54. Init ();
  55. }
  56. public SoapCore ()
  57. {
  58. Init ();
  59. }
  60. public void Init ()
  61. {
  62. RemotingSurrogateSelector surrogateSelector = new RemotingSurrogateSelector ();
  63. StreamingContext context = new StreamingContext (StreamingContextStates.Remoting, null);
  64. _serializationFormatter = CreateFormatter (surrogateSelector, context);
  65. _deserializationFormatter = CreateFormatter (null, context);
  66. #if NET_1_1
  67. _serializationFormatter.FilterLevel = _filterLevel;
  68. _deserializationFormatter.FilterLevel = _filterLevel;
  69. #endif
  70. }
  71. SoapFormatter CreateFormatter (ISurrogateSelector selector, StreamingContext context)
  72. {
  73. SoapFormatter fm = new SoapFormatter (selector, context);
  74. if (!_includeVersions)
  75. fm.AssemblyFormat = FormatterAssemblyStyle.Simple;
  76. if (!_strictBinding)
  77. fm.Binder = ChannelCore.SimpleBinder;
  78. return fm;
  79. }
  80. public SoapFormatter GetSafeDeserializer ()
  81. {
  82. StreamingContext context = new StreamingContext (StreamingContextStates.Remoting, null);
  83. return CreateFormatter (null, context);
  84. }
  85. public SoapFormatter Serializer
  86. {
  87. get { return _serializationFormatter; }
  88. }
  89. public SoapFormatter Deserializer
  90. {
  91. get { return _deserializationFormatter; }
  92. }
  93. public IDictionary Properties
  94. {
  95. get { return _properties; }
  96. }
  97. #if NET_1_1
  98. public TypeFilterLevel TypeFilterLevel
  99. {
  100. get { return _filterLevel; }
  101. }
  102. #endif
  103. }
  104. }