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