ServiceDescriptionReflector.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. using System.Web.Services;
  11. using System.Xml.Serialization;
  12. using System.Xml;
  13. using System.Xml.Schema;
  14. using System.Web.Services.Protocols;
  15. using System.Web.Services.Configuration;
  16. namespace System.Web.Services.Description {
  17. public class ServiceDescriptionReflector
  18. {
  19. ServiceDescriptionCollection serviceDescriptions;
  20. Types types;
  21. #region Constructors
  22. public ServiceDescriptionReflector ()
  23. {
  24. types = new Types ();
  25. serviceDescriptions = new ServiceDescriptionCollection ();
  26. }
  27. #endregion // Constructors
  28. #region Properties
  29. public XmlSchemas Schemas {
  30. get { return types.Schemas; }
  31. }
  32. public ServiceDescriptionCollection ServiceDescriptions {
  33. get { return serviceDescriptions; }
  34. }
  35. #endregion // Properties
  36. #region Methods
  37. public void Reflect (Type type, string url)
  38. {
  39. XmlSchemaExporter schemaExporter = new XmlSchemaExporter (Schemas);
  40. SoapSchemaExporter soapSchemaExporter = new SoapSchemaExporter (Schemas);
  41. new SoapProtocolReflector ().Reflect (this, type, url, schemaExporter, soapSchemaExporter);
  42. if (WSConfig.IsSupported (WSProtocol.HttpGet))
  43. new HttpGetProtocolReflector ().Reflect (this, type, url, schemaExporter, soapSchemaExporter);
  44. if (WSConfig.IsSupported (WSProtocol.HttpPost))
  45. new HttpPostProtocolReflector ().Reflect (this, type, url, schemaExporter, soapSchemaExporter);
  46. if (serviceDescriptions.Count == 1)
  47. serviceDescriptions[0].Types = types;
  48. else
  49. {
  50. foreach (ServiceDescription d in serviceDescriptions)
  51. {
  52. d.Types = new Types();
  53. for (int n=0; n<types.Schemas.Count; n++)
  54. ProtocolReflector.AddImport (d, types.Schemas[n].TargetNamespace, GetSchemaUrl (url, n));
  55. }
  56. }
  57. }
  58. string GetSchemaUrl (string baseUrl, int id)
  59. {
  60. return baseUrl + "?schema=" + id;
  61. }
  62. #endregion
  63. }
  64. }