BaseMessagesFormatter.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  1. //
  2. // DefaultMessageOperationFormatter.cs
  3. //
  4. // Author:
  5. // Atsushi Enomoto <[email protected]>
  6. // Eyal Alaluf <[email protected]>
  7. //
  8. // Copyright (C) 2005-2010 Novell, Inc. http://www.novell.com
  9. // Copyright (C) 2008 Mainsoft Co. http://www.mainsoft.com
  10. //
  11. // Permission is hereby granted, free of charge, to any person obtaining
  12. // a copy of this software and associated documentation files (the
  13. // "Software"), to deal in the Software without restriction, including
  14. // without limitation the rights to use, copy, modify, merge, publish,
  15. // distribute, sublicense, and/or sell copies of the Software, and to
  16. // permit persons to whom the Software is furnished to do so, subject to
  17. // the following conditions:
  18. //
  19. // The above copyright notice and this permission notice shall be
  20. // included in all copies or substantial portions of the Software.
  21. //
  22. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  23. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  24. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  25. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  26. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  27. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  28. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  29. //
  30. using System;
  31. using System.Collections.Generic;
  32. using System.Linq;
  33. using System.Reflection;
  34. using System.Runtime.Serialization;
  35. using System.ServiceModel;
  36. using System.ServiceModel.Channels;
  37. using System.ServiceModel.Description;
  38. using System.Text;
  39. using System.Xml;
  40. using System.Xml.Serialization;
  41. namespace System.ServiceModel.Dispatcher
  42. {
  43. // This type is introduced for moonlight compatibility.
  44. internal class OperationFormatter
  45. : IDispatchMessageFormatter, IClientMessageFormatter
  46. {
  47. BaseMessagesFormatter impl;
  48. string operation_name;
  49. public OperationFormatter (OperationDescription od, bool isRpc, bool isEncoded)
  50. {
  51. Validate (od, isRpc, isEncoded);
  52. impl = BaseMessagesFormatter.Create (od);
  53. operation_name = od.Name;
  54. }
  55. public string OperationName {
  56. get { return operation_name; }
  57. }
  58. internal static bool IsValidReturnValue (MessagePartDescription part)
  59. {
  60. return part != null && part.Type != typeof (void);
  61. }
  62. internal static void Validate (OperationDescription od, bool isRpc, bool isEncoded)
  63. {
  64. bool hasParameter = false, hasVoid = false;
  65. foreach (var md in od.Messages) {
  66. if (md.IsTypedMessage || md.IsUntypedMessage) {
  67. if (isRpc && !isEncoded)
  68. throw new InvalidOperationException ("Message with action {0} is either strongly-typed or untyped, but defined as RPC and encoded.");
  69. if (hasParameter && !md.IsVoid)
  70. throw new InvalidOperationException (String.Format ("Operation '{0}' contains a message with parameters. Strongly-typed or untyped message can be paired only with strongly-typed, untyped or void message.", od.Name));
  71. if (isRpc && hasVoid)
  72. throw new InvalidOperationException (String.Format ("This operation '{0}' is defined as RPC and contains a message with void, which is not allowed.", od.Name));
  73. } else {
  74. hasParameter |= !md.IsVoid;
  75. hasVoid |= md.IsVoid;
  76. }
  77. }
  78. }
  79. public object DeserializeReply (Message message, object [] parameters)
  80. {
  81. return impl.DeserializeReply (message, parameters);
  82. }
  83. public Message SerializeRequest (MessageVersion messageVersion, object [] parameters)
  84. {
  85. return impl.SerializeRequest (messageVersion, parameters);
  86. }
  87. public void DeserializeRequest (Message message, object [] parameters)
  88. {
  89. impl.DeserializeRequest (message, parameters);
  90. }
  91. public Message SerializeReply (MessageVersion messageVersion, object [] parameters, object result)
  92. {
  93. return impl.SerializeReply (messageVersion, parameters, result);
  94. }
  95. }
  96. internal abstract class BaseMessagesFormatter
  97. : IDispatchMessageFormatter, IClientMessageFormatter
  98. {
  99. MessageDescriptionCollection messages;
  100. bool isAsync;
  101. ParameterInfo [] requestMethodParams;
  102. ParameterInfo [] replyMethodParams;
  103. List<Type> operation_known_types = new List<Type> ();
  104. public BaseMessagesFormatter (MessageDescriptionCollection messages)
  105. {
  106. this.messages = messages;
  107. }
  108. public BaseMessagesFormatter (OperationDescription desc)
  109. : this (desc.Messages)
  110. {
  111. if (desc.SyncMethod != null)
  112. {
  113. isAsync = false;
  114. requestMethodParams = replyMethodParams = desc.SyncMethod.GetParameters ();
  115. return;
  116. }
  117. isAsync = true;
  118. ParameterInfo [] methodParams = desc.BeginMethod.GetParameters ();
  119. requestMethodParams = new ParameterInfo [methodParams.Length - 2];
  120. Array.Copy (methodParams, requestMethodParams, requestMethodParams.Length);
  121. methodParams = desc.EndMethod.GetParameters ();
  122. replyMethodParams = new ParameterInfo [methodParams.Length - 1];
  123. Array.Copy (methodParams, replyMethodParams, replyMethodParams.Length);
  124. operation_known_types.AddRange (desc.KnownTypes);
  125. }
  126. // FIXME: this should be refactored and eliminated.
  127. // XmlSerializerFormatAttribute and DataContractFormatAttribute
  128. // should be handled at ContractDescription.GetContract (to fill
  129. // IOperationBehavior for each).
  130. //
  131. // Fixing the issue above should also fix "Formatter is already filled at initial state" issue described in EndpointDispatcher.cs and ContractDescription.cs.
  132. public static BaseMessagesFormatter Create (OperationDescription desc)
  133. {
  134. MethodInfo attrProvider = desc.SyncMethod ?? desc.BeginMethod;
  135. object [] attrs;
  136. #if !NET_2_1
  137. attrs = attrProvider.GetCustomAttributes (typeof (XmlSerializerFormatAttribute), false);
  138. if (attrs != null && attrs.Length > 0)
  139. return new XmlMessagesFormatter (desc, (XmlSerializerFormatAttribute) attrs [0]);
  140. #endif
  141. attrs = attrProvider.GetCustomAttributes (typeof (DataContractFormatAttribute), false);
  142. DataContractFormatAttribute dataAttr = null;
  143. if (attrs != null && attrs.Length > 0)
  144. dataAttr = (DataContractFormatAttribute) attrs [0];
  145. return new DataContractMessagesFormatter (desc, dataAttr);
  146. }
  147. public IEnumerable<Type> OperationKnownTypes {
  148. get { return operation_known_types; }
  149. }
  150. protected abstract Message PartsToMessage (
  151. MessageDescription md, MessageVersion version, string action, object [] parts);
  152. protected abstract object [] MessageToParts (MessageDescription md, Message message);
  153. protected abstract Dictionary<MessageHeaderDescription,object> MessageToHeaderObjects (MessageDescription md, Message message);
  154. public Message SerializeRequest (
  155. MessageVersion version, object [] parameters)
  156. {
  157. MessageDescription md = null;
  158. foreach (MessageDescription mdi in messages)
  159. if (mdi.IsRequest)
  160. md = mdi;
  161. object [] parts = CreatePartsArray (md.Body);
  162. var headers = md.Headers.Count > 0 ? new Dictionary<MessageHeaderDescription,object> () : null;
  163. if (md.MessageType != null)
  164. MessageObjectToParts (md, parameters [0], headers, parts);
  165. else {
  166. int index = 0;
  167. foreach (ParameterInfo pi in requestMethodParams)
  168. if (!pi.IsOut)
  169. parts [index++] = parameters [pi.Position];
  170. }
  171. var msg = PartsToMessage (md, version, md.Action, parts);
  172. if (headers != null)
  173. foreach (var pair in headers)
  174. if (pair.Value != null)
  175. msg.Headers.Add (CreateHeader (pair.Key, pair.Value));
  176. return msg;
  177. }
  178. public Message SerializeReply (
  179. MessageVersion version, object [] parameters, object result)
  180. {
  181. // use_response_converter
  182. MessageDescription md = null;
  183. foreach (MessageDescription mdi in messages)
  184. if (!mdi.IsRequest)
  185. md = mdi;
  186. object [] parts = CreatePartsArray (md.Body);
  187. var headers = md.Headers.Count > 0 ? new Dictionary<MessageHeaderDescription,object> () : null;
  188. if (md.MessageType != null)
  189. MessageObjectToParts (md, result, headers, parts);
  190. else {
  191. if (HasReturnValue (md.Body))
  192. parts [0] = result;
  193. int index = ParamsOffset (md.Body);
  194. int paramsIdx = 0;
  195. foreach (ParameterInfo pi in replyMethodParams)
  196. if (pi.IsOut || pi.ParameterType.IsByRef)
  197. parts [index++] = parameters [paramsIdx++];
  198. }
  199. string action = version.Addressing == AddressingVersion.None ? null : md.Action;
  200. var msg = PartsToMessage (md, version, action, parts);
  201. if (headers != null)
  202. foreach (var pair in headers)
  203. if (pair.Value != null)
  204. msg.Headers.Add (CreateHeader (pair.Key, pair.Value));
  205. return msg;
  206. }
  207. MessageHeader CreateHeader (MessageHeaderDescription mh, object value)
  208. {
  209. return MessageHeader.CreateHeader (mh.Name, mh.Namespace, value, mh.MustUnderstand, mh.Actor, mh.Relay);
  210. }
  211. public void DeserializeRequest (Message message, object [] parameters)
  212. {
  213. string action = message.Headers.Action;
  214. MessageDescription md = messages.Find (action);
  215. if (md == null)
  216. throw new ActionNotSupportedException (String.Format ("Action '{0}' is not supported by this operation.", action));
  217. var headers = MessageToHeaderObjects (md, message);
  218. object [] parts = MessageToParts (md, message);
  219. if (md.MessageType != null) {
  220. #if NET_2_1
  221. parameters [0] = Activator.CreateInstance (md.MessageType);
  222. #else
  223. parameters [0] = Activator.CreateInstance (md.MessageType, true);
  224. #endif
  225. PartsToMessageObject (md, headers, parts, parameters [0]);
  226. }
  227. else
  228. {
  229. int index = 0;
  230. foreach (ParameterInfo pi in requestMethodParams)
  231. if (!pi.IsOut) {
  232. parameters [index] = parts [index];
  233. index++;
  234. }
  235. }
  236. }
  237. public object DeserializeReply (Message message, object [] parameters)
  238. {
  239. MessageDescription md = null;
  240. foreach (MessageDescription mdi in messages)
  241. if (!mdi.IsRequest)
  242. md = mdi;
  243. var headers = MessageToHeaderObjects (md, message);
  244. object [] parts = MessageToParts (md, message);
  245. if (md.MessageType != null) {
  246. #if NET_2_1
  247. object msgObject = Activator.CreateInstance (md.MessageType);
  248. #else
  249. object msgObject = Activator.CreateInstance (md.MessageType, true);
  250. #endif
  251. PartsToMessageObject (md, headers, parts, msgObject);
  252. return msgObject;
  253. }
  254. else {
  255. int index = ParamsOffset (md.Body);
  256. foreach (ParameterInfo pi in requestMethodParams)
  257. if (pi.IsOut || pi.ParameterType.IsByRef)
  258. parameters [pi.Position] = parts [index++];
  259. return HasReturnValue (md.Body) ? parts [0] : null;
  260. }
  261. }
  262. void PartsToMessageObject (MessageDescription md, Dictionary<MessageHeaderDescription,object> headers, object [] parts, object msgObject)
  263. {
  264. if (headers != null)
  265. foreach (var pair in headers) {
  266. var mi = pair.Key.MemberInfo;
  267. if (mi is FieldInfo)
  268. ((FieldInfo) mi).SetValue (msgObject, pair.Value);
  269. else
  270. ((PropertyInfo) mi).SetValue (msgObject, pair.Value, null);
  271. }
  272. foreach (MessagePartDescription partDesc in md.Body.Parts)
  273. if (partDesc.MemberInfo is FieldInfo)
  274. ((FieldInfo) partDesc.MemberInfo).SetValue (msgObject, parts [partDesc.Index]);
  275. else
  276. ((PropertyInfo) partDesc.MemberInfo).SetValue (msgObject, parts [partDesc.Index], null);
  277. }
  278. void MessageObjectToParts (MessageDescription md, object msgObject, Dictionary<MessageHeaderDescription,object> headers, object [] parts)
  279. {
  280. foreach (var headDesc in md.Headers) {
  281. var mi = headDesc.MemberInfo;
  282. if (mi is FieldInfo)
  283. headers [headDesc] = ((FieldInfo) mi).GetValue (msgObject);
  284. else
  285. headers [headDesc] = ((PropertyInfo) mi).GetValue (msgObject, null);
  286. }
  287. foreach (MessagePartDescription partDesc in md.Body.Parts)
  288. if (partDesc.MemberInfo is FieldInfo)
  289. parts [partDesc.Index] = ((FieldInfo) partDesc.MemberInfo).GetValue (msgObject);
  290. else
  291. parts [partDesc.Index] = ((PropertyInfo) partDesc.MemberInfo).GetValue (msgObject, null);
  292. }
  293. internal static bool HasReturnValue (MessageBodyDescription desc)
  294. {
  295. return desc.ReturnValue != null && desc.ReturnValue.Type != typeof (void);
  296. }
  297. protected static int ParamsOffset (MessageBodyDescription desc)
  298. {
  299. return HasReturnValue (desc) ? 1 : 0;
  300. }
  301. protected static object [] CreatePartsArray (MessageBodyDescription desc)
  302. {
  303. if (HasReturnValue (desc))
  304. return new object [desc.Parts.Count + 1];
  305. return new object [desc.Parts.Count];
  306. }
  307. }
  308. #if !NET_2_1
  309. class XmlMessagesFormatter : BaseMessagesFormatter
  310. {
  311. XmlSerializerFormatAttribute attr;
  312. Dictionary<MessageBodyDescription,XmlSerializer> bodySerializers
  313. = new Dictionary<MessageBodyDescription,XmlSerializer> ();
  314. public XmlMessagesFormatter (OperationDescription desc, XmlSerializerFormatAttribute attr)
  315. : base (desc)
  316. {
  317. this.attr = attr;
  318. }
  319. public XmlMessagesFormatter (MessageDescriptionCollection messages, XmlSerializerFormatAttribute attr)
  320. : base (messages)
  321. {
  322. this.attr = attr;
  323. }
  324. private XmlReflectionMember CreateReflectionMember (MessagePartDescription partDesc, bool isReturnValue)
  325. {
  326. XmlReflectionMember m = new XmlReflectionMember ();
  327. m.IsReturnValue = isReturnValue;
  328. m.MemberName = partDesc.Name;
  329. m.MemberType = partDesc.Type;
  330. return m;
  331. }
  332. protected override Message PartsToMessage (
  333. MessageDescription md, MessageVersion version, string action, object [] parts)
  334. {
  335. return Message.CreateMessage (version, action, new XmlBodyWriter (GetSerializer (md.Body), parts));
  336. }
  337. protected override object [] MessageToParts (MessageDescription md, Message message)
  338. {
  339. if (message.IsEmpty)
  340. return null;
  341. XmlDictionaryReader r = message.GetReaderAtBodyContents ();
  342. return (object []) GetSerializer (md.Body).Deserialize (r);
  343. }
  344. protected override Dictionary<MessageHeaderDescription,object> MessageToHeaderObjects (MessageDescription md, Message message)
  345. {
  346. // FIXME: do we need header serializers?
  347. return null;
  348. }
  349. XmlSerializer GetSerializer (MessageBodyDescription desc)
  350. {
  351. if (bodySerializers.ContainsKey (desc))
  352. return bodySerializers [desc];
  353. int count = desc.Parts.Count + (HasReturnValue (desc) ? 1 : 0);
  354. XmlReflectionMember [] members = new XmlReflectionMember [count];
  355. int ind = 0;
  356. if (HasReturnValue (desc))
  357. members [ind++] = CreateReflectionMember (desc.ReturnValue, true);
  358. foreach (MessagePartDescription partDesc in desc.Parts)
  359. members [ind++] = CreateReflectionMember (partDesc, false);
  360. XmlReflectionImporter xmlImporter = new XmlReflectionImporter ();
  361. // Register known types into xmlImporter.
  362. foreach (var type in OperationKnownTypes)
  363. xmlImporter.IncludeType (type);
  364. XmlMembersMapping [] partsMapping = new XmlMembersMapping [1];
  365. partsMapping [0] = xmlImporter.ImportMembersMapping (desc.WrapperName, desc.WrapperNamespace, members, true);
  366. bodySerializers [desc] = XmlSerializer.FromMappings (partsMapping) [0];
  367. return bodySerializers [desc];
  368. }
  369. class XmlBodyWriter : BodyWriter
  370. {
  371. XmlSerializer serializer;
  372. object body;
  373. public XmlBodyWriter (XmlSerializer serializer, object parts)
  374. : base (false)
  375. {
  376. this.serializer = serializer;
  377. this.body = parts;
  378. }
  379. protected override BodyWriter OnCreateBufferedCopy (int maxBufferSize)
  380. {
  381. return new XmlBodyWriter (serializer, body);
  382. }
  383. protected override void OnWriteBodyContents (XmlDictionaryWriter writer)
  384. {
  385. serializer.Serialize (writer, body);
  386. }
  387. }
  388. }
  389. #endif
  390. class DataContractMessagesFormatter : BaseMessagesFormatter
  391. {
  392. DataContractFormatAttribute attr;
  393. #if !NET_2_1
  394. DataContractSerializerOperationBehavior serializerBehavior;
  395. #endif
  396. public DataContractMessagesFormatter (OperationDescription desc, DataContractFormatAttribute attr)
  397. : base (desc)
  398. {
  399. #if !NET_2_1
  400. this.serializerBehavior = desc.Behaviors.Find<DataContractSerializerOperationBehavior>();
  401. #endif
  402. this.attr = attr;
  403. }
  404. public DataContractMessagesFormatter (MessageDescriptionCollection messages, DataContractFormatAttribute attr)
  405. : base (messages)
  406. {
  407. this.attr = attr;
  408. }
  409. Dictionary<MessagePartDescription, XmlObjectSerializer> serializers
  410. = new Dictionary<MessagePartDescription,XmlObjectSerializer> ();
  411. protected override Message PartsToMessage (
  412. MessageDescription md, MessageVersion version, string action, object [] parts)
  413. {
  414. return Message.CreateMessage (version, action, new DataContractBodyWriter (md.Body, this, parts));
  415. }
  416. protected override Dictionary<MessageHeaderDescription,object> MessageToHeaderObjects (MessageDescription md, Message message)
  417. {
  418. if (message.IsEmpty || md.Headers.Count == 0)
  419. return null;
  420. var dic = new Dictionary<MessageHeaderDescription,object> ();
  421. for (int i = 0; i < message.Headers.Count; i++) {
  422. var r = message.Headers.GetReaderAtHeader (i);
  423. var mh = md.Headers.FirstOrDefault (h => h.Name == r.LocalName && h.Namespace == r.NamespaceURI);
  424. if (mh != null)
  425. dic [mh] = ReadHeaderObject (mh.Type, GetSerializer (mh), r);
  426. }
  427. return dic;
  428. }
  429. protected override object [] MessageToParts (
  430. MessageDescription md, Message message)
  431. {
  432. if (message.IsEmpty)
  433. return null;
  434. int offset = ParamsOffset (md.Body);
  435. object [] parts = CreatePartsArray (md.Body);
  436. XmlDictionaryReader r = message.GetReaderAtBodyContents ();
  437. if (md.Body.WrapperName != null)
  438. r.ReadStartElement (md.Body.WrapperName, md.Body.WrapperNamespace);
  439. for (r.MoveToContent (); r.NodeType == XmlNodeType.Element; r.MoveToContent ()) {
  440. XmlQualifiedName key = new XmlQualifiedName (r.LocalName, r.NamespaceURI);
  441. MessagePartDescription rv = md.Body.ReturnValue;
  442. if (rv != null && rv.Name == key.Name && rv.Namespace == key.Namespace)
  443. parts [0] = GetSerializer (md.Body.ReturnValue).ReadObject (r);
  444. else if (md.Body.Parts.Contains (key)) {
  445. MessagePartDescription p = md.Body.Parts [key];
  446. parts [p.Index + offset] = GetSerializer (p).ReadObject (r);
  447. }
  448. else // Skip unknown elements
  449. r.Skip ();
  450. }
  451. if (md.Body.WrapperName != null && !r.EOF)
  452. r.ReadEndElement ();
  453. return parts;
  454. }
  455. XmlObjectSerializer GetSerializer (MessagePartDescription partDesc)
  456. {
  457. if (!serializers.ContainsKey (partDesc))
  458. #if !NET_2_1
  459. if (serializerBehavior != null)
  460. serializers [partDesc] = serializerBehavior.CreateSerializer(
  461. partDesc.Type, partDesc.Name, partDesc.Namespace, OperationKnownTypes as IList<Type>);
  462. else
  463. #endif
  464. serializers [partDesc] = new DataContractSerializer (
  465. partDesc.Type, partDesc.Name, partDesc.Namespace, OperationKnownTypes);
  466. return serializers [partDesc];
  467. }
  468. object ReadHeaderObject (Type type, XmlObjectSerializer serializer, XmlDictionaryReader reader)
  469. {
  470. // FIXME: it's a nasty workaround just to avoid UniqueId output as a string.
  471. // Seealso MessageHeader.DefaultMessageHeader.OnWriteHeaderContents().
  472. // Note that msg.Headers.GetHeader<UniqueId> () simply fails (on .NET too) and it is useless. The API is lame by design.
  473. if (type == typeof (UniqueId))
  474. return new UniqueId (reader.ReadElementContentAsString ());
  475. else
  476. return serializer.ReadObject (reader);
  477. }
  478. class DataContractBodyWriter : BodyWriter
  479. {
  480. MessageBodyDescription desc;
  481. object [] parts;
  482. DataContractMessagesFormatter parent;
  483. public DataContractBodyWriter (MessageBodyDescription desc, DataContractMessagesFormatter parent, object [] parts)
  484. : base (false)
  485. {
  486. this.desc = desc;
  487. this.parent = parent;
  488. this.parts = parts;
  489. }
  490. protected override void OnWriteBodyContents (XmlDictionaryWriter writer)
  491. {
  492. int offset = HasReturnValue (desc) ? 1 : 0;
  493. if (desc.WrapperName != null)
  494. writer.WriteStartElement (desc.WrapperName, desc.WrapperNamespace);
  495. if (HasReturnValue (desc))
  496. WriteMessagePart (writer, desc, desc.ReturnValue, parts [0]);
  497. foreach (MessagePartDescription partDesc in desc.Parts)
  498. WriteMessagePart (writer, desc, partDesc, parts [partDesc.Index + offset]);
  499. if (desc.WrapperName != null)
  500. writer.WriteEndElement ();
  501. }
  502. void WriteMessagePart (
  503. XmlDictionaryWriter writer, MessageBodyDescription desc, MessagePartDescription partDesc, object obj)
  504. {
  505. parent.GetSerializer (partDesc).WriteObject (writer, obj);
  506. }
  507. }
  508. }
  509. }