Merge pull request #2377 from joelmartinez/docs-multiassembly-extension-fix
[mono.git] / mcs / class / System.Web.Services / System.Web.Services.Protocols / SoapDocumentationHandler.cs
index f6f9322aa3637bac8ec85accb0a9335047107073..61ad6a1e20eed75761bafd92e5343b1ab9842933 100644 (file)
@@ -36,6 +36,7 @@ using System.Xml;
 using System.Text;
 using System.Xml.Serialization;
 using System.Xml.Schema;
+using System.Web.Compilation;
 using System.Web.Services.Description;
 using System.Web.Services.Discovery;
 using System.Web.Services.Configuration;
@@ -58,7 +59,7 @@ namespace System.Web.Services.Protocols
                public SoapDocumentationHandler (Type type, HttpContext context): base (type)
                {
                        _url = context.Request.Url.ToString();
-                       int i = _url.LastIndexOf ('?');
+                       int i = _url.IndexOf ('?');
                        if (i != -1) _url = _url.Substring (0,i);
                        _typeStubInfo = (SoapTypeStubInfo) TypeStubManager.GetTypeStub (ServiceType, "Soap");
                        
@@ -76,13 +77,8 @@ namespace System.Web.Services.Protocols
                        if (key == "wsdl" || key == "schema" || key == "code" || key == "disco")
                                return;
                                
-#if NET_2_0
-                       string help = WebServicesSection.Instance.WsdlHelpGenerator.Href;
+                       string help = WebServicesSection.Current.WsdlHelpGenerator.Href;
                        string path = Path.GetDirectoryName (ConfigurationManager.OpenMachineConfiguration().FilePath);
-#else
-                       string help = WSConfig.Instance.WsdlHelpPage;
-                       string path = Path.GetDirectoryName (WSConfig.Instance.ConfigFilePath);
-#endif
                        string appPath = AppDomain.CurrentDomain.GetData (".appPath").ToString ();
                        string vpath;
                        if (path.StartsWith (appPath)) {
@@ -99,12 +95,10 @@ namespace System.Web.Services.Protocols
 
                        string physPath = Path.Combine (path, help);
                        
-#if !TARGET_JVM
                        if (!File.Exists (physPath))
                                throw new InvalidOperationException ("Documentation page '" + physPath + "' not found");
-#endif
+
                        _pageHandler = PageParser.GetCompiledPageInstance (vpath, physPath, context);
-                               
                }
 
                internal IHttpHandler PageHandler {
@@ -136,11 +130,7 @@ namespace System.Web.Services.Protocols
 
                                if (key  == "wsdl") GenerateWsdlDocument (context, req.QueryString ["wsdl"]);
                                else if (key == "schema") GenerateSchema (context, req.QueryString ["schema"]);
-#if !TARGET_JVM //code generation is not supported
                                else if (key == "code") GenerateCode (context, req.QueryString ["code"]);
-#else
-                               else if (key == "code") throw new Exception("Code generation is not supported.");
-#endif
                                else if (key == "disco") GenerateDiscoDocument (context);
                                else throw new Exception ("This should never happen");
                        }
@@ -189,16 +179,28 @@ namespace System.Web.Services.Protocols
                
                void GenerateSchema (HttpContext context, string schemaId)
                {
-                       int di = 0;
-                       if (schemaId != null && schemaId != "") di = int.Parse (schemaId);
-                       
+                       int di = -1;
+                       if (schemaId != null && schemaId != "") {
+                               try {
+                                       di = int.Parse (schemaId);
+                               } catch {
+                                       XmlSchemas xss = GetSchemas ();
+                                       for (int i = 0; i < xss.Count; i++) {
+                                               if (xss [i].Id == schemaId) {
+                                                       di = i;
+                                                       break;
+                                               }
+                                       }
+                               }
+                               if (di < 0)
+                                       throw new InvalidOperationException (String.Format ("HTTP parameter 'schema' needs to specify an Id of a schema in the schemas. {0} points to nowhere.", schemaId));
+                       }
                        context.Response.ContentType = "text/xml; charset=utf-8";
                        XmlTextWriter xtw = new XmlTextWriter (context.Response.OutputStream, new UTF8Encoding (false));
                        xtw.Formatting = Formatting.Indented;
                        GetSchemas() [di].Write (xtw);
                }
 
-#if !TARGET_JVM                
                void GenerateCode (HttpContext context, string langId)
                {
                        context.Response.ContentType = "text/plain; charset=utf-8";
@@ -242,7 +244,6 @@ namespace System.Web.Services.Protocols
 
                        return provider;
                }
-#endif
                
                internal ServiceDescriptionCollection GetDescriptions ()
                {