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