ServiceDescriptionReflector.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. using System.Collections.Generic;
  37. using WSConfig = System.Web.Services.Configuration.WebServicesSection;
  38. using WSProtocol = System.Web.Services.Configuration.WebServiceProtocols;
  39. namespace System.Web.Services.Description {
  40. public class ServiceDescriptionReflector
  41. {
  42. ServiceDescriptionCollection serviceDescriptions;
  43. Types types;
  44. #region Constructors
  45. public ServiceDescriptionReflector ()
  46. {
  47. types = new Types ();
  48. serviceDescriptions = new ServiceDescriptionCollection ();
  49. }
  50. #endregion // Constructors
  51. internal Dictionary<LogicalMethodInfo,Message> MappedMessagesIn =
  52. new Dictionary<LogicalMethodInfo,Message> ();
  53. internal Dictionary<LogicalMethodInfo,Message> MappedMessagesOut =
  54. new Dictionary<LogicalMethodInfo,Message> ();
  55. #region Properties
  56. public XmlSchemas Schemas {
  57. get { return types.Schemas; }
  58. }
  59. public ServiceDescriptionCollection ServiceDescriptions {
  60. get { return serviceDescriptions; }
  61. }
  62. #endregion // Properties
  63. #region Methods
  64. public void Reflect (Type type, string url)
  65. {
  66. XmlSchemaExporter schemaExporter = new XmlSchemaExporter (Schemas);
  67. SoapSchemaExporter soapSchemaExporter = new SoapSchemaExporter (Schemas);
  68. if (WSConfig.IsSupported (WSProtocol.HttpSoap))
  69. new Soap11ProtocolReflector ().Reflect (this, type, url, schemaExporter, soapSchemaExporter);
  70. if (WSConfig.IsSupported (WSProtocol.HttpSoap12))
  71. new Soap12ProtocolReflector ().Reflect (this, type, url, schemaExporter, soapSchemaExporter);
  72. if (WSConfig.IsSupported (WSProtocol.HttpGet))
  73. new HttpGetProtocolReflector ().Reflect (this, type, url, schemaExporter, soapSchemaExporter);
  74. if (WSConfig.IsSupported (WSProtocol.HttpPost))
  75. new HttpPostProtocolReflector ().Reflect (this, type, url, schemaExporter, soapSchemaExporter);
  76. int i=0;
  77. while (i < types.Schemas.Count) {
  78. if (types.Schemas[i].Items.Count == 0) types.Schemas.RemoveAt (i);
  79. else i++;
  80. }
  81. if (serviceDescriptions.Count == 1)
  82. serviceDescriptions[0].Types = types;
  83. else
  84. {
  85. foreach (ServiceDescription d in serviceDescriptions)
  86. {
  87. d.Types = new Types();
  88. for (int n=0; n<types.Schemas.Count; n++)
  89. ProtocolReflector.AddImport (d, types.Schemas[n].TargetNamespace, GetSchemaUrl (url, n));
  90. }
  91. }
  92. }
  93. string GetSchemaUrl (string baseUrl, int id)
  94. {
  95. return baseUrl + "?schema=" + id;
  96. }
  97. #endregion
  98. }
  99. }