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