2008-11-14 Gonzalo Paniagua Javier <gonzalo@novell.com>
authorGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Fri, 14 Nov 2008 06:30:46 +0000 (06:30 -0000)
committerGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Fri, 14 Nov 2008 06:30:46 +0000 (06:30 -0000)
* DefaultWsdlHelpGenerator.aspx: use javascript instead of
HttpWebRequest to avoid a deadlock if the web service uses Session.
Bug #444343 fixed.

svn path=/trunk/mono/; revision=118833

data/net_2_0/ChangeLog
data/net_2_0/DefaultWsdlHelpGenerator.aspx

index e17d38b3e3a4cdf4bf445814aee0e01fed159c7c..95b389e7b21692ab2fedf48b84ad6e76aaa5e1d7 100644 (file)
@@ -1,3 +1,10 @@
+
+2008-11-14 Gonzalo Paniagua Javier <gonzalo@novell.com>
+
+       * DefaultWsdlHelpGenerator.aspx: use javascript instead of
+       HttpWebRequest to avoid a deadlock if the web service uses Session.
+       Bug #444343 fixed.
+
 2008-10-09 Gonzalo Paniagua Javier <gonzalo@novell.com>
 
        * web.config: default values for httpRuntime are different in 2.0
index 1942be1da380471568d1ba098ea07e9a0b908164..e5b830e8a71c0ded3a265bfde09f66dc1041591c 100644 (file)
 <%@ 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;
@@ -329,21 +396,31 @@ class NoCheckCertificatePolicy : ICertificatePolicy {
        }
 }
 
-string GetTestResult ()
-{ 
-       if (!HasFormResult) return null;
-       
+string GetOrPost ()
+{
+       return (CurrentOperationProtocols.IndexOf ("HttpGet") >= 0) ? "GET" : "POST";
+}
+
+string GetQS ()
+{
        bool fill = false;
        string qs = "";
-       for (int n=0; n<Request.QueryString.Count; n++)
-       {
+       NameValueCollection query_string = Request.QueryString;
+       for (int n = 0; n < query_string.Count; n++) {
                if (fill) {
                        if (qs != "") qs += "&";
-                       qs += Request.QueryString.GetKey(n) + "=" + Server.UrlEncode (Request.QueryString [n]);
+                       qs += query_string.GetKey(n) + "=" + Server.UrlEncode (query_string [n]);
                }
-               if (Request.QueryString.GetKey(n) == "ext") fill = true;
+               if (query_string.GetKey(n) == "ext") fill = true;
        }
-               
+
+       return qs;
+}
+
+string GetTestResultUrl ()
+{ 
+       if (!HasFormResult) return "";
+       
        string location = null;
        ServiceDescription desc = descriptions [0];
        Service service = desc.Services[0];
@@ -358,59 +435,7 @@ string GetTestResult ()
        if (location == null) 
                return "Could not locate web service";
        
-       try
-       {
-               string url = location + "/" + CurrentOperationName;
-               Uri uri = new Uri (url);
-               WebRequest req;
-               if (CurrentOperationProtocols.IndexOf ("HttpGet") < 0) {
-                   req = WebRequest.Create (url);
-                   req.Method="POST";
-                   if (!String.IsNullOrEmpty (qs)) {
-                       req.ContentType = "application/x-www-form-urlencoded";
-                       byte [] postBuffer = Encoding.UTF8.GetBytes (qs);
-                       req.ContentLength = postBuffer.Length;
-                       using (Stream requestStream = req.GetRequestStream())
-                           requestStream.Write (postBuffer, 0, postBuffer.Length);
-                   }
-               }
-               else
-                   req = WebRequest.Create (url + "?" + qs);
-               if (url.StartsWith ("https:"))
-                       ServicePointManager.CertificatePolicy = new NoCheckCertificatePolicy ();
-               HttpCookieCollection cookies = Request.Cookies;
-               int last = cookies.Count;
-               if (last > 0) {
-                       CookieContainer container = new CookieContainer ();
-                       for (int i = 0; i < last; i++) {
-                               HttpCookie hcookie = cookies [i];
-                               Cookie cookie = new Cookie (hcookie.Name, hcookie.Value, hcookie.Path, hcookie.Domain);
-                               container.Add (uri, cookie);
-                       }
-                       ((HttpWebRequest) req).CookieContainer = container;
-               }
-               WebResponse resp = req.GetResponse();
-               StreamReader sr = new StreamReader (resp.GetResponseStream());
-               string s = sr.ReadToEnd ();
-               sr.Close ();
-               return "<div class='code-xml'>" + ColorizeXml(WrapText(s,CodeTextColumns)) + "</div>";
-       }
-       catch (Exception ex)
-       { 
-               string res = "<b style='color:red'>" + ex.Message + "</b>";
-               WebException wex = ex as WebException;
-               if (wex != null)
-               {
-                       WebResponse resp = wex.Response;
-                       if (resp != null) {
-                               StreamReader sr = new StreamReader (resp.GetResponseStream());
-                               string s = sr.ReadToEnd ();
-                               sr.Close ();
-                               res += "<div class='code-xml'>" + ColorizeXml(WrapText(s,CodeTextColumns)) + "</div>";
-                       }
-               }
-               return res;
-       }
+       return location + "/" + CurrentOperationName;
 }
 
 string GenerateOperationMessages (string protocol, bool generateInput)
@@ -1747,7 +1772,11 @@ This service does not contain any public web method.
                        </form>
                        <div id="testFormResult" style="display:<%= (HasFormResult?"block":"none") %>">
                        The web service returned the following result:<br/><br/>
-                       <div class="codePanel"><%=GetTestResult()%></div>
+                       <div class="codePanel" id="testresult_div">
+                       </div>
+                       <script language="javascript">
+                               getXML ("<%= GetOrPost () %>", "<%= GetTestResultUrl () %>", "<%= GetQS () %>");
+                       </script>
                        </div>
                <% } else {%>
                The test form is not available for this operation because it has parameters with a complex structure.