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