Addressing.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915
  1. //------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. //------------------------------------------------------------
  4. namespace System.ServiceModel.Channels
  5. {
  6. using System.Runtime;
  7. using System.ServiceModel;
  8. using System.Xml;
  9. abstract class AddressingHeader : DictionaryHeader, IMessageHeaderWithSharedNamespace
  10. {
  11. AddressingVersion version;
  12. protected AddressingHeader(AddressingVersion version)
  13. {
  14. this.version = version;
  15. }
  16. internal AddressingVersion Version
  17. {
  18. get { return this.version; }
  19. }
  20. XmlDictionaryString IMessageHeaderWithSharedNamespace.SharedPrefix
  21. {
  22. get { return XD.AddressingDictionary.Prefix; }
  23. }
  24. XmlDictionaryString IMessageHeaderWithSharedNamespace.SharedNamespace
  25. {
  26. get { return this.version.DictionaryNamespace; }
  27. }
  28. public override XmlDictionaryString DictionaryNamespace
  29. {
  30. get { return this.version.DictionaryNamespace; }
  31. }
  32. }
  33. class ActionHeader : AddressingHeader
  34. {
  35. string action;
  36. const bool mustUnderstandValue = true;
  37. ActionHeader(string action, AddressingVersion version)
  38. : base(version)
  39. {
  40. this.action = action;
  41. }
  42. public string Action
  43. {
  44. get { return action; }
  45. }
  46. public override bool MustUnderstand
  47. {
  48. get { return mustUnderstandValue; }
  49. }
  50. public override XmlDictionaryString DictionaryName
  51. {
  52. get { return XD.AddressingDictionary.Action; }
  53. }
  54. public static ActionHeader Create(string action, AddressingVersion addressingVersion)
  55. {
  56. if (action == null)
  57. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("action"));
  58. if (addressingVersion == null)
  59. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("addressingVersion");
  60. return new ActionHeader(action, addressingVersion);
  61. }
  62. public static ActionHeader Create(XmlDictionaryString dictionaryAction, AddressingVersion addressingVersion)
  63. {
  64. if (dictionaryAction == null)
  65. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("action"));
  66. if (addressingVersion == null)
  67. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("addressingVersion");
  68. return new DictionaryActionHeader(dictionaryAction, addressingVersion);
  69. }
  70. protected override void OnWriteHeaderContents(XmlDictionaryWriter writer, MessageVersion messageVersion)
  71. {
  72. writer.WriteString(action);
  73. }
  74. public static string ReadHeaderValue(XmlDictionaryReader reader, AddressingVersion addressingVersion)
  75. {
  76. Fx.Assert(reader.IsStartElement(XD.AddressingDictionary.Action, addressingVersion.DictionaryNamespace), "");
  77. string act = reader.ReadElementContentAsString();
  78. if (act.Length > 0 && (act[0] <= 32 || act[act.Length - 1] <= 32))
  79. act = XmlUtil.Trim(act);
  80. return act;
  81. }
  82. public static ActionHeader ReadHeader(XmlDictionaryReader reader, AddressingVersion version,
  83. string actor, bool mustUnderstand, bool relay)
  84. {
  85. string action = ReadHeaderValue(reader, version);
  86. if (actor.Length == 0 && mustUnderstand == mustUnderstandValue && !relay)
  87. {
  88. return new ActionHeader(action, version);
  89. }
  90. else
  91. {
  92. return new FullActionHeader(action, actor, mustUnderstand, relay, version);
  93. }
  94. }
  95. class DictionaryActionHeader : ActionHeader
  96. {
  97. XmlDictionaryString dictionaryAction;
  98. public DictionaryActionHeader(XmlDictionaryString dictionaryAction, AddressingVersion version)
  99. : base(dictionaryAction.Value, version)
  100. {
  101. this.dictionaryAction = dictionaryAction;
  102. }
  103. protected override void OnWriteHeaderContents(XmlDictionaryWriter writer, MessageVersion messageVersion)
  104. {
  105. writer.WriteString(dictionaryAction);
  106. }
  107. }
  108. class FullActionHeader : ActionHeader
  109. {
  110. string actor;
  111. bool mustUnderstand;
  112. bool relay;
  113. public FullActionHeader(string action, string actor, bool mustUnderstand, bool relay, AddressingVersion version)
  114. : base(action, version)
  115. {
  116. this.actor = actor;
  117. this.mustUnderstand = mustUnderstand;
  118. this.relay = relay;
  119. }
  120. public override string Actor
  121. {
  122. get { return actor; }
  123. }
  124. public override bool MustUnderstand
  125. {
  126. get { return mustUnderstand; }
  127. }
  128. public override bool Relay
  129. {
  130. get { return relay; }
  131. }
  132. }
  133. }
  134. class FromHeader : AddressingHeader
  135. {
  136. EndpointAddress from;
  137. const bool mustUnderstandValue = false;
  138. FromHeader(EndpointAddress from, AddressingVersion version)
  139. : base(version)
  140. {
  141. this.from = from;
  142. }
  143. public EndpointAddress From
  144. {
  145. get { return from; }
  146. }
  147. public override XmlDictionaryString DictionaryName
  148. {
  149. get { return XD.AddressingDictionary.From; }
  150. }
  151. public override bool MustUnderstand
  152. {
  153. get { return mustUnderstandValue; }
  154. }
  155. public static FromHeader Create(EndpointAddress from, AddressingVersion addressingVersion)
  156. {
  157. if (from == null)
  158. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("from"));
  159. if (addressingVersion == null)
  160. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("addressingVersion");
  161. return new FromHeader(from, addressingVersion);
  162. }
  163. protected override void OnWriteHeaderContents(XmlDictionaryWriter writer, MessageVersion messageVersion)
  164. {
  165. from.WriteContentsTo(this.Version, writer);
  166. }
  167. public static FromHeader ReadHeader(XmlDictionaryReader reader, AddressingVersion version,
  168. string actor, bool mustUnderstand, bool relay)
  169. {
  170. EndpointAddress from = ReadHeaderValue(reader, version);
  171. if (actor.Length == 0 && mustUnderstand == mustUnderstandValue && !relay)
  172. {
  173. return new FromHeader(from, version);
  174. }
  175. else
  176. {
  177. return new FullFromHeader(from, actor, mustUnderstand, relay, version);
  178. }
  179. }
  180. public static EndpointAddress ReadHeaderValue(XmlDictionaryReader reader, AddressingVersion addressingVersion)
  181. {
  182. Fx.Assert(reader.IsStartElement(XD.AddressingDictionary.From, addressingVersion.DictionaryNamespace), "");
  183. return EndpointAddress.ReadFrom(addressingVersion, reader);
  184. }
  185. class FullFromHeader : FromHeader
  186. {
  187. string actor;
  188. bool mustUnderstand;
  189. bool relay;
  190. public FullFromHeader(EndpointAddress from, string actor, bool mustUnderstand, bool relay, AddressingVersion version)
  191. : base(from, version)
  192. {
  193. this.actor = actor;
  194. this.mustUnderstand = mustUnderstand;
  195. this.relay = relay;
  196. }
  197. public override string Actor
  198. {
  199. get { return actor; }
  200. }
  201. public override bool MustUnderstand
  202. {
  203. get { return mustUnderstand; }
  204. }
  205. public override bool Relay
  206. {
  207. get { return relay; }
  208. }
  209. }
  210. }
  211. class FaultToHeader : AddressingHeader
  212. {
  213. EndpointAddress faultTo;
  214. const bool mustUnderstandValue = false;
  215. FaultToHeader(EndpointAddress faultTo, AddressingVersion version)
  216. : base(version)
  217. {
  218. this.faultTo = faultTo;
  219. }
  220. public EndpointAddress FaultTo
  221. {
  222. get { return faultTo; }
  223. }
  224. public override XmlDictionaryString DictionaryName
  225. {
  226. get { return XD.AddressingDictionary.FaultTo; }
  227. }
  228. public override bool MustUnderstand
  229. {
  230. get { return mustUnderstandValue; }
  231. }
  232. protected override void OnWriteHeaderContents(XmlDictionaryWriter writer, MessageVersion messageVersion)
  233. {
  234. faultTo.WriteContentsTo(this.Version, writer);
  235. }
  236. public static FaultToHeader Create(EndpointAddress faultTo, AddressingVersion addressingVersion)
  237. {
  238. if (faultTo == null)
  239. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("faultTo"));
  240. if (addressingVersion == null)
  241. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("addressingVersion");
  242. return new FaultToHeader(faultTo, addressingVersion);
  243. }
  244. public static FaultToHeader ReadHeader(XmlDictionaryReader reader, AddressingVersion version,
  245. string actor, bool mustUnderstand, bool relay)
  246. {
  247. EndpointAddress faultTo = ReadHeaderValue(reader, version);
  248. if (actor.Length == 0 && mustUnderstand == mustUnderstandValue && !relay)
  249. {
  250. return new FaultToHeader(faultTo, version);
  251. }
  252. else
  253. {
  254. return new FullFaultToHeader(faultTo, actor, mustUnderstand, relay, version);
  255. }
  256. }
  257. public static EndpointAddress ReadHeaderValue(XmlDictionaryReader reader, AddressingVersion version)
  258. {
  259. Fx.Assert(reader.IsStartElement(XD.AddressingDictionary.FaultTo, version.DictionaryNamespace), "");
  260. return EndpointAddress.ReadFrom(version, reader);
  261. }
  262. class FullFaultToHeader : FaultToHeader
  263. {
  264. string actor;
  265. bool mustUnderstand;
  266. bool relay;
  267. public FullFaultToHeader(EndpointAddress faultTo, string actor, bool mustUnderstand, bool relay, AddressingVersion version)
  268. : base(faultTo, version)
  269. {
  270. this.actor = actor;
  271. this.mustUnderstand = mustUnderstand;
  272. this.relay = relay;
  273. }
  274. public override string Actor
  275. {
  276. get { return actor; }
  277. }
  278. public override bool MustUnderstand
  279. {
  280. get { return mustUnderstand; }
  281. }
  282. public override bool Relay
  283. {
  284. get { return relay; }
  285. }
  286. }
  287. }
  288. class ToHeader : AddressingHeader
  289. {
  290. Uri to;
  291. const bool mustUnderstandValue = true;
  292. static ToHeader anonymousToHeader10;
  293. static ToHeader anonymousToHeader200408;
  294. protected ToHeader(Uri to, AddressingVersion version)
  295. : base(version)
  296. {
  297. this.to = to;
  298. }
  299. static ToHeader AnonymousTo10
  300. {
  301. get
  302. {
  303. if (anonymousToHeader10 == null)
  304. anonymousToHeader10 = new AnonymousToHeader(AddressingVersion.WSAddressing10);
  305. return anonymousToHeader10;
  306. }
  307. }
  308. static ToHeader AnonymousTo200408
  309. {
  310. get
  311. {
  312. if (anonymousToHeader200408 == null)
  313. anonymousToHeader200408 = new AnonymousToHeader(AddressingVersion.WSAddressingAugust2004);
  314. return anonymousToHeader200408;
  315. }
  316. }
  317. public override XmlDictionaryString DictionaryName
  318. {
  319. get { return XD.AddressingDictionary.To; }
  320. }
  321. public override bool MustUnderstand
  322. {
  323. get { return mustUnderstandValue; }
  324. }
  325. public Uri To
  326. {
  327. get { return to; }
  328. }
  329. public static ToHeader Create(Uri toUri, XmlDictionaryString dictionaryTo, AddressingVersion addressingVersion)
  330. {
  331. if (addressingVersion == null)
  332. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("addressingVersion");
  333. if (((object)toUri == (object)addressingVersion.AnonymousUri))
  334. {
  335. if (addressingVersion == AddressingVersion.WSAddressing10)
  336. return AnonymousTo10;
  337. else
  338. return AnonymousTo200408;
  339. }
  340. else
  341. {
  342. return new DictionaryToHeader(toUri, dictionaryTo, addressingVersion);
  343. }
  344. }
  345. public static ToHeader Create(Uri to, AddressingVersion addressingVersion)
  346. {
  347. if ((object)to == null)
  348. {
  349. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("to"));
  350. }
  351. else if ((object)to == (object)addressingVersion.AnonymousUri)
  352. {
  353. if (addressingVersion == AddressingVersion.WSAddressing10)
  354. return AnonymousTo10;
  355. else
  356. return AnonymousTo200408;
  357. }
  358. else
  359. {
  360. return new ToHeader(to, addressingVersion);
  361. }
  362. }
  363. protected override void OnWriteHeaderContents(XmlDictionaryWriter writer, MessageVersion messageVersion)
  364. {
  365. writer.WriteString(to.AbsoluteUri);
  366. }
  367. public static Uri ReadHeaderValue(XmlDictionaryReader reader, AddressingVersion version)
  368. {
  369. return ReadHeaderValue(reader, version, null);
  370. }
  371. public static Uri ReadHeaderValue(XmlDictionaryReader reader, AddressingVersion version, UriCache uriCache)
  372. {
  373. Fx.Assert(reader.IsStartElement(XD.AddressingDictionary.To, version.DictionaryNamespace), "");
  374. string toString = reader.ReadElementContentAsString();
  375. if ((object)toString == (object)version.Anonymous)
  376. {
  377. return version.AnonymousUri;
  378. }
  379. if (uriCache == null)
  380. {
  381. return new Uri(toString);
  382. }
  383. return uriCache.CreateUri(toString);
  384. }
  385. public static ToHeader ReadHeader(XmlDictionaryReader reader, AddressingVersion version, UriCache uriCache,
  386. string actor, bool mustUnderstand, bool relay)
  387. {
  388. Uri to = ReadHeaderValue(reader, version, uriCache);
  389. if (actor.Length == 0 && mustUnderstand == mustUnderstandValue && !relay)
  390. {
  391. if ((object)to == (object)version.Anonymous)
  392. {
  393. if (version == AddressingVersion.WSAddressing10)
  394. return AnonymousTo10;
  395. else
  396. return AnonymousTo200408;
  397. }
  398. else
  399. {
  400. return new ToHeader(to, version);
  401. }
  402. }
  403. else
  404. {
  405. return new FullToHeader(to, actor, mustUnderstand, relay, version);
  406. }
  407. }
  408. class AnonymousToHeader : ToHeader
  409. {
  410. public AnonymousToHeader(AddressingVersion version)
  411. : base(version.AnonymousUri, version)
  412. {
  413. }
  414. protected override void OnWriteHeaderContents(XmlDictionaryWriter writer, MessageVersion messageVersion)
  415. {
  416. writer.WriteString(this.Version.DictionaryAnonymous);
  417. }
  418. }
  419. class DictionaryToHeader : ToHeader
  420. {
  421. XmlDictionaryString dictionaryTo;
  422. public DictionaryToHeader(Uri to, XmlDictionaryString dictionaryTo, AddressingVersion version)
  423. : base(to, version)
  424. {
  425. this.dictionaryTo = dictionaryTo;
  426. }
  427. protected override void OnWriteHeaderContents(XmlDictionaryWriter writer, MessageVersion messageVersion)
  428. {
  429. writer.WriteString(dictionaryTo);
  430. }
  431. }
  432. class FullToHeader : ToHeader
  433. {
  434. string actor;
  435. bool mustUnderstand;
  436. bool relay;
  437. public FullToHeader(Uri to, string actor, bool mustUnderstand, bool relay, AddressingVersion version)
  438. : base(to, version)
  439. {
  440. this.actor = actor;
  441. this.mustUnderstand = mustUnderstand;
  442. this.relay = relay;
  443. }
  444. public override string Actor
  445. {
  446. get { return actor; }
  447. }
  448. public override bool MustUnderstand
  449. {
  450. get { return mustUnderstand; }
  451. }
  452. public override bool Relay
  453. {
  454. get { return relay; }
  455. }
  456. }
  457. }
  458. class ReplyToHeader : AddressingHeader
  459. {
  460. EndpointAddress replyTo;
  461. const bool mustUnderstandValue = false;
  462. static ReplyToHeader anonymousReplyToHeader10;
  463. static ReplyToHeader anonymousReplyToHeader200408;
  464. ReplyToHeader(EndpointAddress replyTo, AddressingVersion version)
  465. : base(version)
  466. {
  467. this.replyTo = replyTo;
  468. }
  469. public EndpointAddress ReplyTo
  470. {
  471. get { return replyTo; }
  472. }
  473. public override XmlDictionaryString DictionaryName
  474. {
  475. get { return XD.AddressingDictionary.ReplyTo; }
  476. }
  477. public override bool MustUnderstand
  478. {
  479. get { return mustUnderstandValue; }
  480. }
  481. public static ReplyToHeader AnonymousReplyTo10
  482. {
  483. get
  484. {
  485. if (anonymousReplyToHeader10 == null)
  486. anonymousReplyToHeader10 = new ReplyToHeader(EndpointAddress.AnonymousAddress, AddressingVersion.WSAddressing10);
  487. return anonymousReplyToHeader10;
  488. }
  489. }
  490. public static ReplyToHeader AnonymousReplyTo200408
  491. {
  492. get
  493. {
  494. if (anonymousReplyToHeader200408 == null)
  495. anonymousReplyToHeader200408 = new ReplyToHeader(EndpointAddress.AnonymousAddress, AddressingVersion.WSAddressingAugust2004);
  496. return anonymousReplyToHeader200408;
  497. }
  498. }
  499. public static ReplyToHeader Create(EndpointAddress replyTo, AddressingVersion addressingVersion)
  500. {
  501. if (replyTo == null)
  502. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("replyTo"));
  503. if (addressingVersion == null)
  504. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("addressingVersion"));
  505. return new ReplyToHeader(replyTo, addressingVersion);
  506. }
  507. protected override void OnWriteHeaderContents(XmlDictionaryWriter writer, MessageVersion messageVersion)
  508. {
  509. replyTo.WriteContentsTo(this.Version, writer);
  510. }
  511. public static ReplyToHeader ReadHeader(XmlDictionaryReader reader, AddressingVersion version,
  512. string actor, bool mustUnderstand, bool relay)
  513. {
  514. EndpointAddress replyTo = ReadHeaderValue(reader, version);
  515. if (actor.Length == 0 && mustUnderstand == mustUnderstandValue && !relay)
  516. {
  517. if ((object)replyTo == (object)EndpointAddress.AnonymousAddress)
  518. {
  519. if (version == AddressingVersion.WSAddressing10)
  520. return AnonymousReplyTo10;
  521. else
  522. return AnonymousReplyTo200408;
  523. }
  524. return new ReplyToHeader(replyTo, version);
  525. }
  526. else
  527. {
  528. return new FullReplyToHeader(replyTo, actor, mustUnderstand, relay, version);
  529. }
  530. }
  531. public static EndpointAddress ReadHeaderValue(XmlDictionaryReader reader, AddressingVersion version)
  532. {
  533. Fx.Assert(reader.IsStartElement(XD.AddressingDictionary.ReplyTo, version.DictionaryNamespace), "");
  534. return EndpointAddress.ReadFrom(version, reader);
  535. }
  536. class FullReplyToHeader : ReplyToHeader
  537. {
  538. string actor;
  539. bool mustUnderstand;
  540. bool relay;
  541. public FullReplyToHeader(EndpointAddress replyTo, string actor, bool mustUnderstand, bool relay, AddressingVersion version)
  542. : base(replyTo, version)
  543. {
  544. this.actor = actor;
  545. this.mustUnderstand = mustUnderstand;
  546. this.relay = relay;
  547. }
  548. public override string Actor
  549. {
  550. get { return actor; }
  551. }
  552. public override bool MustUnderstand
  553. {
  554. get { return mustUnderstand; }
  555. }
  556. public override bool Relay
  557. {
  558. get { return relay; }
  559. }
  560. }
  561. }
  562. class MessageIDHeader : AddressingHeader
  563. {
  564. UniqueId messageId;
  565. const bool mustUnderstandValue = false;
  566. MessageIDHeader(UniqueId messageId, AddressingVersion version)
  567. : base(version)
  568. {
  569. this.messageId = messageId;
  570. }
  571. public override XmlDictionaryString DictionaryName
  572. {
  573. get { return XD.AddressingDictionary.MessageId; }
  574. }
  575. public UniqueId MessageId
  576. {
  577. get { return messageId; }
  578. }
  579. public override bool MustUnderstand
  580. {
  581. get { return mustUnderstandValue; }
  582. }
  583. public static MessageIDHeader Create(UniqueId messageId, AddressingVersion addressingVersion)
  584. {
  585. if (object.ReferenceEquals(messageId, null))
  586. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("messageId"));
  587. if (addressingVersion == null)
  588. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("addressingVersion"));
  589. return new MessageIDHeader(messageId, addressingVersion);
  590. }
  591. protected override void OnWriteHeaderContents(XmlDictionaryWriter writer, MessageVersion messageVersion)
  592. {
  593. writer.WriteValue(messageId);
  594. }
  595. public static UniqueId ReadHeaderValue(XmlDictionaryReader reader, AddressingVersion version)
  596. {
  597. Fx.Assert(reader.IsStartElement(XD.AddressingDictionary.MessageId, version.DictionaryNamespace), "");
  598. return reader.ReadElementContentAsUniqueId();
  599. }
  600. public static MessageIDHeader ReadHeader(XmlDictionaryReader reader, AddressingVersion version,
  601. string actor, bool mustUnderstand, bool relay)
  602. {
  603. UniqueId messageId = ReadHeaderValue(reader, version);
  604. if (actor.Length == 0 && mustUnderstand == mustUnderstandValue && !relay)
  605. {
  606. return new MessageIDHeader(messageId, version);
  607. }
  608. else
  609. {
  610. return new FullMessageIDHeader(messageId, actor, mustUnderstand, relay, version);
  611. }
  612. }
  613. class FullMessageIDHeader : MessageIDHeader
  614. {
  615. string actor;
  616. bool mustUnderstand;
  617. bool relay;
  618. public FullMessageIDHeader(UniqueId messageId, string actor, bool mustUnderstand, bool relay, AddressingVersion version)
  619. : base(messageId, version)
  620. {
  621. this.actor = actor;
  622. this.mustUnderstand = mustUnderstand;
  623. this.relay = relay;
  624. }
  625. public override string Actor
  626. {
  627. get { return actor; }
  628. }
  629. public override bool MustUnderstand
  630. {
  631. get { return mustUnderstand; }
  632. }
  633. public override bool Relay
  634. {
  635. get { return relay; }
  636. }
  637. }
  638. }
  639. class RelatesToHeader : AddressingHeader
  640. {
  641. UniqueId messageId;
  642. const bool mustUnderstandValue = false;
  643. internal static readonly Uri ReplyRelationshipType = new Uri(Addressing10Strings.ReplyRelationship);
  644. RelatesToHeader(UniqueId messageId, AddressingVersion version)
  645. : base(version)
  646. {
  647. this.messageId = messageId;
  648. }
  649. public override XmlDictionaryString DictionaryName
  650. {
  651. get { return XD.AddressingDictionary.RelatesTo; }
  652. }
  653. public UniqueId UniqueId
  654. {
  655. get { return messageId; }
  656. }
  657. public override bool MustUnderstand
  658. {
  659. get { return mustUnderstandValue; }
  660. }
  661. public virtual Uri RelationshipType
  662. {
  663. get { return ReplyRelationshipType; }
  664. }
  665. public static RelatesToHeader Create(UniqueId messageId, AddressingVersion addressingVersion)
  666. {
  667. if (object.ReferenceEquals(messageId, null))
  668. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("messageId"));
  669. if (addressingVersion == null)
  670. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("addressingVersion"));
  671. return new RelatesToHeader(messageId, addressingVersion);
  672. }
  673. public static RelatesToHeader Create(UniqueId messageId, AddressingVersion addressingVersion, Uri relationshipType)
  674. {
  675. if (object.ReferenceEquals(messageId, null))
  676. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("messageId"));
  677. if (addressingVersion == null)
  678. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("addressingVersion"));
  679. if (relationshipType == null)
  680. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("relationshipType"));
  681. if (relationshipType == ReplyRelationshipType)
  682. {
  683. return new RelatesToHeader(messageId, addressingVersion);
  684. }
  685. else
  686. {
  687. return new FullRelatesToHeader(messageId, "", false, false, addressingVersion);
  688. }
  689. }
  690. protected override void OnWriteHeaderContents(XmlDictionaryWriter writer, MessageVersion messageVersion)
  691. {
  692. writer.WriteValue(messageId);
  693. }
  694. public static void ReadHeaderValue(XmlDictionaryReader reader, AddressingVersion version, out Uri relationshipType, out UniqueId messageId)
  695. {
  696. AddressingDictionary addressingDictionary = XD.AddressingDictionary;
  697. // The RelationshipType attribute has no namespace.
  698. relationshipType = ReplyRelationshipType;
  699. /*
  700. string relation = reader.GetAttribute(addressingDictionary.RelationshipType, addressingDictionary.Empty);
  701. if (relation == null)
  702. {
  703. relationshipType = ReplyRelationshipType;
  704. }
  705. else
  706. {
  707. relationshipType = new Uri(relation);
  708. }
  709. */
  710. Fx.Assert(reader.IsStartElement(addressingDictionary.RelatesTo, version.DictionaryNamespace), "");
  711. messageId = reader.ReadElementContentAsUniqueId();
  712. }
  713. public static RelatesToHeader ReadHeader(XmlDictionaryReader reader, AddressingVersion version,
  714. string actor, bool mustUnderstand, bool relay)
  715. {
  716. UniqueId messageId;
  717. Uri relationship;
  718. ReadHeaderValue(reader, version, out relationship, out messageId);
  719. if (actor.Length == 0 && mustUnderstand == mustUnderstandValue && !relay && (object)relationship == (object)ReplyRelationshipType)
  720. {
  721. return new RelatesToHeader(messageId, version);
  722. }
  723. else
  724. {
  725. return new FullRelatesToHeader(messageId, actor, mustUnderstand, relay, version);
  726. }
  727. }
  728. class FullRelatesToHeader : RelatesToHeader
  729. {
  730. string actor;
  731. bool mustUnderstand;
  732. bool relay;
  733. //Uri relationship;
  734. public FullRelatesToHeader(UniqueId messageId, string actor, bool mustUnderstand, bool relay, AddressingVersion version)
  735. : base(messageId, version)
  736. {
  737. //this.relationship = relationship;
  738. this.actor = actor;
  739. this.mustUnderstand = mustUnderstand;
  740. this.relay = relay;
  741. }
  742. public override string Actor
  743. {
  744. get { return actor; }
  745. }
  746. public override bool MustUnderstand
  747. {
  748. get { return mustUnderstand; }
  749. }
  750. /*
  751. public override Uri RelationshipType
  752. {
  753. get { return relationship; }
  754. }
  755. */
  756. public override bool Relay
  757. {
  758. get { return relay; }
  759. }
  760. protected override void OnWriteHeaderContents(XmlDictionaryWriter writer, MessageVersion messageVersion)
  761. {
  762. /*
  763. if ((object)relationship != (object)ReplyRelationshipType)
  764. {
  765. // The RelationshipType attribute has no namespace.
  766. writer.WriteStartAttribute(AddressingStrings.RelationshipType, AddressingStrings.Empty);
  767. writer.WriteString(relationship.AbsoluteUri);
  768. writer.WriteEndAttribute();
  769. }
  770. */
  771. writer.WriteValue(messageId);
  772. }
  773. }
  774. }
  775. }