SoapCore.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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;
  20. bool _strictBinding;
  21. public static SoapCore DefaultInstance = new SoapCore (true, false);
  22. public SoapCore (object owner, IDictionary properties)
  23. {
  24. _includeVersions = true;
  25. _strictBinding = false;
  26. foreach(DictionaryEntry property in properties)
  27. {
  28. switch((string)property.Key)
  29. {
  30. case "includeVersions":
  31. _includeVersions = Convert.ToBoolean (property.Value);
  32. break;
  33. case "strictBinding":
  34. _strictBinding = Convert.ToBoolean (property.Value);
  35. break;
  36. default:
  37. throw new RemotingException (owner.GetType().Name + " does not recognize '" + property.Key + "' configuration property");
  38. }
  39. }
  40. Init ();
  41. }
  42. public SoapCore (bool includeVersions, bool strictBinding)
  43. {
  44. _includeVersions = includeVersions;
  45. _strictBinding = strictBinding;
  46. Init ();
  47. }
  48. public void Init ()
  49. {
  50. RemotingSurrogateSelector surrogateSelector = new RemotingSurrogateSelector ();
  51. StreamingContext context = new StreamingContext (StreamingContextStates.Remoting, null);
  52. _serializationFormatter = CreateFormatter (surrogateSelector, context);
  53. _deserializationFormatter = CreateFormatter (null, context);
  54. }
  55. SoapFormatter CreateFormatter (ISurrogateSelector selector, StreamingContext context)
  56. {
  57. SoapFormatter fm = new SoapFormatter (selector, context);
  58. if (!_includeVersions)
  59. fm.AssemblyFormat = FormatterAssemblyStyle.Simple;
  60. if (!_strictBinding)
  61. fm.Binder = ChannelCore.SimpleBinder;
  62. return fm;
  63. }
  64. public SoapFormatter GetSafeDeserializer ()
  65. {
  66. StreamingContext context = new StreamingContext (StreamingContextStates.Remoting, null);
  67. return CreateFormatter (null, context);
  68. }
  69. public SoapFormatter Serializer
  70. {
  71. get { return _serializationFormatter; }
  72. }
  73. public SoapFormatter Deserializer
  74. {
  75. get { return _deserializationFormatter; }
  76. }
  77. }
  78. }