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 string url = location + "/" + CurrentOperationName;
341 Uri uri = new Uri (url);
342 WebRequest req = WebRequest.Create (url + "?" + qs);
343 HttpCookieCollection cookies = Request.Cookies;
344 int last = cookies.Count;
346 CookieContainer container = new CookieContainer ();
347 for (int i = 0; i < last; i++) {
348 HttpCookie hcookie = cookies [i];
349 Cookie cookie = new Cookie (hcookie.Name, hcookie.Value, hcookie.Path, hcookie.Domain);
350 container.Add (uri, cookie);
352 ((HttpWebRequest) req).CookieContainer = container;
354 WebResponse resp = req.GetResponse();
355 StreamReader sr = new StreamReader (resp.GetResponseStream());
356 string s = sr.ReadToEnd ();
358 return "<div class='code-xml'>" + ColorizeXml(WrapText(s,CodeTextColumns)) + "</div>";
362 string res = "<b style='color:red'>" + ex.Message + "</b>";
363 WebException wex = ex as WebException;
366 WebResponse resp = wex.Response;
368 StreamReader sr = new StreamReader (resp.GetResponseStream());
369 string s = sr.ReadToEnd ();
371 res += "<div class='code-xml'>" + ColorizeXml(WrapText(s,CodeTextColumns)) + "</div>";
378 string GenerateOperationMessages (string protocol, bool generateInput)
380 if (!IsOperationSupported (protocol)) return "";
383 if (protocol != "Soap") port = FindPort (null, protocol);
384 else port = FindPort (CurrentOperationBinding, null);
386 Binding binding = descriptions.GetBinding (port.Binding);
387 OperationBinding obin = FindOperation (binding, CurrentOperationName);
388 PortType portType = descriptions.GetPortType (binding.Type);
389 Operation oper = FindOperation (portType, CurrentOperationName);
391 HtmlSampleGenerator sg = new HtmlSampleGenerator (descriptions, schemas);
392 string txt = sg.GenerateMessage (port, obin, oper, protocol, generateInput);
393 if (protocol == "Soap") txt = WrapText (txt,CodeTextColumns);
394 txt = ColorizeXml (txt);
395 txt = txt.Replace ("@placeholder!","<span class='literal-placeholder'>");
396 txt = txt.Replace ("!placeholder@","</span>");
400 bool IsOperationSupported (string protocol)
402 if (CurrentPage != "op" || CurrentTab != "msg") return false;
403 if (protocol == "Soap") return true;
405 Port port = FindPort (null, protocol);
406 if (port == null) return false;
407 Binding binding = descriptions.GetBinding (port.Binding);
408 if (binding == null) return false;
409 return FindOperation (binding, CurrentOperationName) != null;
413 // Proxy code generation
416 string GetProxyCode ()
418 CodeNamespace codeNamespace = new CodeNamespace();
419 CodeCompileUnit codeUnit = new CodeCompileUnit();
421 codeUnit.Namespaces.Add (codeNamespace);
423 ServiceDescriptionImporter importer = new ServiceDescriptionImporter();
425 foreach (ServiceDescription sd in descriptions)
426 importer.AddServiceDescription(sd, null, null);
428 foreach (XmlSchema sc in schemas)
429 importer.Schemas.Add (sc);
431 importer.Import(codeNamespace, codeUnit);
433 string langId = Request.QueryString ["lang"];
434 if (langId == null || langId == "") langId = "cs";
435 CodeDomProvider provider = GetProvider (langId);
436 ICodeGenerator generator = provider.CreateGenerator();
437 CodeGeneratorOptions options = new CodeGeneratorOptions();
439 StringWriter sw = new StringWriter ();
440 generator.GenerateCodeFromCompileUnit(codeUnit, sw, options);
442 return Colorize (WrapText (sw.ToString (), CodeTextColumns), langId);
445 public string CurrentLanguage
448 string langId = Request.QueryString ["lang"];
449 if (langId == null || langId == "") langId = "cs";
454 public string CurrentProxytName
457 string lan = CurrentLanguage == "cs" ? "C#" : "Visual Basic";
458 return lan + " Client Proxy";
462 private CodeDomProvider GetProvider(string langId)
464 switch (langId.ToUpper())
466 case "CS": return new CSharpCodeProvider();
467 case "VB": return new VBCodeProvider();
468 default: return null;
473 // Document generation
476 string GenerateDocument ()
478 StringWriter sw = new StringWriter ();
480 if (CurrentDocType == "wsdl")
481 descriptions [CurrentDocInd].Write (sw);
482 else if (CurrentDocType == "schema")
483 schemas [CurrentDocInd].Write (sw);
485 return Colorize (WrapText (sw.ToString (), CodeTextColumns), "xml");
488 public string CurrentDocType
490 get { return Request.QueryString ["doctype"] != null ? Request.QueryString ["doctype"] : "wsdl"; }
493 public int CurrentDocInd
495 get { return Request.QueryString ["docind"] != null ? int.Parse (Request.QueryString ["docind"]) : 0; }
498 public string CurrentDocumentName
501 if (CurrentDocType == "wsdl")
502 return "WSDL document for namespace \"" + descriptions [CurrentDocInd].TargetNamespace + "\"";
504 return "Xml Schema for namespace \"" + schemas [CurrentDocInd].TargetNamespace + "\"";
512 bool firstTab = true;
513 ArrayList disabledTabs = new ArrayList ();
517 get { return Request.QueryString["tab"] != null ? Request.QueryString["tab"] : "main" ; }
522 get { return Request.QueryString["page"] != null ? Request.QueryString["page"] : "main" ; }
527 if (CurrentOperationName != null)
529 WriteTab ("main","Overview");
530 WriteTab ("test","Test Form");
531 WriteTab ("msg","Message Layout");
535 void WriteTab (string id, string label)
537 if (!firstTab) Response.Write(" | ");
540 string cname = CurrentTab == id ? "tabLabelOn" : "tabLabelOff";
541 Response.Write ("<a href='" + PageName + "?" + GetPageContext(null) + GetDataContext() + "tab=" + id + "' style='text-decoration:none'>");
542 Response.Write ("<span class='" + cname + "'>" + label + "</span>");
543 Response.Write ("</a>");
546 string GetTabContext (string pag, string tab)
548 if (tab == null) tab = CurrentTab;
549 if (pag == null) pag = CurrentPage;
550 if (pag != CurrentPage) tab = "main";
551 return "page=" + pag + "&tab=" + tab + "&";
554 string GetPageContext (string pag)
556 if (pag == null) pag = CurrentPage;
557 return "page=" + pag + "&";
570 static string keywords_cs =
571 "(\\babstract\\b|\\bevent\\b|\\bnew\\b|\\bstruct\\b|\\bas\\b|\\bexplicit\\b|\\bnull\\b|\\bswitch\\b|\\bbase\\b|\\bextern\\b|" +
572 "\\bobject\\b|\\bthis\\b|\\bbool\\b|\\bfalse\\b|\\boperator\\b|\\bthrow\\b|\\bbreak\\b|\\bfinally\\b|\\bout\\b|\\btrue\\b|" +
573 "\\bbyte\\b|\\bfixed\\b|\\boverride\\b|\\btry\\b|\\bcase\\b|\\bfloat\\b|\\bparams\\b|\\btypeof\\b|\\bcatch\\b|\\bfor\\b|" +
574 "\\bprivate\\b|\\buint\\b|\\bchar\\b|\\bforeach\\b|\\bprotected\\b|\\bulong\\b|\\bchecked\\b|\\bgoto\\b|\\bpublic\\b|" +
575 "\\bunchecked\\b|\\bclass\\b|\\bif\\b|\\breadonly\\b|\\bunsafe\\b|\\bconst\\b|\\bimplicit\\b|\\bref\\b|\\bushort\\b|" +
576 "\\bcontinue\\b|\\bin\\b|\\breturn\\b|\\busing\\b|\\bdecimal\\b|\\bint\\b|\\bsbyte\\b|\\bvirtual\\b|\\bdefault\\b|" +
577 "\\binterface\\b|\\bsealed\\b|\\bvolatile\\b|\\bdelegate\\b|\\binternal\\b|\\bshort\\b|\\bvoid\\b|\\bdo\\b|\\bis\\b|" +
578 "\\bsizeof\\b|\\bwhile\\b|\\bdouble\\b|\\block\\b|\\bstackalloc\\b|\\belse\\b|\\blong\\b|\\bstatic\\b|\\benum\\b|" +
579 "\\bnamespace\\b|\\bstring\\b)";
581 static string keywords_vb =
582 "(\\bAddHandler\\b|\\bAddressOf\\b|\\bAlias\\b|\\bAnd\\b|\\bAndAlso\\b|\\bAnsi\\b|\\bAs\\b|\\bAssembly\\b|" +
583 "\\bAuto\\b|\\bBoolean\\b|\\bByRef\\b|\\bByte\\b|\\bByVal\\b|\\bCall\\b|\\bCase\\b|\\bCatch\\b|" +
584 "\\bCBool\\b|\\bCByte\\b|\\bCChar\\b|\\bCDate\\b|\\bCDec\\b|\\bCDbl\\b|\\bChar\\b|\\bCInt\\b|" +
585 "\\bClass\\b|\\bCLng\\b|\\bCObj\\b|\\bConst\\b|\\bCShort\\b|\\bCSng\\b|\\bCStr\\b|\\bCType\\b|" +
586 "\\bDate\\b|\\bDecimal\\b|\\bDeclare\\b|\\bDefault\\b|\\bDelegate\\b|\\bDim\\b|\\bDirectCast\\b|\\bDo\\b|" +
587 "\\bDouble\\b|\\bEach\\b|\\bElse\\b|\\bElseIf\\b|\\bEnd\\b|\\bEnum\\b|\\bErase\\b|\\bError\\b|" +
588 "\\bEvent\\b|\\bExit\\b|\\bFalse\\b|\\bFinally\\b|\\bFor\\b|\\bFriend\\b|\\bFunction\\b|\\bGet\\b|" +
589 "\\bGetType\\b|\\bGoSub\\b|\\bGoTo\\b|\\bHandles\\b|\\bIf\\b|\\bImplements\\b|\\bImports\\b|\\bIn\\b|" +
590 "\\bInherits\\b|\\bInteger\\b|\\bInterface\\b|\\bIs\\b|\\bLet\\b|\\bLib\\b|\\bLike\\b|\\bLong\\b|" +
591 "\\bLoop\\b|\\bMe\\b|\\bMod\\b|\\bModule\\b|\\bMustInherit\\b|\\bMustOverride\\b|\\bMyBase\\b|\\bMyClass\\b|" +
592 "\\bNamespace\\b|\\bNew\\b|\\bNext\\b|\\bNot\\b|\\bNothing\\b|\\bNotInheritable\\b|\\bNotOverridable\\b|\\bObject\\b|" +
593 "\\bOn\\b|\\bOption\\b|\\bOptional\\b|\\bOr\\b|\\bOrElse\\b|\\bOverloads\\b|\\bOverridable\\b|\\bOverrides\\b|" +
594 "\\bParamArray\\b|\\bPreserve\\b|\\bPrivate\\b|\\bProperty\\b|\\bProtected\\b|\\bPublic\\b|\\bRaiseEvent\\b|\\bReadOnly\\b|" +
595 "\\bReDim\\b|\\bREM\\b|\\bRemoveHandler\\b|\\bResume\\b|\\bReturn\\b|\\bSelect\\b|\\bSet\\b|\\bShadows\\b|" +
596 "\\bShared\\b|\\bShort\\b|\\bSingle\\b|\\bStatic\\b|\\bStep\\b|\\bStop\\b|\\bString\\b|\\bStructure\\b|" +
597 "\\bSub\\b|\\bSyncLock\\b|\\bThen\\b|\\bThrow\\b|\\bTo\\b|\\bTrue\\b|\\bTry\\b|\\bTypeOf\\b|" +
598 "\\bUnicode\\b|\\bUntil\\b|\\bVariant\\b|\\bWhen\\b|\\bWhile\\b|\\bWith\\b|\\bWithEvents\\b|\\bWriteOnly\\b|\\bXor\\b)";
600 string Colorize (string text, string lang)
602 if (lang == "xml") return ColorizeXml (text);
603 else if (lang == "cs") return ColorizeCs (text);
604 else if (lang == "vb") return ColorizeVb (text);
608 string ColorizeXml (string text)
610 text = text.Replace (" ", " ");
611 Regex re = new Regex ("\r\n|\r|\n");
612 text = re.Replace (text, "_br_");
614 re = new Regex ("<\\s*(\\/?)\\s*([\\s\\S]*?)\\s*(\\/?)\\s*>");
615 text = re.Replace (text,"{blue:<$1}{maroon:$2}{blue:$3>}");
617 re = new Regex ("\\{(\\w*):([\\s\\S]*?)\\}");
618 text = re.Replace (text,"<span style='color:$1'>$2</span>");
620 re = new Regex ("\"(.*?)\"");
621 text = re.Replace (text,"\"<span style='color:purple'>$1</span>\"");
624 text = text.Replace ("\t", " ");
625 text = text.Replace ("_br_", "<br>");
629 string ColorizeCs (string text)
631 text = text.Replace (" ", " ");
633 text = text.Replace ("<", "<");
634 text = text.Replace (">", ">");
636 Regex re = new Regex ("\"((((?!\").)|\\\")*?)\"");
637 text = re.Replace (text,"<span style='color:purple'>\"$1\"</span>");
639 re = new Regex ("//(((.(?!\"</span>))|\"(((?!\").)*)\"</span>)*)(\r|\n|\r\n)");
640 text = re.Replace (text,"<span style='color:green'>//$1</span><br/>");
642 re = new Regex (keywords_cs);
643 text = re.Replace (text,"<span style='color:blue'>$1</span>");
645 text = text.Replace ("\t"," ");
646 text = text.Replace ("\n","<br/>");
651 string ColorizeVb (string text)
653 text = text.Replace (" ", " ");
655 /* Regex re = new Regex ("\"((((?!\").)|\\\")*?)\"");
656 text = re.Replace (text,"<span style='color:purple'>\"$1\"</span>");
658 re = new Regex ("'(((.(?!\"\\<\\/span\\>))|\"(((?!\").)*)\"\\<\\/span\\>)*)(\r|\n|\r\n)");
659 text = re.Replace (text,"<span style='color:green'>//$1</span><br/>");
661 re = new Regex (keywords_vb);
662 text = re.Replace (text,"<span style='color:blue'>$1</span>");
664 text = text.Replace ("\t"," ");
665 text = text.Replace ("\n","<br/>");
670 // Helper methods and classes
673 string GetDataContext ()
675 return "op=" + CurrentOperationName + "&bnd=" + CurrentOperationBinding + "&";
678 string GetOptionSel (string v1, string v2)
680 string op = "<option ";
681 if (v1 == v2) op += "selected ";
682 return op + "value='" + v1 + "'>";
685 string WrapText (string text, int maxChars)
687 text = text.Replace(" />","/>");
689 string linspace = null;
693 bool inquotes = false;
695 string sublineIndent = "";
696 System.Text.StringBuilder sb = new System.Text.StringBuilder ();
697 for (int n=0; n<text.Length; n++)
701 if (c=='\r' || c=='\n' || n==text.Length-1)
703 sb.Append (linspace + sublineIndent + text.Substring (linstart, n-linstart+1));
713 if (lastc==',' || lastc=='(')
715 if (!inquotes) breakpos = n;
718 if (lincount > maxChars && breakpos >= linstart)
720 if (linspace != null)
721 sb.Append (linspace + sublineIndent);
722 sb.Append (text.Substring (linstart, breakpos-linstart));
725 lincount = linspace.Length + sublineIndent.Length + (n-breakpos);
729 if (c==' ' || c=='\t')
736 inquotes = !inquotes;
739 if (linspace == null) {
740 linspace = text.Substring (linstart, n-linstart);
747 return sb.ToString ();
756 public string Name { get { return name; } set { name = value; } }
757 public string Type { get { return type; } set { type = value; } }
758 public string Description { get { return description; } set { description = value; } }
761 public class HtmlSampleGenerator: SampleGenerator
763 public HtmlSampleGenerator (ServiceDescriptionCollection services, XmlSchemas schemas)
764 : base (services, schemas)
768 protected override string GetLiteral (string s)
770 return "@placeholder!" + s + "!placeholder@";
775 public class SampleGenerator
777 protected ServiceDescriptionCollection descriptions;
778 protected XmlSchemas schemas;
779 XmlSchemaElement anyElement;
781 SoapBindingUse currentUse;
782 XmlDocument document = new XmlDocument ();
784 static readonly XmlQualifiedName anyType = new XmlQualifiedName ("anyType",XmlSchema.Namespace);
785 static readonly XmlQualifiedName arrayType = new XmlQualifiedName ("Array","http://schemas.xmlsoap.org/soap/encoding/");
786 static readonly XmlQualifiedName arrayTypeRefName = new XmlQualifiedName ("arrayType","http://schemas.xmlsoap.org/soap/encoding/");
787 const string SoapEnvelopeNamespace = "http://schemas.xmlsoap.org/soap/envelope/";
788 const string WsdlNamespace = "http://schemas.xmlsoap.org/wsdl/";
789 const string SoapEncodingNamespace = "http://schemas.xmlsoap.org/soap/encoding/";
793 public EncodedType (string ns, XmlSchemaElement elem) { Namespace = ns; Element = elem; }
794 public string Namespace;
795 public XmlSchemaElement Element;
798 public SampleGenerator (ServiceDescriptionCollection services, XmlSchemas schemas)
800 descriptions = services;
801 this.schemas = schemas;
802 queue = new ArrayList ();
805 public string GenerateMessage (Port port, OperationBinding obin, Operation oper, string protocol, bool generateInput)
807 OperationMessage msg = null;
808 foreach (OperationMessage opm in oper.Messages)
810 if (opm is OperationInput && generateInput) msg = opm;
811 else if (opm is OperationOutput && !generateInput) msg = opm;
813 if (msg == null) return null;
816 case "Soap": return GenerateHttpSoapMessage (port, obin, oper, msg);
817 case "HttpGet": return GenerateHttpGetMessage (port, obin, oper, msg);
818 case "HttpPost": return GenerateHttpPostMessage (port, obin, oper, msg);
820 return "Unknown protocol";
823 public string GenerateHttpSoapMessage (Port port, OperationBinding obin, Operation oper, OperationMessage msg)
827 if (msg is OperationInput)
829 SoapAddressBinding sab = port.Extensions.Find (typeof(SoapAddressBinding)) as SoapAddressBinding;
830 SoapOperationBinding sob = obin.Extensions.Find (typeof(SoapOperationBinding)) as SoapOperationBinding;
831 req += "POST " + new Uri (sab.Location).AbsolutePath + "\n";
832 req += "SOAPAction: " + sob.SoapAction + "\n";
833 req += "Content-Type: text/xml; charset=utf-8\n";
834 req += "Content-Length: " + GetLiteral ("string") + "\n";
835 req += "Host: " + GetLiteral ("string") + "\n\n";
839 req += "HTTP/1.0 200 OK\n";
840 req += "Content-Type: text/xml; charset=utf-8\n";
841 req += "Content-Length: " + GetLiteral ("string") + "\n\n";
844 req += GenerateSoapMessage (obin, oper, msg);
848 public string GenerateHttpGetMessage (Port port, OperationBinding obin, Operation oper, OperationMessage msg)
852 if (msg is OperationInput)
854 HttpAddressBinding sab = port.Extensions.Find (typeof(HttpAddressBinding)) as HttpAddressBinding;
855 HttpOperationBinding sob = obin.Extensions.Find (typeof(HttpOperationBinding)) as HttpOperationBinding;
856 string location = new Uri (sab.Location).AbsolutePath + sob.Location + "?" + BuildQueryString (msg);
857 req += "GET " + location + "\n";
858 req += "Host: " + GetLiteral ("string");
862 req += "HTTP/1.0 200 OK\n";
863 req += "Content-Type: text/xml; charset=utf-8\n";
864 req += "Content-Length: " + GetLiteral ("string") + "\n\n";
866 MimeXmlBinding mxb = (MimeXmlBinding) obin.Output.Extensions.Find (typeof(MimeXmlBinding)) as MimeXmlBinding;
867 if (mxb == null) return req;
869 Message message = descriptions.GetMessage (msg.Message);
870 XmlQualifiedName ename = null;
871 foreach (MessagePart part in message.Parts)
872 if (part.Name == mxb.Part) ename = part.Element;
874 if (ename == null) return req + GetLiteral("string");
876 StringWriter sw = new StringWriter ();
877 XmlTextWriter xtw = new XmlTextWriter (sw);
878 xtw.Formatting = Formatting.Indented;
879 currentUse = SoapBindingUse.Literal;
880 WriteRootElementSample (xtw, ename);
882 req += sw.ToString ();
888 public string GenerateHttpPostMessage (Port port, OperationBinding obin, Operation oper, OperationMessage msg)
892 if (msg is OperationInput)
894 HttpAddressBinding sab = port.Extensions.Find (typeof(HttpAddressBinding)) as HttpAddressBinding;
895 HttpOperationBinding sob = obin.Extensions.Find (typeof(HttpOperationBinding)) as HttpOperationBinding;
896 string location = new Uri (sab.Location).AbsolutePath + sob.Location;
897 req += "POST " + location + "\n";
898 req += "Content-Type: application/x-www-form-urlencoded\n";
899 req += "Content-Length: " + GetLiteral ("string") + "\n";
900 req += "Host: " + GetLiteral ("string") + "\n\n";
901 req += BuildQueryString (msg);
903 else return GenerateHttpGetMessage (port, obin, oper, msg);
908 string BuildQueryString (OperationMessage opm)
911 Message msg = descriptions.GetMessage (opm.Message);
912 foreach (MessagePart part in msg.Parts)
914 if (s.Length != 0) s += "&";
915 s += part.Name + "=" + GetLiteral (part.Type.Name);
920 public string GenerateSoapMessage (OperationBinding obin, Operation oper, OperationMessage msg)
922 SoapOperationBinding sob = obin.Extensions.Find (typeof(SoapOperationBinding)) as SoapOperationBinding;
923 SoapBindingStyle style = (sob != null) ? sob.Style : SoapBindingStyle.Document;
925 MessageBinding msgbin = (msg is OperationInput) ? (MessageBinding) obin.Input : (MessageBinding)obin.Output;
926 SoapBodyBinding sbb = msgbin.Extensions.Find (typeof(SoapBodyBinding)) as SoapBodyBinding;
927 SoapBindingUse bodyUse = (sbb != null) ? sbb.Use : SoapBindingUse.Literal;
929 StringWriter sw = new StringWriter ();
930 XmlTextWriter xtw = new XmlTextWriter (sw);
931 xtw.Formatting = Formatting.Indented;
933 xtw.WriteStartDocument ();
934 xtw.WriteStartElement ("soap", "Envelope", SoapEnvelopeNamespace);
935 xtw.WriteAttributeString ("xmlns", "xsi", null, XmlSchema.InstanceNamespace);
936 xtw.WriteAttributeString ("xmlns", "xsd", null, XmlSchema.Namespace);
938 if (bodyUse == SoapBindingUse.Encoded)
940 xtw.WriteAttributeString ("xmlns", "soapenc", null, SoapEncodingNamespace);
941 xtw.WriteAttributeString ("xmlns", "tns", null, msg.Message.Namespace);
946 bool writtenHeader = false;
947 foreach (object ob in msgbin.Extensions)
949 SoapHeaderBinding hb = ob as SoapHeaderBinding;
950 if (hb == null) continue;
952 if (!writtenHeader) {
953 xtw.WriteStartElement ("soap", "Header", SoapEnvelopeNamespace);
954 writtenHeader = true;
957 WriteHeader (xtw, hb);
961 xtw.WriteEndElement ();
964 xtw.WriteStartElement ("soap", "Body", SoapEnvelopeNamespace);
966 currentUse = bodyUse;
967 WriteBody (xtw, oper, msg, sbb, style);
969 xtw.WriteEndElement ();
970 xtw.WriteEndElement ();
972 return sw.ToString ();
975 void WriteHeader (XmlTextWriter xtw, SoapHeaderBinding header)
977 Message msg = descriptions.GetMessage (header.Message);
978 if (msg == null) throw new InvalidOperationException ("Message " + header.Message + " not found");
979 MessagePart part = msg.Parts [header.Part];
980 if (part == null) throw new InvalidOperationException ("Message part " + header.Part + " not found in message " + header.Message);
982 currentUse = header.Use;
984 if (currentUse == SoapBindingUse.Literal)
985 WriteRootElementSample (xtw, part.Element);
987 WriteTypeSample (xtw, part.Type);
990 void WriteBody (XmlTextWriter xtw, Operation oper, OperationMessage opm, SoapBodyBinding sbb, SoapBindingStyle style)
992 Message msg = descriptions.GetMessage (opm.Message);
993 if (msg.Parts.Count > 0 && msg.Parts[0].Name == "parameters")
995 MessagePart part = msg.Parts[0];
996 if (part.Element == XmlQualifiedName.Empty)
997 WriteTypeSample (xtw, part.Type);
999 WriteRootElementSample (xtw, part.Element);
1003 string elemName = oper.Name;
1005 if (opm is OperationOutput) elemName += "Response";
1007 if (style == SoapBindingStyle.Rpc) {
1008 xtw.WriteStartElement (elemName, sbb.Namespace);
1012 foreach (MessagePart part in msg.Parts)
1014 if (part.Element == XmlQualifiedName.Empty)
1016 XmlSchemaElement elem = new XmlSchemaElement ();
1017 elem.SchemaTypeName = part.Type;
1018 elem.Name = part.Name;
1019 WriteElementSample (xtw, ns, elem);
1022 WriteRootElementSample (xtw, part.Element);
1025 if (style == SoapBindingStyle.Rpc)
1026 xtw.WriteEndElement ();
1028 WriteQueuedTypeSamples (xtw);
1031 void WriteRootElementSample (XmlTextWriter xtw, XmlQualifiedName qname)
1033 XmlSchemaElement elem = (XmlSchemaElement) schemas.Find (qname, typeof(XmlSchemaElement));
1034 if (elem == null) throw new InvalidOperationException ("Element not found: " + qname);
1035 WriteElementSample (xtw, qname.Namespace, elem);
1038 void WriteElementSample (XmlTextWriter xtw, string ns, XmlSchemaElement elem)
1040 bool sharedAnnType = false;
1041 XmlQualifiedName root;
1043 if (!elem.RefName.IsEmpty) {
1044 XmlSchemaElement refElem = FindRefElement (elem);
1045 if (refElem == null) throw new InvalidOperationException ("Global element not found: " + elem.RefName);
1046 root = elem.RefName;
1048 sharedAnnType = true;
1051 root = new XmlQualifiedName (elem.Name, ns);
1053 if (!elem.SchemaTypeName.IsEmpty)
1055 XmlSchemaComplexType st = FindComplexTyype (elem.SchemaTypeName);
1057 WriteComplexTypeSample (xtw, st, root);
1060 xtw.WriteStartElement (root.Name, root.Namespace);
1061 if (currentUse == SoapBindingUse.Encoded)
1062 xtw.WriteAttributeString ("type", XmlSchema.InstanceNamespace, GetQualifiedNameString (xtw, elem.SchemaTypeName));
1063 xtw.WriteString (GetLiteral (FindBuiltInType (elem.SchemaTypeName)));
1064 xtw.WriteEndElement ();
1067 else if (elem.SchemaType == null)
1069 xtw.WriteStartElement ("any");
1070 xtw.WriteEndElement ();
1073 WriteComplexTypeSample (xtw, (XmlSchemaComplexType) elem.SchemaType, root);
1076 void WriteTypeSample (XmlTextWriter xtw, XmlQualifiedName qname)
1078 XmlSchemaComplexType ctype = FindComplexTyype (qname);
1079 if (ctype != null) {
1080 WriteComplexTypeSample (xtw, ctype, qname);
1084 XmlSchemaSimpleType stype = (XmlSchemaSimpleType) schemas.Find (qname, typeof(XmlSchemaSimpleType));
1085 if (stype != null) {
1086 WriteSimpleTypeSample (xtw, stype);
1090 xtw.WriteString (GetLiteral (FindBuiltInType (qname)));
1091 throw new InvalidOperationException ("Type not found: " + qname);
1094 void WriteComplexTypeSample (XmlTextWriter xtw, XmlSchemaComplexType stype, XmlQualifiedName rootName)
1096 WriteComplexTypeSample (xtw, stype, rootName, -1);
1099 void WriteComplexTypeSample (XmlTextWriter xtw, XmlSchemaComplexType stype, XmlQualifiedName rootName, int id)
1101 string ns = rootName.Namespace;
1103 if (rootName.Name.IndexOf ("[]") != -1) rootName = arrayType;
1105 if (currentUse == SoapBindingUse.Encoded) {
1106 string pref = xtw.LookupPrefix (rootName.Namespace);
1107 if (pref == null) pref = "q1";
1108 xtw.WriteStartElement (pref, rootName.Name, rootName.Namespace);
1112 xtw.WriteStartElement (rootName.Name, rootName.Namespace);
1116 xtw.WriteAttributeString ("id", "id" + id);
1117 if (rootName != arrayType)
1118 xtw.WriteAttributeString ("type", XmlSchema.InstanceNamespace, GetQualifiedNameString (xtw, rootName));
1121 WriteComplexTypeAttributes (xtw, stype);
1122 WriteComplexTypeElements (xtw, ns, stype);
1124 xtw.WriteEndElement ();
1127 void WriteComplexTypeAttributes (XmlTextWriter xtw, XmlSchemaComplexType stype)
1129 WriteAttributes (xtw, stype.Attributes, stype.AnyAttribute);
1132 void WriteComplexTypeElements (XmlTextWriter xtw, string ns, XmlSchemaComplexType stype)
1134 if (stype.Particle != null)
1135 WriteParticleComplexContent (xtw, ns, stype.Particle);
1138 if (stype.ContentModel is XmlSchemaSimpleContent)
1139 WriteSimpleContent (xtw, (XmlSchemaSimpleContent)stype.ContentModel);
1140 else if (stype.ContentModel is XmlSchemaComplexContent)
1141 WriteComplexContent (xtw, ns, (XmlSchemaComplexContent)stype.ContentModel);
1145 void WriteAttributes (XmlTextWriter xtw, XmlSchemaObjectCollection atts, XmlSchemaAnyAttribute anyat)
1147 foreach (XmlSchemaObject at in atts)
1149 if (at is XmlSchemaAttribute)
1152 XmlSchemaAttribute attr = (XmlSchemaAttribute)at;
1153 XmlSchemaAttribute refAttr = attr;
1155 // refAttr.Form; TODO
1157 if (!attr.RefName.IsEmpty) {
1158 refAttr = FindRefAttribute (attr.RefName);
1159 if (refAttr == null) throw new InvalidOperationException ("Global attribute not found: " + attr.RefName);
1163 if (!refAttr.SchemaTypeName.IsEmpty) val = FindBuiltInType (refAttr.SchemaTypeName);
1164 else val = FindBuiltInType ((XmlSchemaSimpleType) refAttr.SchemaType);
1166 xtw.WriteAttributeString (refAttr.Name, val);
1168 else if (at is XmlSchemaAttributeGroupRef)
1170 XmlSchemaAttributeGroupRef gref = (XmlSchemaAttributeGroupRef)at;
1171 XmlSchemaAttributeGroup grp = (XmlSchemaAttributeGroup) schemas.Find (gref.RefName, typeof(XmlSchemaAttributeGroup));
1172 WriteAttributes (xtw, grp.Attributes, grp.AnyAttribute);
1177 xtw.WriteAttributeString ("custom-attribute","value");
1180 void WriteParticleComplexContent (XmlTextWriter xtw, string ns, XmlSchemaParticle particle)
1182 WriteParticleContent (xtw, ns, particle, false);
1185 void WriteParticleContent (XmlTextWriter xtw, string ns, XmlSchemaParticle particle, bool multiValue)
1187 if (particle is XmlSchemaGroupRef)
1188 particle = GetRefGroupParticle ((XmlSchemaGroupRef)particle);
1190 if (particle.MaxOccurs > 1) multiValue = true;
1192 if (particle is XmlSchemaSequence) {
1193 WriteSequenceContent (xtw, ns, ((XmlSchemaSequence)particle).Items, multiValue);
1195 else if (particle is XmlSchemaChoice) {
1196 if (((XmlSchemaChoice)particle).Items.Count == 1)
1197 WriteSequenceContent (xtw, ns, ((XmlSchemaChoice)particle).Items, multiValue);
1199 WriteChoiceContent (xtw, ns, (XmlSchemaChoice)particle, multiValue);
1201 else if (particle is XmlSchemaAll) {
1202 WriteSequenceContent (xtw, ns, ((XmlSchemaAll)particle).Items, multiValue);
1206 void WriteSequenceContent (XmlTextWriter xtw, string ns, XmlSchemaObjectCollection items, bool multiValue)
1208 foreach (XmlSchemaObject item in items)
1209 WriteContentItem (xtw, ns, item, multiValue);
1212 void WriteContentItem (XmlTextWriter xtw, string ns, XmlSchemaObject item, bool multiValue)
1214 if (item is XmlSchemaGroupRef)
1215 item = GetRefGroupParticle ((XmlSchemaGroupRef)item);
1217 if (item is XmlSchemaElement)
1219 XmlSchemaElement elem = (XmlSchemaElement) item;
1220 XmlSchemaElement refElem;
1221 if (!elem.RefName.IsEmpty) refElem = FindRefElement (elem);
1222 else refElem = elem;
1224 int num = (elem.MaxOccurs == 1 && !multiValue) ? 1 : 2;
1225 for (int n=0; n<num; n++)
1227 if (currentUse == SoapBindingUse.Literal)
1228 WriteElementSample (xtw, ns, refElem);
1230 WriteRefTypeSample (xtw, ns, refElem);
1233 else if (item is XmlSchemaAny)
1235 xtw.WriteString (GetLiteral ("xml"));
1237 else if (item is XmlSchemaParticle) {
1238 WriteParticleContent (xtw, ns, (XmlSchemaParticle)item, multiValue);
1242 void WriteChoiceContent (XmlTextWriter xtw, string ns, XmlSchemaChoice choice, bool multiValue)
1244 foreach (XmlSchemaObject item in choice.Items)
1245 WriteContentItem (xtw, ns, item, multiValue);
1248 void WriteSimpleContent (XmlTextWriter xtw, XmlSchemaSimpleContent content)
1250 XmlSchemaSimpleContentExtension ext = content.Content as XmlSchemaSimpleContentExtension;
1252 WriteAttributes (xtw, ext.Attributes, ext.AnyAttribute);
1254 XmlQualifiedName qname = GetContentBaseType (content.Content);
1255 xtw.WriteString (GetLiteral (FindBuiltInType (qname)));
1258 string FindBuiltInType (XmlQualifiedName qname)
1260 if (qname.Namespace == XmlSchema.Namespace)
1263 XmlSchemaComplexType ct = FindComplexTyype (qname);
1266 XmlSchemaSimpleContent sc = ct.ContentModel as XmlSchemaSimpleContent;
1267 if (sc == null) throw new InvalidOperationException ("Invalid schema");
1268 return FindBuiltInType (GetContentBaseType (sc.Content));
1271 XmlSchemaSimpleType st = (XmlSchemaSimpleType) schemas.Find (qname, typeof(XmlSchemaSimpleType));
1273 return FindBuiltInType (st);
1275 throw new InvalidOperationException ("Definition of type " + qname + " not found");
1278 string FindBuiltInType (XmlSchemaSimpleType st)
1280 if (st.Content is XmlSchemaSimpleTypeRestriction) {
1281 return FindBuiltInType (GetContentBaseType (st.Content));
1283 else if (st.Content is XmlSchemaSimpleTypeList) {
1284 string s = FindBuiltInType (GetContentBaseType (st.Content));
1285 return s + " " + s + " ...";
1287 else if (st.Content is XmlSchemaSimpleTypeUnion)
1289 //Check if all types of the union are equal. If not, then will use anyType.
1290 XmlSchemaSimpleTypeUnion uni = (XmlSchemaSimpleTypeUnion) st.Content;
1291 string utype = null;
1293 // Anonymous types are unique
1294 if (uni.BaseTypes.Count != 0 && uni.MemberTypes.Length != 0)
1297 foreach (XmlQualifiedName mt in uni.MemberTypes)
1299 string qn = FindBuiltInType (mt);
1300 if (utype != null && qn != utype) return "string";
1310 XmlQualifiedName GetContentBaseType (XmlSchemaObject ob)
1312 if (ob is XmlSchemaSimpleContentExtension)
1313 return ((XmlSchemaSimpleContentExtension)ob).BaseTypeName;
1314 else if (ob is XmlSchemaSimpleContentRestriction)
1315 return ((XmlSchemaSimpleContentRestriction)ob).BaseTypeName;
1316 else if (ob is XmlSchemaSimpleTypeRestriction)
1317 return ((XmlSchemaSimpleTypeRestriction)ob).BaseTypeName;
1318 else if (ob is XmlSchemaSimpleTypeList)
1319 return ((XmlSchemaSimpleTypeList)ob).ItemTypeName;
1324 void WriteComplexContent (XmlTextWriter xtw, string ns, XmlSchemaComplexContent content)
1326 XmlQualifiedName qname;
1328 XmlSchemaComplexContentExtension ext = content.Content as XmlSchemaComplexContentExtension;
1329 if (ext != null) qname = ext.BaseTypeName;
1331 XmlSchemaComplexContentRestriction rest = (XmlSchemaComplexContentRestriction)content.Content;
1332 qname = rest.BaseTypeName;
1333 if (qname == arrayType) {
1334 ParseArrayType (rest, out qname);
1335 XmlSchemaElement elem = new XmlSchemaElement ();
1337 elem.SchemaTypeName = qname;
1339 xtw.WriteAttributeString ("arrayType", SoapEncodingNamespace, qname.Name + "[2]");
1340 WriteContentItem (xtw, ns, elem, true);
1345 // Add base map members to this map
1346 XmlSchemaComplexType ctype = FindComplexTyype (qname);
1347 WriteComplexTypeAttributes (xtw, ctype);
1350 // Add the members of this map
1351 WriteAttributes (xtw, ext.Attributes, ext.AnyAttribute);
1352 if (ext.Particle != null)
1353 WriteParticleComplexContent (xtw, ns, ext.Particle);
1356 WriteComplexTypeElements (xtw, ns, ctype);
1359 void ParseArrayType (XmlSchemaComplexContentRestriction rest, out XmlQualifiedName qtype)
1361 XmlSchemaAttribute arrayTypeAt = FindArrayAttribute (rest.Attributes);
1362 XmlAttribute[] uatts = arrayTypeAt.UnhandledAttributes;
1363 if (uatts == null || uatts.Length == 0) throw new InvalidOperationException ("arrayType attribute not specified in array declaration");
1365 XmlAttribute xat = null;
1366 foreach (XmlAttribute at in uatts)
1367 if (at.LocalName == "arrayType" && at.NamespaceURI == WsdlNamespace)
1368 { xat = at; break; }
1371 throw new InvalidOperationException ("arrayType attribute not specified in array declaration");
1373 string arrayType = xat.Value;
1375 int i = arrayType.LastIndexOf (":");
1376 if (i == -1) ns = "";
1377 else ns = arrayType.Substring (0,i);
1379 int j = arrayType.IndexOf ("[", i+1);
1380 if (j == -1) throw new InvalidOperationException ("Cannot parse WSDL array type: " + arrayType);
1381 type = arrayType.Substring (i+1);
1382 type = type.Substring (0, type.Length-2);
1384 qtype = new XmlQualifiedName (type, ns);
1387 XmlSchemaAttribute FindArrayAttribute (XmlSchemaObjectCollection atts)
1389 foreach (object ob in atts)
1391 XmlSchemaAttribute att = ob as XmlSchemaAttribute;
1392 if (att != null && att.RefName == arrayTypeRefName) return att;
1394 XmlSchemaAttributeGroupRef gref = ob as XmlSchemaAttributeGroupRef;
1397 XmlSchemaAttributeGroup grp = (XmlSchemaAttributeGroup) schemas.Find (gref.RefName, typeof(XmlSchemaAttributeGroup));
1398 att = FindArrayAttribute (grp.Attributes);
1399 if (att != null) return att;
1405 void WriteSimpleTypeSample (XmlTextWriter xtw, XmlSchemaSimpleType stype)
1407 xtw.WriteString (GetLiteral (FindBuiltInType (stype)));
1410 XmlSchemaParticle GetRefGroupParticle (XmlSchemaGroupRef refGroup)
1412 XmlSchemaGroup grp = (XmlSchemaGroup) schemas.Find (refGroup.RefName, typeof (XmlSchemaGroup));
1413 return grp.Particle;
1416 XmlSchemaElement FindRefElement (XmlSchemaElement elem)
1418 if (elem.RefName.Namespace == XmlSchema.Namespace)
1420 if (anyElement != null) return anyElement;
1421 anyElement = new XmlSchemaElement ();
1422 anyElement.Name = "any";
1423 anyElement.SchemaTypeName = anyType;
1426 return (XmlSchemaElement) schemas.Find (elem.RefName, typeof(XmlSchemaElement));
1429 XmlSchemaAttribute FindRefAttribute (XmlQualifiedName refName)
1431 if (refName.Namespace == XmlSchema.Namespace)
1433 XmlSchemaAttribute at = new XmlSchemaAttribute ();
1434 at.Name = refName.Name;
1435 at.SchemaTypeName = new XmlQualifiedName ("string",XmlSchema.Namespace);
1438 return (XmlSchemaAttribute) schemas.Find (refName, typeof(XmlSchemaAttribute));
1441 void WriteRefTypeSample (XmlTextWriter xtw, string ns, XmlSchemaElement elem)
1443 if (elem.SchemaTypeName.Namespace == XmlSchema.Namespace || schemas.Find (elem.SchemaTypeName, typeof(XmlSchemaSimpleType)) != null)
1444 WriteElementSample (xtw, ns, elem);
1447 xtw.WriteStartElement (elem.Name, ns);
1448 xtw.WriteAttributeString ("href", "#id" + (queue.Count+1));
1449 xtw.WriteEndElement ();
1450 queue.Add (new EncodedType (ns, elem));
1454 void WriteQueuedTypeSamples (XmlTextWriter xtw)
1456 for (int n=0; n<queue.Count; n++)
1458 EncodedType ec = (EncodedType) queue[n];
1459 XmlSchemaComplexType st = FindComplexTyype (ec.Element.SchemaTypeName);
1460 WriteComplexTypeSample (xtw, st, ec.Element.SchemaTypeName, n+1);
1464 XmlSchemaComplexType FindComplexTyype (XmlQualifiedName qname)
1466 if (qname.Name.IndexOf ("[]") != -1)
1468 XmlSchemaComplexType stype = new XmlSchemaComplexType ();
1469 stype.ContentModel = new XmlSchemaComplexContent ();
1471 XmlSchemaComplexContentRestriction res = new XmlSchemaComplexContentRestriction ();
1472 stype.ContentModel.Content = res;
1473 res.BaseTypeName = arrayType;
1475 XmlSchemaAttribute att = new XmlSchemaAttribute ();
1476 att.RefName = arrayTypeRefName;
1477 res.Attributes.Add (att);
1479 XmlAttribute xat = document.CreateAttribute ("arrayType", WsdlNamespace);
1480 xat.Value = qname.Namespace + ":" + qname.Name;
1481 att.UnhandledAttributes = new XmlAttribute[] {xat};
1485 return (XmlSchemaComplexType) schemas.Find (qname, typeof(XmlSchemaComplexType));
1488 string GetQualifiedNameString (XmlTextWriter xtw, XmlQualifiedName qname)
1490 string pref = xtw.LookupPrefix (qname.Namespace);
1491 if (pref != null) return pref + ":" + qname.Name;
1493 xtw.WriteAttributeString ("xmlns", "q1", null, qname.Namespace);
1494 return "q1:" + qname.Name;
1497 protected virtual string GetLiteral (string s)
1502 void GetOperationFormat (OperationBinding obin, out SoapBindingStyle style, out SoapBindingUse use)
1504 style = SoapBindingStyle.Document;
1505 use = SoapBindingUse.Literal;
1506 SoapOperationBinding sob = obin.Extensions.Find (typeof(SoapOperationBinding)) as SoapOperationBinding;
1509 SoapBodyBinding sbb = obin.Input.Extensions.Find (typeof(SoapBodyBinding)) as SoapBodyBinding;
1523 <link rel="alternate" type="text/xml" href="<%=Request.FilePath%>?disco"/>
1525 <title><%=WebServiceName%> Web Service</title>
1526 <style type="text/css">
1527 BODY { font-family: Arial; margin-left: 20px; margin-top: 20px; font-size: x-small}
1528 TABLE { font-size: x-small }
1529 .title { color:dimgray; font-family: Arial; font-size:20pt; font-weight:900}
1530 .operationTitle { color:dimgray; font-family: Arial; font-size:15pt; font-weight:900}
1531 .method { font-size: x-small }
1532 .bindingLabel { font-size: x-small; font-weight:bold; color:darkgray; line-height:8pt; display:block; margin-bottom:3px }
1533 .label { font-size: small; font-weight:bold; color:darkgray }
1534 .paramTable { font-size: x-small }
1535 .paramTable TR { background-color: gainsboro }
1536 .paramFormTable { font-size: x-small; padding: 10px; background-color: gainsboro }
1537 .paramFormTable TR { background-color: gainsboro }
1538 .paramInput { border: solid 1px gray }
1539 .button {border: solid 1px gray }
1540 .smallSeparator { height:3px; overflow:hidden }
1541 .panel { background-color:whitesmoke; border: solid 1px silver; border-top: solid 1px silver }
1542 .codePanel { background-color: white; font-size:x-small; padding:7px; border:solid 1px silver}
1543 .code-xml { font-size:10pt; font-family:courier }
1544 .code-cs { font-size:10pt; font-family:courier }
1545 .code-vb { font-size:10pt; font-family:courier }
1546 .tabLabelOn { font-weight:bold }
1547 .tabLabelOff {color: darkgray }
1548 .literal-placeholder {color: darkblue; font-weight:bold}
1549 A:link { color: black; }
1550 A:visited { color: black; }
1551 A:active { color: black; }
1552 A:hover { color: blue }
1556 function clearForm ()
1558 document.getElementById("testFormResult").style.display="none";
1565 <div class="title" style="margin-left:20px">
1566 <span class="label">Web Service</span><br>
1571 **********************************************************
1575 <table border="0" width="100%" cellpadding="15px" cellspacing="15px">
1576 <tr valign="top"><td width="150px" class="panel">
1577 <div style="width:150px"></div>
1578 <a class="method" href='<%=PageName%>'>Overview</a><br>
1579 <div class="smallSeparator"></div>
1580 <a class="method" href='<%=PageName + "?" + GetPageContext("wsdl")%>'>Service Description</a>
1581 <div class="smallSeparator"></div>
1582 <a class="method" href='<%=PageName + "?" + GetPageContext("proxy")%>'>Client proxy</a>
1584 <asp:repeater id="BindingsRepeater" runat=server>
1585 <itemtemplate name="itemtemplate">
1586 <span class="bindingLabel"><%#FormatBindingName(DataBinder.Eval(Container.DataItem, "Name").ToString())%></span>
1587 <asp:repeater id="OperationsRepeater" runat=server datasource='<%# ((Binding)Container.DataItem).Operations %>'>
1589 <a class="method" href="<%=PageName%>?<%=GetTabContext("op",null)%>op=<%#GetOpName(Container.DataItem)%>&bnd=<%#DataBinder.Eval(Container.DataItem, "Binding.Name")%>"><%#GetOpName(Container.DataItem)%></a>
1590 <div class="smallSeparator"></div>
1597 </td><td class="panel">
1599 <% if (CurrentPage == "main") {%>
1602 **********************************************************
1603 Web service overview
1606 <p class="label">Web Service Overview</p>
1607 <%=WebServiceDescription%>
1609 <%} if (DefaultBinding == null) {%>
1610 This service does not contain any public web method.
1611 <%} else if (CurrentPage == "op") {%>
1614 **********************************************************
1615 Operation description
1618 <span class="operationTitle"><%=CurrentOperationName%></span>
1623 <% if (CurrentTab == "main") { %>
1624 <span class="label">Input Parameters</span>
1625 <div class="smallSeparator"></div>
1626 <% if (InParams.Count == 0) { %>
1627 No input parameters<br>
1629 <table class="paramTable" cellspacing="1" cellpadding="5">
1630 <asp:repeater id="InputParamsRepeater" runat=server>
1633 <td width="150"><%#DataBinder.Eval(Container.DataItem, "Name")%></td>
1634 <td width="150"><%#DataBinder.Eval(Container.DataItem, "Type")%></td>
1642 <% if (OutParams.Count > 0) { %>
1643 <span class="label">Output Parameters</span>
1644 <div class="smallSeparator"></div>
1645 <table class="paramTable" cellspacing="1" cellpadding="5">
1646 <asp:repeater id="OutputParamsRepeater" runat=server>
1649 <td width="150"><%#DataBinder.Eval(Container.DataItem, "Name")%></td>
1650 <td width="150"><%#DataBinder.Eval(Container.DataItem, "Type")%></td>
1658 <span class="label">Remarks</span>
1659 <div class="smallSeparator"></div>
1660 <%=OperationDocumentation%>
1662 <span class="label">Technical information</span>
1663 <div class="smallSeparator"></div>
1664 Format: <%=CurrentOperationFormat%>
1665 <br>Supported protocols: <%=CurrentOperationProtocols%>
1669 **********************************************************
1670 Operation description - Test form
1673 <% if (CurrentTab == "test") {
1674 if (CurrentOperationSupportsTest) {%>
1675 Enter values for the parameters and click the 'Invoke' button to test this method:<br><br>
1676 <form action="<%=PageName%>" method="GET">
1677 <input type="hidden" name="page" value="<%=CurrentPage%>">
1678 <input type="hidden" name="tab" value="<%=CurrentTab%>">
1679 <input type="hidden" name="op" value="<%=CurrentOperationName%>">
1680 <input type="hidden" name="bnd" value="<%=CurrentOperationBinding%>">
1681 <input type="hidden" name="ext" value="testform">
1682 <table class="paramFormTable" cellspacing="0" cellpadding="3">
1683 <asp:repeater id="InputFormParamsRepeater" runat=server>
1686 <td><%#DataBinder.Eval(Container.DataItem, "Name")%>: </td>
1687 <td width="150"><input class="paramInput" type="text" size="20" name="<%#DataBinder.Eval(Container.DataItem, "Name")%>"></td>
1691 <tr><td></td><td><input class="button" type="submit" value="Invoke"> <input class="button" type="button" onclick="clearForm()" value="Clear"></td></tr>
1694 <div id="testFormResult" style="display:<%= (HasFormResult?"block":"none") %>">
1695 The web service returned the following result:<br/><br/>
1696 <div class="codePanel"><%=GetTestResult()%></div>
1699 The test form is not available for this operation because it has parameters with a complex structure.
1704 **********************************************************
1705 Operation description - Message Layout
1708 <% if (CurrentTab == "msg") { %>
1710 The following are sample SOAP requests and responses for each protocol supported by this method:
1713 <% if (IsOperationSupported ("Soap")) { %>
1714 <span class="label">Soap</span>
1716 <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("Soap", true)%></div></div>
1718 <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("Soap", false)%></div></div>
1721 <% if (IsOperationSupported ("HttpGet")) { %>
1722 <span class="label">HTTP Get</span>
1724 <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("HttpGet", true)%></div></div>
1726 <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("HttpGet", false)%></div></div>
1729 <% if (IsOperationSupported ("HttpPost")) { %>
1730 <span class="label">HTTP Post</span>
1732 <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("HttpPost", true)%></div></div>
1734 <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("HttpPost", false)%></div></div>
1739 <%} else if (CurrentPage == "proxy") {%>
1741 **********************************************************
1744 <form action="<%=PageName%>" name="langForm" method="GET">
1745 Select the language for which you want to generate a proxy
1746 <input type="hidden" name="page" value="<%=CurrentPage%>">
1747 <SELECT name="lang" onchange="langForm.submit()">
1748 <%=GetOptionSel("cs",CurrentLanguage)%>C#</option>
1749 <%=GetOptionSel("vb",CurrentLanguage)%>Visual Basic</option>
1754 <span class="label"><%=CurrentProxytName%></span>
1755 <a href="<%=PageName + "?code=" + CurrentLanguage%>">Download</a>
1757 <div class="codePanel">
1758 <div class="code-<%=CurrentLanguage%>"><%=GetProxyCode ()%></div>
1760 <%} else if (CurrentPage == "wsdl") {%>
1762 **********************************************************
1765 <% if (descriptions.Count > 1 || schemas.Count > 1) {%>
1766 The description of this web service is composed by several documents. Click on the document you want to see:
1770 for (int n=0; n<descriptions.Count; n++)
1771 Response.Write ("<li><a href='" + PageName + "?" + GetPageContext(null) + "doctype=wsdl&docind=" + n + "'>WSDL document " + descriptions[n].TargetNamespace + "</a></li>");
1772 for (int n=0; n<schemas.Count; n++)
1773 Response.Write ("<li><a href='" + PageName + "?" + GetPageContext(null) + "doctype=schema&docind=" + n + "'>Xml Schema " + schemas[n].TargetNamespace + "</a></li>");
1780 <span class="label"><%=CurrentDocumentName%></span>
1781 <a href="<%=PageName + "?" + CurrentDocType + "=" + CurrentDocInd %>">Download</a>
1783 <div class="codePanel">
1784 <div class="code-xml"><%=GenerateDocument ()%></div>
1789 <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
1791 <td width="20px"></td>