Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / data / net_2_0 / DefaultWsdlHelpGenerator.jvm.aspx
1 <%--
2 //
3 // DefaultWsdlHelpGenerator.aspx: 
4 //
5 // Author:
6 //   Lluis Sanchez Gual (lluis@ximian.com)
7 //
8 // (C) 2003 Ximian, Inc.  http://www.ximian.com
9 //
10 --%>
11
12 <%@ Import Namespace="System.Collections" %>
13 <%@ Import Namespace="System.IO" %>
14 <%@ Import Namespace="System.Xml.Serialization" %>
15 <%@ Import Namespace="System.Xml" %>
16 <%@ Import Namespace="System.Xml.Schema" %>
17 <%@ Import Namespace="System.Web.Services" %>
18 <%@ Import Namespace="System.Web.Services.Description" %>
19 <%@ Import Namespace="System.Web.Services.Configuration" %>
20 <%@ Import Namespace="System.Web.Configuration" %>
21 <%@ Import Namespace="System" %>
22 <%@ Import Namespace="System.Net" %>
23 <%@ Import Namespace="System.Globalization" %>
24 <%@ Import Namespace="System.Resources" %>
25 <%@ Import Namespace="System.Diagnostics" %>
26 <%@ Import Namespace="System.CodeDom" %>
27 <%@ Import Namespace="System.CodeDom.Compiler" %>
28 <%@ Import Namespace="Microsoft.CSharp" %>
29 <%@ Import Namespace="Microsoft.VisualBasic" %>
30 <%@ Import Namespace="System.Text" %>
31 <%@ Import Namespace="System.Text.RegularExpressions" %>
32 <%@ Assembly name="System.Web.Services" %>
33 <%@ Page debug="true" %>
34
35 <html>
36 <script language="C#" runat="server">
37
38 ServiceDescriptionCollection descriptions;
39 XmlSchemas schemas;
40
41 string WebServiceName;
42 string WebServiceDescription;
43 string PageName;
44
45 string DefaultBinding;
46 ArrayList ServiceProtocols;
47
48 string CurrentOperationName;
49 string CurrentOperationBinding;
50 string OperationDocumentation;
51 string CurrentOperationFormat;
52 bool CurrentOperationSupportsTest;
53 ArrayList InParams;
54 ArrayList OutParams;
55 string CurrentOperationProtocols;
56 int CodeTextColumns = 95;
57 BasicProfileViolationCollection ProfileViolations;
58
59 void Page_Load(object sender, EventArgs e)
60 {
61         descriptions = (ServiceDescriptionCollection) Context.Items["wsdls"];
62         schemas = (XmlSchemas) Context.Items["schemas"];
63
64         ServiceDescription desc = descriptions [0];
65         if (schemas.Count == 0) schemas = desc.Types.Schemas;
66         
67         Service service = desc.Services[0];
68         WebServiceName = service.Name;
69         if (desc.Bindings.Count == 0)
70                 return;
71         
72         DefaultBinding = desc.Bindings[0].Name;
73         WebServiceDescription = service.Documentation;
74         if (WebServiceDescription == "" || WebServiceDescription == null)
75                 WebServiceDescription = "Description has not been provided";
76         ServiceProtocols = FindServiceProtocols (null);
77         
78         CurrentOperationName = Request.QueryString["op"];
79         CurrentOperationBinding = Request.QueryString["bnd"];
80         if (CurrentOperationName != null) BuildOperationInfo ();
81
82         PageName = HttpUtility.UrlEncode (Path.GetFileName(Request.Path), Encoding.UTF8);
83
84         ArrayList list = new ArrayList ();
85         foreach (ServiceDescription sd in descriptions) {
86                 foreach (Binding bin in sd.Bindings)
87                         if (bin.Extensions.Find (typeof(SoapBinding)) != null) list.Add (bin);
88         }
89
90         BindingsRepeater.DataSource = list;
91         Page.DataBind();
92         
93         ProfileViolations = new BasicProfileViolationCollection ();
94         foreach (WsiProfilesElement claims in ((WebServicesSection) WebConfigurationManager.GetSection("system.web/webServices")).ConformanceWarnings)
95                 if (claims.Name != WsiProfiles.None)
96                         WebServicesInteroperability.CheckConformance (claims.Name, descriptions, ProfileViolations);
97 }
98
99 void BuildOperationInfo ()
100 {
101         InParams = new ArrayList ();
102         OutParams = new ArrayList ();
103         
104         Port port = FindPort (CurrentOperationBinding, null);
105         Binding binding = descriptions.GetBinding (port.Binding);
106         
107         PortType portType = descriptions.GetPortType (binding.Type);
108         Operation oper = FindOperation (portType, CurrentOperationName);
109         
110         OperationDocumentation = oper.Documentation;
111         if (OperationDocumentation == null || OperationDocumentation == "")
112                 OperationDocumentation = "No additional remarks";
113         
114         foreach (OperationMessage opm in oper.Messages)
115         {
116                 if (opm is OperationInput)
117                         BuildParameters (InParams, opm);
118                 else if (opm is OperationOutput)
119                         BuildParameters (OutParams, opm);
120         }
121         
122         // Protocols supported by the operation
123         CurrentOperationProtocols = "";
124         ArrayList prots = FindServiceProtocols (CurrentOperationName);
125         for (int n=0; n<prots.Count; n++) {
126                 if (n != 0) CurrentOperationProtocols += ", ";
127                 CurrentOperationProtocols += (string) prots[n];
128         }
129         
130         WebServiceProtocols testProtocols = WebServiceProtocols.HttpGet | WebServiceProtocols.HttpPost;
131         if (Context.Request.IsLocal)
132             testProtocols |= WebServiceProtocols.HttpPostLocalhost;
133         CurrentOperationSupportsTest = (WebServicesSection.Current.EnabledProtocols & testProtocols) != 0;
134
135         // Operation format
136         OperationBinding obin = FindOperation (binding, CurrentOperationName);
137         if (obin != null)
138                 CurrentOperationFormat = GetOperationFormat (obin);
139
140         InputParamsRepeater.DataSource = InParams;
141         InputFormParamsRepeater.DataSource = InParams;
142         OutputParamsRepeater.DataSource = OutParams;
143 }
144
145 void BuildParameters (ArrayList list, OperationMessage opm)
146 {
147         Message msg = descriptions.GetMessage (opm.Message);
148         if (msg.Parts.Count > 0 && msg.Parts[0].Name == "parameters")
149         {
150                 MessagePart part = msg.Parts[0];
151                 XmlSchemaComplexType ctype;
152                 if (part.Element == XmlQualifiedName.Empty)
153                 {
154                         ctype = (XmlSchemaComplexType) schemas.Find (part.Type, typeof(XmlSchemaComplexType));
155                 }
156                 else
157                 {
158                         XmlSchemaElement elem = (XmlSchemaElement) schemas.Find (part.Element, typeof(XmlSchemaElement));
159                         ctype = (XmlSchemaComplexType) elem.SchemaType;
160                 }
161                 XmlSchemaSequence seq = ctype.Particle as XmlSchemaSequence;
162                 if (seq == null) return;
163                 
164                 foreach (XmlSchemaObject ob in seq.Items)
165                 {
166                         Parameter p = new Parameter();
167                         p.Description = "No additional remarks";
168                         
169                         if (ob is XmlSchemaElement)
170                         {
171                                 XmlSchemaElement selem = GetRefElement ((XmlSchemaElement)ob);
172                                 p.Name = selem.Name;
173                                 p.Type = selem.SchemaTypeName.Name;
174                         }
175                         else
176                         {
177                                 p.Name = "Unknown";
178                                 p.Type = "Unknown";
179                         }
180                         list.Add (p);
181                 }
182         }
183         else
184         {
185                 foreach (MessagePart part in msg.Parts)
186                 {
187                         Parameter p = new Parameter ();
188                         p.Description = "No additional remarks";
189                         p.Name = part.Name;
190                         if (part.Element == XmlQualifiedName.Empty)
191                                 p.Type = part.Type.Name;
192                         else
193                         {
194                                 XmlSchemaElement elem = (XmlSchemaElement) schemas.Find (part.Element, typeof(XmlSchemaElement));
195                                 p.Type = elem.SchemaTypeName.Name;
196                         }
197                         list.Add (p);
198                 }
199         }
200 }
201
202 string GetOperationFormat (OperationBinding obin)
203 {
204         string format = "";
205         SoapOperationBinding sob = obin.Extensions.Find (typeof(SoapOperationBinding)) as SoapOperationBinding;
206         if (sob != null) {
207                 format = sob.Style.ToString ();
208                 SoapBodyBinding sbb = obin.Input.Extensions.Find (typeof(SoapBodyBinding)) as SoapBodyBinding;
209                 if (sbb != null)
210                         format += " / " + sbb.Use;
211         }
212         return format;
213 }
214
215 XmlSchemaElement GetRefElement (XmlSchemaElement elem)
216 {
217         if (!elem.RefName.IsEmpty)
218                 return (XmlSchemaElement) schemas.Find (elem.RefName, typeof(XmlSchemaElement));
219         else
220                 return elem;
221 }
222
223 ArrayList FindServiceProtocols(string operName)
224 {
225         ArrayList table = new ArrayList ();
226         Service service = descriptions[0].Services[0];
227         foreach (Port port in service.Ports)
228         {
229                 string prot = null;
230                 Binding bin = descriptions.GetBinding (port.Binding);
231                 if (bin.Extensions.Find (typeof(SoapBinding)) != null)
232                         prot = "Soap";
233                 else 
234                 {
235                         HttpBinding hb = (HttpBinding) bin.Extensions.Find (typeof(HttpBinding));
236                         if (hb != null && hb.Verb == "POST") prot = "HttpPost";
237                         else if (hb != null && hb.Verb == "GET") prot = "HttpGet";
238                 }
239                 
240                 if (prot != null && operName != null)
241                 {
242                         if (FindOperation (bin, operName) == null)
243                                 prot = null;
244                 }
245
246                 if (prot != null && !table.Contains (prot))
247                         table.Add (prot);
248         }
249         return table;
250 }
251
252 Port FindPort (string portName, string protocol)
253 {
254         Service service = descriptions[0].Services[0];
255         foreach (Port port in service.Ports)
256         {
257                 if (portName == null)
258                 {
259                         Binding binding = descriptions.GetBinding (port.Binding);
260                         if (GetProtocol (binding) == protocol) return port;
261                 }
262                 else if (port.Name == portName)
263                         return port;
264         }
265         return null;
266 }
267
268 string GetProtocol (Binding binding)
269 {
270         if (binding.Extensions.Find (typeof(SoapBinding)) != null) return "Soap";
271         HttpBinding hb = (HttpBinding) binding.Extensions.Find (typeof(HttpBinding));
272         if (hb == null) return "";
273         if (hb.Verb == "POST") return "HttpPost";
274         if (hb.Verb == "GET") return "HttpGet";
275         return "";
276 }
277
278
279 Operation FindOperation (PortType portType, string name)
280 {
281         foreach (Operation oper in portType.Operations) {
282                 if (oper.Messages.Input.Name != null) {
283                         if (oper.Messages.Input.Name == name) return oper;
284                 }
285                 else
286                         if (oper.Name == name) return oper;
287         }
288                 
289         return null;
290 }
291
292 OperationBinding FindOperation (Binding binding, string name)
293 {
294         foreach (OperationBinding oper in binding.Operations) {
295                 if (oper.Input.Name != null) {
296                         if (oper.Input.Name == name) return oper;
297                 }
298                 else 
299                         if (oper.Name == name) return oper;
300         }
301                 
302         return null;
303 }
304
305 string FormatBindingName (string name)
306 {
307         if (name.EndsWith("Soap")) return "Soap 1.1";
308         else if (name.EndsWith("Soap12")) return "Soap 1.2";
309         else return "Methods for binding<br>" + name;
310 }
311
312 string GetOpName (object op)
313 {
314         OperationBinding ob = op as OperationBinding;
315         if (ob == null) return "";
316         if (ob.Input.Name != null) return ob.Input.Name;
317         else return ob.Name;
318 }
319
320 bool HasFormResult
321 {
322         get { return Request.QueryString ["ext"] == "testform"; }
323 }
324
325 string GetTestResult ()
326
327         if (!HasFormResult) return null;
328         
329         bool fill = false;
330         string qs = "";
331         for (int n=0; n<Request.QueryString.Count; n++)
332         {
333                 if (fill) {
334                         if (qs != "") qs += "&";
335                         qs += Request.QueryString.GetKey(n) + "=" + Server.UrlEncode (Request.QueryString [n]);
336                 }
337                 if (Request.QueryString.GetKey(n) == "ext") fill = true;
338         }
339                 
340         string location = null;
341         ServiceDescription desc = descriptions [0];
342         Service service = desc.Services[0];
343         foreach (Port port in service.Ports)
344                 if (port.Name == CurrentOperationBinding)
345                 {
346                         SoapAddressBinding sbi = (SoapAddressBinding) port.Extensions.Find (typeof(SoapAddressBinding));
347                         if (sbi != null)
348                                 location = sbi.Location;
349                 }
350
351         if (location == null) 
352                 return "Could not locate web service";
353         
354         try
355         {
356                 string url = location + "/" + CurrentOperationName;
357                 Uri uri = new Uri (url);
358                 WebRequest req;
359                 if (CurrentOperationProtocols.IndexOf ("HttpGet") < 0) {
360                     req = WebRequest.Create (url + ".invoke");
361                     req.Method="POST";
362                     if (!String.IsNullOrEmpty (qs)) {
363                         req.ContentType = "application/x-www-form-urlencoded";
364                         byte [] postBuffer = Encoding.UTF8.GetBytes (qs);
365                         req.ContentLength = postBuffer.Length;
366                         using (Stream requestStream = req.GetRequestStream())
367                             requestStream.Write (postBuffer, 0, postBuffer.Length);
368                     }
369                 }
370                 else
371                     req = WebRequest.Create (url + ".invoke?" + qs);
372                 HttpCookieCollection cookies = Request.Cookies;
373                 int last = cookies.Count;
374                 if (last > 0) {
375                         CookieContainer container = new CookieContainer ();
376                         for (int i = 0; i < last; i++) {
377                                 HttpCookie hcookie = cookies [i];
378                                 Cookie cookie = new Cookie (hcookie.Name, hcookie.Value, hcookie.Path, hcookie.Domain);
379                                 container.Add (uri, cookie);
380                         }
381                         ((HttpWebRequest) req).CookieContainer = container;
382                 }
383                 WebResponse resp = req.GetResponse();
384                 StreamReader sr = new StreamReader (resp.GetResponseStream());
385                 string s = sr.ReadToEnd ();
386                 sr.Close ();
387                 return "<div class='code-xml'>" + ColorizeXml(WrapText(s,CodeTextColumns)) + "</div>";
388         }
389         catch (Exception ex)
390         { 
391                 string res = "<b style='color:red'>" + ex.Message + "</b>";
392                 WebException wex = ex as WebException;
393                 if (wex != null)
394                 {
395                         WebResponse resp = wex.Response;
396                         if (resp != null) {
397                                 StreamReader sr = new StreamReader (resp.GetResponseStream());
398                                 string s = sr.ReadToEnd ();
399                                 sr.Close ();
400                                 res += "<div class='code-xml'>" + ColorizeXml(WrapText(s,CodeTextColumns)) + "</div>";
401                         }
402                 }
403                 return res;
404         }
405 }
406
407 string GenerateOperationMessages (string protocol, bool generateInput)
408 {
409         if (!IsOperationSupported (protocol)) return "";
410         
411         Port port;
412         if (protocol != "Soap") port = FindPort (null, protocol);
413         else port = FindPort (CurrentOperationBinding, null);
414         
415         Binding binding = descriptions.GetBinding (port.Binding);
416         OperationBinding obin = FindOperation (binding, CurrentOperationName);
417         PortType portType = descriptions.GetPortType (binding.Type);
418         Operation oper = FindOperation (portType, CurrentOperationName);
419         
420         HtmlSampleGenerator sg = new HtmlSampleGenerator (descriptions, schemas);
421         string txt = sg.GenerateMessage (port, obin, oper, protocol, generateInput);
422         if (protocol == "Soap") txt = WrapText (txt,CodeTextColumns);
423         txt = ColorizeXml (txt);
424         txt = txt.Replace ("@placeholder!","<span class='literal-placeholder'>");
425         txt = txt.Replace ("!placeholder@","</span>");
426         return txt;
427 }
428
429 bool IsOperationSupported (string protocol)
430 {
431         if (CurrentPage != "op" || CurrentTab != "msg") return false;
432         if (protocol == "Soap") return true;
433
434         Port port = FindPort (null, protocol);
435         if (port == null) return false;
436         Binding binding = descriptions.GetBinding (port.Binding);
437         if (binding == null) return false;
438         return FindOperation (binding, CurrentOperationName) != null;
439 }
440
441 //
442 // Proxy code generation
443 //
444
445 string GetProxyCode ()
446 {
447         return "Proxy code generation is not yet supported.";
448 }
449
450 public string CurrentLanguage
451 {
452         get {
453                 string langId = Request.QueryString ["lang"];
454                 if (langId == null || langId == "") langId = "cs";
455                 return langId;
456         }
457 }
458
459 public string CurrentProxytName
460 {
461         get {
462                 string lan = CurrentLanguage == "cs" ? "C#" : "Visual Basic";
463                 return lan + " Client Proxy";
464         }
465 }
466
467 //
468 // Document generation
469 //
470
471 string GenerateDocument ()
472 {
473         StringWriter sw = new StringWriter ();
474         
475         if (CurrentDocType == "wsdl")
476                 descriptions [CurrentDocInd].Write (sw);
477         else if (CurrentDocType == "schema")
478                 schemas [CurrentDocInd].Write (sw);
479                 
480         return Colorize (WrapText (sw.ToString (), CodeTextColumns), "xml");
481 }
482
483 public string CurrentDocType
484 {
485         get { return Request.QueryString ["doctype"] != null ? Request.QueryString ["doctype"] : "wsdl"; }
486 }
487
488 public int CurrentDocInd
489 {
490         get { return Request.QueryString ["docind"] != null ? int.Parse (Request.QueryString ["docind"]) : 0; }
491 }
492
493 public string CurrentDocumentName
494 {
495         get {
496                 if (CurrentDocType == "wsdl")
497                         return "WSDL document for namespace \"" + descriptions [CurrentDocInd].TargetNamespace + "\"";
498                 else
499                         return "Xml Schema for namespace \"" + schemas [CurrentDocInd].TargetNamespace + "\"";
500         }
501 }
502
503 //
504 // Pages and tabs
505 //
506
507 bool firstTab = true;
508 ArrayList disabledTabs = new ArrayList ();
509
510 string CurrentTab
511 {
512         get { return Request.QueryString["tab"] != null ? Request.QueryString["tab"] : "main" ; }
513 }
514
515 string CurrentPage
516 {
517         get { return Request.QueryString["page"] != null ? Request.QueryString["page"] : "main" ; }
518 }
519
520 void WriteTabs ()
521 {
522         if (CurrentOperationName != null)
523         {
524                 WriteTab ("main","Overview");
525                 WriteTab ("test","Test Form");
526                 WriteTab ("msg","Message Layout");
527         }
528 }
529
530 void WriteTab (string id, string label)
531 {
532         if (!firstTab) Response.Write("&nbsp;|&nbsp;");
533         firstTab = false;
534         
535         string cname = CurrentTab == id ? "tabLabelOn" : "tabLabelOff";
536         Response.Write ("<a href='" + PageName + "?" + GetPageContext(null) + GetDataContext() + "tab=" + id + "' style='text-decoration:none'>");
537         Response.Write ("<span class='" + cname + "'>" + label + "</span>");
538         Response.Write ("</a>");
539 }
540
541 string GetTabContext (string pag, string tab)
542 {
543         if (tab == null) tab = CurrentTab;
544         if (pag == null) pag = CurrentPage;
545         if (pag != CurrentPage) tab = "main";
546         return "page=" + pag + "&tab=" + tab + "&"; 
547 }
548
549 string GetPageContext (string pag)
550 {
551         if (pag == null) pag = CurrentPage;
552         return "page=" + pag + "&"; 
553 }
554
555 class Tab
556 {
557         public string Id;
558         public string Label;
559 }
560
561 //
562 // Syntax coloring
563 //
564
565 static string keywords_cs =
566         "(\\babstract\\b|\\bevent\\b|\\bnew\\b|\\bstruct\\b|\\bas\\b|\\bexplicit\\b|\\bnull\\b|\\bswitch\\b|\\bbase\\b|\\bextern\\b|" +
567         "\\bobject\\b|\\bthis\\b|\\bbool\\b|\\bfalse\\b|\\boperator\\b|\\bthrow\\b|\\bbreak\\b|\\bfinally\\b|\\bout\\b|\\btrue\\b|" +
568         "\\bbyte\\b|\\bfixed\\b|\\boverride\\b|\\btry\\b|\\bcase\\b|\\bfloat\\b|\\bparams\\b|\\btypeof\\b|\\bcatch\\b|\\bfor\\b|" +
569         "\\bprivate\\b|\\buint\\b|\\bchar\\b|\\bforeach\\b|\\bprotected\\b|\\bulong\\b|\\bchecked\\b|\\bgoto\\b|\\bpublic\\b|" +
570         "\\bunchecked\\b|\\bclass\\b|\\bif\\b|\\breadonly\\b|\\bunsafe\\b|\\bconst\\b|\\bimplicit\\b|\\bref\\b|\\bushort\\b|" +
571         "\\bcontinue\\b|\\bin\\b|\\breturn\\b|\\busing\\b|\\bdecimal\\b|\\bint\\b|\\bsbyte\\b|\\bvirtual\\b|\\bdefault\\b|" +
572         "\\binterface\\b|\\bsealed\\b|\\bvolatile\\b|\\bdelegate\\b|\\binternal\\b|\\bshort\\b|\\bvoid\\b|\\bdo\\b|\\bis\\b|" +
573         "\\bsizeof\\b|\\bwhile\\b|\\bdouble\\b|\\block\\b|\\bstackalloc\\b|\\belse\\b|\\blong\\b|\\bstatic\\b|\\benum\\b|" +
574         "\\bnamespace\\b|\\bstring\\b)";
575
576 static string keywords_vb =
577         "(\\bAddHandler\\b|\\bAddressOf\\b|\\bAlias\\b|\\bAnd\\b|\\bAndAlso\\b|\\bAnsi\\b|\\bAs\\b|\\bAssembly\\b|" +
578         "\\bAuto\\b|\\bBoolean\\b|\\bByRef\\b|\\bByte\\b|\\bByVal\\b|\\bCall\\b|\\bCase\\b|\\bCatch\\b|" +
579         "\\bCBool\\b|\\bCByte\\b|\\bCChar\\b|\\bCDate\\b|\\bCDec\\b|\\bCDbl\\b|\\bChar\\b|\\bCInt\\b|" +
580         "\\bClass\\b|\\bCLng\\b|\\bCObj\\b|\\bConst\\b|\\bCShort\\b|\\bCSng\\b|\\bCStr\\b|\\bCType\\b|" +
581         "\\bDate\\b|\\bDecimal\\b|\\bDeclare\\b|\\bDefault\\b|\\bDelegate\\b|\\bDim\\b|\\bDirectCast\\b|\\bDo\\b|" +
582         "\\bDouble\\b|\\bEach\\b|\\bElse\\b|\\bElseIf\\b|\\bEnd\\b|\\bEnum\\b|\\bErase\\b|\\bError\\b|" +
583         "\\bEvent\\b|\\bExit\\b|\\bFalse\\b|\\bFinally\\b|\\bFor\\b|\\bFriend\\b|\\bFunction\\b|\\bGet\\b|" +
584         "\\bGetType\\b|\\bGoSub\\b|\\bGoTo\\b|\\bHandles\\b|\\bIf\\b|\\bImplements\\b|\\bImports\\b|\\bIn\\b|" +
585         "\\bInherits\\b|\\bInteger\\b|\\bInterface\\b|\\bIs\\b|\\bLet\\b|\\bLib\\b|\\bLike\\b|\\bLong\\b|" +
586         "\\bLoop\\b|\\bMe\\b|\\bMod\\b|\\bModule\\b|\\bMustInherit\\b|\\bMustOverride\\b|\\bMyBase\\b|\\bMyClass\\b|" +
587         "\\bNamespace\\b|\\bNew\\b|\\bNext\\b|\\bNot\\b|\\bNothing\\b|\\bNotInheritable\\b|\\bNotOverridable\\b|\\bObject\\b|" +
588         "\\bOn\\b|\\bOption\\b|\\bOptional\\b|\\bOr\\b|\\bOrElse\\b|\\bOverloads\\b|\\bOverridable\\b|\\bOverrides\\b|" +
589         "\\bParamArray\\b|\\bPreserve\\b|\\bPrivate\\b|\\bProperty\\b|\\bProtected\\b|\\bPublic\\b|\\bRaiseEvent\\b|\\bReadOnly\\b|" +
590         "\\bReDim\\b|\\bREM\\b|\\bRemoveHandler\\b|\\bResume\\b|\\bReturn\\b|\\bSelect\\b|\\bSet\\b|\\bShadows\\b|" +
591         "\\bShared\\b|\\bShort\\b|\\bSingle\\b|\\bStatic\\b|\\bStep\\b|\\bStop\\b|\\bString\\b|\\bStructure\\b|" +
592         "\\bSub\\b|\\bSyncLock\\b|\\bThen\\b|\\bThrow\\b|\\bTo\\b|\\bTrue\\b|\\bTry\\b|\\bTypeOf\\b|" +
593         "\\bUnicode\\b|\\bUntil\\b|\\bVariant\\b|\\bWhen\\b|\\bWhile\\b|\\bWith\\b|\\bWithEvents\\b|\\bWriteOnly\\b|\\bXor\\b)";
594
595 string Colorize (string text, string lang)
596 {
597         if (lang == "xml") return ColorizeXml (text);
598         else if (lang == "cs") return ColorizeCs (text);
599         else if (lang == "vb") return ColorizeVb (text);
600         else return text;
601 }
602
603 string ColorizeXml (string text)
604 {
605         text = text.Replace (" ", "&nbsp;");
606         Regex re = new Regex ("\r\n|\r|\n");
607         text = re.Replace (text, "_br_");
608         
609         re = new Regex ("<\\s*(\\/?)\\s*([\\s\\S]*?)\\s*(\\/?)\\s*>");
610         text = re.Replace (text,"{blue:&lt;$1}{maroon:$2}{blue:$3&gt;}");
611         
612         re = new Regex ("\\{(\\w*):([\\s\\S]*?)\\}");
613         text = re.Replace (text,"<span style='color:$1'>$2</span>");
614
615         re = new Regex ("\"(.*?)\"");
616         text = re.Replace (text,"\"<span style='color:purple'>$1</span>\"");
617
618         
619         text = text.Replace ("\t", "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
620         text = text.Replace ("_br_", "<br>");
621         return text;
622 }
623
624 string ColorizeCs (string text)
625 {
626         text = text.Replace (" ", "&nbsp;");
627
628         text = text.Replace ("<", "&lt;");
629         text = text.Replace (">", "&gt;");
630
631         Regex re = new Regex ("\"((((?!\").)|\\\")*?)\"");
632         text = re.Replace (text,"<span style='color:purple'>\"$1\"</span>");
633
634         re = new Regex ("//(((.(?!\"</span>))|\"(((?!\").)*)\"</span>)*)(\r|\n|\r\n)");
635         text = re.Replace (text,"<span style='color:green'>//$1</span><br/>");
636         
637         re = new Regex (keywords_cs);
638         text = re.Replace (text,"<span style='color:blue'>$1</span>");
639         
640         text = text.Replace ("\t","&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
641         text = text.Replace ("\n","<br/>");
642         
643         return text;
644 }
645
646 string ColorizeVb (string text)
647 {
648         text = text.Replace (" ", "&nbsp;");
649         
650 /*      Regex re = new Regex ("\"((((?!\").)|\\\")*?)\"");
651         text = re.Replace (text,"<span style='color:purple'>\"$1\"</span>");
652
653         re = new Regex ("'(((.(?!\"\\<\\/span\\>))|\"(((?!\").)*)\"\\<\\/span\\>)*)(\r|\n|\r\n)");
654         text = re.Replace (text,"<span style='color:green'>//$1</span><br/>");
655         
656         re = new Regex (keywords_vb);
657         text = re.Replace (text,"<span style='color:blue'>$1</span>");
658 */      
659         text = text.Replace ("\t","&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
660         text = text.Replace ("\n","<br/>");
661         return text;
662 }
663
664 //
665 // Helper methods and classes
666 //
667
668 string GetDataContext ()
669 {
670         return "op=" + CurrentOperationName + "&bnd=" + CurrentOperationBinding + "&";
671 }
672
673 string GetOptionSel (string v1, string v2)
674 {
675         string op = "<option ";
676         if (v1 == v2) op += "selected ";
677         return op + "value='" + v1 + "'>";
678 }
679
680 string WrapText (string text, int maxChars)
681 {
682         text =  text.Replace(" />","/>");
683         
684         string linspace = null;
685         int lincount = 0;
686         int breakpos = 0;
687         int linstart = 0;
688         bool inquotes = false;
689         char lastc = ' ';
690         string sublineIndent = "";
691         System.Text.StringBuilder sb = new System.Text.StringBuilder ();
692         for (int n=0; n<text.Length; n++)
693         {
694                 char c = text [n];
695                 
696                 if (c=='\r' || c=='\n' || n==text.Length-1)
697                 {
698                         sb.Append (linspace + sublineIndent + text.Substring (linstart, n-linstart+1));
699                         linspace = null;
700                         lincount = 0;
701                         linstart = n+1;
702                         breakpos = linstart;
703                         sublineIndent = "";
704                         lastc = c;
705                         continue;
706                 }
707                 
708                 if (lastc==',' || lastc=='(')
709                 {
710                         if (!inquotes) breakpos = n;
711                 }
712                 
713                 if (lincount > maxChars && breakpos >= linstart)
714                 {
715                         if (linspace != null)
716                                 sb.Append (linspace + sublineIndent);
717                         sb.Append (text.Substring (linstart, breakpos-linstart));
718                         sb.Append ("\n");
719                         sublineIndent = "     ";
720                         lincount = linspace.Length + sublineIndent.Length + (n-breakpos);
721                         linstart = breakpos;
722                 }
723                 
724                 if (c==' ' || c=='\t')
725                 {
726                         if (!inquotes)
727                                 breakpos = n;
728                 }
729                 else if (c=='"')
730                 {
731                         inquotes = !inquotes;
732                 }
733                 else 
734                         if (linspace == null) {
735                                 linspace = text.Substring (linstart, n-linstart);
736                                 linstart = n;
737                         }
738
739                 lincount++;
740                 lastc = c;
741         }
742         return sb.ToString ();
743 }
744
745 class Parameter
746 {
747         string name;
748         string type;
749         string description;
750
751         public string Name { get { return name; } set { name = value; } }
752         public string Type { get { return type; } set { type = value; } }
753         public string Description { get { return description; } set { description = value; } }
754 }
755
756 public class HtmlSampleGenerator: SampleGenerator
757 {
758         public HtmlSampleGenerator (ServiceDescriptionCollection services, XmlSchemas schemas)
759         : base (services, schemas)
760         {
761         }
762                 
763         protected override string GetLiteral (string s)
764         {
765                 return "@placeholder!" + s + "!placeholder@";
766         }
767 }
768
769
770         public class SampleGenerator
771         {
772                 protected ServiceDescriptionCollection descriptions;
773                 protected XmlSchemas schemas;
774                 XmlSchemaElement anyElement;
775                 ArrayList queue;
776                 SoapBindingUse currentUse;
777                 XmlDocument document = new XmlDocument ();
778                 
779                 static readonly XmlQualifiedName anyType = new XmlQualifiedName ("anyType",XmlSchema.Namespace);
780                 static readonly XmlQualifiedName arrayType = new XmlQualifiedName ("Array","http://schemas.xmlsoap.org/soap/encoding/");
781                 static readonly XmlQualifiedName arrayTypeRefName = new XmlQualifiedName ("arrayType","http://schemas.xmlsoap.org/soap/encoding/");
782                 const string WsdlNamespace = "http://schemas.xmlsoap.org/wsdl/";
783                 const string SoapEncodingNamespace = "http://schemas.xmlsoap.org/soap/encoding/";
784                 
785                 class EncodedType
786                 {
787                         public EncodedType (string ns, XmlSchemaElement elem) { Namespace = ns; Element = elem; }
788                         public string Namespace;
789                         public XmlSchemaElement Element;
790                 }
791
792                 public SampleGenerator (ServiceDescriptionCollection services, XmlSchemas schemas)
793                 {
794                         descriptions = services;
795                         this.schemas = schemas;
796                         queue = new ArrayList ();
797                 }
798                 
799                 public string GenerateMessage (Port port, OperationBinding obin, Operation oper, string protocol, bool generateInput)
800                 {
801                         OperationMessage msg = null;
802                         foreach (OperationMessage opm in oper.Messages)
803                         {
804                                 if (opm is OperationInput && generateInput) msg = opm;
805                                 else if (opm is OperationOutput && !generateInput) msg = opm;
806                         }
807                         if (msg == null) return null;
808                         
809                         switch (protocol) {
810                                 case "Soap": return GenerateHttpSoapMessage (port, obin, oper, msg);
811                                 case "HttpGet": return GenerateHttpGetMessage (port, obin, oper, msg);
812                                 case "HttpPost": return GenerateHttpPostMessage (port, obin, oper, msg);
813                         }
814                         return "Unknown protocol";
815                 }
816                 
817                 public string GenerateHttpSoapMessage (Port port, OperationBinding obin, Operation oper, OperationMessage msg)
818                 {
819                         string req = "";
820                         
821                         if (msg is OperationInput)
822                         {
823                                 SoapAddressBinding sab = port.Extensions.Find (typeof(SoapAddressBinding)) as SoapAddressBinding;
824                                 SoapOperationBinding sob = obin.Extensions.Find (typeof(SoapOperationBinding)) as SoapOperationBinding;
825                                 req += "POST " + new Uri (sab.Location).AbsolutePath + "\n";
826                                 req += "SOAPAction: " + sob.SoapAction + "\n";
827                                 req += "Content-Type: text/xml; charset=utf-8\n";
828                                 req += "Content-Length: " + GetLiteral ("string") + "\n";
829                                 req += "Host: " + GetLiteral ("string") + "\n\n";
830                         }
831                         else
832                         {
833                                 req += "HTTP/1.0 200 OK\n";
834                                 req += "Content-Type: text/xml; charset=utf-8\n";
835                                 req += "Content-Length: " + GetLiteral ("string") + "\n\n";
836                         }
837                         
838                         req += GenerateSoapMessage (obin, oper, msg);
839                         return req;
840                 }
841                 
842                 public string GenerateHttpGetMessage (Port port, OperationBinding obin, Operation oper, OperationMessage msg)
843                 {
844                         string req = "";
845                         
846                         if (msg is OperationInput)
847                         {
848                                 HttpAddressBinding sab = port.Extensions.Find (typeof(HttpAddressBinding)) as HttpAddressBinding;
849                                 HttpOperationBinding sob = obin.Extensions.Find (typeof(HttpOperationBinding)) as HttpOperationBinding;
850                                 string location = new Uri (sab.Location).AbsolutePath + sob.Location + "?" + BuildQueryString (msg);
851                                 req += "GET " + location + "\n";
852                                 req += "Host: " + GetLiteral ("string");
853                         }
854                         else
855                         {
856                                 req += "HTTP/1.0 200 OK\n";
857                                 req += "Content-Type: text/xml; charset=utf-8\n";
858                                 req += "Content-Length: " + GetLiteral ("string") + "\n\n";
859                         
860                                 MimeXmlBinding mxb = (MimeXmlBinding) obin.Output.Extensions.Find (typeof(MimeXmlBinding)) as MimeXmlBinding;
861                                 if (mxb == null) return req;
862                                 
863                                 Message message = descriptions.GetMessage (msg.Message);
864                                 XmlQualifiedName ename = null;
865                                 foreach (MessagePart part in message.Parts)
866                                         if (part.Name == mxb.Part) ename = part.Element;
867                                         
868                                 if (ename == null) return req + GetLiteral("string");
869                                 
870                                 StringWriter sw = new StringWriter ();
871                                 XmlTextWriter xtw = new XmlTextWriter (sw);
872                                 xtw.Formatting = Formatting.Indented;
873                                 currentUse = SoapBindingUse.Literal;
874                                 WriteRootElementSample (xtw, ename);
875                                 xtw.Close ();
876                                 req += sw.ToString ();
877                         }
878                         
879                         return req;
880                 }
881                 
882                 public string GenerateHttpPostMessage (Port port, OperationBinding obin, Operation oper, OperationMessage msg)
883                 {
884                         string req = "";
885                         
886                         if (msg is OperationInput)
887                         {
888                                 HttpAddressBinding sab = port.Extensions.Find (typeof(HttpAddressBinding)) as HttpAddressBinding;
889                                 HttpOperationBinding sob = obin.Extensions.Find (typeof(HttpOperationBinding)) as HttpOperationBinding;
890                                 string location = new Uri (sab.Location).AbsolutePath + sob.Location;
891                                 req += "POST " + location + "\n";
892                                 req += "Content-Type: application/x-www-form-urlencoded\n";
893                                 req += "Content-Length: " + GetLiteral ("string") + "\n";
894                                 req += "Host: " + GetLiteral ("string") + "\n\n";
895                                 req += BuildQueryString (msg);
896                         }
897                         else return GenerateHttpGetMessage (port, obin, oper, msg);
898                         
899                         return req;
900                 }
901                 
902                 string BuildQueryString (OperationMessage opm)
903                 {
904                         string s = "";
905                         Message msg = descriptions.GetMessage (opm.Message);
906                         foreach (MessagePart part in msg.Parts)
907                         {
908                                 if (s.Length != 0) s += "&";
909                                 s += part.Name + "=" + GetLiteral (part.Type.Name);
910                         }
911                         return s;
912                 }
913                 
914                 public string GenerateSoapMessage (OperationBinding obin, Operation oper, OperationMessage msg)
915                 {
916                         string SoapEnvelopeNamespace = "http://schemas.xmlsoap.org/soap/envelope/";
917                         if(obin.Binding.Name.EndsWith("Soap12"))
918                                 SoapEnvelopeNamespace = "http://www.w3.org/2003/05/soap-envelope";
919                 
920                         SoapOperationBinding sob = obin.Extensions.Find (typeof(SoapOperationBinding)) as SoapOperationBinding;
921                         SoapBindingStyle style = (sob != null) ? sob.Style : SoapBindingStyle.Document;
922                         
923                         MessageBinding msgbin = (msg is OperationInput) ? (MessageBinding) obin.Input : (MessageBinding)obin.Output;
924                         SoapBodyBinding sbb = msgbin.Extensions.Find (typeof(SoapBodyBinding)) as SoapBodyBinding;
925                         SoapBindingUse bodyUse = (sbb != null) ? sbb.Use : SoapBindingUse.Literal;
926                         
927                         StringWriter sw = new StringWriter ();
928                         XmlTextWriter xtw = new XmlTextWriter (sw);
929                         xtw.Formatting = Formatting.Indented;
930                         
931                         xtw.WriteStartDocument ();
932                         xtw.WriteStartElement ("soap", "Envelope", SoapEnvelopeNamespace);
933                         xtw.WriteAttributeString ("xmlns", "xsi", null, XmlSchema.InstanceNamespace);
934                         xtw.WriteAttributeString ("xmlns", "xsd", null, XmlSchema.Namespace);
935                         
936                         if (bodyUse == SoapBindingUse.Encoded) 
937                         {
938                                 xtw.WriteAttributeString ("xmlns", "soapenc", null, SoapEncodingNamespace);
939                                 xtw.WriteAttributeString ("xmlns", "tns", null, msg.Message.Namespace);
940                         }
941
942                         // Serialize headers
943                         
944                         bool writtenHeader = false;
945                         foreach (object ob in msgbin.Extensions)
946                         {
947                                 SoapHeaderBinding hb = ob as SoapHeaderBinding;
948                                 if (hb == null) continue;
949                                 
950                                 if (!writtenHeader) {
951                                         xtw.WriteStartElement ("soap", "Header", SoapEnvelopeNamespace);
952                                         writtenHeader = true;
953                                 }
954                                 
955                                 WriteHeader (xtw, hb);
956                         }
957                         
958                         if (writtenHeader)
959                                 xtw.WriteEndElement ();
960
961                         // Serialize body
962                         xtw.WriteStartElement ("soap", "Body", SoapEnvelopeNamespace);
963                         
964                         currentUse = bodyUse;
965                         WriteBody (xtw, oper, msg, sbb, style);
966                         
967                         xtw.WriteEndElement ();
968                         xtw.WriteEndElement ();
969                         xtw.Close ();
970                         return sw.ToString ();
971                 }
972                 
973                 void WriteHeader (XmlTextWriter xtw, SoapHeaderBinding header)
974                 {
975                         Message msg = descriptions.GetMessage (header.Message);
976                         if (msg == null) throw new InvalidOperationException ("Message " + header.Message + " not found");
977                         MessagePart part = msg.Parts [header.Part];
978                         if (part == null) throw new InvalidOperationException ("Message part " + header.Part + " not found in message " + header.Message);
979
980                         currentUse = header.Use;
981                         
982                         if (currentUse == SoapBindingUse.Literal)
983                                 WriteRootElementSample (xtw, part.Element);
984                         else
985                                 WriteTypeSample (xtw, part.Type);
986                 }
987                 
988                 void WriteBody (XmlTextWriter xtw, Operation oper, OperationMessage opm, SoapBodyBinding sbb, SoapBindingStyle style)
989                 {
990                         Message msg = descriptions.GetMessage (opm.Message);
991                         if (msg.Parts.Count > 0 && msg.Parts[0].Name == "parameters")
992                         {
993                                 MessagePart part = msg.Parts[0];
994                                 if (part.Element == XmlQualifiedName.Empty)
995                                         WriteTypeSample (xtw, part.Type);
996                                 else
997                                         WriteRootElementSample (xtw, part.Element);
998                         }
999                         else
1000                         {
1001                                 string elemName = oper.Name;
1002                                 string ns = "";
1003                                 if (opm is OperationOutput) elemName += "Response";
1004                                 
1005                                 if (style == SoapBindingStyle.Rpc) {
1006                                         xtw.WriteStartElement (elemName, sbb.Namespace);
1007                                         ns = sbb.Namespace;
1008                                 }
1009                                         
1010                                 foreach (MessagePart part in msg.Parts)
1011                                 {
1012                                         if (part.Element == XmlQualifiedName.Empty)
1013                                         {
1014                                                 XmlSchemaElement elem = new XmlSchemaElement ();
1015                                                 elem.SchemaTypeName = part.Type;
1016                                                 elem.Name = part.Name;
1017                                                 WriteElementSample (xtw, ns, elem);
1018                                         }
1019                                         else
1020                                                 WriteRootElementSample (xtw, part.Element);
1021                                 }
1022                                 
1023                                 if (style == SoapBindingStyle.Rpc)
1024                                         xtw.WriteEndElement ();
1025                         }
1026                         WriteQueuedTypeSamples (xtw);
1027                 }
1028                 
1029                 void WriteRootElementSample (XmlTextWriter xtw, XmlQualifiedName qname)
1030                 {
1031                         XmlSchemaElement elem = (XmlSchemaElement) schemas.Find (qname, typeof(XmlSchemaElement));
1032                         if (elem == null) throw new InvalidOperationException ("Element not found: " + qname);
1033                         WriteElementSample (xtw, qname.Namespace, elem);
1034                 }
1035                 
1036                 void WriteElementSample (XmlTextWriter xtw, string ns, XmlSchemaElement elem)
1037                 {
1038                         bool sharedAnnType = false;
1039                         XmlQualifiedName root;
1040                         
1041                         if (!elem.RefName.IsEmpty) {
1042                                 XmlSchemaElement refElem = FindRefElement (elem);
1043                                 if (refElem == null) throw new InvalidOperationException ("Global element not found: " + elem.RefName);
1044                                 root = elem.RefName;
1045                                 elem = refElem;
1046                                 sharedAnnType = true;
1047                         }
1048                         else
1049                                 root = new XmlQualifiedName (elem.Name, ns);
1050                         
1051                         if (!elem.SchemaTypeName.IsEmpty)
1052                         {
1053                                 XmlSchemaComplexType st = FindComplexTyype (elem.SchemaTypeName);
1054                                 if (st != null) 
1055                                         WriteComplexTypeSample (xtw, st, root);
1056                                 else
1057                                 {
1058                                         xtw.WriteStartElement (root.Name, root.Namespace);
1059                                         if (currentUse == SoapBindingUse.Encoded) 
1060                                                 xtw.WriteAttributeString ("type", XmlSchema.InstanceNamespace, GetQualifiedNameString (xtw, elem.SchemaTypeName));
1061                                         xtw.WriteString (GetLiteral (FindBuiltInType (elem.SchemaTypeName)));
1062                                         xtw.WriteEndElement ();
1063                                 }
1064                         }
1065                         else if (elem.SchemaType == null)
1066                         {
1067                                 xtw.WriteStartElement ("any");
1068                                 xtw.WriteEndElement ();
1069                         }
1070                         else
1071                                 WriteComplexTypeSample (xtw, (XmlSchemaComplexType) elem.SchemaType, root);
1072                 }
1073                 
1074                 void WriteTypeSample (XmlTextWriter xtw, XmlQualifiedName qname)
1075                 {
1076                         XmlSchemaComplexType ctype = FindComplexTyype (qname);
1077                         if (ctype != null) {
1078                                 WriteComplexTypeSample (xtw, ctype, qname);
1079                                 return;
1080                         }
1081                         
1082                         XmlSchemaSimpleType stype = (XmlSchemaSimpleType) schemas.Find (qname, typeof(XmlSchemaSimpleType));
1083                         if (stype != null) {
1084                                 WriteSimpleTypeSample (xtw, stype);
1085                                 return;
1086                         }
1087                         
1088                         xtw.WriteString (GetLiteral (FindBuiltInType (qname)));
1089                         throw new InvalidOperationException ("Type not found: " + qname);
1090                 }
1091                 
1092                 void WriteComplexTypeSample (XmlTextWriter xtw, XmlSchemaComplexType stype, XmlQualifiedName rootName)
1093                 {
1094                         WriteComplexTypeSample (xtw, stype, rootName, -1);
1095                 }
1096                 
1097                 void WriteComplexTypeSample (XmlTextWriter xtw, XmlSchemaComplexType stype, XmlQualifiedName rootName, int id)
1098                 {
1099                         string ns = rootName.Namespace;
1100                         
1101                         if (rootName.Name.IndexOf ("[]") != -1) rootName = arrayType;
1102                         
1103                         if (currentUse == SoapBindingUse.Encoded) {
1104                                 string pref = xtw.LookupPrefix (rootName.Namespace);
1105                                 if (pref == null) pref = "q1";
1106                                 xtw.WriteStartElement (pref, rootName.Name, rootName.Namespace);
1107                                 ns = "";
1108                         }
1109                         else
1110                                 xtw.WriteStartElement (rootName.Name, rootName.Namespace);
1111                         
1112                         if (id != -1)
1113                         {
1114                                 xtw.WriteAttributeString ("id", "id" + id);
1115                                 if (rootName != arrayType)
1116                                         xtw.WriteAttributeString ("type", XmlSchema.InstanceNamespace, GetQualifiedNameString (xtw, rootName));
1117                         }
1118                         
1119                         WriteComplexTypeAttributes (xtw, stype);
1120                         WriteComplexTypeElements (xtw, ns, stype);
1121                         
1122                         xtw.WriteEndElement ();
1123                 }
1124                 
1125                 void WriteComplexTypeAttributes (XmlTextWriter xtw, XmlSchemaComplexType stype)
1126                 {
1127                         WriteAttributes (xtw, stype.Attributes, stype.AnyAttribute);
1128                 }
1129                 
1130                 void WriteComplexTypeElements (XmlTextWriter xtw, string ns, XmlSchemaComplexType stype)
1131                 {
1132                         if (stype.Particle != null)
1133                                 WriteParticleComplexContent (xtw, ns, stype.Particle);
1134                         else
1135                         {
1136                                 if (stype.ContentModel is XmlSchemaSimpleContent)
1137                                         WriteSimpleContent (xtw, (XmlSchemaSimpleContent)stype.ContentModel);
1138                                 else if (stype.ContentModel is XmlSchemaComplexContent)
1139                                         WriteComplexContent (xtw, ns, (XmlSchemaComplexContent)stype.ContentModel);
1140                         }
1141                 }
1142
1143                 void WriteAttributes (XmlTextWriter xtw, XmlSchemaObjectCollection atts, XmlSchemaAnyAttribute anyat)
1144                 {
1145                         foreach (XmlSchemaObject at in atts)
1146                         {
1147                                 if (at is XmlSchemaAttribute)
1148                                 {
1149                                         string ns;
1150                                         XmlSchemaAttribute attr = (XmlSchemaAttribute)at;
1151                                         XmlSchemaAttribute refAttr = attr;
1152                                         
1153                                         // refAttr.Form; TODO
1154                                         
1155                                         if (!attr.RefName.IsEmpty) {
1156                                                 refAttr = FindRefAttribute (attr.RefName);
1157                                                 if (refAttr == null) throw new InvalidOperationException ("Global attribute not found: " + attr.RefName);
1158                                         }
1159                                         
1160                                         string val;
1161                                         if (!refAttr.SchemaTypeName.IsEmpty) val = FindBuiltInType (refAttr.SchemaTypeName);
1162                                         else val = FindBuiltInType ((XmlSchemaSimpleType) refAttr.SchemaType);
1163                                         
1164                                         xtw.WriteAttributeString (refAttr.Name, val);
1165                                 }
1166                                 else if (at is XmlSchemaAttributeGroupRef)
1167                                 {
1168                                         XmlSchemaAttributeGroupRef gref = (XmlSchemaAttributeGroupRef)at;
1169                                         XmlSchemaAttributeGroup grp = (XmlSchemaAttributeGroup) schemas.Find (gref.RefName, typeof(XmlSchemaAttributeGroup));
1170                                         WriteAttributes (xtw, grp.Attributes, grp.AnyAttribute);
1171                                 }
1172                         }
1173                         
1174                         if (anyat != null)
1175                                 xtw.WriteAttributeString ("custom-attribute","value");
1176                 }
1177                 
1178                 void WriteParticleComplexContent (XmlTextWriter xtw, string ns, XmlSchemaParticle particle)
1179                 {
1180                         WriteParticleContent (xtw, ns, particle, false);
1181                 }
1182                 
1183                 void WriteParticleContent (XmlTextWriter xtw, string ns, XmlSchemaParticle particle, bool multiValue)
1184                 {
1185                         if (particle is XmlSchemaGroupRef)
1186                                 particle = GetRefGroupParticle ((XmlSchemaGroupRef)particle);
1187
1188                         if (particle.MaxOccurs > 1) multiValue = true;
1189                         
1190                         if (particle is XmlSchemaSequence) {
1191                                 WriteSequenceContent (xtw, ns, ((XmlSchemaSequence)particle).Items, multiValue);
1192                         }
1193                         else if (particle is XmlSchemaChoice) {
1194                                 if (((XmlSchemaChoice)particle).Items.Count == 1)
1195                                         WriteSequenceContent (xtw, ns, ((XmlSchemaChoice)particle).Items, multiValue);
1196                                 else
1197                                         WriteChoiceContent (xtw, ns, (XmlSchemaChoice)particle, multiValue);
1198                         }
1199                         else if (particle is XmlSchemaAll) {
1200                                 WriteSequenceContent (xtw, ns, ((XmlSchemaAll)particle).Items, multiValue);
1201                         }
1202                 }
1203
1204                 void WriteSequenceContent (XmlTextWriter xtw, string ns, XmlSchemaObjectCollection items, bool multiValue)
1205                 {
1206                         foreach (XmlSchemaObject item in items)
1207                                 WriteContentItem (xtw, ns, item, multiValue);
1208                 }
1209                 
1210                 void WriteContentItem (XmlTextWriter xtw, string ns, XmlSchemaObject item, bool multiValue)
1211                 {
1212                         if (item is XmlSchemaGroupRef)
1213                                 item = GetRefGroupParticle ((XmlSchemaGroupRef)item);
1214                                         
1215                         if (item is XmlSchemaElement)
1216                         {
1217                                 XmlSchemaElement elem = (XmlSchemaElement) item;
1218                                 XmlSchemaElement refElem;
1219                                 if (!elem.RefName.IsEmpty) refElem = FindRefElement (elem);
1220                                 else refElem = elem;
1221
1222                                 int num = (elem.MaxOccurs == 1 && !multiValue) ? 1 : 2;
1223                                 for (int n=0; n<num; n++)
1224                                 {
1225                                         if (currentUse == SoapBindingUse.Literal)
1226                                                 WriteElementSample (xtw, ns, refElem);
1227                                         else
1228                                                 WriteRefTypeSample (xtw, ns, refElem);
1229                                 }
1230                         }
1231                         else if (item is XmlSchemaAny)
1232                         {
1233                                 xtw.WriteString (GetLiteral ("xml"));
1234                         }
1235                         else if (item is XmlSchemaParticle) {
1236                                 WriteParticleContent (xtw, ns, (XmlSchemaParticle)item, multiValue);
1237                         }
1238                 }
1239                 
1240                 void WriteChoiceContent (XmlTextWriter xtw, string ns, XmlSchemaChoice choice, bool multiValue)
1241                 {
1242                         foreach (XmlSchemaObject item in choice.Items)
1243                                 WriteContentItem (xtw, ns, item, multiValue);
1244                 }
1245
1246                 void WriteSimpleContent (XmlTextWriter xtw, XmlSchemaSimpleContent content)
1247                 {
1248                         XmlSchemaSimpleContentExtension ext = content.Content as XmlSchemaSimpleContentExtension;
1249                         if (ext != null)
1250                                 WriteAttributes (xtw, ext.Attributes, ext.AnyAttribute);
1251                                 
1252                         XmlQualifiedName qname = GetContentBaseType (content.Content);
1253                         xtw.WriteString (GetLiteral (FindBuiltInType (qname)));
1254                 }
1255
1256                 string FindBuiltInType (XmlQualifiedName qname)
1257                 {
1258                         if (qname.Namespace == XmlSchema.Namespace)
1259                                 return qname.Name;
1260
1261                         XmlSchemaComplexType ct = FindComplexTyype (qname);
1262                         if (ct != null)
1263                         {
1264                                 XmlSchemaSimpleContent sc = ct.ContentModel as XmlSchemaSimpleContent;
1265                                 if (sc == null) throw new InvalidOperationException ("Invalid schema");
1266                                 return FindBuiltInType (GetContentBaseType (sc.Content));
1267                         }
1268                         
1269                         XmlSchemaSimpleType st = (XmlSchemaSimpleType) schemas.Find (qname, typeof(XmlSchemaSimpleType));
1270                         if (st != null)
1271                                 return FindBuiltInType (st);
1272
1273                         throw new InvalidOperationException ("Definition of type " + qname + " not found");
1274                 }
1275
1276                 string FindBuiltInType (XmlSchemaSimpleType st)
1277                 {
1278                         if (st.Content is XmlSchemaSimpleTypeRestriction) {
1279                                 return FindBuiltInType (GetContentBaseType (st.Content));
1280                         }
1281                         else if (st.Content is XmlSchemaSimpleTypeList) {
1282                                 string s = FindBuiltInType (GetContentBaseType (st.Content));
1283                                 return s + " " + s + " ...";
1284                         }
1285                         else if (st.Content is XmlSchemaSimpleTypeUnion)
1286                         {
1287                                 //Check if all types of the union are equal. If not, then will use anyType.
1288                                 XmlSchemaSimpleTypeUnion uni = (XmlSchemaSimpleTypeUnion) st.Content;
1289                                 string utype = null;
1290
1291                                 // Anonymous types are unique
1292                                 if (uni.BaseTypes.Count != 0 && uni.MemberTypes.Length != 0)
1293                                         return "string";
1294
1295                                 foreach (XmlQualifiedName mt in uni.MemberTypes)
1296                                 {
1297                                         string qn = FindBuiltInType (mt);
1298                                         if (utype != null && qn != utype) return "string";
1299                                         else utype = qn;
1300                                 }
1301                                 return utype;
1302                         }
1303                         else
1304                                 return "string";
1305                 }
1306                 
1307
1308                 XmlQualifiedName GetContentBaseType (XmlSchemaObject ob)
1309                 {
1310                         if (ob is XmlSchemaSimpleContentExtension)
1311                                 return ((XmlSchemaSimpleContentExtension)ob).BaseTypeName;
1312                         else if (ob is XmlSchemaSimpleContentRestriction)
1313                                 return ((XmlSchemaSimpleContentRestriction)ob).BaseTypeName;
1314                         else if (ob is XmlSchemaSimpleTypeRestriction)
1315                                 return ((XmlSchemaSimpleTypeRestriction)ob).BaseTypeName;
1316                         else if (ob is XmlSchemaSimpleTypeList)
1317                                 return ((XmlSchemaSimpleTypeList)ob).ItemTypeName;
1318                         else
1319                                 return null;
1320                 }
1321
1322                 void WriteComplexContent (XmlTextWriter xtw, string ns, XmlSchemaComplexContent content)
1323                 {
1324                         XmlQualifiedName qname;
1325
1326                         XmlSchemaComplexContentExtension ext = content.Content as XmlSchemaComplexContentExtension;
1327                         if (ext != null) qname = ext.BaseTypeName;
1328                         else {
1329                                 XmlSchemaComplexContentRestriction rest = (XmlSchemaComplexContentRestriction)content.Content;
1330                                 qname = rest.BaseTypeName;
1331                                 if (qname == arrayType) {
1332                                         ParseArrayType (rest, out qname);
1333                                         XmlSchemaElement elem = new XmlSchemaElement ();
1334                                         elem.Name = "Item";
1335                                         elem.SchemaTypeName = qname;
1336                                         
1337                                         xtw.WriteAttributeString ("arrayType", SoapEncodingNamespace, qname.Name + "[2]");
1338                                         WriteContentItem (xtw, ns, elem, true);
1339                                         return;
1340                                 }
1341                         }
1342                         
1343                         // Add base map members to this map
1344                         XmlSchemaComplexType ctype = FindComplexTyype (qname);
1345                         WriteComplexTypeAttributes (xtw, ctype);
1346                         
1347                         if (ext != null) {
1348                                 // Add the members of this map
1349                                 WriteAttributes (xtw, ext.Attributes, ext.AnyAttribute);
1350                                 if (ext.Particle != null)
1351                                         WriteParticleComplexContent (xtw, ns, ext.Particle);
1352                         }
1353                         
1354                         WriteComplexTypeElements (xtw, ns, ctype);
1355                 }
1356                 
1357                 void ParseArrayType (XmlSchemaComplexContentRestriction rest, out XmlQualifiedName qtype)
1358                 {
1359                         XmlSchemaAttribute arrayTypeAt = FindArrayAttribute (rest.Attributes);
1360                         XmlAttribute[] uatts = arrayTypeAt.UnhandledAttributes;
1361                         if (uatts == null || uatts.Length == 0) throw new InvalidOperationException ("arrayType attribute not specified in array declaration");
1362                         
1363                         XmlAttribute xat = null;
1364                         foreach (XmlAttribute at in uatts)
1365                                 if (at.LocalName == "arrayType" && at.NamespaceURI == WsdlNamespace)
1366                                         { xat = at; break; }
1367                         
1368                         if (xat == null) 
1369                                 throw new InvalidOperationException ("arrayType attribute not specified in array declaration");
1370                         
1371                         string arrayType = xat.Value;
1372                         string type, ns;
1373                         int i = arrayType.LastIndexOf (":");
1374                         if (i == -1) ns = "";
1375                         else ns = arrayType.Substring (0,i);
1376                         
1377                         int j = arrayType.IndexOf ("[", i+1);
1378                         if (j == -1) throw new InvalidOperationException ("Cannot parse WSDL array type: " + arrayType);
1379                         type = arrayType.Substring (i+1);
1380                         type = type.Substring (0, type.Length-2);
1381                         
1382                         qtype = new XmlQualifiedName (type, ns);
1383                 }
1384                 
1385                 XmlSchemaAttribute FindArrayAttribute (XmlSchemaObjectCollection atts)
1386                 {
1387                         foreach (object ob in atts)
1388                         {
1389                                 XmlSchemaAttribute att = ob as XmlSchemaAttribute;
1390                                 if (att != null && att.RefName == arrayTypeRefName) return att;
1391                                 
1392                                 XmlSchemaAttributeGroupRef gref = ob as XmlSchemaAttributeGroupRef;
1393                                 if (gref != null)
1394                                 {
1395                                         XmlSchemaAttributeGroup grp = (XmlSchemaAttributeGroup) schemas.Find (gref.RefName, typeof(XmlSchemaAttributeGroup));
1396                                         att = FindArrayAttribute (grp.Attributes);
1397                                         if (att != null) return att;
1398                                 }
1399                         }
1400                         return null;
1401                 }
1402                 
1403                 void WriteSimpleTypeSample (XmlTextWriter xtw, XmlSchemaSimpleType stype)
1404                 {
1405                         xtw.WriteString (GetLiteral (FindBuiltInType (stype)));
1406                 }
1407                 
1408                 XmlSchemaParticle GetRefGroupParticle (XmlSchemaGroupRef refGroup)
1409                 {
1410                         XmlSchemaGroup grp = (XmlSchemaGroup) schemas.Find (refGroup.RefName, typeof (XmlSchemaGroup));
1411                         return grp.Particle;
1412                 }
1413
1414                 XmlSchemaElement FindRefElement (XmlSchemaElement elem)
1415                 {
1416                         if (elem.RefName.Namespace == XmlSchema.Namespace)
1417                         {
1418                                 if (anyElement != null) return anyElement;
1419                                 anyElement = new XmlSchemaElement ();
1420                                 anyElement.Name = "any";
1421                                 anyElement.SchemaTypeName = anyType;
1422                                 return anyElement;
1423                         }
1424                         return (XmlSchemaElement) schemas.Find (elem.RefName, typeof(XmlSchemaElement));
1425                 }
1426                 
1427                 XmlSchemaAttribute FindRefAttribute (XmlQualifiedName refName)
1428                 {
1429                         if (refName.Namespace == XmlSchema.Namespace)
1430                         {
1431                                 XmlSchemaAttribute at = new XmlSchemaAttribute ();
1432                                 at.Name = refName.Name;
1433                                 at.SchemaTypeName = new XmlQualifiedName ("string",XmlSchema.Namespace);
1434                                 return at;
1435                         }
1436                         return (XmlSchemaAttribute) schemas.Find (refName, typeof(XmlSchemaAttribute));
1437                 }
1438                 
1439                 void WriteRefTypeSample (XmlTextWriter xtw, string ns, XmlSchemaElement elem)
1440                 {
1441                         if (elem.SchemaTypeName.Namespace == XmlSchema.Namespace || schemas.Find (elem.SchemaTypeName, typeof(XmlSchemaSimpleType)) != null)
1442                                 WriteElementSample (xtw, ns, elem);
1443                         else
1444                         {
1445                                 xtw.WriteStartElement (elem.Name, ns);
1446                                 xtw.WriteAttributeString ("href", "#id" + (queue.Count+1));
1447                                 xtw.WriteEndElement ();
1448                                 queue.Add (new EncodedType (ns, elem));
1449                         }
1450                 }
1451                 
1452                 void WriteQueuedTypeSamples (XmlTextWriter xtw)
1453                 {
1454                         for (int n=0; n<queue.Count; n++)
1455                         {
1456                                 EncodedType ec = (EncodedType) queue[n];
1457                                 XmlSchemaComplexType st = FindComplexTyype (ec.Element.SchemaTypeName);
1458                                 WriteComplexTypeSample (xtw, st, ec.Element.SchemaTypeName, n+1);
1459                         }
1460                 }
1461                 
1462                 XmlSchemaComplexType FindComplexTyype (XmlQualifiedName qname)
1463                 {
1464                         if (qname.Name.IndexOf ("[]") != -1)
1465                         {
1466                                 XmlSchemaComplexType stype = new XmlSchemaComplexType ();
1467                                 stype.ContentModel = new XmlSchemaComplexContent ();
1468                                 
1469                                 XmlSchemaComplexContentRestriction res = new XmlSchemaComplexContentRestriction ();
1470                                 stype.ContentModel.Content = res;
1471                                 res.BaseTypeName = arrayType;
1472                                 
1473                                 XmlSchemaAttribute att = new XmlSchemaAttribute ();
1474                                 att.RefName = arrayTypeRefName;
1475                                 res.Attributes.Add (att);
1476                                 
1477                                 XmlAttribute xat = document.CreateAttribute ("arrayType", WsdlNamespace);
1478                                 xat.Value = qname.Namespace + ":" + qname.Name;
1479                                 att.UnhandledAttributes = new XmlAttribute[] {xat};
1480                                 return stype;
1481                         }
1482                                 
1483                         return (XmlSchemaComplexType) schemas.Find (qname, typeof(XmlSchemaComplexType));
1484                 }
1485                 
1486                 string GetQualifiedNameString (XmlTextWriter xtw, XmlQualifiedName qname)
1487                 {
1488                         string pref = xtw.LookupPrefix (qname.Namespace);
1489                         if (pref != null) return pref + ":" + qname.Name;
1490                         
1491                         xtw.WriteAttributeString ("xmlns", "q1", null, qname.Namespace);
1492                         return "q1:" + qname.Name;
1493                 }
1494                                 
1495                 protected virtual string GetLiteral (string s)
1496                 {
1497                         return s;
1498                 }
1499
1500                 void GetOperationFormat (OperationBinding obin, out SoapBindingStyle style, out SoapBindingUse use)
1501                 {
1502                         style = SoapBindingStyle.Document;
1503                         use = SoapBindingUse.Literal;
1504                         SoapOperationBinding sob = obin.Extensions.Find (typeof(SoapOperationBinding)) as SoapOperationBinding;
1505                         if (sob != null) {
1506                                 style = sob.Style;
1507                                 SoapBodyBinding sbb = obin.Input.Extensions.Find (typeof(SoapBodyBinding)) as SoapBodyBinding;
1508                                 if (sbb != null)
1509                                         use = sbb.Use;
1510                         }
1511                 }
1512         }
1513
1514
1515
1516
1517
1518 </script>
1519
1520 <head>
1521         <link rel="alternate" type="text/xml" href="<%=Request.FilePath%>?disco"/>
1522
1523         <title><%=WebServiceName%> Web Service</title>
1524     <style type="text/css">
1525                 BODY { font-family: Arial; margin-left: 20px; margin-top: 20px; font-size: x-small}
1526                 TABLE { font-size: x-small }
1527                 .title { color:dimgray; font-family: Arial; font-size:20pt; font-weight:900}
1528                 .operationTitle { color:dimgray; font-family: Arial; font-size:15pt; font-weight:900}
1529                 .method { font-size: x-small }
1530                 .bindingLabel { font-size: medium; font-weight:bold; color:darkgray; line-height:8pt; display:block; margin-bottom:3px }
1531                 .label { font-size: small; font-weight:bold; color:darkgray }
1532                 .paramTable { font-size: x-small }
1533                 .paramTable TR { background-color: gainsboro }
1534                 .paramFormTable { font-size: x-small; padding: 10px; background-color: gainsboro }
1535                 .paramFormTable TR { background-color: gainsboro }
1536                 .paramInput { border: solid 1px gray }
1537                 .button {border: solid 1px gray }
1538                 .smallSeparator { height:3px; overflow:hidden }
1539                 .panel { background-color:whitesmoke; border: solid 1px silver; border-top: solid 1px silver  }
1540                 .codePanel { background-color: white; font-size:x-small; padding:7px; border:solid 1px silver}
1541                 .code-xml { font-size:10pt; font-family:courier }
1542                 .code-cs { font-size:10pt; font-family:courier }
1543                 .code-vb { font-size:10pt; font-family:courier }
1544                 .tabLabelOn { font-weight:bold }
1545                 .tabLabelOff {color: darkgray }
1546                 .literal-placeholder {color: darkblue; font-weight:bold}
1547                 A:link { color: black; }
1548                 A:visited { color: black; }
1549                 A:active { color: black; }
1550                 A:hover { color: blue }
1551     </style>
1552         
1553 <script>
1554 function clearForm ()
1555 {
1556         document.getElementById("testFormResult").style.display="none";
1557 }
1558 </script>
1559
1560 </head>
1561
1562 <body>
1563 <div class="title" style="margin-left:20px">
1564 <span class="label">Web Service</span><br>
1565 <%=WebServiceName%>
1566 </div>
1567
1568 <!--
1569         **********************************************************
1570         Left panel
1571 -->
1572
1573 <table border="0" width="100%" cellpadding="15px" cellspacing="15px">
1574 <tr valign="top"><td width="150px" class="panel">
1575 <div style="width:150px"></div>
1576 <a class="method" href='<%=PageName%>'>Overview</a><br>
1577 <div class="smallSeparator"></div>
1578 <a class="method" href='<%=PageName + "?" + GetPageContext("wsdl")%>'>Service Description</a>
1579 <!--
1580 <div class="smallSeparator"></div>
1581 <a class="method" href='<%=PageName + "?" + GetPageContext("proxy")%>'>Client proxy</a>
1582 -->
1583 <br><br>
1584         <asp:repeater id="BindingsRepeater" runat=server>
1585                 <itemtemplate>
1586                         <span class="bindingLabel"><%#FormatBindingName(DataBinder.Eval(Container.DataItem, "Name").ToString())%></span>
1587                         <asp:repeater id="OperationsRepeater" runat=server datasource='<%# ((Binding)Container.DataItem).Operations %>'>
1588                                 <itemtemplate>
1589                                         <a class="method" href="<%=PageName%>?<%=GetTabContext("op",null)%>op=<%#GetOpName(Container.DataItem)%>&bnd=<%#DataBinder.Eval(Container.DataItem, "Binding.Name")%>"><%#GetOpName(Container.DataItem)%></a>
1590                                         <div class="smallSeparator"></div>
1591                                 </itemtemplate>
1592                         </asp:repeater>
1593                         <br>
1594                 </itemtemplate>
1595         </asp:repeater>
1596
1597 </td><td class="panel">
1598
1599 <% if (CurrentPage == "main") {%>
1600
1601 <!--
1602         **********************************************************
1603         Web service overview
1604 -->
1605
1606         <p class="label">Web Service Overview</p>
1607         <%=WebServiceDescription%>
1608         <br/><br/>
1609         <% if (ProfileViolations.Count > 0) { %>
1610                 <p class="label">Basic Profile Conformance</p>
1611                 This web service does not conform to WS-I Basic Profile v1.1
1612         <%
1613                 Response.Write ("<ul>");
1614                 foreach (BasicProfileViolation vio in ProfileViolations) {
1615                         Response.Write ("<li><b>" + vio.NormativeStatement + "</b>: " + vio.Details);
1616                         Response.Write ("<ul>");
1617                         foreach (string ele in vio.Elements)
1618                                 Response.Write ("<li>" + ele + "</li>");
1619                         Response.Write ("</ul>");
1620                         Response.Write ("</li>");
1621                 }
1622                 Response.Write ("</ul>");
1623         }%>
1624
1625 <%} if (DefaultBinding == null) {%>
1626 This service does not contain any public web method.
1627 <%} else if (CurrentPage == "op") {%>
1628
1629 <!--
1630         **********************************************************
1631         Operation description
1632 -->
1633
1634         <span class="operationTitle"><%=CurrentOperationName%></span>
1635         <br><br>
1636         <% WriteTabs (); %>
1637         <br><br><br>
1638         
1639         <% if (CurrentTab == "main") { %>
1640                 <span class="label">Input Parameters</span>
1641                 <div class="smallSeparator"></div>
1642                 <% if (InParams.Count == 0) { %>
1643                         No input parameters<br>
1644                 <% } else { %>
1645                         <table class="paramTable" cellspacing="1" cellpadding="5">
1646                         <asp:repeater id="InputParamsRepeater" runat=server>
1647                                 <itemtemplate>
1648                                         <tr>
1649                                         <td width="150"><%#DataBinder.Eval(Container.DataItem, "Name")%></td>
1650                                         <td width="150"><%#DataBinder.Eval(Container.DataItem, "Type")%></td>
1651                                         </tr>
1652                                 </itemtemplate>
1653                         </asp:repeater>
1654                         </table>
1655                 <% } %>
1656                 <br>
1657                 
1658                 <% if (OutParams.Count > 0) { %>
1659                 <span class="label">Output Parameters</span>
1660                         <div class="smallSeparator"></div>
1661                         <table class="paramTable" cellspacing="1" cellpadding="5">
1662                         <asp:repeater id="OutputParamsRepeater" runat=server>
1663                                 <itemtemplate>
1664                                         <tr>
1665                                         <td width="150"><%#DataBinder.Eval(Container.DataItem, "Name")%></td>
1666                                         <td width="150"><%#DataBinder.Eval(Container.DataItem, "Type")%></td>
1667                                         </tr>
1668                                 </itemtemplate>
1669                         </asp:repeater>
1670                         </table>
1671                 <br>
1672                 <% } %>
1673                 
1674                 <span class="label">Remarks</span>
1675                 <div class="smallSeparator"></div>
1676                 <%=OperationDocumentation%>
1677                 <br><br>
1678                 <span class="label">Technical information</span>
1679                 <div class="smallSeparator"></div>
1680                 Format: <%=CurrentOperationFormat%>
1681                 <br>Supported protocols: <%=CurrentOperationProtocols%>
1682         <% } %>
1683         
1684 <!--
1685         **********************************************************
1686         Operation description - Test form
1687 -->
1688
1689         <% if (CurrentTab == "test") { 
1690                 if (CurrentOperationSupportsTest) {%>
1691                         Enter values for the parameters and click the 'Invoke' button to test this method:<br><br>
1692                         <form action="<%=PageName%>" method="GET">
1693                         <input type="hidden" name="page" value="<%=CurrentPage%>">
1694                         <input type="hidden" name="tab" value="<%=CurrentTab%>">
1695                         <input type="hidden" name="op" value="<%=CurrentOperationName%>">
1696                         <input type="hidden" name="bnd" value="<%=CurrentOperationBinding%>">
1697                         <input type="hidden" name="ext" value="testform">
1698                         <table class="paramFormTable" cellspacing="0" cellpadding="3">
1699                         <asp:repeater id="InputFormParamsRepeater" runat=server>
1700                                 <itemtemplate>
1701                                         <tr>
1702                                         <td><%#DataBinder.Eval(Container.DataItem, "Name")%>:&nbsp;</td>
1703                                         <td width="150"><input class="paramInput" type="text" size="20" name="<%#DataBinder.Eval(Container.DataItem, "Name")%>"></td>
1704                                         </tr>
1705                                 </itemtemplate>
1706                         </asp:repeater>
1707                         <tr><td></td><td><input class="button" type="submit" value="Invoke">&nbsp;<input class="button" type="button" onclick="clearForm()" value="Clear"></td></tr>
1708                         </table>
1709                         </form>
1710                         <div id="testFormResult" style="display:<%= (HasFormResult?"block":"none") %>">
1711                         The web service returned the following result:<br/><br/>
1712                         <div class="codePanel"><%=GetTestResult()%></div>
1713                         </div>
1714                 <% } else {%>
1715                 The test form is not available for this operation because it has parameters with a complex structure.
1716                 <% } %>
1717         <% } %>
1718         
1719 <!--
1720         **********************************************************
1721         Operation description - Message Layout
1722 -->
1723
1724         <% if (CurrentTab == "msg") { %>
1725                 
1726                 The following are sample SOAP requests and responses for each protocol supported by this method:
1727                         <br/><br/>
1728                 
1729                 <% if (IsOperationSupported ("Soap")) { %>
1730                         <span class="label">Soap</span>
1731                         <br/><br/>
1732                         <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("Soap", true)%></div></div>
1733                         <br/>
1734                         <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("Soap", false)%></div></div>
1735                         <br/>
1736                 <% } %>
1737                 <% if (IsOperationSupported ("HttpGet")) { %>
1738                         <span class="label">HTTP Get</span>
1739                         <br/><br/>
1740                         <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("HttpGet", true)%></div></div>
1741                         <br/>
1742                         <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("HttpGet", false)%></div></div>
1743                         <br/>
1744                 <% } %>
1745                 <% if (IsOperationSupported ("HttpPost")) { %>
1746                         <span class="label">HTTP Post</span>
1747                         <br/><br/>
1748                         <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("HttpPost", true)%></div></div>
1749                         <br/>
1750                         <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("HttpPost", false)%></div></div>
1751                         <br/>
1752                 <% } %>
1753                 
1754         <% } %>
1755 <%} else if (CurrentPage == "proxy") {%>
1756 <!--
1757         **********************************************************
1758         Client Proxy
1759 -->
1760         <form action="<%=PageName%>" name="langForm" method="GET">
1761                 Select the language for which you want to generate a proxy 
1762                 <input type="hidden" name="page" value="<%=CurrentPage%>">&nbsp;
1763                 <SELECT name="lang" onchange="langForm.submit()">
1764                         <%=GetOptionSel("cs",CurrentLanguage)%>C#</option>
1765                         <%=GetOptionSel("vb",CurrentLanguage)%>Visual Basic</option>
1766                 </SELECT>
1767                 &nbsp;&nbsp;
1768         </form>
1769         <br>
1770         <span class="label"><%=CurrentProxytName%></span>&nbsp;&nbsp;&nbsp;
1771         <a href="<%=PageName + "?code=" + CurrentLanguage%>">Download</a>
1772         <br><br>
1773         <div class="codePanel">
1774         <div class="code-<%=CurrentLanguage%>"><%=GetProxyCode ()%></div>
1775         </div>
1776 <%} else if (CurrentPage == "wsdl") {%>
1777 <!--
1778         **********************************************************
1779         Service description
1780 -->
1781         <% if (descriptions.Count > 1 || schemas.Count > 1) {%>
1782         The description of this web service is composed by several documents. Click on the document you want to see:
1783         
1784         <ul>
1785         <% 
1786                 for (int n=0; n<descriptions.Count; n++)
1787                         Response.Write ("<li><a href='" + PageName + "?" + GetPageContext(null) + "doctype=wsdl&docind=" + n + "'>WSDL document " + descriptions[n].TargetNamespace + "</a></li>");
1788                 for (int n=0; n<schemas.Count; n++)
1789                         Response.Write ("<li><a href='" + PageName + "?" + GetPageContext(null) + "doctype=schema&docind=" + n + "'>Xml Schema " + schemas[n].TargetNamespace + "</a></li>");
1790         %>
1791         </ul>
1792         
1793         <%} else {%>
1794         <%}%>
1795         <br>
1796         <span class="label"><%=CurrentDocumentName%></span>&nbsp;&nbsp;&nbsp;
1797         <a href="<%=PageName + "?" + CurrentDocType + "=" + CurrentDocInd %>">Download</a>
1798         <br><br>
1799         <div class="codePanel">
1800         <div class="code-xml"><%=GenerateDocument ()%></div>
1801         </div>
1802
1803 <%}%>
1804
1805 <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
1806 </td>
1807 <td width="20px"></td>
1808 </tr>
1809
1810 </table>
1811 </body>
1812 </html>