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