ServiceDescriptionImporter.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. //
  2. // System.Web.Services.Description.ServiceDescriptionImporter.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;
  31. using System.CodeDom;
  32. using System.CodeDom.Compiler;
  33. using System.Web.Services;
  34. using System.Web.Services.Protocols;
  35. using System.Web.Services.Description;
  36. using System.Xml.Serialization;
  37. using System.Xml;
  38. using System.Collections;
  39. using System.Collections.Specialized;
  40. using System.Configuration;
  41. namespace System.Web.Services.Description {
  42. public class ServiceDescriptionImporter {
  43. #region Fields
  44. string protocolName;
  45. XmlSchemas schemas;
  46. ServiceDescriptionCollection serviceDescriptions;
  47. ServiceDescriptionImportStyle style;
  48. ArrayList importInfo = new ArrayList ();
  49. #endregion // Fields
  50. #region Constructors
  51. public ServiceDescriptionImporter ()
  52. {
  53. protocolName = String.Empty;
  54. schemas = new XmlSchemas ();
  55. serviceDescriptions = new ServiceDescriptionCollection ();
  56. style = ServiceDescriptionImportStyle.Client;
  57. }
  58. #endregion // Constructors
  59. #region Properties
  60. public string ProtocolName {
  61. get { return protocolName; }
  62. set { protocolName = value; }
  63. }
  64. public XmlSchemas Schemas {
  65. get { return schemas; }
  66. }
  67. public ServiceDescriptionCollection ServiceDescriptions {
  68. get { return serviceDescriptions; }
  69. }
  70. public ServiceDescriptionImportStyle Style {
  71. get { return style; }
  72. set { style = value; }
  73. }
  74. #if NET_2_0
  75. [MonoTODO]
  76. [System.Runtime.InteropServices.ComVisible(false)]
  77. public CodeGenerationOptions CodeGenerationOptions {
  78. get { throw new NotImplementedException (); }
  79. set { throw new NotImplementedException (); }
  80. }
  81. [MonoTODO]
  82. [System.Runtime.InteropServices.ComVisible(false)]
  83. public ICodeGenerator CodeGenerator {
  84. get { throw new NotImplementedException (); }
  85. set { throw new NotImplementedException (); }
  86. }
  87. #endif
  88. #endregion // Properties
  89. #region Methods
  90. public void AddServiceDescription (ServiceDescription serviceDescription, string appSettingUrlKey, string appSettingBaseUrl)
  91. {
  92. if (appSettingUrlKey != null && appSettingUrlKey == string.Empty && style == ServiceDescriptionImportStyle.Server)
  93. throw new InvalidOperationException ("Cannot set appSettingUrlKey if Style is Server");
  94. ImportInfo info = new ImportInfo ();
  95. info.ServiceDescription = serviceDescription;
  96. info.AppSettingUrlKey = appSettingUrlKey;
  97. info.AppSettingBaseUrl = appSettingBaseUrl;
  98. importInfo.Add (info);
  99. serviceDescriptions.Add (serviceDescription);
  100. if (serviceDescription.Types != null)
  101. schemas.Add (serviceDescription.Types.Schemas);
  102. }
  103. public ServiceDescriptionImportWarnings Import (CodeNamespace codeNamespace, CodeCompileUnit codeCompileUnit)
  104. {
  105. ProtocolImporter importer = GetImporter ();
  106. if (!importer.Import (this, codeNamespace, codeCompileUnit, importInfo))
  107. throw new Exception ("None of the supported bindings was found");
  108. return importer.Warnings;
  109. }
  110. ProtocolImporter GetImporter ()
  111. {
  112. ArrayList importers = GetSupportedImporters ();
  113. if (protocolName == null || protocolName == "") protocolName = "Soap";
  114. foreach (ProtocolImporter importer in importers) {
  115. if (importer.ProtocolName == protocolName)
  116. return importer;
  117. }
  118. throw new Exception ("Protocol " + protocolName + " not supported");
  119. }
  120. ArrayList GetSupportedImporters ()
  121. {
  122. ArrayList list = new ArrayList ();
  123. list.Add (new SoapProtocolImporter ());
  124. list.Add (new HttpGetProtocolImporter ());
  125. list.Add (new HttpPostProtocolImporter ());
  126. return list;
  127. }
  128. #if NET_2_0
  129. [MonoTODO]
  130. public static StringCollection GenerateWebReferences (
  131. WebReferenceCollection webReferences,
  132. CodeGenerationOptions options,
  133. ServiceDescriptionImportStyle style,
  134. ICodeGenerator codeGenerator)
  135. {
  136. throw new NotImplementedException ();
  137. }
  138. [MonoTODO]
  139. public static StringCollection GenerateWebReferences (
  140. WebReferenceCollection webReferences,
  141. CodeGenerationOptions options,
  142. ServiceDescriptionImportStyle style,
  143. ICodeGenerator codeGenerator,
  144. CodeCompileUnit codeCompileUnit,
  145. bool verbose)
  146. {
  147. throw new NotImplementedException ();
  148. }
  149. #endif
  150. #endregion
  151. }
  152. internal class ImportInfo
  153. {
  154. public ServiceDescription ServiceDescription;
  155. public string AppSettingUrlKey;
  156. public string AppSettingBaseUrl;
  157. }
  158. }