3 // DefaultWsdlHelpGenerator.aspx:
6 // Lluis Sanchez Gual (lluis@ximian.com)
8 // (C) 2003 Ximian, Inc. http://www.ximian.com
12 <%@ Import Namespace="System.Collections" %>
13 <%@ Import Namespace="System.IO" %>
14 <%@ Import Namespace="System.Xml.Serialization" %>
15 <%@ Import Namespace="System.Xml" %>
16 <%@ Import Namespace="System.Xml.Schema" %>
17 <%@ Import Namespace="System.Web.Services.Description" %>
18 <%@ Import Namespace="System" %>
19 <%@ Import Namespace="System.Net" %>
20 <%@ Import Namespace="System.Globalization" %>
21 <%@ Import Namespace="System.Resources" %>
22 <%@ Import Namespace="System.Diagnostics" %>
23 <%@ Import Namespace="System.CodeDom" %>
24 <%@ Import Namespace="System.CodeDom.Compiler" %>
25 <%@ Import Namespace="Microsoft.CSharp" %>
26 <%@ Import Namespace="Microsoft.VisualBasic" %>
27 <%@ Import Namespace="System.Text.RegularExpressions" %>
28 <%@ Assembly name="System.Web.Services" %>
29 <%@ Page debug="true" %>
32 <script language="C#" runat="server">
34 ServiceDescriptionCollection descriptions;
37 string WebServiceName;
38 string WebServiceDescription;
41 string DefaultBinding;
42 ArrayList ServiceProtocols;
44 string CurrentOperationName;
45 string CurrentOperationBinding;
46 string OperationDocumentation;
47 string CurrentOperationFormat;
48 bool CurrentOperationSupportsTest;
51 string CurrentOperationProtocols;
52 int CodeTextColumns = 95;
54 void Page_Load(object sender, EventArgs e)
56 descriptions = (ServiceDescriptionCollection) Context.Items["wsdls"];
57 schemas = (XmlSchemas) Context.Items["schemas"];
59 ServiceDescription desc = descriptions [0];
60 if (schemas.Count == 0) schemas = desc.Types.Schemas;
62 Service service = desc.Services[0];
63 WebServiceName = service.Name;
64 if (desc.Bindings.Count == 0)
67 DefaultBinding = desc.Bindings[0].Name;
68 WebServiceDescription = service.Documentation;
69 ServiceProtocols = FindServiceProtocols (null);
71 CurrentOperationName = Request.QueryString["op"];
72 CurrentOperationBinding = Request.QueryString["bnd"];
73 if (CurrentOperationName != null) BuildOperationInfo ();
75 PageName = HttpUtility.UrlEncode (Path.GetFileName(Request.Path), Encoding.UTF8);
77 ArrayList list = new ArrayList ();
78 foreach (ServiceDescription sd in descriptions) {
79 foreach (Binding bin in sd.Bindings)
80 if (bin.Extensions.Find (typeof(SoapBinding)) != null) list.Add (bin);
83 BindingsRepeater.DataSource = list;
87 void BuildOperationInfo ()
89 InParams = new ArrayList ();
90 OutParams = new ArrayList ();
92 Port port = FindPort (CurrentOperationBinding, null);
93 Binding binding = descriptions.GetBinding (port.Binding);
95 PortType portType = descriptions.GetPortType (binding.Type);
96 Operation oper = FindOperation (portType, CurrentOperationName);
98 OperationDocumentation = oper.Documentation;
99 if (OperationDocumentation == null || OperationDocumentation == "")
100 OperationDocumentation = "No additional remarks";
102 foreach (OperationMessage opm in oper.Messages)
104 if (opm is OperationInput)
105 BuildParameters (InParams, opm);
106 else if (opm is OperationOutput)
107 BuildParameters (OutParams, opm);
110 // Protocols supported by the operation
111 CurrentOperationProtocols = "";
112 ArrayList prots = FindServiceProtocols (CurrentOperationName);
113 for (int n=0; n<prots.Count; n++) {
114 if (n != 0) CurrentOperationProtocols += ", ";
115 CurrentOperationProtocols += (string) prots[n];
118 CurrentOperationSupportsTest = prots.Contains ("HttpGet") || prots.Contains ("HttpPost");
121 OperationBinding obin = FindOperation (binding, CurrentOperationName);
123 CurrentOperationFormat = GetOperationFormat (obin);
125 InputParamsRepeater.DataSource = InParams;
126 InputFormParamsRepeater.DataSource = InParams;
127 OutputParamsRepeater.DataSource = OutParams;
130 void BuildParameters (ArrayList list, OperationMessage opm)
132 Message msg = descriptions.GetMessage (opm.Message);
133 if (msg.Parts.Count > 0 && msg.Parts[0].Name == "parameters")
135 MessagePart part = msg.Parts[0];
136 XmlSchemaComplexType ctype;
137 if (part.Element == XmlQualifiedName.Empty)
139 ctype = (XmlSchemaComplexType) schemas.Find (part.Type, typeof(XmlSchemaComplexType));
143 XmlSchemaElement elem = (XmlSchemaElement) schemas.Find (part.Element, typeof(XmlSchemaElement));
144 ctype = (XmlSchemaComplexType) elem.SchemaType;
146 XmlSchemaSequence seq = ctype.Particle as XmlSchemaSequence;
147 if (seq == null) return;
149 foreach (XmlSchemaObject ob in seq.Items)
151 Parameter p = new Parameter();
152 p.Description = "No additional remarks";
154 if (ob is XmlSchemaElement)
156 XmlSchemaElement selem = GetRefElement ((XmlSchemaElement)ob);
158 p.Type = selem.SchemaTypeName.Name;
170 foreach (MessagePart part in msg.Parts)
172 Parameter p = new Parameter ();
173 p.Description = "No additional remarks";
175 if (part.Element == XmlQualifiedName.Empty)
176 p.Type = part.Type.Name;
179 XmlSchemaElement elem = (XmlSchemaElement) schemas.Find (part.Element, typeof(XmlSchemaElement));
180 p.Type = elem.SchemaTypeName.Name;
187 string GetOperationFormat (OperationBinding obin)
190 SoapOperationBinding sob = obin.Extensions.Find (typeof(SoapOperationBinding)) as SoapOperationBinding;
192 format = sob.Style.ToString ();
193 SoapBodyBinding sbb = obin.Input.Extensions.Find (typeof(SoapBodyBinding)) as SoapBodyBinding;
195 format += " / " + sbb.Use;
200 XmlSchemaElement GetRefElement (XmlSchemaElement elem)
202 if (!elem.RefName.IsEmpty)
203 return (XmlSchemaElement) schemas.Find (elem.RefName, typeof(XmlSchemaElement));
208 ArrayList FindServiceProtocols(string operName)
210 ArrayList table = new ArrayList ();
211 Service service = descriptions[0].Services[0];
212 foreach (Port port in service.Ports)
215 Binding bin = descriptions.GetBinding (port.Binding);
216 if (bin.Extensions.Find (typeof(SoapBinding)) != null)
220 HttpBinding hb = (HttpBinding) bin.Extensions.Find (typeof(HttpBinding));
221 if (hb != null && hb.Verb == "POST") prot = "HttpPost";
222 else if (hb != null && hb.Verb == "GET") prot = "HttpGet";
225 if (prot != null && operName != null)
227 if (FindOperation (bin, operName) == null)
231 if (prot != null && !table.Contains (prot))
237 Port FindPort (string portName, string protocol)
239 Service service = descriptions[0].Services[0];
240 foreach (Port port in service.Ports)
242 if (portName == null)
244 Binding binding = descriptions.GetBinding (port.Binding);
245 if (GetProtocol (binding) == protocol) return port;
247 else if (port.Name == portName)
253 string GetProtocol (Binding binding)
255 if (binding.Extensions.Find (typeof(SoapBinding)) != null) return "Soap";
256 HttpBinding hb = (HttpBinding) binding.Extensions.Find (typeof(HttpBinding));
257 if (hb == null) return "";
258 if (hb.Verb == "POST") return "HttpPost";
259 if (hb.Verb == "GET") return "HttpGet";
264 Operation FindOperation (PortType portType, string name)
266 foreach (Operation oper in portType.Operations) {
267 if (oper.Messages.Input.Name != null) {
268 if (oper.Messages.Input.Name == name) return oper;
271 if (oper.Name == name) return oper;
277 OperationBinding FindOperation (Binding binding, string name)
279 foreach (OperationBinding oper in binding.Operations) {
280 if (oper.Input.Name != null) {
281 if (oper.Input.Name == name) return oper;
284 if (oper.Name == name) return oper;
290 string FormatBindingName (string name)
292 if (name == DefaultBinding) return "Methods";
293 else return "Methods for binding<br>" + name;
296 string GetOpName (object op)
298 OperationBinding ob = op as OperationBinding;
299 if (ob == null) return "";
300 if (ob.Input.Name != null) return ob.Input.Name;
306 get { return Request.QueryString ["ext"] == "testform"; }
309 string GetTestResult ()
311 if (!HasFormResult) return null;
315 for (int n=0; n<Request.QueryString.Count; n++)
318 if (qs != "") qs += "&";
319 qs += Request.QueryString.GetKey(n) + "=" + Server.UrlEncode (Request.QueryString [n]);
321 if (Request.QueryString.GetKey(n) == "ext") fill = true;
324 string location = null;
325 ServiceDescription desc = descriptions [0];
326 Service service = desc.Services[0];
327 foreach (Port port in service.Ports)
328 if (port.Name == CurrentOperationBinding)
330 SoapAddressBinding sbi = (SoapAddressBinding) port.Extensions.Find (typeof(SoapAddressBinding));
332 location = sbi.Location;
335 if (location == null)
336 return "Could not locate web service";
340 WebRequest req = WebRequest.Create (location + "/" + CurrentOperationName + "?" + qs);
341 HttpCookieCollection cookies = Request.Cookies;
342 int last = cookies.Count;
344 CookieContainer container = new CookieContainer ();
345 for (int i = 0; i < last; i++) {
346 HttpCookie hcookie = cookies [i];
347 Cookie cookie = new Cookie (hcookie.Name, hcookie.Value, hcookie.Path, hcookie.Domain);
348 container.Add (cookie);
350 ((HttpWebRequest) req).CookieContainer = container;
352 WebResponse resp = req.GetResponse();
353 StreamReader sr = new StreamReader (resp.GetResponseStream());
354 string s = sr.ReadToEnd ();
356 return "<div class='code-xml'>" + ColorizeXml(WrapText(s,CodeTextColumns)) + "</div>";
360 string res = "<b style='color:red'>" + ex.Message + "</b>";
361 WebException wex = ex as WebException;
364 WebResponse resp = wex.Response;
366 StreamReader sr = new StreamReader (resp.GetResponseStream());
367 string s = sr.ReadToEnd ();
369 res += "<div class='code-xml'>" + ColorizeXml(WrapText(s,CodeTextColumns)) + "</div>";
376 string GenerateOperationMessages (string protocol, bool generateInput)
378 if (!IsOperationSupported (protocol)) return "";
381 if (protocol != "Soap") port = FindPort (null, protocol);
382 else port = FindPort (CurrentOperationBinding, null);
384 Binding binding = descriptions.GetBinding (port.Binding);
385 OperationBinding obin = FindOperation (binding, CurrentOperationName);
386 PortType portType = descriptions.GetPortType (binding.Type);
387 Operation oper = FindOperation (portType, CurrentOperationName);
389 HtmlSampleGenerator sg = new HtmlSampleGenerator (descriptions, schemas);
390 string txt = sg.GenerateMessage (port, obin, oper, protocol, generateInput);
391 if (protocol == "Soap") txt = WrapText (txt,CodeTextColumns);
392 txt = ColorizeXml (txt);
393 txt = txt.Replace ("@placeholder!","<span class='literal-placeholder'>");
394 txt = txt.Replace ("!placeholder@","</span>");
398 bool IsOperationSupported (string protocol)
400 if (CurrentPage != "op" || CurrentTab != "msg") return false;
401 if (protocol == "Soap") return true;
403 Port port = FindPort (null, protocol);
404 if (port == null) return false;
405 Binding binding = descriptions.GetBinding (port.Binding);
406 if (binding == null) return false;
407 return FindOperation (binding, CurrentOperationName) != null;
411 // Proxy code generation
414 string GetProxyCode ()
416 CodeNamespace codeNamespace = new CodeNamespace();
417 CodeCompileUnit codeUnit = new CodeCompileUnit();
419 codeUnit.Namespaces.Add (codeNamespace);
421 ServiceDescriptionImporter importer = new ServiceDescriptionImporter();
423 foreach (ServiceDescription sd in descriptions)
424 importer.AddServiceDescription(sd, null, null);
426 foreach (XmlSchema sc in schemas)
427 importer.Schemas.Add (sc);
429 importer.Import(codeNamespace, codeUnit);
431 string langId = Request.QueryString ["lang"];
432 if (langId == null || langId == "") langId = "cs";
433 CodeDomProvider provider = GetProvider (langId);
434 ICodeGenerator generator = provider.CreateGenerator();
435 CodeGeneratorOptions options = new CodeGeneratorOptions();
437 StringWriter sw = new StringWriter ();
438 generator.GenerateCodeFromCompileUnit(codeUnit, sw, options);
440 return Colorize (WrapText (sw.ToString (), CodeTextColumns), langId);
443 public string CurrentLanguage
446 string langId = Request.QueryString ["lang"];
447 if (langId == null || langId == "") langId = "cs";
452 public string CurrentProxytName
455 string lan = CurrentLanguage == "cs" ? "C#" : "Visual Basic";
456 return lan + " Client Proxy";
460 private CodeDomProvider GetProvider(string langId)
462 switch (langId.ToUpper())
464 case "CS": return new CSharpCodeProvider();
465 case "VB": return new VBCodeProvider();
466 default: return null;
471 // Document generation
474 string GenerateDocument ()
476 StringWriter sw = new StringWriter ();
478 if (CurrentDocType == "wsdl")
479 descriptions [CurrentDocInd].Write (sw);
480 else if (CurrentDocType == "schema")
481 schemas [CurrentDocInd].Write (sw);
483 return Colorize (WrapText (sw.ToString (), CodeTextColumns), "xml");
486 public string CurrentDocType
488 get { return Request.QueryString ["doctype"] != null ? Request.QueryString ["doctype"] : "wsdl"; }
491 public int CurrentDocInd
493 get { return Request.QueryString ["docind"] != null ? int.Parse (Request.QueryString ["docind"]) : 0; }
496 public string CurrentDocumentName
499 if (CurrentDocType == "wsdl")
500 return "WSDL document for namespace \"" + descriptions [CurrentDocInd].TargetNamespace + "\"";
502 return "Xml Schema for namespace \"" + schemas [CurrentDocInd].TargetNamespace + "\"";
510 bool firstTab = true;
511 ArrayList disabledTabs = new ArrayList ();
515 get { return Request.QueryString["tab"] != null ? Request.QueryString["tab"] : "main" ; }
520 get { return Request.QueryString["page"] != null ? Request.QueryString["page"] : "main" ; }
525 if (CurrentOperationName != null)
527 WriteTab ("main","Overview");
528 WriteTab ("test","Test Form");
529 WriteTab ("msg","Message Layout");
533 void WriteTab (string id, string label)
535 if (!firstTab) Response.Write(" | ");
538 string cname = CurrentTab == id ? "tabLabelOn" : "tabLabelOff";
539 Response.Write ("<a href='" + PageName + "?" + GetPageContext(null) + GetDataContext() + "tab=" + id + "' style='text-decoration:none'>");
540 Response.Write ("<span class='" + cname + "'>" + label + "</span>");
541 Response.Write ("</a>");
544 string GetTabContext (string pag, string tab)
546 if (tab == null) tab = CurrentTab;
547 if (pag == null) pag = CurrentPage;
548 if (pag != CurrentPage) tab = "main";
549 return "page=" + pag + "&tab=" + tab + "&";
552 string GetPageContext (string pag)
554 if (pag == null) pag = CurrentPage;
555 return "page=" + pag + "&";
568 static string keywords_cs =
569 "(\\babstract\\b|\\bevent\\b|\\bnew\\b|\\bstruct\\b|\\bas\\b|\\bexplicit\\b|\\bnull\\b|\\bswitch\\b|\\bbase\\b|\\bextern\\b|" +
570 "\\bobject\\b|\\bthis\\b|\\bbool\\b|\\bfalse\\b|\\boperator\\b|\\bthrow\\b|\\bbreak\\b|\\bfinally\\b|\\bout\\b|\\btrue\\b|" +
571 "\\bbyte\\b|\\bfixed\\b|\\boverride\\b|\\btry\\b|\\bcase\\b|\\bfloat\\b|\\bparams\\b|\\btypeof\\b|\\bcatch\\b|\\bfor\\b|" +
572 "\\bprivate\\b|\\buint\\b|\\bchar\\b|\\bforeach\\b|\\bprotected\\b|\\bulong\\b|\\bchecked\\b|\\bgoto\\b|\\bpublic\\b|" +
573 "\\bunchecked\\b|\\bclass\\b|\\bif\\b|\\breadonly\\b|\\bunsafe\\b|\\bconst\\b|\\bimplicit\\b|\\bref\\b|\\bushort\\b|" +
574 "\\bcontinue\\b|\\bin\\b|\\breturn\\b|\\busing\\b|\\bdecimal\\b|\\bint\\b|\\bsbyte\\b|\\bvirtual\\b|\\bdefault\\b|" +
575 "\\binterface\\b|\\bsealed\\b|\\bvolatile\\b|\\bdelegate\\b|\\binternal\\b|\\bshort\\b|\\bvoid\\b|\\bdo\\b|\\bis\\b|" +
576 "\\bsizeof\\b|\\bwhile\\b|\\bdouble\\b|\\block\\b|\\bstackalloc\\b|\\belse\\b|\\blong\\b|\\bstatic\\b|\\benum\\b|" +
577 "\\bnamespace\\b|\\bstring\\b)";
579 static string keywords_vb =
580 "(\\bAddHandler\\b|\\bAddressOf\\b|\\bAlias\\b|\\bAnd\\b|\\bAndAlso\\b|\\bAnsi\\b|\\bAs\\b|\\bAssembly\\b|" +
581 "\\bAuto\\b|\\bBoolean\\b|\\bByRef\\b|\\bByte\\b|\\bByVal\\b|\\bCall\\b|\\bCase\\b|\\bCatch\\b|" +
582 "\\bCBool\\b|\\bCByte\\b|\\bCChar\\b|\\bCDate\\b|\\bCDec\\b|\\bCDbl\\b|\\bChar\\b|\\bCInt\\b|" +
583 "\\bClass\\b|\\bCLng\\b|\\bCObj\\b|\\bConst\\b|\\bCShort\\b|\\bCSng\\b|\\bCStr\\b|\\bCType\\b|" +
584 "\\bDate\\b|\\bDecimal\\b|\\bDeclare\\b|\\bDefault\\b|\\bDelegate\\b|\\bDim\\b|\\bDirectCast\\b|\\bDo\\b|" +
585 "\\bDouble\\b|\\bEach\\b|\\bElse\\b|\\bElseIf\\b|\\bEnd\\b|\\bEnum\\b|\\bErase\\b|\\bError\\b|" +
586 "\\bEvent\\b|\\bExit\\b|\\bFalse\\b|\\bFinally\\b|\\bFor\\b|\\bFriend\\b|\\bFunction\\b|\\bGet\\b|" +
587 "\\bGetType\\b|\\bGoSub\\b|\\bGoTo\\b|\\bHandles\\b|\\bIf\\b|\\bImplements\\b|\\bImports\\b|\\bIn\\b|" +
588 "\\bInherits\\b|\\bInteger\\b|\\bInterface\\b|\\bIs\\b|\\bLet\\b|\\bLib\\b|\\bLike\\b|\\bLong\\b|" +
589 "\\bLoop\\b|\\bMe\\b|\\bMod\\b|\\bModule\\b|\\bMustInherit\\b|\\bMustOverride\\b|\\bMyBase\\b|\\bMyClass\\b|" +
590 "\\bNamespace\\b|\\bNew\\b|\\bNext\\b|\\bNot\\b|\\bNothing\\b|\\bNotInheritable\\b|\\bNotOverridable\\b|\\bObject\\b|" +
591 "\\bOn\\b|\\bOption\\b|\\bOptional\\b|\\bOr\\b|\\bOrElse\\b|\\bOverloads\\b|\\bOverridable\\b|\\bOverrides\\b|" +
592 "\\bParamArray\\b|\\bPreserve\\b|\\bPrivate\\b|\\bProperty\\b|\\bProtected\\b|\\bPublic\\b|\\bRaiseEvent\\b|\\bReadOnly\\b|" +
593 "\\bReDim\\b|\\bREM\\b|\\bRemoveHandler\\b|\\bResume\\b|\\bReturn\\b|\\bSelect\\b|\\bSet\\b|\\bShadows\\b|" +
594 "\\bShared\\b|\\bShort\\b|\\bSingle\\b|\\bStatic\\b|\\bStep\\b|\\bStop\\b|\\bString\\b|\\bStructure\\b|" +
595 "\\bSub\\b|\\bSyncLock\\b|\\bThen\\b|\\bThrow\\b|\\bTo\\b|\\bTrue\\b|\\bTry\\b|\\bTypeOf\\b|" +
596 "\\bUnicode\\b|\\bUntil\\b|\\bVariant\\b|\\bWhen\\b|\\bWhile\\b|\\bWith\\b|\\bWithEvents\\b|\\bWriteOnly\\b|\\bXor\\b)";
598 string Colorize (string text, string lang)
600 if (lang == "xml") return ColorizeXml (text);
601 else if (lang == "cs") return ColorizeCs (text);
602 else if (lang == "vb") return ColorizeVb (text);
606 string ColorizeXml (string text)
608 text = text.Replace (" ", " ");
609 Regex re = new Regex ("\r\n|\r|\n");
610 text = re.Replace (text, "_br_");
612 re = new Regex ("<\\s*(\\/?)\\s*([\\s\\S]*?)\\s*(\\/?)\\s*>");
613 text = re.Replace (text,"{blue:<$1}{maroon:$2}{blue:$3>}");
615 re = new Regex ("\\{(\\w*):([\\s\\S]*?)\\}");
616 text = re.Replace (text,"<span style='color:$1'>$2</span>");
618 re = new Regex ("\"(.*?)\"");
619 text = re.Replace (text,"\"<span style='color:purple'>$1</span>\"");
622 text = text.Replace ("\t", " ");
623 text = text.Replace ("_br_", "<br>");
627 string ColorizeCs (string text)
629 text = text.Replace (" ", " ");
631 text = text.Replace ("<", "<");
632 text = text.Replace (">", ">");
634 Regex re = new Regex ("\"((((?!\").)|\\\")*?)\"");
635 text = re.Replace (text,"<span style='color:purple'>\"$1\"</span>");
637 re = new Regex ("//(((.(?!\"</span>))|\"(((?!\").)*)\"</span>)*)(\r|\n|\r\n)");
638 text = re.Replace (text,"<span style='color:green'>//$1</span><br/>");
640 re = new Regex (keywords_cs);
641 text = re.Replace (text,"<span style='color:blue'>$1</span>");
643 text = text.Replace ("\t"," ");
644 text = text.Replace ("\n","<br/>");
649 string ColorizeVb (string text)
651 text = text.Replace (" ", " ");
653 /* Regex re = new Regex ("\"((((?!\").)|\\\")*?)\"");
654 text = re.Replace (text,"<span style='color:purple'>\"$1\"</span>");
656 re = new Regex ("'(((.(?!\"\\<\\/span\\>))|\"(((?!\").)*)\"\\<\\/span\\>)*)(\r|\n|\r\n)");
657 text = re.Replace (text,"<span style='color:green'>//$1</span><br/>");
659 re = new Regex (keywords_vb);
660 text = re.Replace (text,"<span style='color:blue'>$1</span>");
662 text = text.Replace ("\t"," ");
663 text = text.Replace ("\n","<br/>");
668 // Helper methods and classes
671 string GetDataContext ()
673 return "op=" + CurrentOperationName + "&bnd=" + CurrentOperationBinding + "&";
676 string GetOptionSel (string v1, string v2)
678 string op = "<option ";
679 if (v1 == v2) op += "selected ";
680 return op + "value='" + v1 + "'>";
683 string WrapText (string text, int maxChars)
685 text = text.Replace(" />","/>");
687 string linspace = null;
691 bool inquotes = false;
693 string sublineIndent = "";
694 System.Text.StringBuilder sb = new System.Text.StringBuilder ();
695 for (int n=0; n<text.Length; n++)
699 if (c=='\r' || c=='\n' || n==text.Length-1)
701 sb.Append (linspace + sublineIndent + text.Substring (linstart, n-linstart+1));
711 if (lastc==',' || lastc=='(')
713 if (!inquotes) breakpos = n;
716 if (lincount > maxChars && breakpos >= linstart)
718 if (linspace != null)
719 sb.Append (linspace + sublineIndent);
720 sb.Append (text.Substring (linstart, breakpos-linstart));
723 lincount = linspace.Length + sublineIndent.Length + (n-breakpos);
727 if (c==' ' || c=='\t')
734 inquotes = !inquotes;
737 if (linspace == null) {
738 linspace = text.Substring (linstart, n-linstart);
745 return sb.ToString ();
754 public string Name { get { return name; } set { name = value; } }
755 public string Type { get { return type; } set { type = value; } }
756 public string Description { get { return description; } set { description = value; } }
759 public class HtmlSampleGenerator: SampleGenerator
761 public HtmlSampleGenerator (ServiceDescriptionCollection services, XmlSchemas schemas)
762 : base (services, schemas)
766 protected override string GetLiteral (string s)
768 return "@placeholder!" + s + "!placeholder@";
773 public class SampleGenerator
775 protected ServiceDescriptionCollection descriptions;
776 protected XmlSchemas schemas;
777 XmlSchemaElement anyElement;
779 SoapBindingUse currentUse;
780 XmlDocument document = new XmlDocument ();
782 static readonly XmlQualifiedName anyType = new XmlQualifiedName ("anyType",XmlSchema.Namespace);
783 static readonly XmlQualifiedName arrayType = new XmlQualifiedName ("Array","http://schemas.xmlsoap.org/soap/encoding/");
784 static readonly XmlQualifiedName arrayTypeRefName = new XmlQualifiedName ("arrayType","http://schemas.xmlsoap.org/soap/encoding/");
785 const string SoapEnvelopeNamespace = "http://schemas.xmlsoap.org/soap/envelope/";
786 const string WsdlNamespace = "http://schemas.xmlsoap.org/wsdl/";
787 const string SoapEncodingNamespace = "http://schemas.xmlsoap.org/soap/encoding/";
791 public EncodedType (string ns, XmlSchemaElement elem) { Namespace = ns; Element = elem; }
792 public string Namespace;
793 public XmlSchemaElement Element;
796 public SampleGenerator (ServiceDescriptionCollection services, XmlSchemas schemas)
798 descriptions = services;
799 this.schemas = schemas;
800 queue = new ArrayList ();
803 public string GenerateMessage (Port port, OperationBinding obin, Operation oper, string protocol, bool generateInput)
805 OperationMessage msg = null;
806 foreach (OperationMessage opm in oper.Messages)
808 if (opm is OperationInput && generateInput) msg = opm;
809 else if (opm is OperationOutput && !generateInput) msg = opm;
811 if (msg == null) return null;
814 case "Soap": return GenerateHttpSoapMessage (port, obin, oper, msg);
815 case "HttpGet": return GenerateHttpGetMessage (port, obin, oper, msg);
816 case "HttpPost": return GenerateHttpPostMessage (port, obin, oper, msg);
818 return "Unknown protocol";
821 public string GenerateHttpSoapMessage (Port port, OperationBinding obin, Operation oper, OperationMessage msg)
825 if (msg is OperationInput)
827 SoapAddressBinding sab = port.Extensions.Find (typeof(SoapAddressBinding)) as SoapAddressBinding;
828 SoapOperationBinding sob = obin.Extensions.Find (typeof(SoapOperationBinding)) as SoapOperationBinding;
829 req += "POST " + new Uri (sab.Location).AbsolutePath + "\n";
830 req += "SOAPAction: " + sob.SoapAction + "\n";
831 req += "Content-Type: text/xml; charset=utf-8\n";
832 req += "Content-Length: " + GetLiteral ("string") + "\n";
833 req += "Host: " + GetLiteral ("string") + "\n\n";
837 req += "HTTP/1.0 200 OK\n";
838 req += "Content-Type: text/xml; charset=utf-8\n";
839 req += "Content-Length: " + GetLiteral ("string") + "\n\n";
842 req += GenerateSoapMessage (obin, oper, msg);
846 public string GenerateHttpGetMessage (Port port, OperationBinding obin, Operation oper, OperationMessage msg)
850 if (msg is OperationInput)
852 HttpAddressBinding sab = port.Extensions.Find (typeof(HttpAddressBinding)) as HttpAddressBinding;
853 HttpOperationBinding sob = obin.Extensions.Find (typeof(HttpOperationBinding)) as HttpOperationBinding;
854 string location = new Uri (sab.Location).AbsolutePath + sob.Location + "?" + BuildQueryString (msg);
855 req += "GET " + location + "\n";
856 req += "Host: " + GetLiteral ("string");
860 req += "HTTP/1.0 200 OK\n";
861 req += "Content-Type: text/xml; charset=utf-8\n";
862 req += "Content-Length: " + GetLiteral ("string") + "\n\n";
864 MimeXmlBinding mxb = (MimeXmlBinding) obin.Output.Extensions.Find (typeof(MimeXmlBinding)) as MimeXmlBinding;
865 if (mxb == null) return req;
867 Message message = descriptions.GetMessage (msg.Message);
868 XmlQualifiedName ename = null;
869 foreach (MessagePart part in message.Parts)
870 if (part.Name == mxb.Part) ename = part.Element;
872 if (ename == null) return req + GetLiteral("string");
874 StringWriter sw = new StringWriter ();
875 XmlTextWriter xtw = new XmlTextWriter (sw);
876 xtw.Formatting = Formatting.Indented;
877 currentUse = SoapBindingUse.Literal;
878 WriteRootElementSample (xtw, ename);
880 req += sw.ToString ();
886 public string GenerateHttpPostMessage (Port port, OperationBinding obin, Operation oper, OperationMessage msg)
890 if (msg is OperationInput)
892 HttpAddressBinding sab = port.Extensions.Find (typeof(HttpAddressBinding)) as HttpAddressBinding;
893 HttpOperationBinding sob = obin.Extensions.Find (typeof(HttpOperationBinding)) as HttpOperationBinding;
894 string location = new Uri (sab.Location).AbsolutePath + sob.Location;
895 req += "POST " + location + "\n";
896 req += "Content-Type: application/x-www-form-urlencoded\n";
897 req += "Content-Length: " + GetLiteral ("string") + "\n";
898 req += "Host: " + GetLiteral ("string") + "\n\n";
899 req += BuildQueryString (msg);
901 else return GenerateHttpGetMessage (port, obin, oper, msg);
906 string BuildQueryString (OperationMessage opm)
909 Message msg = descriptions.GetMessage (opm.Message);
910 foreach (MessagePart part in msg.Parts)
912 if (s.Length != 0) s += "&";
913 s += part.Name + "=" + GetLiteral (part.Type.Name);
918 public string GenerateSoapMessage (OperationBinding obin, Operation oper, OperationMessage msg)
920 SoapOperationBinding sob = obin.Extensions.Find (typeof(SoapOperationBinding)) as SoapOperationBinding;
921 SoapBindingStyle style = (sob != null) ? sob.Style : SoapBindingStyle.Document;
923 MessageBinding msgbin = (msg is OperationInput) ? (MessageBinding) obin.Input : (MessageBinding)obin.Output;
924 SoapBodyBinding sbb = msgbin.Extensions.Find (typeof(SoapBodyBinding)) as SoapBodyBinding;
925 SoapBindingUse bodyUse = (sbb != null) ? sbb.Use : SoapBindingUse.Literal;
927 StringWriter sw = new StringWriter ();
928 XmlTextWriter xtw = new XmlTextWriter (sw);
929 xtw.Formatting = Formatting.Indented;
931 xtw.WriteStartDocument ();
932 xtw.WriteStartElement ("soap", "Envelope", SoapEnvelopeNamespace);
933 xtw.WriteAttributeString ("xmlns", "xsi", null, XmlSchema.InstanceNamespace);
934 xtw.WriteAttributeString ("xmlns", "xsd", null, XmlSchema.Namespace);
936 if (bodyUse == SoapBindingUse.Encoded)
938 xtw.WriteAttributeString ("xmlns", "soapenc", null, SoapEncodingNamespace);
939 xtw.WriteAttributeString ("xmlns", "tns", null, msg.Message.Namespace);
943 foreach (object ob in msgbin.Extensions)
945 SoapHeaderBinding hb = ob as SoapHeaderBinding;
946 if (hb == null) continue;
948 xtw.WriteStartElement ("soap", "Header", SoapEnvelopeNamespace);
949 WriteHeader (xtw, hb);
950 xtw.WriteEndElement ();
954 xtw.WriteStartElement ("soap", "Body", SoapEnvelopeNamespace);
956 currentUse = bodyUse;
957 WriteBody (xtw, oper, msg, sbb, style);
959 xtw.WriteEndElement ();
960 xtw.WriteEndElement ();
962 return sw.ToString ();
965 void WriteHeader (XmlTextWriter xtw, SoapHeaderBinding header)
967 Message msg = descriptions.GetMessage (header.Message);
968 if (msg == null) throw new InvalidOperationException ("Message " + header.Message + " not found");
969 MessagePart part = msg.Parts [header.Part];
970 if (part == null) throw new InvalidOperationException ("Message part " + header.Part + " not found in message " + header.Message);
972 currentUse = header.Use;
974 if (currentUse == SoapBindingUse.Literal)
975 WriteRootElementSample (xtw, part.Element);
977 WriteTypeSample (xtw, part.Type);
980 void WriteBody (XmlTextWriter xtw, Operation oper, OperationMessage opm, SoapBodyBinding sbb, SoapBindingStyle style)
982 Message msg = descriptions.GetMessage (opm.Message);
983 if (msg.Parts.Count > 0 && msg.Parts[0].Name == "parameters")
985 MessagePart part = msg.Parts[0];
986 if (part.Element == XmlQualifiedName.Empty)
987 WriteTypeSample (xtw, part.Type);
989 WriteRootElementSample (xtw, part.Element);
993 string elemName = oper.Name;
995 if (opm is OperationOutput) elemName += "Response";
997 if (style == SoapBindingStyle.Rpc) {
998 xtw.WriteStartElement (elemName, sbb.Namespace);
1002 foreach (MessagePart part in msg.Parts)
1004 if (part.Element == XmlQualifiedName.Empty)
1006 XmlSchemaElement elem = new XmlSchemaElement ();
1007 elem.SchemaTypeName = part.Type;
1008 elem.Name = part.Name;
1009 WriteElementSample (xtw, ns, elem);
1012 WriteRootElementSample (xtw, part.Element);
1015 if (style == SoapBindingStyle.Rpc)
1016 xtw.WriteEndElement ();
1018 WriteQueuedTypeSamples (xtw);
1021 void WriteRootElementSample (XmlTextWriter xtw, XmlQualifiedName qname)
1023 XmlSchemaElement elem = (XmlSchemaElement) schemas.Find (qname, typeof(XmlSchemaElement));
1024 if (elem == null) throw new InvalidOperationException ("Element not found: " + qname);
1025 WriteElementSample (xtw, qname.Namespace, elem);
1028 void WriteElementSample (XmlTextWriter xtw, string ns, XmlSchemaElement elem)
1030 bool sharedAnnType = false;
1031 XmlQualifiedName root;
1033 if (!elem.RefName.IsEmpty) {
1034 XmlSchemaElement refElem = FindRefElement (elem);
1035 if (refElem == null) throw new InvalidOperationException ("Global element not found: " + elem.RefName);
1036 root = elem.RefName;
1038 sharedAnnType = true;
1041 root = new XmlQualifiedName (elem.Name, ns);
1043 if (!elem.SchemaTypeName.IsEmpty)
1045 XmlSchemaComplexType st = FindComplexTyype (elem.SchemaTypeName);
1047 WriteComplexTypeSample (xtw, st, root);
1050 xtw.WriteStartElement (root.Name, root.Namespace);
1051 if (currentUse == SoapBindingUse.Encoded)
1052 xtw.WriteAttributeString ("type", XmlSchema.InstanceNamespace, GetQualifiedNameString (xtw, elem.SchemaTypeName));
1053 xtw.WriteString (GetLiteral (FindBuiltInType (elem.SchemaTypeName)));
1054 xtw.WriteEndElement ();
1057 else if (elem.SchemaType == null)
1059 xtw.WriteStartElement ("any");
1060 xtw.WriteEndElement ();
1063 WriteComplexTypeSample (xtw, (XmlSchemaComplexType) elem.SchemaType, root);
1066 void WriteTypeSample (XmlTextWriter xtw, XmlQualifiedName qname)
1068 XmlSchemaComplexType ctype = FindComplexTyype (qname);
1069 if (ctype != null) {
1070 WriteComplexTypeSample (xtw, ctype, qname);
1074 XmlSchemaSimpleType stype = (XmlSchemaSimpleType) schemas.Find (qname, typeof(XmlSchemaSimpleType));
1075 if (stype != null) {
1076 WriteSimpleTypeSample (xtw, stype);
1080 xtw.WriteString (GetLiteral (FindBuiltInType (qname)));
1081 throw new InvalidOperationException ("Type not found: " + qname);
1084 void WriteComplexTypeSample (XmlTextWriter xtw, XmlSchemaComplexType stype, XmlQualifiedName rootName)
1086 WriteComplexTypeSample (xtw, stype, rootName, -1);
1089 void WriteComplexTypeSample (XmlTextWriter xtw, XmlSchemaComplexType stype, XmlQualifiedName rootName, int id)
1091 string ns = rootName.Namespace;
1093 if (rootName.Name.IndexOf ("[]") != -1) rootName = arrayType;
1095 if (currentUse == SoapBindingUse.Encoded) {
1096 string pref = xtw.LookupPrefix (rootName.Namespace);
1097 if (pref == null) pref = "q1";
1098 xtw.WriteStartElement (pref, rootName.Name, rootName.Namespace);
1102 xtw.WriteStartElement (rootName.Name, rootName.Namespace);
1106 xtw.WriteAttributeString ("id", "id" + id);
1107 if (rootName != arrayType)
1108 xtw.WriteAttributeString ("type", XmlSchema.InstanceNamespace, GetQualifiedNameString (xtw, rootName));
1111 WriteComplexTypeAttributes (xtw, stype);
1112 WriteComplexTypeElements (xtw, ns, stype);
1114 xtw.WriteEndElement ();
1117 void WriteComplexTypeAttributes (XmlTextWriter xtw, XmlSchemaComplexType stype)
1119 WriteAttributes (xtw, stype.Attributes, stype.AnyAttribute);
1122 void WriteComplexTypeElements (XmlTextWriter xtw, string ns, XmlSchemaComplexType stype)
1124 if (stype.Particle != null)
1125 WriteParticleComplexContent (xtw, ns, stype.Particle);
1128 if (stype.ContentModel is XmlSchemaSimpleContent)
1129 WriteSimpleContent (xtw, (XmlSchemaSimpleContent)stype.ContentModel);
1130 else if (stype.ContentModel is XmlSchemaComplexContent)
1131 WriteComplexContent (xtw, ns, (XmlSchemaComplexContent)stype.ContentModel);
1135 void WriteAttributes (XmlTextWriter xtw, XmlSchemaObjectCollection atts, XmlSchemaAnyAttribute anyat)
1137 foreach (XmlSchemaObject at in atts)
1139 if (at is XmlSchemaAttribute)
1142 XmlSchemaAttribute attr = (XmlSchemaAttribute)at;
1143 XmlSchemaAttribute refAttr = attr;
1145 // refAttr.Form; TODO
1147 if (!attr.RefName.IsEmpty) {
1148 refAttr = FindRefAttribute (attr.RefName);
1149 if (refAttr == null) throw new InvalidOperationException ("Global attribute not found: " + attr.RefName);
1153 if (!refAttr.SchemaTypeName.IsEmpty) val = FindBuiltInType (refAttr.SchemaTypeName);
1154 else val = FindBuiltInType ((XmlSchemaSimpleType) refAttr.SchemaType);
1156 xtw.WriteAttributeString (refAttr.Name, val);
1158 else if (at is XmlSchemaAttributeGroupRef)
1160 XmlSchemaAttributeGroupRef gref = (XmlSchemaAttributeGroupRef)at;
1161 XmlSchemaAttributeGroup grp = (XmlSchemaAttributeGroup) schemas.Find (gref.RefName, typeof(XmlSchemaAttributeGroup));
1162 WriteAttributes (xtw, grp.Attributes, grp.AnyAttribute);
1167 xtw.WriteAttributeString ("custom-attribute","value");
1170 void WriteParticleComplexContent (XmlTextWriter xtw, string ns, XmlSchemaParticle particle)
1172 WriteParticleContent (xtw, ns, particle, false);
1175 void WriteParticleContent (XmlTextWriter xtw, string ns, XmlSchemaParticle particle, bool multiValue)
1177 if (particle is XmlSchemaGroupRef)
1178 particle = GetRefGroupParticle ((XmlSchemaGroupRef)particle);
1180 if (particle.MaxOccurs > 1) multiValue = true;
1182 if (particle is XmlSchemaSequence) {
1183 WriteSequenceContent (xtw, ns, ((XmlSchemaSequence)particle).Items, multiValue);
1185 else if (particle is XmlSchemaChoice) {
1186 if (((XmlSchemaChoice)particle).Items.Count == 1)
1187 WriteSequenceContent (xtw, ns, ((XmlSchemaChoice)particle).Items, multiValue);
1189 WriteChoiceContent (xtw, ns, (XmlSchemaChoice)particle, multiValue);
1191 else if (particle is XmlSchemaAll) {
1192 WriteSequenceContent (xtw, ns, ((XmlSchemaAll)particle).Items, multiValue);
1196 void WriteSequenceContent (XmlTextWriter xtw, string ns, XmlSchemaObjectCollection items, bool multiValue)
1198 foreach (XmlSchemaObject item in items)
1199 WriteContentItem (xtw, ns, item, multiValue);
1202 void WriteContentItem (XmlTextWriter xtw, string ns, XmlSchemaObject item, bool multiValue)
1204 if (item is XmlSchemaGroupRef)
1205 item = GetRefGroupParticle ((XmlSchemaGroupRef)item);
1207 if (item is XmlSchemaElement)
1209 XmlSchemaElement elem = (XmlSchemaElement) item;
1210 XmlSchemaElement refElem;
1211 if (!elem.RefName.IsEmpty) refElem = FindRefElement (elem);
1212 else refElem = elem;
1214 int num = (elem.MaxOccurs == 1 && !multiValue) ? 1 : 2;
1215 for (int n=0; n<num; n++)
1217 if (currentUse == SoapBindingUse.Literal)
1218 WriteElementSample (xtw, ns, refElem);
1220 WriteRefTypeSample (xtw, ns, refElem);
1223 else if (item is XmlSchemaAny)
1225 xtw.WriteString (GetLiteral ("xml"));
1227 else if (item is XmlSchemaParticle) {
1228 WriteParticleContent (xtw, ns, (XmlSchemaParticle)item, multiValue);
1232 void WriteChoiceContent (XmlTextWriter xtw, string ns, XmlSchemaChoice choice, bool multiValue)
1234 foreach (XmlSchemaObject item in choice.Items)
1235 WriteContentItem (xtw, ns, item, multiValue);
1238 void WriteSimpleContent (XmlTextWriter xtw, XmlSchemaSimpleContent content)
1240 XmlSchemaSimpleContentExtension ext = content.Content as XmlSchemaSimpleContentExtension;
1242 WriteAttributes (xtw, ext.Attributes, ext.AnyAttribute);
1244 XmlQualifiedName qname = GetContentBaseType (content.Content);
1245 xtw.WriteString (GetLiteral (FindBuiltInType (qname)));
1248 string FindBuiltInType (XmlQualifiedName qname)
1250 if (qname.Namespace == XmlSchema.Namespace)
1253 XmlSchemaComplexType ct = FindComplexTyype (qname);
1256 XmlSchemaSimpleContent sc = ct.ContentModel as XmlSchemaSimpleContent;
1257 if (sc == null) throw new InvalidOperationException ("Invalid schema");
1258 return FindBuiltInType (GetContentBaseType (sc.Content));
1261 XmlSchemaSimpleType st = (XmlSchemaSimpleType) schemas.Find (qname, typeof(XmlSchemaSimpleType));
1263 return FindBuiltInType (st);
1265 throw new InvalidOperationException ("Definition of type " + qname + " not found");
1268 string FindBuiltInType (XmlSchemaSimpleType st)
1270 if (st.Content is XmlSchemaSimpleTypeRestriction) {
1271 return FindBuiltInType (GetContentBaseType (st.Content));
1273 else if (st.Content is XmlSchemaSimpleTypeList) {
1274 string s = FindBuiltInType (GetContentBaseType (st.Content));
1275 return s + " " + s + " ...";
1277 else if (st.Content is XmlSchemaSimpleTypeUnion)
1279 //Check if all types of the union are equal. If not, then will use anyType.
1280 XmlSchemaSimpleTypeUnion uni = (XmlSchemaSimpleTypeUnion) st.Content;
1281 string utype = null;
1283 // Anonymous types are unique
1284 if (uni.BaseTypes.Count != 0 && uni.MemberTypes.Length != 0)
1287 foreach (XmlQualifiedName mt in uni.MemberTypes)
1289 string qn = FindBuiltInType (mt);
1290 if (utype != null && qn != utype) return "string";
1300 XmlQualifiedName GetContentBaseType (XmlSchemaObject ob)
1302 if (ob is XmlSchemaSimpleContentExtension)
1303 return ((XmlSchemaSimpleContentExtension)ob).BaseTypeName;
1304 else if (ob is XmlSchemaSimpleContentRestriction)
1305 return ((XmlSchemaSimpleContentRestriction)ob).BaseTypeName;
1306 else if (ob is XmlSchemaSimpleTypeRestriction)
1307 return ((XmlSchemaSimpleTypeRestriction)ob).BaseTypeName;
1308 else if (ob is XmlSchemaSimpleTypeList)
1309 return ((XmlSchemaSimpleTypeList)ob).ItemTypeName;
1314 void WriteComplexContent (XmlTextWriter xtw, string ns, XmlSchemaComplexContent content)
1316 XmlQualifiedName qname;
1318 XmlSchemaComplexContentExtension ext = content.Content as XmlSchemaComplexContentExtension;
1319 if (ext != null) qname = ext.BaseTypeName;
1321 XmlSchemaComplexContentRestriction rest = (XmlSchemaComplexContentRestriction)content.Content;
1322 qname = rest.BaseTypeName;
1323 if (qname == arrayType) {
1324 ParseArrayType (rest, out qname);
1325 XmlSchemaElement elem = new XmlSchemaElement ();
1327 elem.SchemaTypeName = qname;
1329 xtw.WriteAttributeString ("arrayType", SoapEncodingNamespace, qname.Name + "[2]");
1330 WriteContentItem (xtw, ns, elem, true);
1335 // Add base map members to this map
1336 XmlSchemaComplexType ctype = FindComplexTyype (qname);
1337 WriteComplexTypeAttributes (xtw, ctype);
1340 // Add the members of this map
1341 WriteAttributes (xtw, ext.Attributes, ext.AnyAttribute);
1342 if (ext.Particle != null)
1343 WriteParticleComplexContent (xtw, ns, ext.Particle);
1346 WriteComplexTypeElements (xtw, ns, ctype);
1349 void ParseArrayType (XmlSchemaComplexContentRestriction rest, out XmlQualifiedName qtype)
1351 XmlSchemaAttribute arrayTypeAt = FindArrayAttribute (rest.Attributes);
1352 XmlAttribute[] uatts = arrayTypeAt.UnhandledAttributes;
1353 if (uatts == null || uatts.Length == 0) throw new InvalidOperationException ("arrayType attribute not specified in array declaration");
1355 XmlAttribute xat = null;
1356 foreach (XmlAttribute at in uatts)
1357 if (at.LocalName == "arrayType" && at.NamespaceURI == WsdlNamespace)
1358 { xat = at; break; }
1361 throw new InvalidOperationException ("arrayType attribute not specified in array declaration");
1363 string arrayType = xat.Value;
1365 int i = arrayType.LastIndexOf (":");
1366 if (i == -1) ns = "";
1367 else ns = arrayType.Substring (0,i);
1369 int j = arrayType.IndexOf ("[", i+1);
1370 if (j == -1) throw new InvalidOperationException ("Cannot parse WSDL array type: " + arrayType);
1371 type = arrayType.Substring (i+1);
1372 type = type.Substring (0, type.Length-2);
1374 qtype = new XmlQualifiedName (type, ns);
1377 XmlSchemaAttribute FindArrayAttribute (XmlSchemaObjectCollection atts)
1379 foreach (object ob in atts)
1381 XmlSchemaAttribute att = ob as XmlSchemaAttribute;
1382 if (att != null && att.RefName == arrayTypeRefName) return att;
1384 XmlSchemaAttributeGroupRef gref = ob as XmlSchemaAttributeGroupRef;
1387 XmlSchemaAttributeGroup grp = (XmlSchemaAttributeGroup) schemas.Find (gref.RefName, typeof(XmlSchemaAttributeGroup));
1388 att = FindArrayAttribute (grp.Attributes);
1389 if (att != null) return att;
1395 void WriteSimpleTypeSample (XmlTextWriter xtw, XmlSchemaSimpleType stype)
1397 xtw.WriteString (GetLiteral (FindBuiltInType (stype)));
1400 XmlSchemaParticle GetRefGroupParticle (XmlSchemaGroupRef refGroup)
1402 XmlSchemaGroup grp = (XmlSchemaGroup) schemas.Find (refGroup.RefName, typeof (XmlSchemaGroup));
1403 return grp.Particle;
1406 XmlSchemaElement FindRefElement (XmlSchemaElement elem)
1408 if (elem.RefName.Namespace == XmlSchema.Namespace)
1410 if (anyElement != null) return anyElement;
1411 anyElement = new XmlSchemaElement ();
1412 anyElement.Name = "any";
1413 anyElement.SchemaTypeName = anyType;
1416 return (XmlSchemaElement) schemas.Find (elem.RefName, typeof(XmlSchemaElement));
1419 XmlSchemaAttribute FindRefAttribute (XmlQualifiedName refName)
1421 if (refName.Namespace == XmlSchema.Namespace)
1423 XmlSchemaAttribute at = new XmlSchemaAttribute ();
1424 at.Name = refName.Name;
1425 at.SchemaTypeName = new XmlQualifiedName ("string",XmlSchema.Namespace);
1428 return (XmlSchemaAttribute) schemas.Find (refName, typeof(XmlSchemaAttribute));
1431 void WriteRefTypeSample (XmlTextWriter xtw, string ns, XmlSchemaElement elem)
1433 if (elem.SchemaTypeName.Namespace == XmlSchema.Namespace || schemas.Find (elem.SchemaTypeName, typeof(XmlSchemaSimpleType)) != null)
1434 WriteElementSample (xtw, ns, elem);
1437 xtw.WriteStartElement (elem.Name, ns);
1438 xtw.WriteAttributeString ("href", "#id" + (queue.Count+1));
1439 xtw.WriteEndElement ();
1440 queue.Add (new EncodedType (ns, elem));
1444 void WriteQueuedTypeSamples (XmlTextWriter xtw)
1446 for (int n=0; n<queue.Count; n++)
1448 EncodedType ec = (EncodedType) queue[n];
1449 XmlSchemaComplexType st = FindComplexTyype (ec.Element.SchemaTypeName);
1450 WriteComplexTypeSample (xtw, st, ec.Element.SchemaTypeName, n+1);
1454 XmlSchemaComplexType FindComplexTyype (XmlQualifiedName qname)
1456 if (qname.Name.IndexOf ("[]") != -1)
1458 XmlSchemaComplexType stype = new XmlSchemaComplexType ();
1459 stype.ContentModel = new XmlSchemaComplexContent ();
1461 XmlSchemaComplexContentRestriction res = new XmlSchemaComplexContentRestriction ();
1462 stype.ContentModel.Content = res;
1463 res.BaseTypeName = arrayType;
1465 XmlSchemaAttribute att = new XmlSchemaAttribute ();
1466 att.RefName = arrayTypeRefName;
1467 res.Attributes.Add (att);
1469 XmlAttribute xat = document.CreateAttribute ("arrayType", WsdlNamespace);
1470 xat.Value = qname.Namespace + ":" + qname.Name;
1471 att.UnhandledAttributes = new XmlAttribute[] {xat};
1475 return (XmlSchemaComplexType) schemas.Find (qname, typeof(XmlSchemaComplexType));
1478 string GetQualifiedNameString (XmlTextWriter xtw, XmlQualifiedName qname)
1480 string pref = xtw.LookupPrefix (qname.Namespace);
1481 if (pref != null) return pref + ":" + qname.Name;
1483 xtw.WriteAttributeString ("xmlns", "q1", null, qname.Namespace);
1484 return "q1:" + qname.Name;
1487 protected virtual string GetLiteral (string s)
1492 void GetOperationFormat (OperationBinding obin, out SoapBindingStyle style, out SoapBindingUse use)
1494 style = SoapBindingStyle.Document;
1495 use = SoapBindingUse.Literal;
1496 SoapOperationBinding sob = obin.Extensions.Find (typeof(SoapOperationBinding)) as SoapOperationBinding;
1499 SoapBodyBinding sbb = obin.Input.Extensions.Find (typeof(SoapBodyBinding)) as SoapBodyBinding;
1513 <link rel="alternate" type="text/xml" href="<%=Request.FilePath%>?disco"/>
1515 <title><%=WebServiceName%> Web Service</title>
1516 <style type="text/css">
1517 BODY { font-family: Arial; margin-left: 20px; margin-top: 20px; font-size: x-small}
1518 TABLE { font-size: x-small }
1519 .title { color:dimgray; font-family: Arial; font-size:20pt; font-weight:900}
1520 .operationTitle { color:dimgray; font-family: Arial; font-size:15pt; font-weight:900}
1521 .method { font-size: x-small }
1522 .bindingLabel { font-size: x-small; font-weight:bold; color:darkgray; line-height:8pt; display:block; margin-bottom:3px }
1523 .label { font-size: small; font-weight:bold; color:darkgray }
1524 .paramTable { font-size: x-small }
1525 .paramTable TR { background-color: gainsboro }
1526 .paramFormTable { font-size: x-small; padding: 10px; background-color: gainsboro }
1527 .paramFormTable TR { background-color: gainsboro }
1528 .paramInput { border: solid 1px gray }
1529 .button {border: solid 1px gray }
1530 .smallSeparator { height:3px; overflow:hidden }
1531 .panel { background-color:whitesmoke; border: solid 1px silver; border-top: solid 1px silver }
1532 .codePanel { background-color: white; font-size:x-small; padding:7px; border:solid 1px silver}
1533 .code-xml { font-size:10pt; font-family:courier }
1534 .code-cs { font-size:10pt; font-family:courier }
1535 .code-vb { font-size:10pt; font-family:courier }
1536 .tabLabelOn { font-weight:bold }
1537 .tabLabelOff {color: darkgray }
1538 .literal-placeholder {color: darkblue; font-weight:bold}
1539 A:link { color: black; }
1540 A:visited { color: black; }
1541 A:active { color: black; }
1542 A:hover { color: blue }
1546 function clearForm ()
1548 document.getElementById("testFormResult").style.display="none";
1555 <div class="title" style="margin-left:20px">
1556 <span class="label">Web Service</span><br>
1561 **********************************************************
1565 <table border="0" width="100%" cellpadding="15px" cellspacing="15px">
1566 <tr valign="top"><td width="150px" class="panel">
1567 <div style="width:150px"></div>
1568 <a class="method" href='<%=PageName%>'>Overview</a><br>
1569 <div class="smallSeparator"></div>
1570 <a class="method" href='<%=PageName + "?" + GetPageContext("wsdl")%>'>Service Description</a>
1571 <div class="smallSeparator"></div>
1572 <a class="method" href='<%=PageName + "?" + GetPageContext("proxy")%>'>Client proxy</a>
1574 <asp:repeater id="BindingsRepeater" runat=server>
1575 <itemtemplate name="itemtemplate">
1576 <span class="bindingLabel"><%#FormatBindingName(DataBinder.Eval(Container.DataItem, "Name").ToString())%></span>
1577 <asp:repeater id="OperationsRepeater" runat=server datasource='<%# ((Binding)Container.DataItem).Operations %>'>
1579 <a class="method" href="<%#PageName%>?<%#GetTabContext("op",null)%>op=<%#GetOpName(Container.DataItem)%>&bnd=<%#DataBinder.Eval(Container.DataItem, "Binding.Name")%>"><%#GetOpName(Container.DataItem)%></a>
1580 <div class="smallSeparator"></div>
1587 </td><td class="panel">
1589 <% if (CurrentPage == "main") {%>
1592 **********************************************************
1593 Web service overview
1596 <p class="label">Web Service Overview</p>
1597 <%#WebServiceDescription%>
1599 <%} if (DefaultBinding == null) {%>
1600 This service does not contain any public web method.
1601 <%} else if (CurrentPage == "op") {%>
1604 **********************************************************
1605 Operation description
1608 <span class="operationTitle"><%#CurrentOperationName%></span>
1613 <% if (CurrentTab == "main") { %>
1614 <span class="label">Input Parameters</span>
1615 <div class="smallSeparator"></div>
1616 <% if (InParams.Count == 0) { %>
1617 No input parameters<br>
1619 <table class="paramTable" cellspacing="1" cellpadding="5">
1620 <asp:repeater id="InputParamsRepeater" runat=server>
1623 <td width="150"><%#DataBinder.Eval(Container.DataItem, "Name")%></td>
1624 <td width="150"><%#DataBinder.Eval(Container.DataItem, "Type")%></td>
1632 <% if (OutParams.Count > 0) { %>
1633 <span class="label">Output Parameters</span>
1634 <div class="smallSeparator"></div>
1635 <table class="paramTable" cellspacing="1" cellpadding="5">
1636 <asp:repeater id="OutputParamsRepeater" runat=server>
1639 <td width="150"><%#DataBinder.Eval(Container.DataItem, "Name")%></td>
1640 <td width="150"><%#DataBinder.Eval(Container.DataItem, "Type")%></td>
1648 <span class="label">Remarks</span>
1649 <div class="smallSeparator"></div>
1650 <%#OperationDocumentation%>
1652 <span class="label">Technical information</span>
1653 <div class="smallSeparator"></div>
1654 Format: <%#CurrentOperationFormat%>
1655 <br>Supported protocols: <%#CurrentOperationProtocols%>
1659 **********************************************************
1660 Operation description - Test form
1663 <% if (CurrentTab == "test") {
1664 if (CurrentOperationSupportsTest) {%>
1665 Enter values for the parameters and click the 'Invoke' button to test this method:<br><br>
1666 <form action="<%#PageName%>" method="GET">
1667 <input type="hidden" name="page" value="<%#CurrentPage%>">
1668 <input type="hidden" name="tab" value="<%#CurrentTab%>">
1669 <input type="hidden" name="op" value="<%#CurrentOperationName%>">
1670 <input type="hidden" name="bnd" value="<%#CurrentOperationBinding%>">
1671 <input type="hidden" name="ext" value="testform">
1672 <table class="paramFormTable" cellspacing="0" cellpadding="3">
1673 <asp:repeater id="InputFormParamsRepeater" runat=server>
1676 <td><%#DataBinder.Eval(Container.DataItem, "Name")%>: </td>
1677 <td width="150"><input class="paramInput" type="text" size="20" name="<%#DataBinder.Eval(Container.DataItem, "Name")%>"></td>
1681 <tr><td></td><td><input class="button" type="submit" value="Invoke"> <input class="button" type="button" onclick="clearForm()" value="Clear"></td></tr>
1684 <div id="testFormResult" style="display:<%# (HasFormResult?"block":"none") %>">
1685 The web service returned the following result:<br/><br/>
1686 <div class="codePanel"><%#GetTestResult()%></div>
1689 The test form is not available for this operation because it has parameters with a complex structure.
1694 **********************************************************
1695 Operation description - Message Layout
1698 <% if (CurrentTab == "msg") { %>
1700 The following are sample SOAP requests and responses for each protocol supported by this method:
1703 <% if (IsOperationSupported ("Soap")) { %>
1704 <span class="label">Soap</span>
1706 <div class="codePanel"><div class="code-xml"><%#GenerateOperationMessages ("Soap", true)%></div></div>
1708 <div class="codePanel"><div class="code-xml"><%#GenerateOperationMessages ("Soap", false)%></div></div>
1711 <% if (IsOperationSupported ("HttpGet")) { %>
1712 <span class="label">HTTP Get</span>
1714 <div class="codePanel"><div class="code-xml"><%#GenerateOperationMessages ("HttpGet", true)%></div></div>
1716 <div class="codePanel"><div class="code-xml"><%#GenerateOperationMessages ("HttpGet", false)%></div></div>
1719 <% if (IsOperationSupported ("HttpPost")) { %>
1720 <span class="label">HTTP Post</span>
1722 <div class="codePanel"><div class="code-xml"><%#GenerateOperationMessages ("HttpPost", true)%></div></div>
1724 <div class="codePanel"><div class="code-xml"><%#GenerateOperationMessages ("HttpPost", false)%></div></div>
1729 <%} else if (CurrentPage == "proxy") {%>
1731 **********************************************************
1734 <form action="<%#PageName%>" name="langForm" method="GET">
1735 Select the language for which you want to generate a proxy
1736 <input type="hidden" name="page" value="<%#CurrentPage%>">
1737 <SELECT name="lang" onchange="langForm.submit()">
1738 <%#GetOptionSel("cs",CurrentLanguage)%>C#</option>
1739 <%#GetOptionSel("vb",CurrentLanguage)%>Visual Basic</option>
1744 <span class="label"><%#CurrentProxytName%></span>
1745 <a href="<%#PageName + "?code=" + CurrentLanguage%>">Download</a>
1747 <div class="codePanel">
1748 <div class="code-<%#CurrentLanguage%>"><%#GetProxyCode ()%></div>
1750 <%} else if (CurrentPage == "wsdl") {%>
1752 **********************************************************
1755 <% if (descriptions.Count > 1 || schemas.Count > 1) {%>
1756 The description of this web service is composed by several documents. Click on the document you want to see:
1760 for (int n=0; n<descriptions.Count; n++)
1761 Response.Write ("<li><a href='" + PageName + "?" + GetPageContext(null) + "doctype=wsdl&docind=" + n + "'>WSDL document " + descriptions[n].TargetNamespace + "</a></li>");
1762 for (int n=0; n<schemas.Count; n++)
1763 Response.Write ("<li><a href='" + PageName + "?" + GetPageContext(null) + "doctype=schema&docind=" + n + "'>Xml Schema " + schemas[n].TargetNamespace + "</a></li>");
1770 <span class="label"><%#CurrentDocumentName%></span>
1771 <a href="<%=PageName + "?" + CurrentDocType + "=" + CurrentDocInd %>">Download</a>
1773 <div class="codePanel">
1774 <div class="code-xml"><%#GenerateDocument ()%></div>
1779 <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
1781 <td withd="20px"></td>