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