Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / data / net_2_0 / DefaultWsdlHelpGenerator.aspx
index e5b830e8a71c0ded3a265bfde09f66dc1041591c..f4d74bff7f5bca96ad3fc764e518b4d710854177 100644 (file)
@@ -10,6 +10,7 @@
 --%>
 
 <%@ Import Namespace="System.Collections" %>
+<%@ Import Namespace="System.Collections.Generic" %>
 <%@ Import Namespace="System.IO" %>
 <%@ Import Namespace="System.Xml.Serialization" %>
 <%@ Import Namespace="System.Xml" %>
 <%@ Page debug="true" %>
 
 <html>
-<script language="javascript" type="text/javascript">
-var req;
-function getXML (command, url, qs) {
-       if (url == "" || url.substring (0, 4) != "http")
-               return;
-       
-       var post_data = null;
-       req = getReq ();
-       req.onreadystatechange = stateChange;
-       if (command == "GET") {
-               url = url + "?" + qs;
-       } else {
-               post_data = qs;
-       }
-       req.open (command, url,  true); 
-       if (command == "POST")
-               req.setRequestHeader ("Content-Type", "application/x-www-form-urlencoded");
-       req.send (post_data); 
-}
-
-function stateChange () {
-       if (req.readyState == 4) {
-               var node = document.getElementById("testresult_div");
-               var text = "";
-               if (req.status == 200) {
-                       node.innerHTML = "<div class='code-xml'>" + formatXml (req.responseText) + "</div>";
-               } else {
-                       var ht = "<b style='color: red'>" + formatXml (req.status + " - " + req.statusText) + "</b>";
-                       if (req.responseText != "")
-                               ht = ht + "\n<div class='code-xml'>" + formatXml (req.responseText) + "</div>";
-                       node.innerHTML = ht;
-                                       
-               }
-       }
-}
-
-function formatXml (text)
-{      
-       var re = / /g;
-       text = text.replace (re, "&nbsp;");
-
-       re = /\t/g;
-       text = text.replace (re, "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
-       
-       re = /\<\s*(\/?)\s*(.*?)\s*(\/?)\s*\>/g;
-       text = text.replace (re,"{blue:&lt;$1}{maroon:$2}{blue:$3&gt;}");
-       
-       re = /{(\w*):(.*?)}/g;
-       text = text.replace (re,"<span style='color:$1'>$2</span>");
-
-       re = /"(.*?)"/g;
-       text = text.replace (re,"\"<span style='color:purple'>$1</span>\"");
-
-       re = /\r\n|\r|\n/g;
-       text = text.replace (re, "<br/>");
-       
-       return text;
-}
-
-function getReq () {
-       if (window.XMLHttpRequest) {
-               return new XMLHttpRequest();     // Firefox, Safari, ...
-       } else if (window.ActiveXObject) {
-               return new ActiveXObject("Microsoft.XMLHTTP");
-       }
-}
-</script>
 <script language="C#" runat="server">
 
 ServiceDescriptionCollection descriptions;
@@ -189,15 +123,20 @@ void BuildOperationInfo ()
        
        // Protocols supported by the operation
        CurrentOperationProtocols = "";
+       WebServiceProtocols testProtocols = 0;
        ArrayList prots = FindServiceProtocols (CurrentOperationName);
        for (int n=0; n<prots.Count; n++) {
+               string prot = (string) prots [n];
                if (n != 0) CurrentOperationProtocols += ", ";
-               CurrentOperationProtocols += (string) prots[n];
+               CurrentOperationProtocols += prot;
+               if (prot == "HttpGet")
+                       testProtocols |= WebServiceProtocols.HttpGet;
+               else if (prot == "HttpPost") {
+                       testProtocols |= WebServiceProtocols.HttpPost;
+                       if (Context.Request.IsLocal)
+                               testProtocols |= WebServiceProtocols.HttpPostLocalhost;
+               }
        }
-       
-       WebServiceProtocols testProtocols = WebServiceProtocols.HttpGet | WebServiceProtocols.HttpPost;
-       if (Context.Request.IsLocal)
-           testProtocols |= WebServiceProtocols.HttpPostLocalhost;
        CurrentOperationSupportsTest = (WebServicesSection.Current.EnabledProtocols & testProtocols) != 0;
 
        // Operation format
@@ -535,10 +474,15 @@ private CodeDomProvider GetProvider(string langId)
 //
 // Document generation
 //
+class UTF8StringWriter : StringWriter {
+       public override Encoding Encoding {
+               get { return Encoding.UTF8; }
+       }
+}
 
 string GenerateDocument ()
 {
-       StringWriter sw = new StringWriter ();
+       UTF8StringWriter sw = new UTF8StringWriter ();
        
        if (CurrentDocType == "wsdl")
                descriptions [CurrentDocInd].Write (sw);
@@ -1097,7 +1041,7 @@ public class HtmlSampleGenerator: SampleGenerator
                        if (elem == null) throw new InvalidOperationException ("Element not found: " + qname);
                        WriteElementSample (xtw, qname.Namespace, elem);
                }
-               
+
                void WriteElementSample (XmlTextWriter xtw, string ns, XmlSchemaElement elem)
                {
                        bool sharedAnnType = false;
@@ -1191,9 +1135,18 @@ public class HtmlSampleGenerator: SampleGenerator
                {
                        WriteAttributes (xtw, stype.Attributes, stype.AnyAttribute);
                }
-               
+
+               Dictionary<XmlSchemaComplexType,int> recursed_types = new Dictionary<XmlSchemaComplexType,int> ();
                void WriteComplexTypeElements (XmlTextWriter xtw, string ns, XmlSchemaComplexType stype)
                {
+                       int prev = 0;
+                       if (recursed_types.ContainsKey (stype))
+                               prev = recursed_types [stype];
+
+                       if (prev > 1)
+                               return;
+                       recursed_types [stype] = ++prev;
+
                        if (stype.Particle != null)
                                WriteParticleComplexContent (xtw, ns, stype.Particle);
                        else
@@ -1203,6 +1156,8 @@ public class HtmlSampleGenerator: SampleGenerator
                                else if (stype.ContentModel is XmlSchemaComplexContent)
                                        WriteComplexContent (xtw, ns, (XmlSchemaComplexContent)stype.ContentModel);
                        }
+                       prev = recursed_types [stype];
+                       recursed_types [stype] = --prev;
                }
 
                void WriteAttributes (XmlTextWriter xtw, XmlSchemaObjectCollection atts, XmlSchemaAnyAttribute anyat)
@@ -1583,8 +1538,9 @@ public class HtmlSampleGenerator: SampleGenerator
 </script>
 
 <head runat="server">
-       <link rel="alternate" type="text/xml" href="<%=Request.FilePath%>?disco"/>
-
+       <%
+       Response.Write ("<link rel=\"alternate\" type=\"text/xml\" href=\"" + Request.FilePath + "?disco\"/>");
+       %>
        <title><%=WebServiceName%> Web Service</title>
     <style type="text/css">
                BODY { font-family: Arial; margin-left: 20px; margin-top: 20px; font-size: x-small}
@@ -1615,7 +1571,73 @@ public class HtmlSampleGenerator: SampleGenerator
                A:hover { color: blue }
     </style>
        
-<script>
+<script language="javascript" type="text/javascript">
+var req;
+function getXML (command, url, qs) {
+       if (url == "" || url.substring (0, 4) != "http")
+               return;
+       
+       var post_data = null;
+       req = getReq ();
+       req.onreadystatechange = stateChange;
+       if (command == "GET") {
+               url = url + "?" + qs;
+       } else {
+               post_data = qs;
+       }
+       req.open (command, url,  true); 
+       if (command == "POST")
+               req.setRequestHeader ("Content-Type", "application/x-www-form-urlencoded");
+       req.send (post_data); 
+}
+
+function stateChange () {
+       if (req.readyState == 4) {
+               var node = document.getElementById("testresult_div");
+               var text = "";
+               if (req.status == 200) {
+                       node.innerHTML = "<div class='code-xml'>" + formatXml (req.responseText) + "</div>";
+               } else {
+                       var ht = "<b style='color: red'>" + formatXml (req.status + " - " + req.statusText) + "</b>";
+                       if (req.responseText != "")
+                               ht = ht + "\n<div class='code-xml'>" + formatXml (req.responseText) + "</div>";
+                       node.innerHTML = ht;
+                                       
+               }
+       }
+}
+
+function formatXml (text)
+{      
+       var re = / /g;
+       text = text.replace (re, "&nbsp;");
+
+       re = /\t/g;
+       text = text.replace (re, "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
+       
+       re = /\<\s*(\/?)\s*(.*?)\s*(\/?)\s*\>/g;
+       text = text.replace (re,"{blue:&lt;$1}{maroon:$2}{blue:$3&gt;}");
+       
+       re = /{(\w*):(.*?)}/g;
+       text = text.replace (re,"<span style='color:$1'>$2</span>");
+
+       re = /"(.*?)"/g;
+       text = text.replace (re,"\"<span style='color:purple'>$1</span>\"");
+
+       re = /\r\n|\r|\n/g;
+       text = text.replace (re, "<br/>");
+       
+       return text;
+}
+
+function getReq () {
+       if (window.XMLHttpRequest) {
+               return new XMLHttpRequest();     // Firefox, Safari, ...
+       } else if (window.ActiveXObject) {
+               return new ActiveXObject("Microsoft.XMLHTTP");
+       }
+}
+
 function clearForm ()
 {
        document.getElementById("testFormResult").style.display="none";