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