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.Web.Services;
\r
35 using System.Web.Services.Protocols;
\r
36 using System.Web.Services.Description;
\r
37 using System.Xml.Serialization;
\r
39 using System.Collections;
\r
40 using System.Configuration;
\r
42 namespace System.Web.Services.Description {
\r
43 public class ServiceDescriptionImporter {
\r
47 string protocolName;
\r
49 ServiceDescriptionCollection serviceDescriptions;
\r
50 ServiceDescriptionImportStyle style;
\r
52 ArrayList importInfo = new ArrayList ();
\r
55 #endregion // Fields
\r
57 #region Constructors
\r
59 public ServiceDescriptionImporter ()
\r
61 protocolName = String.Empty;
\r
62 schemas = new XmlSchemas ();
\r
63 serviceDescriptions = new ServiceDescriptionCollection ();
\r
64 style = ServiceDescriptionImportStyle.Client;
\r
67 #endregion // Constructors
\r
71 public string ProtocolName {
\r
72 get { return protocolName; }
\r
73 set { protocolName = value; }
\r
76 public XmlSchemas Schemas {
\r
77 get { return schemas; }
\r
80 public ServiceDescriptionCollection ServiceDescriptions {
\r
81 get { return serviceDescriptions; }
\r
84 public ServiceDescriptionImportStyle Style {
\r
85 get { return style; }
\r
86 set { style = value; }
\r
89 #endregion // Properties
\r
93 public void AddServiceDescription (ServiceDescription serviceDescription, string appSettingUrlKey, string appSettingBaseUrl)
\r
95 if (appSettingUrlKey != null && appSettingUrlKey == string.Empty && style == ServiceDescriptionImportStyle.Server)
\r
96 throw new InvalidOperationException ("Cannot set appSettingUrlKey if Style is Server");
\r
98 ImportInfo info = new ImportInfo ();
\r
99 info.ServiceDescription = serviceDescription;
\r
100 info.AppSettingUrlKey = appSettingUrlKey;
\r
101 info.AppSettingBaseUrl = appSettingBaseUrl;
\r
102 importInfo.Add (info);
\r
103 serviceDescriptions.Add (serviceDescription);
\r
105 if (serviceDescription.Types != null)
\r
106 schemas.Add (serviceDescription.Types.Schemas);
\r
109 public ServiceDescriptionImportWarnings Import (CodeNamespace codeNamespace, CodeCompileUnit codeCompileUnit)
\r
111 ProtocolImporter importer = GetImporter ();
\r
113 if (!importer.Import (this, codeNamespace, codeCompileUnit, importInfo))
\r
114 throw new Exception ("None of the supported bindings was found");
\r
116 return importer.Warnings;
\r
119 ProtocolImporter GetImporter ()
\r
121 ArrayList importers = GetSupportedImporters ();
\r
122 if (protocolName == null || protocolName == "") protocolName = "Soap";
\r
123 foreach (ProtocolImporter importer in importers) {
\r
124 if (importer.ProtocolName == protocolName)
\r
128 throw new Exception ("Protocol " + protocolName + " not supported");
\r
131 ArrayList GetSupportedImporters ()
\r
133 ArrayList list = new ArrayList ();
\r
134 list.Add (new SoapProtocolImporter ());
\r
135 list.Add (new HttpGetProtocolImporter ());
\r
136 list.Add (new HttpPostProtocolImporter ());
\r
143 internal class ImportInfo
\r
145 public ServiceDescription ServiceDescription;
\r
146 public string AppSettingUrlKey;
\r
147 public string AppSettingBaseUrl;
\r