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