(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / System.Runtime.Serialization.Formatters.Soap / Test / SerializationTest.cs
blob4ad3a1d2fd219549b90273f8dfef6fddf862cde2
1 //
2 // System.Runtime.Serialization.SerializationTest.cs
3 //
4 // Author: Lluis Sanchez Gual (lluis@ximian.com)
5 //
6 // (C) Ximian, Inc.
7 //
9 using System;
10 using System.Diagnostics;
11 using System.IO;
12 using System.Runtime.Serialization;
13 using System.Runtime.Serialization.Formatters.Soap;
14 using System.Reflection;
15 using System.Runtime.Remoting;
16 using System.Runtime.Remoting.Channels;
17 using System.Runtime.Remoting.Proxies;
18 using System.Runtime.Remoting.Messaging;
19 using System.Collections;
20 using NUnit.Framework;
22 namespace MonoTests.System.Runtime.Serialization.Formatters.Soap
24 [TestFixture]
25 public class SerializationTest
27 MemoryStream ms;
29 [Test]
30 public void TestSerialization ()
32 MethodTester mt = new MethodTester();
33 RemotingServices.Marshal (mt, "myuri");
35 WriteData();
36 ReadData();
38 RemotingServices.Disconnect (mt);
41 public static void Main()
43 SerializationTest test = new SerializationTest();
44 test.TestSerialization();
47 void WriteData ()
49 StreamingContext context = new StreamingContext (StreamingContextStates.Other);
50 SurrogateSelector sel = new SurrogateSelector();
51 sel.AddSurrogate (typeof (Point), context, new PointSurrogate());
53 List list = CreateTestData();
54 BinderTester_A bta = CreateBinderTestData();
56 ms = new MemoryStream();
57 SoapFormatter f = new SoapFormatter (sel, new StreamingContext(StreamingContextStates.Other));
58 f.Serialize (ms, list);
59 // ProcessMessages (ms, null);
60 // f.Serialize (ms, bta);
61 ms.Flush ();
62 ms.Position = 0;
63 StreamReader reader = new StreamReader(ms);
64 Console.WriteLine(reader.ReadToEnd());
65 ms.Position = 0;
68 void ReadData()
70 StreamingContext context = new StreamingContext (StreamingContextStates.Other);
71 SurrogateSelector sel = new SurrogateSelector();
72 sel.AddSurrogate (typeof (Point), context, new PointSurrogate());
74 SoapFormatter f = new SoapFormatter (sel, context);
76 object list = f.Deserialize (ms);
78 object[][] originalMsgData = null;
79 IMessage[] calls = null;
80 IMessage[] resps = null;
82 // originalMsgData = ProcessMessages (null, null);
84 // calls = new IMessage[originalMsgData.Length];
85 // resps = new IMessage[originalMsgData.Length];
88 // for (int n=0; n<originalMsgData.Length; n++)
89 // {
90 // calls[n] = (IMessage) f.Deserialize (ms);
91 // resps[n] = (IMessage) f.DeserializeMethodResponse (ms, null, (IMethodCallMessage)calls[n]);
92 // }
94 // f.Binder = new TestBinder ();
95 // object btbob = f.Deserialize (ms);
97 ms.Close();
99 ((List)list).CheckEquals(CreateTestData());
101 // BinderTester_A bta = CreateBinderTestData();
102 // Assertion.AssertEquals ("BinderTest.class", btbob.GetType(), typeof (BinderTester_B));
103 // BinderTester_B btb = btbob as BinderTester_B;
104 // if (btb != null)
105 // {
106 // Assertion.AssertEquals ("BinderTest.x", btb.x, bta.x);
107 // Assertion.AssertEquals ("BinderTest.y", btb.y, bta.y);
108 // }
110 // CheckMessages ("MethodCall", originalMsgData, ProcessMessages (null, calls));
111 // CheckMessages ("MethodResponse", originalMsgData, ProcessMessages (null, resps));
114 BinderTester_A CreateBinderTestData ()
116 BinderTester_A bta = new BinderTester_A();
117 bta.x = 11;
118 bta.y = "binder tester";
119 return bta;
122 List CreateTestData()
124 List list = new List();
125 list.name = "my list";
126 list.values = new SomeValues();
127 list.values.Init();
129 ListItem item1 = new ListItem();
130 ListItem item2 = new ListItem();
131 ListItem item3 = new ListItem();
133 item1.label = "value label 1";
134 item1.next = item2;
135 item1.value.color = 111;
136 item1.value.point = new Point();
137 item1.value.point.x = 11;
138 item1.value.point.y = 22;
140 item2.label = "value label 2";
141 item2.next = item3;
142 item2.value.color = 222;
144 item2.value.point = new Point();
145 item2.value.point.x = 33;
146 item2.value.point.y = 44;
148 item3.label = "value label 3";
149 item3.value.color = 333;
150 item3.value.point = new Point();
151 item3.value.point.x = 55;
152 item3.value.point.y = 66;
154 list.children = new ListItem[3];
156 list.children[0] = item1;
157 list.children[1] = item2;
158 list.children[2] = item3;
160 return list;
164 object[][] ProcessMessages (Stream stream, IMessage[] messages)
166 object[][] results = new object[9][];
168 AuxProxy prx = new AuxProxy (stream, "myuri");
169 MethodTester mt = (MethodTester)prx.GetTransparentProxy();
170 object res;
172 if (messages != null) prx.SetTestMessage (messages[0]);
173 res = mt.OverloadedMethod();
174 results[0] = new object[] {res};
176 if (messages != null) prx.SetTestMessage (messages[1]);
177 res = mt.OverloadedMethod(22);
178 results[1] = new object[] {res};
180 if (messages != null) prx.SetTestMessage (messages[2]);
181 int[] par1 = new int[] {1,2,3};
182 res = mt.OverloadedMethod(par1);
183 results[2] = new object[] { res, par1 };
185 if (messages != null) prx.SetTestMessage (messages[3]);
186 mt.NoReturn();
188 if (messages != null) prx.SetTestMessage (messages[4]);
189 res = mt.Simple ("hello",44);
190 results[4] = new object[] { res };
192 if (messages != null) prx.SetTestMessage (messages[5]);
193 res = mt.Simple2 ('F');
194 results[5] = new object[] { res };
196 if (messages != null) prx.SetTestMessage (messages[6]);
197 char[] par2 = new char[] { 'G' };
198 res = mt.Simple3 (par2);
199 results[6] = new object[] { res, par2 };
201 if (messages != null) prx.SetTestMessage (messages[7]);
202 res = mt.Simple3 (null);
203 results[7] = new object[] { res };
205 if (messages != null) prx.SetTestMessage (messages[8]);
207 SimpleClass b = new SimpleClass ('H');
208 res = mt.SomeMethod (123456, b);
209 results[8] = new object[] { res, b };
211 return results;
214 void CheckMessages (string label, object[][] original, object[][] serialized)
216 for (int n=0; n<original.Length; n++)
217 EqualsArray (label + " " + n, original[n], serialized[n]);
220 public static void AssertEquals(string message, Object expected, Object actual)
222 if (expected != null && expected.GetType().IsArray)
223 EqualsArray (message, (Array)expected, (Array)actual);
224 else
225 Assertion.AssertEquals (message, expected, actual);
228 public static void EqualsArray (string message, object oar1, object oar2)
230 if (oar1 == null || oar2 == null || !(oar1 is Array) || !(oar2 is Array))
232 SerializationTest.AssertEquals (message, oar1, oar2);
233 return;
236 Array ar1 = (Array) oar1;
237 Array ar2 = (Array) oar2;
239 SerializationTest.AssertEquals(message + ".Length", ar1.Length,ar2.Length);
241 for (int n=0; n<ar1.Length; n++)
243 object av1 = ar1.GetValue(n);
244 object av2 = ar2.GetValue(n);
245 SerializationTest.AssertEquals (message + "[" + n + "]", av1, av2);
252 class PointSurrogate: ISerializationSurrogate
254 public void GetObjectData(object obj, SerializationInfo info, StreamingContext context)
256 Point p = (Point)obj;
257 info.AddValue ("xv",p.x);
258 info.AddValue ("yv",p.y);
261 public object SetObjectData(object obj, SerializationInfo info, StreamingContext context, ISurrogateSelector selector)
263 typeof (Point).GetField ("x").SetValue (obj, info.GetInt32 ("xv"));
264 typeof (Point).GetField ("y").SetValue (obj, info.GetInt32 ("yv"));
265 return obj;
269 [Serializable]
270 public class List
272 public string name = null;
273 public ListItem[] children = null;
274 public SomeValues values;
276 public void CheckEquals(List val)
278 SerializationTest.AssertEquals ("List.children.Length", children.Length, val.children.Length);
280 for (int n=0; n<children.Length; n++)
281 children[n].CheckEquals (val.children[n]);
283 SerializationTest.AssertEquals ("List.name", name, val.name);
284 values.CheckEquals (val.values);
288 [Serializable]
289 public class ListItem: ISerializable
291 public ListItem()
295 ListItem (SerializationInfo info, StreamingContext ctx)
297 next = (ListItem)info.GetValue ("next", typeof (ListItem));
298 value = (ListValue)info.GetValue ("value", typeof (ListValue));
299 label = info.GetString ("label");
302 public void GetObjectData (SerializationInfo info, StreamingContext ctx)
304 info.AddValue ("next", next);
305 info.AddValue ("value", value);
306 info.AddValue ("label", label);
309 public void CheckEquals(ListItem val)
311 SerializationTest.AssertEquals ("ListItem.next", next, val.next);
312 SerializationTest.AssertEquals ("ListItem.label", label, val.label);
313 value.CheckEquals (val.value);
316 public override bool Equals(object obj)
318 ListItem val = (ListItem)obj;
319 if ((next == null || val.next == null) && (next != val.next)) return false;
320 if (next == null) return true;
321 if (!next.Equals(val.next)) return false;
322 return value.Equals (val.value) && label == val.label;
325 public override int GetHashCode ()
327 return base.GetHashCode ();
330 public ListItem next;
331 public ListValue value;
332 public string label;
335 [Serializable]
336 public struct ListValue
338 public int color;
339 public Point point;
341 public override bool Equals(object obj)
343 ListValue val = (ListValue)obj;
344 return (color == val.color && point.Equals(val.point));
347 public void CheckEquals(ListValue val)
349 SerializationTest.AssertEquals ("ListValue.color", color, val.color);
350 point.CheckEquals (val.point);
353 public override int GetHashCode ()
355 return base.GetHashCode ();
359 // [Serializable]
360 public struct Point
362 public int x;
363 public int y;
365 public override bool Equals(object obj)
367 Point p = (Point)obj;
368 return (x == p.x && y == p.y);
371 public void CheckEquals(Point p)
373 SerializationTest.AssertEquals ("Point.x", x, p.x);
374 SerializationTest.AssertEquals ("Point.y", y, p.y);
377 public override int GetHashCode ()
379 return base.GetHashCode ();
383 [Serializable]
384 public class SimpleClass
386 public SimpleClass (char v) { val = v; }
388 public override bool Equals(object obj)
390 if (obj == null) return false;
391 return val == ((SimpleClass)obj).val;
394 public override int GetHashCode()
396 return val.GetHashCode();
399 public int SampleCall (string str, SomeValues sv, ref int acum)
401 acum += (int)val;
402 return (int)val;
405 public char val;
408 enum IntEnum { aaa, bbb, ccc }
409 enum ByteEnum: byte { aaa=221, bbb=3, ccc=44 }
411 delegate int SampleDelegate (string str, SomeValues sv, ref int acum);
413 [Serializable]
414 public class SomeValues
416 Type _type;
417 Type _type2;
418 DBNull _dbnull;
419 Assembly _assembly;
420 IntEnum _intEnum;
421 ByteEnum _byteEnum;
423 bool _bool;
424 bool _bool2;
425 byte _byte;
426 char _char;
427 DateTime _dateTime;
428 decimal _decimal;
429 double _double;
430 short _short;
431 int _int;
432 long _long;
433 sbyte _sbyte;
434 float _float;
435 ushort _ushort;
436 uint _uint;
437 ulong _ulong;
439 object[] _objects;
440 string[] _strings;
441 int[] _ints;
442 public int[,,] _intsMulti;
443 int[][] _intsJagged;
444 SimpleClass[] _simples;
445 SimpleClass[,] _simplesMulti;
446 SimpleClass[][] _simplesJagged;
447 double[] _doubles;
448 object[] _almostEmpty;
450 object[] _emptyObjectArray;
451 Type[] _emptyTypeArray;
452 SimpleClass[] _emptySimpleArray;
453 int[] _emptyIntArray;
454 string[] _emptyStringArray;
457 SampleDelegate _sampleDelegate;
458 SampleDelegate _sampleDelegate2;
459 SampleDelegate _sampleDelegate3;
460 SampleDelegate _sampleDelegateStatic;
461 SampleDelegate _sampleDelegateCombined;
463 SimpleClass _shared1;
464 SimpleClass _shared2;
465 SimpleClass _shared3;
467 public void Init()
469 _type = typeof (string);
470 _type2 = typeof (SomeValues);
471 _dbnull = DBNull.Value;
472 _assembly = typeof (SomeValues).Assembly;
473 _intEnum = IntEnum.bbb;
474 _byteEnum = ByteEnum.ccc;
475 _bool = true;
476 _bool2 = false;
477 _byte = 254;
478 _char = 'A';
479 _dateTime = new DateTime (1972,7,13,1,20,59);
480 _decimal = (decimal)101010.10101;
481 _double = 123456.6789;
482 _short = -19191;
483 _int = -28282828;
484 _long = 37373737373;
485 _sbyte = -123;
486 _float = (float)654321.321;
487 _ushort = 61616;
488 _uint = 464646464;
489 _ulong = 55555555;
491 Point p = new Point();
492 p.x = 56; p.y = 67;
493 object boxedPoint = p;
495 long i = 22;
496 object boxedLong = i;
498 _objects = new object[] { "string", (int)1234, null , /*boxedPoint, boxedPoint,*/ boxedLong, boxedLong};
499 _strings = new string[] { "an", "array", "of", "strings","I","repeat","an", "array", "of", "strings" };
500 _ints = new int[] { 4,5,6,7,8 };
501 _intsMulti = new int[2,3,4] { { {1,2,3,4},{5,6,7,8},{9,10,11,12}}, { {13,14,15,16},{17,18,19,20},{21,22,23,24} } };
502 _intsJagged = new int[2][] { new int[3] {1,2,3}, new int[2] {4,5} };
503 _simples = new SimpleClass[] { new SimpleClass('a'),new SimpleClass('b'),new SimpleClass('c') };
504 _simplesMulti = new SimpleClass[2,3] {{new SimpleClass('d'),new SimpleClass('e'),new SimpleClass('f')}, {new SimpleClass('g'),new SimpleClass('j'),new SimpleClass('h')}};
505 _simplesJagged = new SimpleClass[2][] { new SimpleClass[1] { new SimpleClass('i') }, new SimpleClass[2] {null, new SimpleClass('k')}};
506 _almostEmpty = new object[2000];
507 _almostEmpty[1000] = 4;
509 _emptyObjectArray = new object[0];
510 _emptyTypeArray = new Type[0];
511 _emptySimpleArray = new SimpleClass[0];
512 _emptyIntArray = new int[0];
513 _emptyStringArray = new string[0];
515 // FIXME: Once double.ToString("G17") is implemented
516 // we'll be able to serialize double.MaxValue and double.MinValue.
517 // Currently, it throws a System.OverflowException.
518 //_doubles = new double[] { 1010101.101010, 292929.29292, 3838383.38383, 4747474.474, 56565.5656565, 0, Double.NaN, Double.MaxValue, Double.MinValue, Double.NegativeInfinity, Double.PositiveInfinity };
519 _doubles = new double[] { 1010101.101010, 292929.29292, 3838383.38383, 4747474.474, 56565.5656565, 0, Double.NaN, Double.NegativeInfinity, Double.PositiveInfinity };
521 _sampleDelegate = new SampleDelegate(SampleCall);
522 _sampleDelegate2 = new SampleDelegate(_simples[0].SampleCall);
523 _sampleDelegate3 = new SampleDelegate(new SimpleClass('x').SampleCall);
524 _sampleDelegateStatic = new SampleDelegate(SampleStaticCall);
525 _sampleDelegateCombined = (SampleDelegate)Delegate.Combine (new Delegate[] {_sampleDelegate, _sampleDelegate2, _sampleDelegate3, _sampleDelegateStatic });
527 // This is to test that references are correctly solved
528 _shared1 = new SimpleClass('A');
529 _shared2 = new SimpleClass('A');
530 _shared3 = _shared1;
533 public int SampleCall (string str, SomeValues sv, ref int acum)
535 acum += _int;
536 return _int;
539 public static int SampleStaticCall (string str, SomeValues sv, ref int acum)
541 acum += 99;
542 return 99;
545 public void CheckEquals(SomeValues obj)
547 SerializationTest.AssertEquals ("SomeValues._type", _type, obj._type);
548 SerializationTest.AssertEquals ("SomeValues._type2", _type2, obj._type2);
549 SerializationTest.AssertEquals ("SomeValues._dbnull", _dbnull, obj._dbnull);
550 SerializationTest.AssertEquals ("SomeValues._assembly", _assembly, obj._assembly);
552 SerializationTest.AssertEquals ("SomeValues._intEnum", _intEnum, obj._intEnum);
553 SerializationTest.AssertEquals ("SomeValues._byteEnum", _byteEnum, obj._byteEnum);
554 SerializationTest.AssertEquals ("SomeValues._bool", _bool, obj._bool);
555 SerializationTest.AssertEquals ("SomeValues._bool2", _bool2, obj._bool2);
556 SerializationTest.AssertEquals ("SomeValues._byte", _byte, obj._byte);
557 SerializationTest.AssertEquals ("SomeValues._char", _char, obj._char);
558 SerializationTest.AssertEquals ("SomeValues._dateTime", _dateTime, obj._dateTime);
559 SerializationTest.AssertEquals ("SomeValues._decimal", _decimal, obj._decimal);
560 SerializationTest.AssertEquals ("SomeValues._int", _int, obj._int);
561 SerializationTest.AssertEquals ("SomeValues._long", _long, obj._long);
562 SerializationTest.AssertEquals ("SomeValues._sbyte", _sbyte, obj._sbyte);
563 SerializationTest.AssertEquals ("SomeValues._float", _float, obj._float);
564 SerializationTest.AssertEquals ("SomeValues._ushort", _ushort, obj._ushort);
565 SerializationTest.AssertEquals ("SomeValues._uint", _uint, obj._uint);
566 SerializationTest.AssertEquals ("SomeValues._ulong", _ulong, obj._ulong);
568 SerializationTest.EqualsArray ("SomeValues._objects", _objects, obj._objects);
569 SerializationTest.EqualsArray ("SomeValues._strings", _strings, obj._strings);
570 SerializationTest.EqualsArray ("SomeValues._doubles", _doubles, obj._doubles);
571 SerializationTest.EqualsArray ("SomeValues._ints", _ints, obj._ints);
572 SerializationTest.EqualsArray ("SomeValues._simples", _simples, obj._simples);
573 SerializationTest.EqualsArray ("SomeValues._almostEmpty", _almostEmpty, obj._almostEmpty);
575 SerializationTest.EqualsArray ("SomeValues._emptyObjectArray", _emptyObjectArray, obj._emptyObjectArray);
576 SerializationTest.EqualsArray ("SomeValues._emptyTypeArray", _emptyTypeArray, obj._emptyTypeArray);
577 SerializationTest.EqualsArray ("SomeValues._emptySimpleArray", _emptySimpleArray, obj._emptySimpleArray);
578 SerializationTest.EqualsArray ("SomeValues._emptyIntArray", _emptyIntArray, obj._emptyIntArray);
579 SerializationTest.EqualsArray ("SomeValues._emptyStringArray", _emptyStringArray, obj._emptyStringArray);
581 for (int i=0; i<2; i++)
582 for (int j=0; j<3; j++)
583 for (int k=0; k<4; k++)
584 SerializationTest.AssertEquals("SomeValues._intsMulti[" + i + "," + j + "," + k + "]", _intsMulti[i,j,k], obj._intsMulti[i,j,k]);
586 for (int i=0; i<_intsJagged.Length; i++)
587 for (int j=0; j<_intsJagged[i].Length; j++)
588 SerializationTest.AssertEquals ("SomeValues._intsJagged[" + i + "][" + j + "]", _intsJagged[i][j], obj._intsJagged[i][j]);
590 for (int i=0; i<2; i++)
591 for (int j=0; j<3; j++)
592 SerializationTest.AssertEquals ("SomeValues._simplesMulti[" + i + "," + j + "]", _simplesMulti[i,j], obj._simplesMulti[i,j]);
594 for (int i=0; i<_simplesJagged.Length; i++)
595 SerializationTest.EqualsArray ("SomeValues._simplesJagged", _simplesJagged[i], obj._simplesJagged[i]);
597 int acum = 0;
598 SerializationTest.AssertEquals ("SomeValues._sampleDelegate", _sampleDelegate ("hi", this, ref acum), _int);
599 SerializationTest.AssertEquals ("SomeValues._sampleDelegate_bis", _sampleDelegate ("hi", this, ref acum), obj._sampleDelegate ("hi", this, ref acum));
601 SerializationTest.AssertEquals ("SomeValues._sampleDelegate2", _sampleDelegate2 ("hi", this, ref acum), (int)_simples[0].val);
602 SerializationTest.AssertEquals ("SomeValues._sampleDelegate2_bis", _sampleDelegate2 ("hi", this, ref acum), obj._sampleDelegate2 ("hi", this, ref acum));
604 SerializationTest.AssertEquals ("SomeValues._sampleDelegate3", _sampleDelegate3 ("hi", this, ref acum), (int)'x');
605 SerializationTest.AssertEquals ("SomeValues._sampleDelegate3_bis", _sampleDelegate3 ("hi", this, ref acum), obj._sampleDelegate3 ("hi", this, ref acum));
607 SerializationTest.AssertEquals ("SomeValues._sampleDelegateStatic", _sampleDelegateStatic ("hi", this, ref acum), 99);
608 SerializationTest.AssertEquals ("SomeValues._sampleDelegateStatic_bis", _sampleDelegateStatic ("hi", this, ref acum), obj._sampleDelegateStatic ("hi", this, ref acum));
610 int acum1 = 0;
611 int acum2 = 0;
612 _sampleDelegateCombined ("hi", this, ref acum1);
613 obj._sampleDelegateCombined ("hi", this, ref acum2);
615 SerializationTest.AssertEquals ("_sampleDelegateCombined", acum1, _int + (int)_simples[0].val + (int)'x' + 99);
616 SerializationTest.AssertEquals ("_sampleDelegateCombined_bis", acum1, acum2);
618 SerializationTest.AssertEquals ("SomeValues._shared1", _shared1, _shared2);
619 SerializationTest.AssertEquals ("SomeValues._shared1_bis", _shared1, _shared3);
621 _shared1.val = 'B';
622 SerializationTest.AssertEquals ("SomeValues._shared2", _shared2.val, 'A');
623 SerializationTest.AssertEquals ("SomeValues._shared3", _shared3.val, 'B');
627 class MethodTester : MarshalByRefObject
629 public int OverloadedMethod ()
631 return 123456789;
634 public int OverloadedMethod (int a)
636 return a+2;
639 public int OverloadedMethod (int[] a)
641 return a.Length;
644 public void NoReturn ()
647 public string Simple (string a, int b)
649 return a + b;
652 public SimpleClass Simple2 (char c)
654 return new SimpleClass(c);
657 public SimpleClass Simple3 (char[] c)
659 if (c != null) return new SimpleClass(c[0]);
660 else return null;
663 public int SomeMethod (int a, SimpleClass b)
665 object[] d;
666 string c = "hi";
667 int r = a + c.Length;
668 c = "bye";
669 d = new object[3];
670 d[1] = b;
671 return r;
675 class AuxProxy: RealProxy
677 public static bool useHeaders = false;
678 Stream _stream;
679 string _uri;
680 IMethodMessage _testMsg;
682 public AuxProxy(Stream stream, string uri): base(typeof(MethodTester))
684 _stream = stream;
685 _uri = uri;
688 public void SetTestMessage (IMessage msg)
690 _testMsg = (IMethodMessage)msg;
691 _testMsg.Properties["__Uri"] = _uri;
694 public override IMessage Invoke(IMessage msg)
696 IMethodCallMessage call = (IMethodCallMessage)msg;
697 if (call.MethodName.StartsWith ("Initialize")) return new ReturnMessage(null,null,0,null,(IMethodCallMessage)msg);
699 call.Properties["__Uri"] = _uri;
701 if (_stream != null)
703 SerializeCall (call);
704 IMessage response = ChannelServices.SyncDispatchMessage (call);
705 SerializeResponse (response);
706 return response;
708 else if (_testMsg != null)
710 if (_testMsg is IMethodCallMessage)
711 return ChannelServices.SyncDispatchMessage (_testMsg);
712 else
713 return _testMsg;
715 else
716 return ChannelServices.SyncDispatchMessage (call);
719 void SerializeCall (IMessage call)
721 RemotingSurrogateSelector rss = new RemotingSurrogateSelector();
722 IRemotingFormatter fmt = new SoapFormatter (rss, new StreamingContext(StreamingContextStates.Remoting));
723 fmt.Serialize (_stream, call, GetHeaders());
726 void SerializeResponse (IMessage resp)
728 RemotingSurrogateSelector rss = new RemotingSurrogateSelector();
729 IRemotingFormatter fmt = new SoapFormatter (rss, new StreamingContext(StreamingContextStates.Remoting));
730 fmt.Serialize (_stream, resp, GetHeaders());
733 Header[] GetHeaders()
735 Header[] hs = null;
736 if (useHeaders)
738 hs = new Header[1];
739 hs[0] = new Header("unom",new SimpleClass('R'));
741 return hs;
745 public class TestBinder : SerializationBinder
747 public override Type BindToType (string assemblyName, string typeName)
749 if (typeName.IndexOf("BinderTester_A") != -1)
750 typeName = typeName.Replace ("BinderTester_A", "BinderTester_B");
752 return Assembly.Load (assemblyName).GetType (typeName);
756 [Serializable]
757 public class BinderTester_A
759 public int x;
760 public string y;
763 [Serializable]
764 public class BinderTester_B
766 public string y;
767 public int x;