2 // System.Web.Services.Description.ServiceDescriptionImporter.cs
\r
5 // Tim Coleman (tim@timcoleman.com)
\r
6 // Lluis Sanchez Gual (lluis@ximian.com)
\r
8 // Copyright (C) Tim Coleman, 2002
\r
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 using System.CodeDom;
\r
34 using System.CodeDom.Compiler;
\r
35 using System.Web.Services;
\r
36 using System.Web.Services.Protocols;
\r
37 using System.Web.Services.Description;
\r
38 using System.Xml.Serialization;
\r
40 using System.Collections;
\r
41 using System.Collections.Specialized;
\r
42 using System.Configuration;
\r
44 namespace System.Web.Services.Description {
\r
45 public class ServiceDescriptionImporter {
\r
49 string protocolName;
\r
51 ServiceDescriptionCollection serviceDescriptions;
\r
52 ServiceDescriptionImportStyle style;
\r
54 ArrayList importInfo = new ArrayList ();
\r
57 #endregion // Fields
\r
59 #region Constructors
\r
61 public ServiceDescriptionImporter ()
\r
63 protocolName = String.Empty;
\r
64 schemas = new XmlSchemas ();
\r
65 serviceDescriptions = new ServiceDescriptionCollection ();
\r
66 style = ServiceDescriptionImportStyle.Client;
\r
69 #endregion // Constructors
\r
73 public string ProtocolName {
\r
74 get { return protocolName; }
\r
75 set { protocolName = value; }
\r
78 public XmlSchemas Schemas {
\r
79 get { return schemas; }
\r
82 public ServiceDescriptionCollection ServiceDescriptions {
\r
83 get { return serviceDescriptions; }
\r
86 public ServiceDescriptionImportStyle Style {
\r
87 get { return style; }
\r
88 set { style = value; }
\r
93 [System.Runtime.InteropServices.ComVisible(false)]
\r
94 public CodeGenerationOptions CodeGenerationOptions {
\r
95 get { throw new NotImplementedException (); }
\r
96 set { throw new NotImplementedException (); }
\r
100 [System.Runtime.InteropServices.ComVisible(false)]
\r
101 public ICodeGenerator CodeGenerator {
\r
102 get { throw new NotImplementedException (); }
\r
103 set { throw new NotImplementedException (); }
\r
107 #endregion // Properties
\r
111 public void AddServiceDescription (ServiceDescription serviceDescription, string appSettingUrlKey, string appSettingBaseUrl)
\r
113 if (appSettingUrlKey != null && appSettingUrlKey == string.Empty && style == ServiceDescriptionImportStyle.Server)
\r
114 throw new InvalidOperationException ("Cannot set appSettingUrlKey if Style is Server");
\r
116 ImportInfo info = new ImportInfo ();
\r
117 info.ServiceDescription = serviceDescription;
\r
118 info.AppSettingUrlKey = appSettingUrlKey;
\r
119 info.AppSettingBaseUrl = appSettingBaseUrl;
\r
120 importInfo.Add (info);
\r
121 serviceDescriptions.Add (serviceDescription);
\r
123 if (serviceDescription.Types != null)
\r
124 schemas.Add (serviceDescription.Types.Schemas);
\r
127 public ServiceDescriptionImportWarnings Import (CodeNamespace codeNamespace, CodeCompileUnit codeCompileUnit)
\r
129 ProtocolImporter importer = GetImporter ();
\r
131 if (!importer.Import (this, codeNamespace, codeCompileUnit, importInfo))
\r
132 throw new Exception ("None of the supported bindings was found");
\r
134 return importer.Warnings;
\r
137 ProtocolImporter GetImporter ()
\r
139 ArrayList importers = GetSupportedImporters ();
\r
140 if (protocolName == null || protocolName == "") protocolName = "Soap";
\r
141 foreach (ProtocolImporter importer in importers) {
\r
142 if (importer.ProtocolName == protocolName)
\r
146 throw new Exception ("Protocol " + protocolName + " not supported");
\r
149 ArrayList GetSupportedImporters ()
\r
151 ArrayList list = new ArrayList ();
\r
152 list.Add (new SoapProtocolImporter ());
\r
153 list.Add (new HttpGetProtocolImporter ());
\r
154 list.Add (new HttpPostProtocolImporter ());
\r
160 public static StringCollection GenerateWebReferences (
\r
161 WebReferenceCollection webReferences,
\r
162 CodeGenerationOptions options,
\r
163 ServiceDescriptionImportStyle style,
\r
164 ICodeGenerator codeGenerator)
\r
166 throw new NotImplementedException ();
\r
170 public static StringCollection GenerateWebReferences (
\r
171 WebReferenceCollection webReferences,
\r
172 CodeGenerationOptions options,
\r
173 ServiceDescriptionImportStyle style,
\r
174 ICodeGenerator codeGenerator,
\r
175 CodeCompileUnit codeCompileUnit,
\r
178 throw new NotImplementedException ();
\r
185 internal class ImportInfo
\r
187 public ServiceDescription ServiceDescription;
\r
188 public string AppSettingUrlKey;
\r
189 public string AppSettingBaseUrl;
\r