ServiceDescriptionReflector.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. //
  2. // System.Web.Services.Description.ServiceDescriptionReflector.cs
  3. //
  4. // Author:
  5. // Tim Coleman ([email protected])
  6. // Lluis Sanchez Gual ([email protected])
  7. //
  8. // Copyright (C) Tim Coleman, 2002
  9. //
  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.Web.Services;
  31. using System.Xml.Serialization;
  32. using System.Xml;
  33. using System.Xml.Schema;
  34. using System.Web.Services.Protocols;
  35. using System.Web.Services.Configuration;
  36. namespace System.Web.Services.Description {
  37. public class ServiceDescriptionReflector
  38. {
  39. ServiceDescriptionCollection serviceDescriptions;
  40. Types types;
  41. #region Constructors
  42. public ServiceDescriptionReflector ()
  43. {
  44. types = new Types ();
  45. serviceDescriptions = new ServiceDescriptionCollection ();
  46. }
  47. #endregion // Constructors
  48. #region Properties
  49. public XmlSchemas Schemas {
  50. get { return types.Schemas; }
  51. }
  52. public ServiceDescriptionCollection ServiceDescriptions {
  53. get { return serviceDescriptions; }
  54. }
  55. #endregion // Properties
  56. #region Methods
  57. public void Reflect (Type type, string url)
  58. {
  59. XmlSchemaExporter schemaExporter = new XmlSchemaExporter (Schemas);
  60. SoapSchemaExporter soapSchemaExporter = new SoapSchemaExporter (Schemas);
  61. new SoapProtocolReflector ().Reflect (this, type, url, schemaExporter, soapSchemaExporter);
  62. if (WSConfig.IsSupported (WSProtocol.HttpGet))
  63. new HttpGetProtocolReflector ().Reflect (this, type, url, schemaExporter, soapSchemaExporter);
  64. if (WSConfig.IsSupported (WSProtocol.HttpPost))
  65. new HttpPostProtocolReflector ().Reflect (this, type, url, schemaExporter, soapSchemaExporter);
  66. if (serviceDescriptions.Count == 1)
  67. serviceDescriptions[0].Types = types;
  68. else
  69. {
  70. foreach (ServiceDescription d in serviceDescriptions)
  71. {
  72. d.Types = new Types();
  73. for (int n=0; n<types.Schemas.Count; n++)
  74. ProtocolReflector.AddImport (d, types.Schemas[n].TargetNamespace, GetSchemaUrl (url, n));
  75. }
  76. }
  77. }
  78. string GetSchemaUrl (string baseUrl, int id)
  79. {
  80. return baseUrl + "?schema=" + id;
  81. }
  82. #endregion
  83. }
  84. }