2 // System.Web.Services.Discovery.DiscoveryRequestHandler.cs
\r
5 // Dave Bettin (javabettin@yahoo.com)
\r
6 // Lluis Sanchez Gual (lluis@ximian.com)
\r
8 // Copyright (C) Dave Bettin, 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.
34 using System.Web.Services.Discovery;
\r
36 namespace System.Web.Services.Discovery {
\r
37 public sealed class DiscoveryRequestHandler : IHttpHandler {
\r
39 #region Constructors
\r
41 public DiscoveryRequestHandler ()
\r
45 #endregion // Constructors
\r
49 public bool IsReusable {
\r
50 get { return true; }
\r
53 #endregion // Properties
\r
57 public void ProcessRequest (HttpContext context)
\r
59 string path = context.Request.PhysicalPath;
\r
60 FileStream fs = new FileStream (path, FileMode.Open);
\r
61 DynamicDiscoveryDocument ddoc = DynamicDiscoveryDocument.Load (fs);
\r
64 string url = context.Request.Url.ToString();
\r
65 int i = url.LastIndexOf ('/');
\r
66 if (i != -1) url = url.Substring (0,i+1);
\r
68 DiscoveryDocument doc = new DiscoveryDocument ();
\r
69 GetFiles (url, "", Path.GetDirectoryName(path), doc, ddoc);
\r
71 context.Response.ContentType = "text/xml; charset=utf-8";
\r
72 doc.Write (context.Response.OutputStream);
\r
75 void GetFiles (string baseUrl, string relPath, string path, DiscoveryDocument doc, DynamicDiscoveryDocument ddoc)
\r
77 string url = baseUrl + relPath;
\r
78 if (!url.EndsWith ("/")) url += "/";
\r
80 string[] files = Directory.GetFiles (path);
\r
81 foreach (string file in files)
\r
83 string ext = Path.GetExtension (file).ToLower();
\r
86 ContractReference cref = new ContractReference ();
\r
87 cref.DocRef = url + Path.GetFileName (file);
\r
88 cref.Ref = cref.DocRef + "?wsdl";
\r
89 doc.References.Add (cref);
\r
91 else if (ext == ".disco")
\r
93 DiscoveryDocumentReference dref = new DiscoveryDocumentReference ();
\r
94 dref.Ref = url + Path.GetFileName (file);
\r
95 doc.References.Add (dref);
\r
98 string[] dirs = Directory.GetDirectories (path);
\r
100 foreach (string dir in dirs)
\r
102 string rel = Path.Combine (relPath, Path.GetFileName(dir));
\r
103 if (!ddoc.IsExcluded (rel))
\r
104 GetFiles (baseUrl, rel, Path.Combine (path, dir), doc, ddoc);
\r
108 #endregion // Methods
\r