ContractReference.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. //
  2. // System.Web.Services.Discovery.ContractReference.cs
  3. //
  4. // Author:
  5. // Dave Bettin ([email protected])
  6. // Lluis Sanchez Gual ([email protected])
  7. //
  8. // Copyright (C) Dave Bettin, 2002
  9. //
  10. using System.IO;
  11. using System.Web.Services.Description;
  12. using System.Xml.Serialization;
  13. namespace System.Web.Services.Discovery {
  14. [XmlRootAttribute("contractRef", Namespace="http://schemas.xmlsoap.org/disco/scl/", IsNullable=true)]
  15. public class ContractReference : DiscoveryReference {
  16. #region Fields
  17. public const string Namespace = "http://schemas.xmlsoap.org/disco/scl/";
  18. private ServiceDescription contract;
  19. private string defaultFilename;
  20. private string docRef;
  21. private string href;
  22. #endregion // Fields
  23. #region Constructors
  24. public ContractReference ()
  25. {
  26. }
  27. public ContractReference (string href) : this()
  28. {
  29. this.href = href;
  30. }
  31. public ContractReference (string href, string docRef)
  32. {
  33. this.href = href;
  34. this.docRef = docRef;
  35. }
  36. #endregion // Constructors
  37. #region Properties
  38. [XmlIgnore]
  39. public ServiceDescription Contract {
  40. get {
  41. if (ClientProtocol == null)
  42. throw new InvalidOperationException ("The ClientProtocol property is a null reference");
  43. ServiceDescription desc = ClientProtocol.Documents [Url] as ServiceDescription;
  44. if (desc == null)
  45. throw new Exception ("The Documents property of ClientProtocol does not contain a WSDL document with the url " + Url);
  46. return desc;
  47. }
  48. }
  49. [XmlIgnore]
  50. public override string DefaultFilename {
  51. get { return FilenameFromUrl (Url) + ".wsdl"; }
  52. }
  53. [XmlAttribute("docRef")]
  54. public string DocRef {
  55. get { return docRef; }
  56. set { docRef = value; }
  57. }
  58. [XmlAttribute("ref")]
  59. public string Ref {
  60. get { return href; }
  61. set { href = value; }
  62. }
  63. [XmlIgnore]
  64. public override string Url {
  65. get { return href;}
  66. set { href = value; }
  67. }
  68. #endregion // Properties
  69. #region Methods
  70. public override object ReadDocument (Stream stream)
  71. {
  72. return ServiceDescription.Read (stream);
  73. }
  74. protected internal override void Resolve (string contentType, Stream stream)
  75. {
  76. ServiceDescription wsdl = ServiceDescription.Read (stream);
  77. ClientProtocol.Documents.Add (Url, wsdl);
  78. if (!ClientProtocol.References.Contains (Url))
  79. ClientProtocol.References.Add (this);
  80. }
  81. public override void WriteDocument (object document, Stream stream)
  82. {
  83. ((ServiceDescription)document).Write (stream);
  84. }
  85. #endregion // Methods
  86. }
  87. }