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