(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / System.Web.Services / System.Web.Services.Discovery / DiscoveryRequestHandler.cs
blob394bf7f5a91d8467999a053a24dc3a19029696c8
1 //
2 // System.Web.Services.Discovery.DiscoveryRequestHandler.cs
3 //
4 // Author:
5 // Dave Bettin (javabettin@yahoo.com)
6 // Lluis Sanchez Gual (lluis@ximian.com)
7 //
8 // Copyright (C) Dave Bettin, 2002
9 //
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:
19 //
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
22 //
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.
32 using System.Web;
33 using System.IO;
34 using System.Web.Services.Discovery;
36 namespace System.Web.Services.Discovery {
37 public sealed class DiscoveryRequestHandler : IHttpHandler {
39 #region Constructors
41 public DiscoveryRequestHandler ()
45 #endregion // Constructors
47 #region Properties
49 public bool IsReusable {
50 get { return true; }
53 #endregion // Properties
55 #region Methods
57 public void ProcessRequest (HttpContext context)
59 string path = context.Request.PhysicalPath;
60 FileStream fs = new FileStream (path, FileMode.Open);
61 DynamicDiscoveryDocument ddoc = DynamicDiscoveryDocument.Load (fs);
62 fs.Close ();
64 string url = context.Request.Url.ToString();
65 int i = url.LastIndexOf ('/');
66 if (i != -1) url = url.Substring (0,i+1);
68 DiscoveryDocument doc = new DiscoveryDocument ();
69 GetFiles (url, "", Path.GetDirectoryName(path), doc, ddoc);
71 context.Response.ContentType = "text/xml; charset=utf-8";
72 doc.Write (context.Response.OutputStream);
75 void GetFiles (string baseUrl, string relPath, string path, DiscoveryDocument doc, DynamicDiscoveryDocument ddoc)
77 string url = baseUrl + relPath;
78 if (!url.EndsWith ("/")) url += "/";
80 string[] files = Directory.GetFiles (path);
81 foreach (string file in files)
83 string ext = Path.GetExtension (file).ToLower();
84 if (ext == ".asmx")
86 ContractReference cref = new ContractReference ();
87 cref.DocRef = url + Path.GetFileName (file);
88 cref.Ref = cref.DocRef + "?wsdl";
89 doc.References.Add (cref);
91 else if (ext == ".disco")
93 DiscoveryDocumentReference dref = new DiscoveryDocumentReference ();
94 dref.Ref = url + Path.GetFileName (file);
95 doc.References.Add (dref);
98 string[] dirs = Directory.GetDirectories (path);
100 foreach (string dir in dirs)
102 string rel = Path.Combine (relPath, Path.GetFileName(dir));
103 if (!ddoc.IsExcluded (rel))
104 GetFiles (baseUrl, rel, Path.Combine (path, dir), doc, ddoc);
108 #endregion // Methods