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" %>
18 <%@ Import Namespace="System.Web.Services.Description" %>
19 <%@ Import Namespace="System.Web.Services.Configuration" %>
20 <%@ Import Namespace="System.Web.Configuration" %>
21 <%@ Import Namespace="System" %>
22 <%@ Import Namespace="System.Net" %>
23 <%@ Import Namespace="System.Globalization" %>
24 <%@ Import Namespace="System.Resources" %>
25 <%@ Import Namespace="System.Diagnostics" %>
26 <%@ Import Namespace="System.CodeDom" %>
27 <%@ Import Namespace="System.CodeDom.Compiler" %>
28 <%@ Import Namespace="Microsoft.CSharp" %>
29 <%@ Import Namespace="Microsoft.VisualBasic" %>
30 <%@ Import Namespace="System.Text" %>
31 <%@ Import Namespace="System.Text.RegularExpressions" %>
32 <%@ Import Namespace="System.Security.Cryptography.X509Certificates" %>
33 <%@ Assembly name="System.Web.Services" %>
34 <%@ Page debug="true" %>
37 <script language="C#" runat="server">
39 ServiceDescriptionCollection descriptions;
42 string WebServiceName;
43 string WebServiceDescription;
46 string DefaultBinding;
47 ArrayList ServiceProtocols;
49 string CurrentOperationName;
50 string CurrentOperationBinding;
51 string OperationDocumentation;
52 string CurrentOperationFormat;
53 bool CurrentOperationSupportsTest;
56 string CurrentOperationProtocols;
57 int CodeTextColumns = 95;
58 BasicProfileViolationCollection ProfileViolations;
60 void Page_Load(object sender, EventArgs e)
62 descriptions = (ServiceDescriptionCollection) Context.Items["wsdls"];
63 schemas = (XmlSchemas) Context.Items["schemas"];
65 ServiceDescription desc = descriptions [0];
66 if (schemas.Count == 0) schemas = desc.Types.Schemas;
68 Service service = desc.Services[0];
69 WebServiceName = service.Name;
70 if (desc.Bindings.Count == 0)
73 DefaultBinding = desc.Bindings[0].Name;
74 WebServiceDescription = service.Documentation;
75 if (WebServiceDescription == "" || WebServiceDescription == null)
76 WebServiceDescription = "Description has not been provided";
77 ServiceProtocols = FindServiceProtocols (null);
79 CurrentOperationName = Request.QueryString["op"];
80 CurrentOperationBinding = Request.QueryString["bnd"];
81 if (CurrentOperationName != null) BuildOperationInfo ();
83 PageName = HttpUtility.UrlEncode (Path.GetFileName(Request.Path), Encoding.UTF8);
85 ArrayList list = new ArrayList ();
86 foreach (ServiceDescription sd in descriptions) {
87 foreach (Binding bin in sd.Bindings)
88 if (bin.Extensions.Find (typeof(SoapBinding)) != null) list.Add (bin);
91 BindingsRepeater.DataSource = list;
94 ProfileViolations = new BasicProfileViolationCollection ();
95 foreach (WsiProfilesElement claims in ((WebServicesSection) WebConfigurationManager.GetSection("system.web/webServices")).ConformanceWarnings)
96 if (claims.Name != WsiProfiles.None)
97 WebServicesInteroperability.CheckConformance (claims.Name, descriptions, ProfileViolations);
100 void BuildOperationInfo ()
102 InParams = new ArrayList ();
103 OutParams = new ArrayList ();
105 Port port = FindPort (CurrentOperationBinding, null);
106 Binding binding = descriptions.GetBinding (port.Binding);
108 PortType portType = descriptions.GetPortType (binding.Type);
109 Operation oper = FindOperation (portType, CurrentOperationName);
111 OperationDocumentation = oper.Documentation;
112 if (OperationDocumentation == null || OperationDocumentation == "")
113 OperationDocumentation = "No additional remarks";
115 foreach (OperationMessage opm in oper.Messages)
117 if (opm is OperationInput)
118 BuildParameters (InParams, opm);
119 else if (opm is OperationOutput)
120 BuildParameters (OutParams, opm);
123 // Protocols supported by the operation
124 CurrentOperationProtocols = "";
125 WebServiceProtocols testProtocols = 0;
126 ArrayList prots = FindServiceProtocols (CurrentOperationName);
127 for (int n=0; n<prots.Count; n++) {
128 string prot = (string) prots [n];
129 if (n != 0) CurrentOperationProtocols += ", ";
130 CurrentOperationProtocols += prot;
131 if (prot == "HttpGet")
132 testProtocols |= WebServiceProtocols.HttpGet;
133 else if (prot == "HttpPost") {
134 testProtocols |= WebServiceProtocols.HttpPost;
135 if (Context.Request.IsLocal)
136 testProtocols |= WebServiceProtocols.HttpPostLocalhost;
139 CurrentOperationSupportsTest = (WebServicesSection.Current.EnabledProtocols & testProtocols) != 0;
142 OperationBinding obin = FindOperation (binding, CurrentOperationName);
144 CurrentOperationFormat = GetOperationFormat (obin);
146 InputParamsRepeater.DataSource = InParams;
147 InputFormParamsRepeater.DataSource = InParams;
148 OutputParamsRepeater.DataSource = OutParams;
151 void BuildParameters (ArrayList list, OperationMessage opm)
153 Message msg = descriptions.GetMessage (opm.Message);
154 if (msg.Parts.Count > 0 && msg.Parts[0].Name == "parameters")
156 MessagePart part = msg.Parts[0];
157 XmlSchemaComplexType ctype;
158 if (part.Element == XmlQualifiedName.Empty)
160 ctype = (XmlSchemaComplexType) schemas.Find (part.Type, typeof(XmlSchemaComplexType));
164 XmlSchemaElement elem = (XmlSchemaElement) schemas.Find (part.Element, typeof(XmlSchemaElement));
165 ctype = (XmlSchemaComplexType) elem.SchemaType;
167 XmlSchemaSequence seq = ctype.Particle as XmlSchemaSequence;
168 if (seq == null) return;
170 foreach (XmlSchemaObject ob in seq.Items)
172 Parameter p = new Parameter();
173 p.Description = "No additional remarks";
175 if (ob is XmlSchemaElement)
177 XmlSchemaElement selem = GetRefElement ((XmlSchemaElement)ob);
179 p.Type = selem.SchemaTypeName.Name;
191 foreach (MessagePart part in msg.Parts)
193 Parameter p = new Parameter ();
194 p.Description = "No additional remarks";
196 if (part.Element == XmlQualifiedName.Empty)
197 p.Type = part.Type.Name;
200 XmlSchemaElement elem = (XmlSchemaElement) schemas.Find (part.Element, typeof(XmlSchemaElement));
201 p.Type = elem.SchemaTypeName.Name;
208 string GetOperationFormat (OperationBinding obin)
211 SoapOperationBinding sob = obin.Extensions.Find (typeof(SoapOperationBinding)) as SoapOperationBinding;
213 format = sob.Style.ToString ();
214 SoapBodyBinding sbb = obin.Input.Extensions.Find (typeof(SoapBodyBinding)) as SoapBodyBinding;
216 format += " / " + sbb.Use;
221 XmlSchemaElement GetRefElement (XmlSchemaElement elem)
223 if (!elem.RefName.IsEmpty)
224 return (XmlSchemaElement) schemas.Find (elem.RefName, typeof(XmlSchemaElement));
229 ArrayList FindServiceProtocols(string operName)
231 ArrayList table = new ArrayList ();
232 Service service = descriptions[0].Services[0];
233 foreach (Port port in service.Ports)
236 Binding bin = descriptions.GetBinding (port.Binding);
237 if (bin.Extensions.Find (typeof(SoapBinding)) != null)
241 HttpBinding hb = (HttpBinding) bin.Extensions.Find (typeof(HttpBinding));
242 if (hb != null && hb.Verb == "POST") prot = "HttpPost";
243 else if (hb != null && hb.Verb == "GET") prot = "HttpGet";
246 if (prot != null && operName != null)
248 if (FindOperation (bin, operName) == null)
252 if (prot != null && !table.Contains (prot))
258 Port FindPort (string portName, string protocol)
260 Service service = descriptions[0].Services[0];
261 foreach (Port port in service.Ports)
263 if (portName == null)
265 Binding binding = descriptions.GetBinding (port.Binding);
266 if (GetProtocol (binding) == protocol) return port;
268 else if (port.Name == portName)
274 string GetProtocol (Binding binding)
276 if (binding.Extensions.Find (typeof(SoapBinding)) != null) return "Soap";
277 HttpBinding hb = (HttpBinding) binding.Extensions.Find (typeof(HttpBinding));
278 if (hb == null) return "";
279 if (hb.Verb == "POST") return "HttpPost";
280 if (hb.Verb == "GET") return "HttpGet";
285 Operation FindOperation (PortType portType, string name)
287 foreach (Operation oper in portType.Operations) {
288 if (oper.Messages.Input.Name != null) {
289 if (oper.Messages.Input.Name == name) return oper;
292 if (oper.Name == name) return oper;
298 OperationBinding FindOperation (Binding binding, string name)
300 foreach (OperationBinding oper in binding.Operations) {
301 if (oper.Input.Name != null) {
302 if (oper.Input.Name == name) return oper;
305 if (oper.Name == name) return oper;
311 string FormatBindingName (string name)
313 if (name == DefaultBinding) return "Methods";
314 else return "Methods for binding<br>" + name;
317 string GetOpName (object op)
319 OperationBinding ob = op as OperationBinding;
320 if (ob == null) return "";
321 if (ob.Input.Name != null) return ob.Input.Name;
327 get { return Request.QueryString ["ext"] == "testform"; }
330 class NoCheckCertificatePolicy : ICertificatePolicy {
331 public bool CheckValidationResult (ServicePoint a, X509Certificate b, WebRequest c, int d)
339 return (CurrentOperationProtocols.IndexOf ("HttpGet") >= 0) ? "GET" : "POST";
346 NameValueCollection query_string = Request.QueryString;
347 for (int n = 0; n < query_string.Count; n++) {
349 if (qs != "") qs += "&";
350 qs += query_string.GetKey(n) + "=" + Server.UrlEncode (query_string [n]);
352 if (query_string.GetKey(n) == "ext") fill = true;
358 string GetTestResultUrl ()
360 if (!HasFormResult) return "";
362 string location = null;
363 ServiceDescription desc = descriptions [0];
364 Service service = desc.Services[0];
365 foreach (Port port in service.Ports)
366 if (port.Name == CurrentOperationBinding)
368 SoapAddressBinding sbi = (SoapAddressBinding) port.Extensions.Find (typeof(SoapAddressBinding));
370 location = sbi.Location;
373 if (location == null)
374 return "Could not locate web service";
376 return location + "/" + CurrentOperationName;
379 string GenerateOperationMessages (string protocol, bool generateInput)
381 if (!IsOperationSupported (protocol)) return "";
384 if (protocol != "Soap") port = FindPort (null, protocol);
385 else port = FindPort (CurrentOperationBinding, null);
387 Binding binding = descriptions.GetBinding (port.Binding);
388 OperationBinding obin = FindOperation (binding, CurrentOperationName);
389 PortType portType = descriptions.GetPortType (binding.Type);
390 Operation oper = FindOperation (portType, CurrentOperationName);
392 HtmlSampleGenerator sg = new HtmlSampleGenerator (descriptions, schemas);
393 string txt = sg.GenerateMessage (port, obin, oper, protocol, generateInput);
394 if (protocol == "Soap") txt = WrapText (txt,CodeTextColumns);
395 txt = ColorizeXml (txt);
396 txt = txt.Replace ("@placeholder!","<span class='literal-placeholder'>");
397 txt = txt.Replace ("!placeholder@","</span>");
401 bool IsOperationSupported (string protocol)
403 if (CurrentPage != "op" || CurrentTab != "msg") return false;
404 if (protocol == "Soap") return true;
406 Port port = FindPort (null, protocol);
407 if (port == null) return false;
408 Binding binding = descriptions.GetBinding (port.Binding);
409 if (binding == null) return false;
410 return FindOperation (binding, CurrentOperationName) != null;
414 // Proxy code generation
417 string GetProxyCode ()
419 CodeNamespace codeNamespace = new CodeNamespace();
420 CodeCompileUnit codeUnit = new CodeCompileUnit();
422 codeUnit.Namespaces.Add (codeNamespace);
424 ServiceDescriptionImporter importer = new ServiceDescriptionImporter();
426 foreach (ServiceDescription sd in descriptions)
427 importer.AddServiceDescription(sd, null, null);
429 foreach (XmlSchema sc in schemas)
430 importer.Schemas.Add (sc);
432 importer.Import(codeNamespace, codeUnit);
434 string langId = Request.QueryString ["lang"];
435 if (langId == null || langId == "") langId = "cs";
436 CodeDomProvider provider = GetProvider (langId);
437 ICodeGenerator generator = provider.CreateGenerator();
438 CodeGeneratorOptions options = new CodeGeneratorOptions();
440 StringWriter sw = new StringWriter ();
441 generator.GenerateCodeFromCompileUnit(codeUnit, sw, options);
443 return Colorize (WrapText (sw.ToString (), CodeTextColumns), langId);
446 public string CurrentLanguage
449 string langId = Request.QueryString ["lang"];
450 if (langId == null || langId == "") langId = "cs";
455 public string CurrentProxytName
458 string lan = CurrentLanguage == "cs" ? "C#" : "Visual Basic";
459 return lan + " Client Proxy";
463 private CodeDomProvider GetProvider(string langId)
465 switch (langId.ToUpper())
467 case "CS": return new CSharpCodeProvider();
468 case "VB": return new VBCodeProvider();
469 default: return null;
474 // Document generation
477 string GenerateDocument ()
479 StringWriter sw = new StringWriter ();
481 if (CurrentDocType == "wsdl")
482 descriptions [CurrentDocInd].Write (sw);
483 else if (CurrentDocType == "schema")
484 schemas [CurrentDocInd].Write (sw);
486 return Colorize (WrapText (sw.ToString (), CodeTextColumns), "xml");
489 public string CurrentDocType
491 get { return Request.QueryString ["doctype"] != null ? Request.QueryString ["doctype"] : "wsdl"; }
494 public int CurrentDocInd
496 get { return Request.QueryString ["docind"] != null ? int.Parse (Request.QueryString ["docind"]) : 0; }
499 public string CurrentDocumentName
502 if (CurrentDocType == "wsdl")
503 return "WSDL document for namespace \"" + descriptions [CurrentDocInd].TargetNamespace + "\"";
505 return "Xml Schema for namespace \"" + schemas [CurrentDocInd].TargetNamespace + "\"";
513 bool firstTab = true;
514 ArrayList disabledTabs = new ArrayList ();
518 get { return Request.QueryString["tab"] != null ? Request.QueryString["tab"] : "main" ; }
523 get { return Request.QueryString["page"] != null ? Request.QueryString["page"] : "main" ; }
528 if (CurrentOperationName != null)
530 WriteTab ("main","Overview");
531 WriteTab ("test","Test Form");
532 WriteTab ("msg","Message Layout");
536 void WriteTab (string id, string label)
538 if (!firstTab) Response.Write(" | ");
541 string cname = CurrentTab == id ? "tabLabelOn" : "tabLabelOff";
542 Response.Write ("<a href='" + PageName + "?" + GetPageContext(null) + GetDataContext() + "tab=" + id + "' style='text-decoration:none'>");
543 Response.Write ("<span class='" + cname + "'>" + label + "</span>");
544 Response.Write ("</a>");
547 string GetTabContext (string pag, string tab)
549 if (tab == null) tab = CurrentTab;
550 if (pag == null) pag = CurrentPage;
551 if (pag != CurrentPage) tab = "main";
552 return "page=" + pag + "&tab=" + tab + "&";
555 string GetPageContext (string pag)
557 if (pag == null) pag = CurrentPage;
558 return "page=" + pag + "&";
571 static string keywords_cs =
572 "(\\babstract\\b|\\bevent\\b|\\bnew\\b|\\bstruct\\b|\\bas\\b|\\bexplicit\\b|\\bnull\\b|\\bswitch\\b|\\bbase\\b|\\bextern\\b|" +
573 "\\bobject\\b|\\bthis\\b|\\bbool\\b|\\bfalse\\b|\\boperator\\b|\\bthrow\\b|\\bbreak\\b|\\bfinally\\b|\\bout\\b|\\btrue\\b|" +
574 "\\bbyte\\b|\\bfixed\\b|\\boverride\\b|\\btry\\b|\\bcase\\b|\\bfloat\\b|\\bparams\\b|\\btypeof\\b|\\bcatch\\b|\\bfor\\b|" +
575 "\\bprivate\\b|\\buint\\b|\\bchar\\b|\\bforeach\\b|\\bprotected\\b|\\bulong\\b|\\bchecked\\b|\\bgoto\\b|\\bpublic\\b|" +
576 "\\bunchecked\\b|\\bclass\\b|\\bif\\b|\\breadonly\\b|\\bunsafe\\b|\\bconst\\b|\\bimplicit\\b|\\bref\\b|\\bushort\\b|" +
577 "\\bcontinue\\b|\\bin\\b|\\breturn\\b|\\busing\\b|\\bdecimal\\b|\\bint\\b|\\bsbyte\\b|\\bvirtual\\b|\\bdefault\\b|" +
578 "\\binterface\\b|\\bsealed\\b|\\bvolatile\\b|\\bdelegate\\b|\\binternal\\b|\\bshort\\b|\\bvoid\\b|\\bdo\\b|\\bis\\b|" +
579 "\\bsizeof\\b|\\bwhile\\b|\\bdouble\\b|\\block\\b|\\bstackalloc\\b|\\belse\\b|\\blong\\b|\\bstatic\\b|\\benum\\b|" +
580 "\\bnamespace\\b|\\bstring\\b)";
582 static string keywords_vb =
583 "(\\bAddHandler\\b|\\bAddressOf\\b|\\bAlias\\b|\\bAnd\\b|\\bAndAlso\\b|\\bAnsi\\b|\\bAs\\b|\\bAssembly\\b|" +
584 "\\bAuto\\b|\\bBoolean\\b|\\bByRef\\b|\\bByte\\b|\\bByVal\\b|\\bCall\\b|\\bCase\\b|\\bCatch\\b|" +
585 "\\bCBool\\b|\\bCByte\\b|\\bCChar\\b|\\bCDate\\b|\\bCDec\\b|\\bCDbl\\b|\\bChar\\b|\\bCInt\\b|" +
586 "\\bClass\\b|\\bCLng\\b|\\bCObj\\b|\\bConst\\b|\\bCShort\\b|\\bCSng\\b|\\bCStr\\b|\\bCType\\b|" +
587 "\\bDate\\b|\\bDecimal\\b|\\bDeclare\\b|\\bDefault\\b|\\bDelegate\\b|\\bDim\\b|\\bDirectCast\\b|\\bDo\\b|" +
588 "\\bDouble\\b|\\bEach\\b|\\bElse\\b|\\bElseIf\\b|\\bEnd\\b|\\bEnum\\b|\\bErase\\b|\\bError\\b|" +
589 "\\bEvent\\b|\\bExit\\b|\\bFalse\\b|\\bFinally\\b|\\bFor\\b|\\bFriend\\b|\\bFunction\\b|\\bGet\\b|" +
590 "\\bGetType\\b|\\bGoSub\\b|\\bGoTo\\b|\\bHandles\\b|\\bIf\\b|\\bImplements\\b|\\bImports\\b|\\bIn\\b|" +
591 "\\bInherits\\b|\\bInteger\\b|\\bInterface\\b|\\bIs\\b|\\bLet\\b|\\bLib\\b|\\bLike\\b|\\bLong\\b|" +
592 "\\bLoop\\b|\\bMe\\b|\\bMod\\b|\\bModule\\b|\\bMustInherit\\b|\\bMustOverride\\b|\\bMyBase\\b|\\bMyClass\\b|" +
593 "\\bNamespace\\b|\\bNew\\b|\\bNext\\b|\\bNot\\b|\\bNothing\\b|\\bNotInheritable\\b|\\bNotOverridable\\b|\\bObject\\b|" +
594 "\\bOn\\b|\\bOption\\b|\\bOptional\\b|\\bOr\\b|\\bOrElse\\b|\\bOverloads\\b|\\bOverridable\\b|\\bOverrides\\b|" +
595 "\\bParamArray\\b|\\bPreserve\\b|\\bPrivate\\b|\\bProperty\\b|\\bProtected\\b|\\bPublic\\b|\\bRaiseEvent\\b|\\bReadOnly\\b|" +
596 "\\bReDim\\b|\\bREM\\b|\\bRemoveHandler\\b|\\bResume\\b|\\bReturn\\b|\\bSelect\\b|\\bSet\\b|\\bShadows\\b|" +
597 "\\bShared\\b|\\bShort\\b|\\bSingle\\b|\\bStatic\\b|\\bStep\\b|\\bStop\\b|\\bString\\b|\\bStructure\\b|" +
598 "\\bSub\\b|\\bSyncLock\\b|\\bThen\\b|\\bThrow\\b|\\bTo\\b|\\bTrue\\b|\\bTry\\b|\\bTypeOf\\b|" +
599 "\\bUnicode\\b|\\bUntil\\b|\\bVariant\\b|\\bWhen\\b|\\bWhile\\b|\\bWith\\b|\\bWithEvents\\b|\\bWriteOnly\\b|\\bXor\\b)";
601 string Colorize (string text, string lang)
603 if (lang == "xml") return ColorizeXml (text);
604 else if (lang == "cs") return ColorizeCs (text);
605 else if (lang == "vb") return ColorizeVb (text);
609 string ColorizeXml (string text)
611 text = text.Replace (" ", " ");
612 Regex re = new Regex ("\r\n|\r|\n");
613 text = re.Replace (text, "_br_");
615 re = new Regex ("<\\s*(\\/?)\\s*([\\s\\S]*?)\\s*(\\/?)\\s*>");
616 text = re.Replace (text,"{blue:<$1}{maroon:$2}{blue:$3>}");
618 re = new Regex ("\\{(\\w*):([\\s\\S]*?)\\}");
619 text = re.Replace (text,"<span style='color:$1'>$2</span>");
621 re = new Regex ("\"(.*?)\"");
622 text = re.Replace (text,"\"<span style='color:purple'>$1</span>\"");
625 text = text.Replace ("\t", " ");
626 text = text.Replace ("_br_", "<br>");
630 string ColorizeCs (string text)
632 text = text.Replace (" ", " ");
634 text = text.Replace ("<", "<");
635 text = text.Replace (">", ">");
637 Regex re = new Regex ("\"((((?!\").)|\\\")*?)\"");
638 text = re.Replace (text,"<span style='color:purple'>\"$1\"</span>");
640 re = new Regex ("//(((.(?!\"</span>))|\"(((?!\").)*)\"</span>)*)(\r|\n|\r\n)");
641 text = re.Replace (text,"<span style='color:green'>//$1</span><br/>");
643 re = new Regex (keywords_cs);
644 text = re.Replace (text,"<span style='color:blue'>$1</span>");
646 text = text.Replace ("\t"," ");
647 text = text.Replace ("\n","<br/>");
652 string ColorizeVb (string text)
654 text = text.Replace (" ", " ");
656 /* Regex re = new Regex ("\"((((?!\").)|\\\")*?)\"");
657 text = re.Replace (text,"<span style='color:purple'>\"$1\"</span>");
659 re = new Regex ("'(((.(?!\"\\<\\/span\\>))|\"(((?!\").)*)\"\\<\\/span\\>)*)(\r|\n|\r\n)");
660 text = re.Replace (text,"<span style='color:green'>//$1</span><br/>");
662 re = new Regex (keywords_vb);
663 text = re.Replace (text,"<span style='color:blue'>$1</span>");
665 text = text.Replace ("\t"," ");
666 text = text.Replace ("\n","<br/>");
671 // Helper methods and classes
674 string GetDataContext ()
676 return "op=" + CurrentOperationName + "&bnd=" + CurrentOperationBinding + "&";
679 string GetOptionSel (string v1, string v2)
681 string op = "<option ";
682 if (v1 == v2) op += "selected ";
683 return op + "value='" + v1 + "'>";
686 string WrapText (string text, int maxChars)
688 text = text.Replace(" />","/>");
690 string linspace = null;
694 bool inquotes = false;
696 string sublineIndent = "";
697 System.Text.StringBuilder sb = new System.Text.StringBuilder ();
698 for (int n=0; n<text.Length; n++)
702 if (c=='\r' || c=='\n' || n==text.Length-1)
704 sb.Append (linspace + sublineIndent + text.Substring (linstart, n-linstart+1));
714 if (lastc==',' || lastc=='(')
716 if (!inquotes) breakpos = n;
719 if (lincount > maxChars && breakpos >= linstart)
721 if (linspace != null)
722 sb.Append (linspace + sublineIndent);
723 sb.Append (text.Substring (linstart, breakpos-linstart));
726 lincount = linspace.Length + sublineIndent.Length + (n-breakpos);
730 if (c==' ' || c=='\t')
737 inquotes = !inquotes;
740 if (linspace == null) {
741 linspace = text.Substring (linstart, n-linstart);
748 return sb.ToString ();
757 public string Name { get { return name; } set { name = value; } }
758 public string Type { get { return type; } set { type = value; } }
759 public string Description { get { return description; } set { description = value; } }
762 public class HtmlSampleGenerator: SampleGenerator
764 public HtmlSampleGenerator (ServiceDescriptionCollection services, XmlSchemas schemas)
765 : base (services, schemas)
769 protected override string GetLiteral (string s)
771 return "@placeholder!" + s + "!placeholder@";
776 public class SampleGenerator
778 protected ServiceDescriptionCollection descriptions;
779 protected XmlSchemas schemas;
780 XmlSchemaElement anyElement;
782 SoapBindingUse currentUse;
783 XmlDocument document = new XmlDocument ();
785 static readonly XmlQualifiedName anyType = new XmlQualifiedName ("anyType",XmlSchema.Namespace);
786 static readonly XmlQualifiedName arrayType = new XmlQualifiedName ("Array","http://schemas.xmlsoap.org/soap/encoding/");
787 static readonly XmlQualifiedName arrayTypeRefName = new XmlQualifiedName ("arrayType","http://schemas.xmlsoap.org/soap/encoding/");
788 const string SoapEnvelopeNamespace = "http://schemas.xmlsoap.org/soap/envelope/";
789 const string WsdlNamespace = "http://schemas.xmlsoap.org/wsdl/";
790 const string SoapEncodingNamespace = "http://schemas.xmlsoap.org/soap/encoding/";
794 public EncodedType (string ns, XmlSchemaElement elem) { Namespace = ns; Element = elem; }
795 public string Namespace;
796 public XmlSchemaElement Element;
799 public SampleGenerator (ServiceDescriptionCollection services, XmlSchemas schemas)
801 descriptions = services;
802 this.schemas = schemas;
803 queue = new ArrayList ();
806 public string GenerateMessage (Port port, OperationBinding obin, Operation oper, string protocol, bool generateInput)
808 OperationMessage msg = null;
809 foreach (OperationMessage opm in oper.Messages)
811 if (opm is OperationInput && generateInput) msg = opm;
812 else if (opm is OperationOutput && !generateInput) msg = opm;
814 if (msg == null) return null;
817 case "Soap": return GenerateHttpSoapMessage (port, obin, oper, msg);
818 case "HttpGet": return GenerateHttpGetMessage (port, obin, oper, msg);
819 case "HttpPost": return GenerateHttpPostMessage (port, obin, oper, msg);
821 return "Unknown protocol";
824 public string GenerateHttpSoapMessage (Port port, OperationBinding obin, Operation oper, OperationMessage msg)
828 if (msg is OperationInput)
830 SoapAddressBinding sab = port.Extensions.Find (typeof(SoapAddressBinding)) as SoapAddressBinding;
831 SoapOperationBinding sob = obin.Extensions.Find (typeof(SoapOperationBinding)) as SoapOperationBinding;
832 req += "POST " + new Uri (sab.Location).AbsolutePath + "\n";
833 req += "SOAPAction: " + sob.SoapAction + "\n";
834 req += "Content-Type: text/xml; charset=utf-8\n";
835 req += "Content-Length: " + GetLiteral ("string") + "\n";
836 req += "Host: " + GetLiteral ("string") + "\n\n";
840 req += "HTTP/1.0 200 OK\n";
841 req += "Content-Type: text/xml; charset=utf-8\n";
842 req += "Content-Length: " + GetLiteral ("string") + "\n\n";
845 req += GenerateSoapMessage (obin, oper, msg);
849 public string GenerateHttpGetMessage (Port port, OperationBinding obin, Operation oper, OperationMessage msg)
853 if (msg is OperationInput)
855 HttpAddressBinding sab = port.Extensions.Find (typeof(HttpAddressBinding)) as HttpAddressBinding;
856 HttpOperationBinding sob = obin.Extensions.Find (typeof(HttpOperationBinding)) as HttpOperationBinding;
857 string location = new Uri (sab.Location).AbsolutePath + sob.Location + "?" + BuildQueryString (msg);
858 req += "GET " + location + "\n";
859 req += "Host: " + GetLiteral ("string");
863 req += "HTTP/1.0 200 OK\n";
864 req += "Content-Type: text/xml; charset=utf-8\n";
865 req += "Content-Length: " + GetLiteral ("string") + "\n\n";
867 MimeXmlBinding mxb = (MimeXmlBinding) obin.Output.Extensions.Find (typeof(MimeXmlBinding)) as MimeXmlBinding;
868 if (mxb == null) return req;
870 Message message = descriptions.GetMessage (msg.Message);
871 XmlQualifiedName ename = null;
872 foreach (MessagePart part in message.Parts)
873 if (part.Name == mxb.Part) ename = part.Element;
875 if (ename == null) return req + GetLiteral("string");
877 StringWriter sw = new StringWriter ();
878 XmlTextWriter xtw = new XmlTextWriter (sw);
879 xtw.Formatting = Formatting.Indented;
880 currentUse = SoapBindingUse.Literal;
881 WriteRootElementSample (xtw, ename);
883 req += sw.ToString ();
889 public string GenerateHttpPostMessage (Port port, OperationBinding obin, Operation oper, OperationMessage msg)
893 if (msg is OperationInput)
895 HttpAddressBinding sab = port.Extensions.Find (typeof(HttpAddressBinding)) as HttpAddressBinding;
896 HttpOperationBinding sob = obin.Extensions.Find (typeof(HttpOperationBinding)) as HttpOperationBinding;
897 string location = new Uri (sab.Location).AbsolutePath + sob.Location;
898 req += "POST " + location + "\n";
899 req += "Content-Type: application/x-www-form-urlencoded\n";
900 req += "Content-Length: " + GetLiteral ("string") + "\n";
901 req += "Host: " + GetLiteral ("string") + "\n\n";
902 req += BuildQueryString (msg);
904 else return GenerateHttpGetMessage (port, obin, oper, msg);
909 string BuildQueryString (OperationMessage opm)
912 Message msg = descriptions.GetMessage (opm.Message);
913 foreach (MessagePart part in msg.Parts)
915 if (s.Length != 0) s += "&";
916 s += part.Name + "=" + GetLiteral (part.Type.Name);
921 public string GenerateSoapMessage (OperationBinding obin, Operation oper, OperationMessage msg)
923 SoapOperationBinding sob = obin.Extensions.Find (typeof(SoapOperationBinding)) as SoapOperationBinding;
924 SoapBindingStyle style = (sob != null) ? sob.Style : SoapBindingStyle.Document;
926 MessageBinding msgbin = (msg is OperationInput) ? (MessageBinding) obin.Input : (MessageBinding)obin.Output;
927 SoapBodyBinding sbb = msgbin.Extensions.Find (typeof(SoapBodyBinding)) as SoapBodyBinding;
928 SoapBindingUse bodyUse = (sbb != null) ? sbb.Use : SoapBindingUse.Literal;
930 StringWriter sw = new StringWriter ();
931 XmlTextWriter xtw = new XmlTextWriter (sw);
932 xtw.Formatting = Formatting.Indented;
934 xtw.WriteStartDocument ();
935 xtw.WriteStartElement ("soap", "Envelope", SoapEnvelopeNamespace);
936 xtw.WriteAttributeString ("xmlns", "xsi", null, XmlSchema.InstanceNamespace);
937 xtw.WriteAttributeString ("xmlns", "xsd", null, XmlSchema.Namespace);
939 if (bodyUse == SoapBindingUse.Encoded)
941 xtw.WriteAttributeString ("xmlns", "soapenc", null, SoapEncodingNamespace);
942 xtw.WriteAttributeString ("xmlns", "tns", null, msg.Message.Namespace);
947 bool writtenHeader = false;
948 foreach (object ob in msgbin.Extensions)
950 SoapHeaderBinding hb = ob as SoapHeaderBinding;
951 if (hb == null) continue;
953 if (!writtenHeader) {
954 xtw.WriteStartElement ("soap", "Header", SoapEnvelopeNamespace);
955 writtenHeader = true;
958 WriteHeader (xtw, hb);
962 xtw.WriteEndElement ();
965 xtw.WriteStartElement ("soap", "Body", SoapEnvelopeNamespace);
967 currentUse = bodyUse;
968 WriteBody (xtw, oper, msg, sbb, style);
970 xtw.WriteEndElement ();
971 xtw.WriteEndElement ();
973 return sw.ToString ();
976 void WriteHeader (XmlTextWriter xtw, SoapHeaderBinding header)
978 Message msg = descriptions.GetMessage (header.Message);
979 if (msg == null) throw new InvalidOperationException ("Message " + header.Message + " not found");
980 MessagePart part = msg.Parts [header.Part];
981 if (part == null) throw new InvalidOperationException ("Message part " + header.Part + " not found in message " + header.Message);
983 currentUse = header.Use;
985 if (currentUse == SoapBindingUse.Literal)
986 WriteRootElementSample (xtw, part.Element);
988 WriteTypeSample (xtw, part.Type);
991 void WriteBody (XmlTextWriter xtw, Operation oper, OperationMessage opm, SoapBodyBinding sbb, SoapBindingStyle style)
993 Message msg = descriptions.GetMessage (opm.Message);
994 if (msg.Parts.Count > 0 && msg.Parts[0].Name == "parameters")
996 MessagePart part = msg.Parts[0];
997 if (part.Element == XmlQualifiedName.Empty)
998 WriteTypeSample (xtw, part.Type);
1000 WriteRootElementSample (xtw, part.Element);
1004 string elemName = oper.Name;
1006 if (opm is OperationOutput) elemName += "Response";
1008 if (style == SoapBindingStyle.Rpc) {
1009 xtw.WriteStartElement (elemName, sbb.Namespace);
1013 foreach (MessagePart part in msg.Parts)
1015 if (part.Element == XmlQualifiedName.Empty)
1017 XmlSchemaElement elem = new XmlSchemaElement ();
1018 elem.SchemaTypeName = part.Type;
1019 elem.Name = part.Name;
1020 WriteElementSample (xtw, ns, elem);
1023 WriteRootElementSample (xtw, part.Element);
1026 if (style == SoapBindingStyle.Rpc)
1027 xtw.WriteEndElement ();
1029 WriteQueuedTypeSamples (xtw);
1032 void WriteRootElementSample (XmlTextWriter xtw, XmlQualifiedName qname)
1034 XmlSchemaElement elem = (XmlSchemaElement) schemas.Find (qname, typeof(XmlSchemaElement));
1035 if (elem == null) throw new InvalidOperationException ("Element not found: " + qname);
1036 WriteElementSample (xtw, qname.Namespace, elem);
1039 void WriteElementSample (XmlTextWriter xtw, string ns, XmlSchemaElement elem)
1041 bool sharedAnnType = false;
1042 XmlQualifiedName root;
1044 if (!elem.RefName.IsEmpty) {
1045 XmlSchemaElement refElem = FindRefElement (elem);
1046 if (refElem == null) throw new InvalidOperationException ("Global element not found: " + elem.RefName);
1047 root = elem.RefName;
1049 sharedAnnType = true;
1052 root = new XmlQualifiedName (elem.Name, ns);
1054 if (!elem.SchemaTypeName.IsEmpty)
1056 XmlSchemaComplexType st = FindComplexTyype (elem.SchemaTypeName);
1058 WriteComplexTypeSample (xtw, st, root);
1061 xtw.WriteStartElement (root.Name, root.Namespace);
1062 if (currentUse == SoapBindingUse.Encoded)
1063 xtw.WriteAttributeString ("type", XmlSchema.InstanceNamespace, GetQualifiedNameString (xtw, elem.SchemaTypeName));
1064 xtw.WriteString (GetLiteral (FindBuiltInType (elem.SchemaTypeName)));
1065 xtw.WriteEndElement ();
1068 else if (elem.SchemaType == null)
1070 xtw.WriteStartElement ("any");
1071 xtw.WriteEndElement ();
1074 WriteComplexTypeSample (xtw, (XmlSchemaComplexType) elem.SchemaType, root);
1077 void WriteTypeSample (XmlTextWriter xtw, XmlQualifiedName qname)
1079 XmlSchemaComplexType ctype = FindComplexTyype (qname);
1080 if (ctype != null) {
1081 WriteComplexTypeSample (xtw, ctype, qname);
1085 XmlSchemaSimpleType stype = (XmlSchemaSimpleType) schemas.Find (qname, typeof(XmlSchemaSimpleType));
1086 if (stype != null) {
1087 WriteSimpleTypeSample (xtw, stype);
1091 xtw.WriteString (GetLiteral (FindBuiltInType (qname)));
1092 throw new InvalidOperationException ("Type not found: " + qname);
1095 void WriteComplexTypeSample (XmlTextWriter xtw, XmlSchemaComplexType stype, XmlQualifiedName rootName)
1097 WriteComplexTypeSample (xtw, stype, rootName, -1);
1100 void WriteComplexTypeSample (XmlTextWriter xtw, XmlSchemaComplexType stype, XmlQualifiedName rootName, int id)
1102 string ns = rootName.Namespace;
1104 if (rootName.Name.IndexOf ("[]") != -1) rootName = arrayType;
1106 if (currentUse == SoapBindingUse.Encoded) {
1107 string pref = xtw.LookupPrefix (rootName.Namespace);
1108 if (pref == null) pref = "q1";
1109 xtw.WriteStartElement (pref, rootName.Name, rootName.Namespace);
1113 xtw.WriteStartElement (rootName.Name, rootName.Namespace);
1117 xtw.WriteAttributeString ("id", "id" + id);
1118 if (rootName != arrayType)
1119 xtw.WriteAttributeString ("type", XmlSchema.InstanceNamespace, GetQualifiedNameString (xtw, rootName));
1122 WriteComplexTypeAttributes (xtw, stype);
1123 WriteComplexTypeElements (xtw, ns, stype);
1125 xtw.WriteEndElement ();
1128 void WriteComplexTypeAttributes (XmlTextWriter xtw, XmlSchemaComplexType stype)
1130 WriteAttributes (xtw, stype.Attributes, stype.AnyAttribute);
1133 void WriteComplexTypeElements (XmlTextWriter xtw, string ns, XmlSchemaComplexType stype)
1135 if (stype.Particle != null)
1136 WriteParticleComplexContent (xtw, ns, stype.Particle);
1139 if (stype.ContentModel is XmlSchemaSimpleContent)
1140 WriteSimpleContent (xtw, (XmlSchemaSimpleContent)stype.ContentModel);
1141 else if (stype.ContentModel is XmlSchemaComplexContent)
1142 WriteComplexContent (xtw, ns, (XmlSchemaComplexContent)stype.ContentModel);
1146 void WriteAttributes (XmlTextWriter xtw, XmlSchemaObjectCollection atts, XmlSchemaAnyAttribute anyat)
1148 foreach (XmlSchemaObject at in atts)
1150 if (at is XmlSchemaAttribute)
1153 XmlSchemaAttribute attr = (XmlSchemaAttribute)at;
1154 XmlSchemaAttribute refAttr = attr;
1156 // refAttr.Form; TODO
1158 if (!attr.RefName.IsEmpty) {
1159 refAttr = FindRefAttribute (attr.RefName);
1160 if (refAttr == null) throw new InvalidOperationException ("Global attribute not found: " + attr.RefName);
1164 if (!refAttr.SchemaTypeName.IsEmpty) val = FindBuiltInType (refAttr.SchemaTypeName);
1165 else val = FindBuiltInType ((XmlSchemaSimpleType) refAttr.SchemaType);
1167 xtw.WriteAttributeString (refAttr.Name, val);
1169 else if (at is XmlSchemaAttributeGroupRef)
1171 XmlSchemaAttributeGroupRef gref = (XmlSchemaAttributeGroupRef)at;
1172 XmlSchemaAttributeGroup grp = (XmlSchemaAttributeGroup) schemas.Find (gref.RefName, typeof(XmlSchemaAttributeGroup));
1173 WriteAttributes (xtw, grp.Attributes, grp.AnyAttribute);
1178 xtw.WriteAttributeString ("custom-attribute","value");
1181 void WriteParticleComplexContent (XmlTextWriter xtw, string ns, XmlSchemaParticle particle)
1183 WriteParticleContent (xtw, ns, particle, false);
1186 void WriteParticleContent (XmlTextWriter xtw, string ns, XmlSchemaParticle particle, bool multiValue)
1188 if (particle is XmlSchemaGroupRef)
1189 particle = GetRefGroupParticle ((XmlSchemaGroupRef)particle);
1191 if (particle.MaxOccurs > 1) multiValue = true;
1193 if (particle is XmlSchemaSequence) {
1194 WriteSequenceContent (xtw, ns, ((XmlSchemaSequence)particle).Items, multiValue);
1196 else if (particle is XmlSchemaChoice) {
1197 if (((XmlSchemaChoice)particle).Items.Count == 1)
1198 WriteSequenceContent (xtw, ns, ((XmlSchemaChoice)particle).Items, multiValue);
1200 WriteChoiceContent (xtw, ns, (XmlSchemaChoice)particle, multiValue);
1202 else if (particle is XmlSchemaAll) {
1203 WriteSequenceContent (xtw, ns, ((XmlSchemaAll)particle).Items, multiValue);
1207 void WriteSequenceContent (XmlTextWriter xtw, string ns, XmlSchemaObjectCollection items, bool multiValue)
1209 foreach (XmlSchemaObject item in items)
1210 WriteContentItem (xtw, ns, item, multiValue);
1213 void WriteContentItem (XmlTextWriter xtw, string ns, XmlSchemaObject item, bool multiValue)
1215 if (item is XmlSchemaGroupRef)
1216 item = GetRefGroupParticle ((XmlSchemaGroupRef)item);
1218 if (item is XmlSchemaElement)
1220 XmlSchemaElement elem = (XmlSchemaElement) item;
1221 XmlSchemaElement refElem;
1222 if (!elem.RefName.IsEmpty) refElem = FindRefElement (elem);
1223 else refElem = elem;
1225 int num = (elem.MaxOccurs == 1 && !multiValue) ? 1 : 2;
1226 for (int n=0; n<num; n++)
1228 if (currentUse == SoapBindingUse.Literal)
1229 WriteElementSample (xtw, ns, refElem);
1231 WriteRefTypeSample (xtw, ns, refElem);
1234 else if (item is XmlSchemaAny)
1236 xtw.WriteString (GetLiteral ("xml"));
1238 else if (item is XmlSchemaParticle) {
1239 WriteParticleContent (xtw, ns, (XmlSchemaParticle)item, multiValue);
1243 void WriteChoiceContent (XmlTextWriter xtw, string ns, XmlSchemaChoice choice, bool multiValue)
1245 foreach (XmlSchemaObject item in choice.Items)
1246 WriteContentItem (xtw, ns, item, multiValue);
1249 void WriteSimpleContent (XmlTextWriter xtw, XmlSchemaSimpleContent content)
1251 XmlSchemaSimpleContentExtension ext = content.Content as XmlSchemaSimpleContentExtension;
1253 WriteAttributes (xtw, ext.Attributes, ext.AnyAttribute);
1255 XmlQualifiedName qname = GetContentBaseType (content.Content);
1256 xtw.WriteString (GetLiteral (FindBuiltInType (qname)));
1259 string FindBuiltInType (XmlQualifiedName qname)
1261 if (qname.Namespace == XmlSchema.Namespace)
1264 XmlSchemaComplexType ct = FindComplexTyype (qname);
1267 XmlSchemaSimpleContent sc = ct.ContentModel as XmlSchemaSimpleContent;
1268 if (sc == null) throw new InvalidOperationException ("Invalid schema");
1269 return FindBuiltInType (GetContentBaseType (sc.Content));
1272 XmlSchemaSimpleType st = (XmlSchemaSimpleType) schemas.Find (qname, typeof(XmlSchemaSimpleType));
1274 return FindBuiltInType (st);
1276 throw new InvalidOperationException ("Definition of type " + qname + " not found");
1279 string FindBuiltInType (XmlSchemaSimpleType st)
1281 if (st.Content is XmlSchemaSimpleTypeRestriction) {
1282 return FindBuiltInType (GetContentBaseType (st.Content));
1284 else if (st.Content is XmlSchemaSimpleTypeList) {
1285 string s = FindBuiltInType (GetContentBaseType (st.Content));
1286 return s + " " + s + " ...";
1288 else if (st.Content is XmlSchemaSimpleTypeUnion)
1290 //Check if all types of the union are equal. If not, then will use anyType.
1291 XmlSchemaSimpleTypeUnion uni = (XmlSchemaSimpleTypeUnion) st.Content;
1292 string utype = null;
1294 // Anonymous types are unique
1295 if (uni.BaseTypes.Count != 0 && uni.MemberTypes.Length != 0)
1298 foreach (XmlQualifiedName mt in uni.MemberTypes)
1300 string qn = FindBuiltInType (mt);
1301 if (utype != null && qn != utype) return "string";
1311 XmlQualifiedName GetContentBaseType (XmlSchemaObject ob)
1313 if (ob is XmlSchemaSimpleContentExtension)
1314 return ((XmlSchemaSimpleContentExtension)ob).BaseTypeName;
1315 else if (ob is XmlSchemaSimpleContentRestriction)
1316 return ((XmlSchemaSimpleContentRestriction)ob).BaseTypeName;
1317 else if (ob is XmlSchemaSimpleTypeRestriction)
1318 return ((XmlSchemaSimpleTypeRestriction)ob).BaseTypeName;
1319 else if (ob is XmlSchemaSimpleTypeList)
1320 return ((XmlSchemaSimpleTypeList)ob).ItemTypeName;
1325 void WriteComplexContent (XmlTextWriter xtw, string ns, XmlSchemaComplexContent content)
1327 XmlQualifiedName qname;
1329 XmlSchemaComplexContentExtension ext = content.Content as XmlSchemaComplexContentExtension;
1330 if (ext != null) qname = ext.BaseTypeName;
1332 XmlSchemaComplexContentRestriction rest = (XmlSchemaComplexContentRestriction)content.Content;
1333 qname = rest.BaseTypeName;
1334 if (qname == arrayType) {
1335 ParseArrayType (rest, out qname);
1336 XmlSchemaElement elem = new XmlSchemaElement ();
1338 elem.SchemaTypeName = qname;
1340 xtw.WriteAttributeString ("arrayType", SoapEncodingNamespace, qname.Name + "[2]");
1341 WriteContentItem (xtw, ns, elem, true);
1346 // Add base map members to this map
1347 XmlSchemaComplexType ctype = FindComplexTyype (qname);
1348 WriteComplexTypeAttributes (xtw, ctype);
1351 // Add the members of this map
1352 WriteAttributes (xtw, ext.Attributes, ext.AnyAttribute);
1353 if (ext.Particle != null)
1354 WriteParticleComplexContent (xtw, ns, ext.Particle);
1357 WriteComplexTypeElements (xtw, ns, ctype);
1360 void ParseArrayType (XmlSchemaComplexContentRestriction rest, out XmlQualifiedName qtype)
1362 XmlSchemaAttribute arrayTypeAt = FindArrayAttribute (rest.Attributes);
1363 XmlAttribute[] uatts = arrayTypeAt.UnhandledAttributes;
1364 if (uatts == null || uatts.Length == 0) throw new InvalidOperationException ("arrayType attribute not specified in array declaration");
1366 XmlAttribute xat = null;
1367 foreach (XmlAttribute at in uatts)
1368 if (at.LocalName == "arrayType" && at.NamespaceURI == WsdlNamespace)
1369 { xat = at; break; }
1372 throw new InvalidOperationException ("arrayType attribute not specified in array declaration");
1374 string arrayType = xat.Value;
1376 int i = arrayType.LastIndexOf (":");
1377 if (i == -1) ns = "";
1378 else ns = arrayType.Substring (0,i);
1380 int j = arrayType.IndexOf ("[", i+1);
1381 if (j == -1) throw new InvalidOperationException ("Cannot parse WSDL array type: " + arrayType);
1382 type = arrayType.Substring (i+1);
1383 type = type.Substring (0, type.Length-2);
1385 qtype = new XmlQualifiedName (type, ns);
1388 XmlSchemaAttribute FindArrayAttribute (XmlSchemaObjectCollection atts)
1390 foreach (object ob in atts)
1392 XmlSchemaAttribute att = ob as XmlSchemaAttribute;
1393 if (att != null && att.RefName == arrayTypeRefName) return att;
1395 XmlSchemaAttributeGroupRef gref = ob as XmlSchemaAttributeGroupRef;
1398 XmlSchemaAttributeGroup grp = (XmlSchemaAttributeGroup) schemas.Find (gref.RefName, typeof(XmlSchemaAttributeGroup));
1399 att = FindArrayAttribute (grp.Attributes);
1400 if (att != null) return att;
1406 void WriteSimpleTypeSample (XmlTextWriter xtw, XmlSchemaSimpleType stype)
1408 xtw.WriteString (GetLiteral (FindBuiltInType (stype)));
1411 XmlSchemaParticle GetRefGroupParticle (XmlSchemaGroupRef refGroup)
1413 XmlSchemaGroup grp = (XmlSchemaGroup) schemas.Find (refGroup.RefName, typeof (XmlSchemaGroup));
1414 return grp.Particle;
1417 XmlSchemaElement FindRefElement (XmlSchemaElement elem)
1419 if (elem.RefName.Namespace == XmlSchema.Namespace)
1421 if (anyElement != null) return anyElement;
1422 anyElement = new XmlSchemaElement ();
1423 anyElement.Name = "any";
1424 anyElement.SchemaTypeName = anyType;
1427 return (XmlSchemaElement) schemas.Find (elem.RefName, typeof(XmlSchemaElement));
1430 XmlSchemaAttribute FindRefAttribute (XmlQualifiedName refName)
1432 if (refName.Namespace == XmlSchema.Namespace)
1434 XmlSchemaAttribute at = new XmlSchemaAttribute ();
1435 at.Name = refName.Name;
1436 at.SchemaTypeName = new XmlQualifiedName ("string",XmlSchema.Namespace);
1439 return (XmlSchemaAttribute) schemas.Find (refName, typeof(XmlSchemaAttribute));
1442 void WriteRefTypeSample (XmlTextWriter xtw, string ns, XmlSchemaElement elem)
1444 if (elem.SchemaTypeName.Namespace == XmlSchema.Namespace || schemas.Find (elem.SchemaTypeName, typeof(XmlSchemaSimpleType)) != null)
1445 WriteElementSample (xtw, ns, elem);
1448 xtw.WriteStartElement (elem.Name, ns);
1449 xtw.WriteAttributeString ("href", "#id" + (queue.Count+1));
1450 xtw.WriteEndElement ();
1451 queue.Add (new EncodedType (ns, elem));
1455 void WriteQueuedTypeSamples (XmlTextWriter xtw)
1457 for (int n=0; n<queue.Count; n++)
1459 EncodedType ec = (EncodedType) queue[n];
1460 XmlSchemaComplexType st = FindComplexTyype (ec.Element.SchemaTypeName);
1461 WriteComplexTypeSample (xtw, st, ec.Element.SchemaTypeName, n+1);
1465 XmlSchemaComplexType FindComplexTyype (XmlQualifiedName qname)
1467 if (qname.Name.IndexOf ("[]") != -1)
1469 XmlSchemaComplexType stype = new XmlSchemaComplexType ();
1470 stype.ContentModel = new XmlSchemaComplexContent ();
1472 XmlSchemaComplexContentRestriction res = new XmlSchemaComplexContentRestriction ();
1473 stype.ContentModel.Content = res;
1474 res.BaseTypeName = arrayType;
1476 XmlSchemaAttribute att = new XmlSchemaAttribute ();
1477 att.RefName = arrayTypeRefName;
1478 res.Attributes.Add (att);
1480 XmlAttribute xat = document.CreateAttribute ("arrayType", WsdlNamespace);
1481 xat.Value = qname.Namespace + ":" + qname.Name;
1482 att.UnhandledAttributes = new XmlAttribute[] {xat};
1486 return (XmlSchemaComplexType) schemas.Find (qname, typeof(XmlSchemaComplexType));
1489 string GetQualifiedNameString (XmlTextWriter xtw, XmlQualifiedName qname)
1491 string pref = xtw.LookupPrefix (qname.Namespace);
1492 if (pref != null) return pref + ":" + qname.Name;
1494 xtw.WriteAttributeString ("xmlns", "q1", null, qname.Namespace);
1495 return "q1:" + qname.Name;
1498 protected virtual string GetLiteral (string s)
1503 void GetOperationFormat (OperationBinding obin, out SoapBindingStyle style, out SoapBindingUse use)
1505 style = SoapBindingStyle.Document;
1506 use = SoapBindingUse.Literal;
1507 SoapOperationBinding sob = obin.Extensions.Find (typeof(SoapOperationBinding)) as SoapOperationBinding;
1510 SoapBodyBinding sbb = obin.Input.Extensions.Find (typeof(SoapBodyBinding)) as SoapBodyBinding;
1523 <head runat="server">
1525 Response.Write ("<link rel=\"alternate\" type=\"text/xml\" href=\"" + Request.FilePath + "?disco\"/>");
1527 <title><%=WebServiceName%> Web Service</title>
1528 <style type="text/css">
1529 BODY { font-family: Arial; margin-left: 20px; margin-top: 20px; font-size: x-small}
1530 TABLE { font-size: x-small }
1531 .title { color:dimgray; font-family: Arial; font-size:20pt; font-weight:900}
1532 .operationTitle { color:dimgray; font-family: Arial; font-size:15pt; font-weight:900}
1533 .method { font-size: x-small }
1534 .bindingLabel { font-size: x-small; font-weight:bold; color:darkgray; line-height:8pt; display:block; margin-bottom:3px }
1535 .label { font-size: small; font-weight:bold; color:darkgray }
1536 .paramTable { font-size: x-small }
1537 .paramTable TR { background-color: gainsboro }
1538 .paramFormTable { font-size: x-small; padding: 10px; background-color: gainsboro }
1539 .paramFormTable TR { background-color: gainsboro }
1540 .paramInput { border: solid 1px gray }
1541 .button {border: solid 1px gray }
1542 .smallSeparator { height:3px; overflow:hidden }
1543 .panel { background-color:whitesmoke; border: solid 1px silver; border-top: solid 1px silver }
1544 .codePanel { background-color: white; font-size:x-small; padding:7px; border:solid 1px silver}
1545 .code-xml { font-size:10pt; font-family:courier }
1546 .code-cs { font-size:10pt; font-family:courier }
1547 .code-vb { font-size:10pt; font-family:courier }
1548 .tabLabelOn { font-weight:bold }
1549 .tabLabelOff {color: darkgray }
1550 .literal-placeholder {color: darkblue; font-weight:bold}
1551 A:link { color: black; }
1552 A:visited { color: black; }
1553 A:active { color: black; }
1554 A:hover { color: blue }
1557 <script language="javascript" type="text/javascript">
1559 function getXML (command, url, qs) {
1560 if (url == "" || url.substring (0, 4) != "http")
1563 var post_data = null;
1565 req.onreadystatechange = stateChange;
1566 if (command == "GET") {
1567 url = url + "?" + qs;
1571 req.open (command, url, true);
1572 if (command == "POST")
1573 req.setRequestHeader ("Content-Type", "application/x-www-form-urlencoded");
1574 req.send (post_data);
1577 function stateChange () {
1578 if (req.readyState == 4) {
1579 var node = document.getElementById("testresult_div");
1581 if (req.status == 200) {
1582 node.innerHTML = "<div class='code-xml'>" + formatXml (req.responseText) + "</div>";
1584 var ht = "<b style='color: red'>" + formatXml (req.status + " - " + req.statusText) + "</b>";
1585 if (req.responseText != "")
1586 ht = ht + "\n<div class='code-xml'>" + formatXml (req.responseText) + "</div>";
1587 node.innerHTML = ht;
1593 function formatXml (text)
1596 text = text.replace (re, " ");
1599 text = text.replace (re, " ");
1601 re = /\<\s*(\/?)\s*(.*?)\s*(\/?)\s*\>/g;
1602 text = text.replace (re,"{blue:<$1}{maroon:$2}{blue:$3>}");
1604 re = /{(\w*):(.*?)}/g;
1605 text = text.replace (re,"<span style='color:$1'>$2</span>");
1608 text = text.replace (re,"\"<span style='color:purple'>$1</span>\"");
1611 text = text.replace (re, "<br/>");
1616 function getReq () {
1617 if (window.XMLHttpRequest) {
1618 return new XMLHttpRequest(); // Firefox, Safari, ...
1619 } else if (window.ActiveXObject) {
1620 return new ActiveXObject("Microsoft.XMLHTTP");
1624 function clearForm ()
1626 document.getElementById("testFormResult").style.display="none";
1633 <div class="title" style="margin-left:20px">
1634 <span class="label">Web Service</span><br>
1639 **********************************************************
1643 <table border="0" width="100%" cellpadding="15px" cellspacing="15px">
1644 <tr valign="top"><td width="150px" class="panel">
1645 <div style="width:150px"></div>
1646 <a class="method" href='<%=PageName%>'>Overview</a><br>
1647 <div class="smallSeparator"></div>
1648 <a class="method" href='<%=PageName + "?" + GetPageContext("wsdl")%>'>Service Description</a>
1649 <div class="smallSeparator"></div>
1650 <a class="method" href='<%=PageName + "?" + GetPageContext("proxy")%>'>Client proxy</a>
1652 <asp:repeater id="BindingsRepeater" runat=server>
1653 <itemtemplate name="itemtemplate">
1654 <span class="bindingLabel"><%#FormatBindingName(DataBinder.Eval(Container.DataItem, "Name").ToString())%></span>
1655 <asp:repeater id="OperationsRepeater" runat=server datasource='<%# ((Binding)Container.DataItem).Operations %>'>
1657 <a class="method" href="<%=PageName%>?<%=GetTabContext("op",null)%>op=<%#GetOpName(Container.DataItem)%>&bnd=<%#DataBinder.Eval(Container.DataItem, "Binding.Name")%>"><%#GetOpName(Container.DataItem)%></a>
1658 <div class="smallSeparator"></div>
1665 </td><td class="panel">
1667 <% if (CurrentPage == "main") {%>
1670 **********************************************************
1671 Web service overview
1674 <p class="label">Web Service Overview</p>
1675 <%=WebServiceDescription%>
1677 <% if (ProfileViolations != null && ProfileViolations.Count > 0) { %>
1678 <p class="label">Basic Profile Conformance</p>
1679 This web service does not conform to WS-I Basic Profile v1.1
1681 Response.Write ("<ul>");
1682 foreach (BasicProfileViolation vio in ProfileViolations) {
1683 Response.Write ("<li><b>" + vio.NormativeStatement + "</b>: " + vio.Details);
1684 Response.Write ("<ul>");
1685 foreach (string ele in vio.Elements)
1686 Response.Write ("<li>" + ele + "</li>");
1687 Response.Write ("</ul>");
1688 Response.Write ("</li>");
1690 Response.Write ("</ul>");
1693 <%} if (DefaultBinding == null) {%>
1694 This service does not contain any public web method.
1695 <%} else if (CurrentPage == "op") {%>
1698 **********************************************************
1699 Operation description
1702 <span class="operationTitle"><%=CurrentOperationName%></span>
1707 <% if (CurrentTab == "main") { %>
1708 <span class="label">Input Parameters</span>
1709 <div class="smallSeparator"></div>
1710 <% if (InParams.Count == 0) { %>
1711 No input parameters<br>
1713 <table class="paramTable" cellspacing="1" cellpadding="5">
1714 <asp:repeater id="InputParamsRepeater" runat=server>
1717 <td width="150"><%#DataBinder.Eval(Container.DataItem, "Name")%></td>
1718 <td width="150"><%#DataBinder.Eval(Container.DataItem, "Type")%></td>
1726 <% if (OutParams.Count > 0) { %>
1727 <span class="label">Output Parameters</span>
1728 <div class="smallSeparator"></div>
1729 <table class="paramTable" cellspacing="1" cellpadding="5">
1730 <asp:repeater id="OutputParamsRepeater" runat=server>
1733 <td width="150"><%#DataBinder.Eval(Container.DataItem, "Name")%></td>
1734 <td width="150"><%#DataBinder.Eval(Container.DataItem, "Type")%></td>
1742 <span class="label">Remarks</span>
1743 <div class="smallSeparator"></div>
1744 <%=OperationDocumentation%>
1746 <span class="label">Technical information</span>
1747 <div class="smallSeparator"></div>
1748 Format: <%=CurrentOperationFormat%>
1749 <br>Supported protocols: <%=CurrentOperationProtocols%>
1753 **********************************************************
1754 Operation description - Test form
1757 <% if (CurrentTab == "test") {
1758 if (CurrentOperationSupportsTest) {%>
1759 Enter values for the parameters and click the 'Invoke' button to test this method:<br><br>
1760 <form action="<%=PageName%>" method="GET">
1761 <input type="hidden" name="page" value="<%=CurrentPage%>">
1762 <input type="hidden" name="tab" value="<%=CurrentTab%>">
1763 <input type="hidden" name="op" value="<%=CurrentOperationName%>">
1764 <input type="hidden" name="bnd" value="<%=CurrentOperationBinding%>">
1765 <input type="hidden" name="ext" value="testform">
1766 <table class="paramFormTable" cellspacing="0" cellpadding="3">
1767 <asp:repeater id="InputFormParamsRepeater" runat=server>
1770 <td><%#DataBinder.Eval(Container.DataItem, "Name")%>: </td>
1771 <td width="150"><input class="paramInput" type="text" size="20" name="<%#DataBinder.Eval(Container.DataItem, "Name")%>"></td>
1775 <tr><td></td><td><input class="button" type="submit" value="Invoke"> <input class="button" type="button" onclick="clearForm()" value="Clear"></td></tr>
1778 <div id="testFormResult" style="display:<%= (HasFormResult?"block":"none") %>">
1779 The web service returned the following result:<br/><br/>
1780 <div class="codePanel" id="testresult_div">
1782 <script language="javascript">
1783 getXML ("<%= GetOrPost () %>", "<%= GetTestResultUrl () %>", "<%= GetQS () %>");
1787 The test form is not available for this operation because it has parameters with a complex structure.
1792 **********************************************************
1793 Operation description - Message Layout
1796 <% if (CurrentTab == "msg") { %>
1798 The following are sample SOAP requests and responses for each protocol supported by this method:
1801 <% if (IsOperationSupported ("Soap")) { %>
1802 <span class="label">Soap</span>
1804 <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("Soap", true)%></div></div>
1806 <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("Soap", false)%></div></div>
1809 <% if (IsOperationSupported ("HttpGet")) { %>
1810 <span class="label">HTTP Get</span>
1812 <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("HttpGet", true)%></div></div>
1814 <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("HttpGet", false)%></div></div>
1817 <% if (IsOperationSupported ("HttpPost")) { %>
1818 <span class="label">HTTP Post</span>
1820 <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("HttpPost", true)%></div></div>
1822 <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("HttpPost", false)%></div></div>
1827 <%} else if (CurrentPage == "proxy") {%>
1829 **********************************************************
1832 <form action="<%=PageName%>" name="langForm" method="GET">
1833 Select the language for which you want to generate a proxy
1834 <input type="hidden" name="page" value="<%=CurrentPage%>">
1835 <SELECT name="lang" onchange="langForm.submit()">
1836 <%=GetOptionSel("cs",CurrentLanguage)%>C#</option>
1837 <%=GetOptionSel("vb",CurrentLanguage)%>Visual Basic</option>
1842 <span class="label"><%=CurrentProxytName%></span>
1843 <a href="<%=PageName + "?code=" + CurrentLanguage%>">Download</a>
1845 <div class="codePanel">
1846 <div class="code-<%=CurrentLanguage%>"><%=GetProxyCode ()%></div>
1848 <%} else if (CurrentPage == "wsdl") {%>
1850 **********************************************************
1853 <% if (descriptions.Count > 1 || schemas.Count > 1) {%>
1854 The description of this web service is composed by several documents. Click on the document you want to see:
1858 for (int n=0; n<descriptions.Count; n++)
1859 Response.Write ("<li><a href='" + PageName + "?" + GetPageContext(null) + "doctype=wsdl&docind=" + n + "'>WSDL document " + descriptions[n].TargetNamespace + "</a></li>");
1860 for (int n=0; n<schemas.Count; n++)
1861 Response.Write ("<li><a href='" + PageName + "?" + GetPageContext(null) + "doctype=schema&docind=" + n + "'>Xml Schema " + schemas[n].TargetNamespace + "</a></li>");
1868 <span class="label"><%=CurrentDocumentName%></span>
1869 <a href="<%=PageName + "?" + CurrentDocType + "=" + CurrentDocInd %>">Download</a>
1871 <div class="codePanel">
1872 <div class="code-xml"><%=GenerateDocument ()%></div>
1877 <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
1879 <td width="20px"></td>