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 ArrayList prots = FindServiceProtocols (CurrentOperationName);
126 for (int n=0; n<prots.Count; n++) {
127 if (n != 0) CurrentOperationProtocols += ", ";
128 CurrentOperationProtocols += (string) prots[n];
131 WebServiceProtocols testProtocols = WebServiceProtocols.HttpGet | WebServiceProtocols.HttpPost;
132 if (Context.Request.IsLocal)
133 testProtocols |= WebServiceProtocols.HttpPostLocalhost;
134 CurrentOperationSupportsTest = (WebServicesSection.Current.EnabledProtocols & testProtocols) != 0;
137 OperationBinding obin = FindOperation (binding, CurrentOperationName);
139 CurrentOperationFormat = GetOperationFormat (obin);
141 InputParamsRepeater.DataSource = InParams;
142 InputFormParamsRepeater.DataSource = InParams;
143 OutputParamsRepeater.DataSource = OutParams;
146 void BuildParameters (ArrayList list, OperationMessage opm)
148 Message msg = descriptions.GetMessage (opm.Message);
149 if (msg.Parts.Count > 0 && msg.Parts[0].Name == "parameters")
151 MessagePart part = msg.Parts[0];
152 XmlSchemaComplexType ctype;
153 if (part.Element == XmlQualifiedName.Empty)
155 ctype = (XmlSchemaComplexType) schemas.Find (part.Type, typeof(XmlSchemaComplexType));
159 XmlSchemaElement elem = (XmlSchemaElement) schemas.Find (part.Element, typeof(XmlSchemaElement));
160 ctype = (XmlSchemaComplexType) elem.SchemaType;
162 XmlSchemaSequence seq = ctype.Particle as XmlSchemaSequence;
163 if (seq == null) return;
165 foreach (XmlSchemaObject ob in seq.Items)
167 Parameter p = new Parameter();
168 p.Description = "No additional remarks";
170 if (ob is XmlSchemaElement)
172 XmlSchemaElement selem = GetRefElement ((XmlSchemaElement)ob);
174 p.Type = selem.SchemaTypeName.Name;
186 foreach (MessagePart part in msg.Parts)
188 Parameter p = new Parameter ();
189 p.Description = "No additional remarks";
191 if (part.Element == XmlQualifiedName.Empty)
192 p.Type = part.Type.Name;
195 XmlSchemaElement elem = (XmlSchemaElement) schemas.Find (part.Element, typeof(XmlSchemaElement));
196 p.Type = elem.SchemaTypeName.Name;
203 string GetOperationFormat (OperationBinding obin)
206 SoapOperationBinding sob = obin.Extensions.Find (typeof(SoapOperationBinding)) as SoapOperationBinding;
208 format = sob.Style.ToString ();
209 SoapBodyBinding sbb = obin.Input.Extensions.Find (typeof(SoapBodyBinding)) as SoapBodyBinding;
211 format += " / " + sbb.Use;
216 XmlSchemaElement GetRefElement (XmlSchemaElement elem)
218 if (!elem.RefName.IsEmpty)
219 return (XmlSchemaElement) schemas.Find (elem.RefName, typeof(XmlSchemaElement));
224 ArrayList FindServiceProtocols(string operName)
226 ArrayList table = new ArrayList ();
227 Service service = descriptions[0].Services[0];
228 foreach (Port port in service.Ports)
231 Binding bin = descriptions.GetBinding (port.Binding);
232 if (bin.Extensions.Find (typeof(SoapBinding)) != null)
236 HttpBinding hb = (HttpBinding) bin.Extensions.Find (typeof(HttpBinding));
237 if (hb != null && hb.Verb == "POST") prot = "HttpPost";
238 else if (hb != null && hb.Verb == "GET") prot = "HttpGet";
241 if (prot != null && operName != null)
243 if (FindOperation (bin, operName) == null)
247 if (prot != null && !table.Contains (prot))
253 Port FindPort (string portName, string protocol)
255 Service service = descriptions[0].Services[0];
256 foreach (Port port in service.Ports)
258 if (portName == null)
260 Binding binding = descriptions.GetBinding (port.Binding);
261 if (GetProtocol (binding) == protocol) return port;
263 else if (port.Name == portName)
269 string GetProtocol (Binding binding)
271 if (binding.Extensions.Find (typeof(SoapBinding)) != null) return "Soap";
272 HttpBinding hb = (HttpBinding) binding.Extensions.Find (typeof(HttpBinding));
273 if (hb == null) return "";
274 if (hb.Verb == "POST") return "HttpPost";
275 if (hb.Verb == "GET") return "HttpGet";
280 Operation FindOperation (PortType portType, string name)
282 foreach (Operation oper in portType.Operations) {
283 if (oper.Messages.Input.Name != null) {
284 if (oper.Messages.Input.Name == name) return oper;
287 if (oper.Name == name) return oper;
293 OperationBinding FindOperation (Binding binding, string name)
295 foreach (OperationBinding oper in binding.Operations) {
296 if (oper.Input.Name != null) {
297 if (oper.Input.Name == name) return oper;
300 if (oper.Name == name) return oper;
306 string FormatBindingName (string name)
308 if (name == DefaultBinding) return "Methods";
309 else return "Methods for binding<br>" + name;
312 string GetOpName (object op)
314 OperationBinding ob = op as OperationBinding;
315 if (ob == null) return "";
316 if (ob.Input.Name != null) return ob.Input.Name;
322 get { return Request.QueryString ["ext"] == "testform"; }
325 class NoCheckCertificatePolicy : ICertificatePolicy {
326 public bool CheckValidationResult (ServicePoint a, X509Certificate b, WebRequest c, int d)
334 return (CurrentOperationProtocols.IndexOf ("HttpGet") >= 0) ? "GET" : "POST";
341 NameValueCollection query_string = Request.QueryString;
342 for (int n = 0; n < query_string.Count; n++) {
344 if (qs != "") qs += "&";
345 qs += query_string.GetKey(n) + "=" + Server.UrlEncode (query_string [n]);
347 if (query_string.GetKey(n) == "ext") fill = true;
353 string GetTestResultUrl ()
355 if (!HasFormResult) return "";
357 string location = null;
358 ServiceDescription desc = descriptions [0];
359 Service service = desc.Services[0];
360 foreach (Port port in service.Ports)
361 if (port.Name == CurrentOperationBinding)
363 SoapAddressBinding sbi = (SoapAddressBinding) port.Extensions.Find (typeof(SoapAddressBinding));
365 location = sbi.Location;
368 if (location == null)
369 return "Could not locate web service";
371 return location + "/" + CurrentOperationName;
374 string GenerateOperationMessages (string protocol, bool generateInput)
376 if (!IsOperationSupported (protocol)) return "";
379 if (protocol != "Soap") port = FindPort (null, protocol);
380 else port = FindPort (CurrentOperationBinding, null);
382 Binding binding = descriptions.GetBinding (port.Binding);
383 OperationBinding obin = FindOperation (binding, CurrentOperationName);
384 PortType portType = descriptions.GetPortType (binding.Type);
385 Operation oper = FindOperation (portType, CurrentOperationName);
387 HtmlSampleGenerator sg = new HtmlSampleGenerator (descriptions, schemas);
388 string txt = sg.GenerateMessage (port, obin, oper, protocol, generateInput);
389 if (protocol == "Soap") txt = WrapText (txt,CodeTextColumns);
390 txt = ColorizeXml (txt);
391 txt = txt.Replace ("@placeholder!","<span class='literal-placeholder'>");
392 txt = txt.Replace ("!placeholder@","</span>");
396 bool IsOperationSupported (string protocol)
398 if (CurrentPage != "op" || CurrentTab != "msg") return false;
399 if (protocol == "Soap") return true;
401 Port port = FindPort (null, protocol);
402 if (port == null) return false;
403 Binding binding = descriptions.GetBinding (port.Binding);
404 if (binding == null) return false;
405 return FindOperation (binding, CurrentOperationName) != null;
409 // Proxy code generation
412 string GetProxyCode ()
414 CodeNamespace codeNamespace = new CodeNamespace();
415 CodeCompileUnit codeUnit = new CodeCompileUnit();
417 codeUnit.Namespaces.Add (codeNamespace);
419 ServiceDescriptionImporter importer = new ServiceDescriptionImporter();
421 foreach (ServiceDescription sd in descriptions)
422 importer.AddServiceDescription(sd, null, null);
424 foreach (XmlSchema sc in schemas)
425 importer.Schemas.Add (sc);
427 importer.Import(codeNamespace, codeUnit);
429 string langId = Request.QueryString ["lang"];
430 if (langId == null || langId == "") langId = "cs";
431 CodeDomProvider provider = GetProvider (langId);
432 ICodeGenerator generator = provider.CreateGenerator();
433 CodeGeneratorOptions options = new CodeGeneratorOptions();
435 StringWriter sw = new StringWriter ();
436 generator.GenerateCodeFromCompileUnit(codeUnit, sw, options);
438 return Colorize (WrapText (sw.ToString (), CodeTextColumns), langId);
441 public string CurrentLanguage
444 string langId = Request.QueryString ["lang"];
445 if (langId == null || langId == "") langId = "cs";
450 public string CurrentProxytName
453 string lan = CurrentLanguage == "cs" ? "C#" : "Visual Basic";
454 return lan + " Client Proxy";
458 private CodeDomProvider GetProvider(string langId)
460 switch (langId.ToUpper())
462 case "CS": return new CSharpCodeProvider();
463 case "VB": return new VBCodeProvider();
464 default: return null;
469 // Document generation
472 string GenerateDocument ()
474 StringWriter sw = new StringWriter ();
476 if (CurrentDocType == "wsdl")
477 descriptions [CurrentDocInd].Write (sw);
478 else if (CurrentDocType == "schema")
479 schemas [CurrentDocInd].Write (sw);
481 return Colorize (WrapText (sw.ToString (), CodeTextColumns), "xml");
484 public string CurrentDocType
486 get { return Request.QueryString ["doctype"] != null ? Request.QueryString ["doctype"] : "wsdl"; }
489 public int CurrentDocInd
491 get { return Request.QueryString ["docind"] != null ? int.Parse (Request.QueryString ["docind"]) : 0; }
494 public string CurrentDocumentName
497 if (CurrentDocType == "wsdl")
498 return "WSDL document for namespace \"" + descriptions [CurrentDocInd].TargetNamespace + "\"";
500 return "Xml Schema for namespace \"" + schemas [CurrentDocInd].TargetNamespace + "\"";
508 bool firstTab = true;
509 ArrayList disabledTabs = new ArrayList ();
513 get { return Request.QueryString["tab"] != null ? Request.QueryString["tab"] : "main" ; }
518 get { return Request.QueryString["page"] != null ? Request.QueryString["page"] : "main" ; }
523 if (CurrentOperationName != null)
525 WriteTab ("main","Overview");
526 WriteTab ("test","Test Form");
527 WriteTab ("msg","Message Layout");
531 void WriteTab (string id, string label)
533 if (!firstTab) Response.Write(" | ");
536 string cname = CurrentTab == id ? "tabLabelOn" : "tabLabelOff";
537 Response.Write ("<a href='" + PageName + "?" + GetPageContext(null) + GetDataContext() + "tab=" + id + "' style='text-decoration:none'>");
538 Response.Write ("<span class='" + cname + "'>" + label + "</span>");
539 Response.Write ("</a>");
542 string GetTabContext (string pag, string tab)
544 if (tab == null) tab = CurrentTab;
545 if (pag == null) pag = CurrentPage;
546 if (pag != CurrentPage) tab = "main";
547 return "page=" + pag + "&tab=" + tab + "&";
550 string GetPageContext (string pag)
552 if (pag == null) pag = CurrentPage;
553 return "page=" + pag + "&";
566 static string keywords_cs =
567 "(\\babstract\\b|\\bevent\\b|\\bnew\\b|\\bstruct\\b|\\bas\\b|\\bexplicit\\b|\\bnull\\b|\\bswitch\\b|\\bbase\\b|\\bextern\\b|" +
568 "\\bobject\\b|\\bthis\\b|\\bbool\\b|\\bfalse\\b|\\boperator\\b|\\bthrow\\b|\\bbreak\\b|\\bfinally\\b|\\bout\\b|\\btrue\\b|" +
569 "\\bbyte\\b|\\bfixed\\b|\\boverride\\b|\\btry\\b|\\bcase\\b|\\bfloat\\b|\\bparams\\b|\\btypeof\\b|\\bcatch\\b|\\bfor\\b|" +
570 "\\bprivate\\b|\\buint\\b|\\bchar\\b|\\bforeach\\b|\\bprotected\\b|\\bulong\\b|\\bchecked\\b|\\bgoto\\b|\\bpublic\\b|" +
571 "\\bunchecked\\b|\\bclass\\b|\\bif\\b|\\breadonly\\b|\\bunsafe\\b|\\bconst\\b|\\bimplicit\\b|\\bref\\b|\\bushort\\b|" +
572 "\\bcontinue\\b|\\bin\\b|\\breturn\\b|\\busing\\b|\\bdecimal\\b|\\bint\\b|\\bsbyte\\b|\\bvirtual\\b|\\bdefault\\b|" +
573 "\\binterface\\b|\\bsealed\\b|\\bvolatile\\b|\\bdelegate\\b|\\binternal\\b|\\bshort\\b|\\bvoid\\b|\\bdo\\b|\\bis\\b|" +
574 "\\bsizeof\\b|\\bwhile\\b|\\bdouble\\b|\\block\\b|\\bstackalloc\\b|\\belse\\b|\\blong\\b|\\bstatic\\b|\\benum\\b|" +
575 "\\bnamespace\\b|\\bstring\\b)";
577 static string keywords_vb =
578 "(\\bAddHandler\\b|\\bAddressOf\\b|\\bAlias\\b|\\bAnd\\b|\\bAndAlso\\b|\\bAnsi\\b|\\bAs\\b|\\bAssembly\\b|" +
579 "\\bAuto\\b|\\bBoolean\\b|\\bByRef\\b|\\bByte\\b|\\bByVal\\b|\\bCall\\b|\\bCase\\b|\\bCatch\\b|" +
580 "\\bCBool\\b|\\bCByte\\b|\\bCChar\\b|\\bCDate\\b|\\bCDec\\b|\\bCDbl\\b|\\bChar\\b|\\bCInt\\b|" +
581 "\\bClass\\b|\\bCLng\\b|\\bCObj\\b|\\bConst\\b|\\bCShort\\b|\\bCSng\\b|\\bCStr\\b|\\bCType\\b|" +
582 "\\bDate\\b|\\bDecimal\\b|\\bDeclare\\b|\\bDefault\\b|\\bDelegate\\b|\\bDim\\b|\\bDirectCast\\b|\\bDo\\b|" +
583 "\\bDouble\\b|\\bEach\\b|\\bElse\\b|\\bElseIf\\b|\\bEnd\\b|\\bEnum\\b|\\bErase\\b|\\bError\\b|" +
584 "\\bEvent\\b|\\bExit\\b|\\bFalse\\b|\\bFinally\\b|\\bFor\\b|\\bFriend\\b|\\bFunction\\b|\\bGet\\b|" +
585 "\\bGetType\\b|\\bGoSub\\b|\\bGoTo\\b|\\bHandles\\b|\\bIf\\b|\\bImplements\\b|\\bImports\\b|\\bIn\\b|" +
586 "\\bInherits\\b|\\bInteger\\b|\\bInterface\\b|\\bIs\\b|\\bLet\\b|\\bLib\\b|\\bLike\\b|\\bLong\\b|" +
587 "\\bLoop\\b|\\bMe\\b|\\bMod\\b|\\bModule\\b|\\bMustInherit\\b|\\bMustOverride\\b|\\bMyBase\\b|\\bMyClass\\b|" +
588 "\\bNamespace\\b|\\bNew\\b|\\bNext\\b|\\bNot\\b|\\bNothing\\b|\\bNotInheritable\\b|\\bNotOverridable\\b|\\bObject\\b|" +
589 "\\bOn\\b|\\bOption\\b|\\bOptional\\b|\\bOr\\b|\\bOrElse\\b|\\bOverloads\\b|\\bOverridable\\b|\\bOverrides\\b|" +
590 "\\bParamArray\\b|\\bPreserve\\b|\\bPrivate\\b|\\bProperty\\b|\\bProtected\\b|\\bPublic\\b|\\bRaiseEvent\\b|\\bReadOnly\\b|" +
591 "\\bReDim\\b|\\bREM\\b|\\bRemoveHandler\\b|\\bResume\\b|\\bReturn\\b|\\bSelect\\b|\\bSet\\b|\\bShadows\\b|" +
592 "\\bShared\\b|\\bShort\\b|\\bSingle\\b|\\bStatic\\b|\\bStep\\b|\\bStop\\b|\\bString\\b|\\bStructure\\b|" +
593 "\\bSub\\b|\\bSyncLock\\b|\\bThen\\b|\\bThrow\\b|\\bTo\\b|\\bTrue\\b|\\bTry\\b|\\bTypeOf\\b|" +
594 "\\bUnicode\\b|\\bUntil\\b|\\bVariant\\b|\\bWhen\\b|\\bWhile\\b|\\bWith\\b|\\bWithEvents\\b|\\bWriteOnly\\b|\\bXor\\b)";
596 string Colorize (string text, string lang)
598 if (lang == "xml") return ColorizeXml (text);
599 else if (lang == "cs") return ColorizeCs (text);
600 else if (lang == "vb") return ColorizeVb (text);
604 string ColorizeXml (string text)
606 text = text.Replace (" ", " ");
607 Regex re = new Regex ("\r\n|\r|\n");
608 text = re.Replace (text, "_br_");
610 re = new Regex ("<\\s*(\\/?)\\s*([\\s\\S]*?)\\s*(\\/?)\\s*>");
611 text = re.Replace (text,"{blue:<$1}{maroon:$2}{blue:$3>}");
613 re = new Regex ("\\{(\\w*):([\\s\\S]*?)\\}");
614 text = re.Replace (text,"<span style='color:$1'>$2</span>");
616 re = new Regex ("\"(.*?)\"");
617 text = re.Replace (text,"\"<span style='color:purple'>$1</span>\"");
620 text = text.Replace ("\t", " ");
621 text = text.Replace ("_br_", "<br>");
625 string ColorizeCs (string text)
627 text = text.Replace (" ", " ");
629 text = text.Replace ("<", "<");
630 text = text.Replace (">", ">");
632 Regex re = new Regex ("\"((((?!\").)|\\\")*?)\"");
633 text = re.Replace (text,"<span style='color:purple'>\"$1\"</span>");
635 re = new Regex ("//(((.(?!\"</span>))|\"(((?!\").)*)\"</span>)*)(\r|\n|\r\n)");
636 text = re.Replace (text,"<span style='color:green'>//$1</span><br/>");
638 re = new Regex (keywords_cs);
639 text = re.Replace (text,"<span style='color:blue'>$1</span>");
641 text = text.Replace ("\t"," ");
642 text = text.Replace ("\n","<br/>");
647 string ColorizeVb (string text)
649 text = text.Replace (" ", " ");
651 /* Regex re = new Regex ("\"((((?!\").)|\\\")*?)\"");
652 text = re.Replace (text,"<span style='color:purple'>\"$1\"</span>");
654 re = new Regex ("'(((.(?!\"\\<\\/span\\>))|\"(((?!\").)*)\"\\<\\/span\\>)*)(\r|\n|\r\n)");
655 text = re.Replace (text,"<span style='color:green'>//$1</span><br/>");
657 re = new Regex (keywords_vb);
658 text = re.Replace (text,"<span style='color:blue'>$1</span>");
660 text = text.Replace ("\t"," ");
661 text = text.Replace ("\n","<br/>");
666 // Helper methods and classes
669 string GetDataContext ()
671 return "op=" + CurrentOperationName + "&bnd=" + CurrentOperationBinding + "&";
674 string GetOptionSel (string v1, string v2)
676 string op = "<option ";
677 if (v1 == v2) op += "selected ";
678 return op + "value='" + v1 + "'>";
681 string WrapText (string text, int maxChars)
683 text = text.Replace(" />","/>");
685 string linspace = null;
689 bool inquotes = false;
691 string sublineIndent = "";
692 System.Text.StringBuilder sb = new System.Text.StringBuilder ();
693 for (int n=0; n<text.Length; n++)
697 if (c=='\r' || c=='\n' || n==text.Length-1)
699 sb.Append (linspace + sublineIndent + text.Substring (linstart, n-linstart+1));
709 if (lastc==',' || lastc=='(')
711 if (!inquotes) breakpos = n;
714 if (lincount > maxChars && breakpos >= linstart)
716 if (linspace != null)
717 sb.Append (linspace + sublineIndent);
718 sb.Append (text.Substring (linstart, breakpos-linstart));
721 lincount = linspace.Length + sublineIndent.Length + (n-breakpos);
725 if (c==' ' || c=='\t')
732 inquotes = !inquotes;
735 if (linspace == null) {
736 linspace = text.Substring (linstart, n-linstart);
743 return sb.ToString ();
752 public string Name { get { return name; } set { name = value; } }
753 public string Type { get { return type; } set { type = value; } }
754 public string Description { get { return description; } set { description = value; } }
757 public class HtmlSampleGenerator: SampleGenerator
759 public HtmlSampleGenerator (ServiceDescriptionCollection services, XmlSchemas schemas)
760 : base (services, schemas)
764 protected override string GetLiteral (string s)
766 return "@placeholder!" + s + "!placeholder@";
771 public class SampleGenerator
773 protected ServiceDescriptionCollection descriptions;
774 protected XmlSchemas schemas;
775 XmlSchemaElement anyElement;
777 SoapBindingUse currentUse;
778 XmlDocument document = new XmlDocument ();
780 static readonly XmlQualifiedName anyType = new XmlQualifiedName ("anyType",XmlSchema.Namespace);
781 static readonly XmlQualifiedName arrayType = new XmlQualifiedName ("Array","http://schemas.xmlsoap.org/soap/encoding/");
782 static readonly XmlQualifiedName arrayTypeRefName = new XmlQualifiedName ("arrayType","http://schemas.xmlsoap.org/soap/encoding/");
783 const string SoapEnvelopeNamespace = "http://schemas.xmlsoap.org/soap/envelope/";
784 const string WsdlNamespace = "http://schemas.xmlsoap.org/wsdl/";
785 const string SoapEncodingNamespace = "http://schemas.xmlsoap.org/soap/encoding/";
789 public EncodedType (string ns, XmlSchemaElement elem) { Namespace = ns; Element = elem; }
790 public string Namespace;
791 public XmlSchemaElement Element;
794 public SampleGenerator (ServiceDescriptionCollection services, XmlSchemas schemas)
796 descriptions = services;
797 this.schemas = schemas;
798 queue = new ArrayList ();
801 public string GenerateMessage (Port port, OperationBinding obin, Operation oper, string protocol, bool generateInput)
803 OperationMessage msg = null;
804 foreach (OperationMessage opm in oper.Messages)
806 if (opm is OperationInput && generateInput) msg = opm;
807 else if (opm is OperationOutput && !generateInput) msg = opm;
809 if (msg == null) return null;
812 case "Soap": return GenerateHttpSoapMessage (port, obin, oper, msg);
813 case "HttpGet": return GenerateHttpGetMessage (port, obin, oper, msg);
814 case "HttpPost": return GenerateHttpPostMessage (port, obin, oper, msg);
816 return "Unknown protocol";
819 public string GenerateHttpSoapMessage (Port port, OperationBinding obin, Operation oper, OperationMessage msg)
823 if (msg is OperationInput)
825 SoapAddressBinding sab = port.Extensions.Find (typeof(SoapAddressBinding)) as SoapAddressBinding;
826 SoapOperationBinding sob = obin.Extensions.Find (typeof(SoapOperationBinding)) as SoapOperationBinding;
827 req += "POST " + new Uri (sab.Location).AbsolutePath + "\n";
828 req += "SOAPAction: " + sob.SoapAction + "\n";
829 req += "Content-Type: text/xml; charset=utf-8\n";
830 req += "Content-Length: " + GetLiteral ("string") + "\n";
831 req += "Host: " + GetLiteral ("string") + "\n\n";
835 req += "HTTP/1.0 200 OK\n";
836 req += "Content-Type: text/xml; charset=utf-8\n";
837 req += "Content-Length: " + GetLiteral ("string") + "\n\n";
840 req += GenerateSoapMessage (obin, oper, msg);
844 public string GenerateHttpGetMessage (Port port, OperationBinding obin, Operation oper, OperationMessage msg)
848 if (msg is OperationInput)
850 HttpAddressBinding sab = port.Extensions.Find (typeof(HttpAddressBinding)) as HttpAddressBinding;
851 HttpOperationBinding sob = obin.Extensions.Find (typeof(HttpOperationBinding)) as HttpOperationBinding;
852 string location = new Uri (sab.Location).AbsolutePath + sob.Location + "?" + BuildQueryString (msg);
853 req += "GET " + location + "\n";
854 req += "Host: " + GetLiteral ("string");
858 req += "HTTP/1.0 200 OK\n";
859 req += "Content-Type: text/xml; charset=utf-8\n";
860 req += "Content-Length: " + GetLiteral ("string") + "\n\n";
862 MimeXmlBinding mxb = (MimeXmlBinding) obin.Output.Extensions.Find (typeof(MimeXmlBinding)) as MimeXmlBinding;
863 if (mxb == null) return req;
865 Message message = descriptions.GetMessage (msg.Message);
866 XmlQualifiedName ename = null;
867 foreach (MessagePart part in message.Parts)
868 if (part.Name == mxb.Part) ename = part.Element;
870 if (ename == null) return req + GetLiteral("string");
872 StringWriter sw = new StringWriter ();
873 XmlTextWriter xtw = new XmlTextWriter (sw);
874 xtw.Formatting = Formatting.Indented;
875 currentUse = SoapBindingUse.Literal;
876 WriteRootElementSample (xtw, ename);
878 req += sw.ToString ();
884 public string GenerateHttpPostMessage (Port port, OperationBinding obin, Operation oper, OperationMessage msg)
888 if (msg is OperationInput)
890 HttpAddressBinding sab = port.Extensions.Find (typeof(HttpAddressBinding)) as HttpAddressBinding;
891 HttpOperationBinding sob = obin.Extensions.Find (typeof(HttpOperationBinding)) as HttpOperationBinding;
892 string location = new Uri (sab.Location).AbsolutePath + sob.Location;
893 req += "POST " + location + "\n";
894 req += "Content-Type: application/x-www-form-urlencoded\n";
895 req += "Content-Length: " + GetLiteral ("string") + "\n";
896 req += "Host: " + GetLiteral ("string") + "\n\n";
897 req += BuildQueryString (msg);
899 else return GenerateHttpGetMessage (port, obin, oper, msg);
904 string BuildQueryString (OperationMessage opm)
907 Message msg = descriptions.GetMessage (opm.Message);
908 foreach (MessagePart part in msg.Parts)
910 if (s.Length != 0) s += "&";
911 s += part.Name + "=" + GetLiteral (part.Type.Name);
916 public string GenerateSoapMessage (OperationBinding obin, Operation oper, OperationMessage msg)
918 SoapOperationBinding sob = obin.Extensions.Find (typeof(SoapOperationBinding)) as SoapOperationBinding;
919 SoapBindingStyle style = (sob != null) ? sob.Style : SoapBindingStyle.Document;
921 MessageBinding msgbin = (msg is OperationInput) ? (MessageBinding) obin.Input : (MessageBinding)obin.Output;
922 SoapBodyBinding sbb = msgbin.Extensions.Find (typeof(SoapBodyBinding)) as SoapBodyBinding;
923 SoapBindingUse bodyUse = (sbb != null) ? sbb.Use : SoapBindingUse.Literal;
925 StringWriter sw = new StringWriter ();
926 XmlTextWriter xtw = new XmlTextWriter (sw);
927 xtw.Formatting = Formatting.Indented;
929 xtw.WriteStartDocument ();
930 xtw.WriteStartElement ("soap", "Envelope", SoapEnvelopeNamespace);
931 xtw.WriteAttributeString ("xmlns", "xsi", null, XmlSchema.InstanceNamespace);
932 xtw.WriteAttributeString ("xmlns", "xsd", null, XmlSchema.Namespace);
934 if (bodyUse == SoapBindingUse.Encoded)
936 xtw.WriteAttributeString ("xmlns", "soapenc", null, SoapEncodingNamespace);
937 xtw.WriteAttributeString ("xmlns", "tns", null, msg.Message.Namespace);
942 bool writtenHeader = false;
943 foreach (object ob in msgbin.Extensions)
945 SoapHeaderBinding hb = ob as SoapHeaderBinding;
946 if (hb == null) continue;
948 if (!writtenHeader) {
949 xtw.WriteStartElement ("soap", "Header", SoapEnvelopeNamespace);
950 writtenHeader = true;
953 WriteHeader (xtw, hb);
957 xtw.WriteEndElement ();
960 xtw.WriteStartElement ("soap", "Body", SoapEnvelopeNamespace);
962 currentUse = bodyUse;
963 WriteBody (xtw, oper, msg, sbb, style);
965 xtw.WriteEndElement ();
966 xtw.WriteEndElement ();
968 return sw.ToString ();
971 void WriteHeader (XmlTextWriter xtw, SoapHeaderBinding header)
973 Message msg = descriptions.GetMessage (header.Message);
974 if (msg == null) throw new InvalidOperationException ("Message " + header.Message + " not found");
975 MessagePart part = msg.Parts [header.Part];
976 if (part == null) throw new InvalidOperationException ("Message part " + header.Part + " not found in message " + header.Message);
978 currentUse = header.Use;
980 if (currentUse == SoapBindingUse.Literal)
981 WriteRootElementSample (xtw, part.Element);
983 WriteTypeSample (xtw, part.Type);
986 void WriteBody (XmlTextWriter xtw, Operation oper, OperationMessage opm, SoapBodyBinding sbb, SoapBindingStyle style)
988 Message msg = descriptions.GetMessage (opm.Message);
989 if (msg.Parts.Count > 0 && msg.Parts[0].Name == "parameters")
991 MessagePart part = msg.Parts[0];
992 if (part.Element == XmlQualifiedName.Empty)
993 WriteTypeSample (xtw, part.Type);
995 WriteRootElementSample (xtw, part.Element);
999 string elemName = oper.Name;
1001 if (opm is OperationOutput) elemName += "Response";
1003 if (style == SoapBindingStyle.Rpc) {
1004 xtw.WriteStartElement (elemName, sbb.Namespace);
1008 foreach (MessagePart part in msg.Parts)
1010 if (part.Element == XmlQualifiedName.Empty)
1012 XmlSchemaElement elem = new XmlSchemaElement ();
1013 elem.SchemaTypeName = part.Type;
1014 elem.Name = part.Name;
1015 WriteElementSample (xtw, ns, elem);
1018 WriteRootElementSample (xtw, part.Element);
1021 if (style == SoapBindingStyle.Rpc)
1022 xtw.WriteEndElement ();
1024 WriteQueuedTypeSamples (xtw);
1027 void WriteRootElementSample (XmlTextWriter xtw, XmlQualifiedName qname)
1029 XmlSchemaElement elem = (XmlSchemaElement) schemas.Find (qname, typeof(XmlSchemaElement));
1030 if (elem == null) throw new InvalidOperationException ("Element not found: " + qname);
1031 WriteElementSample (xtw, qname.Namespace, elem);
1034 void WriteElementSample (XmlTextWriter xtw, string ns, XmlSchemaElement elem)
1036 bool sharedAnnType = false;
1037 XmlQualifiedName root;
1039 if (!elem.RefName.IsEmpty) {
1040 XmlSchemaElement refElem = FindRefElement (elem);
1041 if (refElem == null) throw new InvalidOperationException ("Global element not found: " + elem.RefName);
1042 root = elem.RefName;
1044 sharedAnnType = true;
1047 root = new XmlQualifiedName (elem.Name, ns);
1049 if (!elem.SchemaTypeName.IsEmpty)
1051 XmlSchemaComplexType st = FindComplexTyype (elem.SchemaTypeName);
1053 WriteComplexTypeSample (xtw, st, root);
1056 xtw.WriteStartElement (root.Name, root.Namespace);
1057 if (currentUse == SoapBindingUse.Encoded)
1058 xtw.WriteAttributeString ("type", XmlSchema.InstanceNamespace, GetQualifiedNameString (xtw, elem.SchemaTypeName));
1059 xtw.WriteString (GetLiteral (FindBuiltInType (elem.SchemaTypeName)));
1060 xtw.WriteEndElement ();
1063 else if (elem.SchemaType == null)
1065 xtw.WriteStartElement ("any");
1066 xtw.WriteEndElement ();
1069 WriteComplexTypeSample (xtw, (XmlSchemaComplexType) elem.SchemaType, root);
1072 void WriteTypeSample (XmlTextWriter xtw, XmlQualifiedName qname)
1074 XmlSchemaComplexType ctype = FindComplexTyype (qname);
1075 if (ctype != null) {
1076 WriteComplexTypeSample (xtw, ctype, qname);
1080 XmlSchemaSimpleType stype = (XmlSchemaSimpleType) schemas.Find (qname, typeof(XmlSchemaSimpleType));
1081 if (stype != null) {
1082 WriteSimpleTypeSample (xtw, stype);
1086 xtw.WriteString (GetLiteral (FindBuiltInType (qname)));
1087 throw new InvalidOperationException ("Type not found: " + qname);
1090 void WriteComplexTypeSample (XmlTextWriter xtw, XmlSchemaComplexType stype, XmlQualifiedName rootName)
1092 WriteComplexTypeSample (xtw, stype, rootName, -1);
1095 void WriteComplexTypeSample (XmlTextWriter xtw, XmlSchemaComplexType stype, XmlQualifiedName rootName, int id)
1097 string ns = rootName.Namespace;
1099 if (rootName.Name.IndexOf ("[]") != -1) rootName = arrayType;
1101 if (currentUse == SoapBindingUse.Encoded) {
1102 string pref = xtw.LookupPrefix (rootName.Namespace);
1103 if (pref == null) pref = "q1";
1104 xtw.WriteStartElement (pref, rootName.Name, rootName.Namespace);
1108 xtw.WriteStartElement (rootName.Name, rootName.Namespace);
1112 xtw.WriteAttributeString ("id", "id" + id);
1113 if (rootName != arrayType)
1114 xtw.WriteAttributeString ("type", XmlSchema.InstanceNamespace, GetQualifiedNameString (xtw, rootName));
1117 WriteComplexTypeAttributes (xtw, stype);
1118 WriteComplexTypeElements (xtw, ns, stype);
1120 xtw.WriteEndElement ();
1123 void WriteComplexTypeAttributes (XmlTextWriter xtw, XmlSchemaComplexType stype)
1125 WriteAttributes (xtw, stype.Attributes, stype.AnyAttribute);
1128 void WriteComplexTypeElements (XmlTextWriter xtw, string ns, XmlSchemaComplexType stype)
1130 if (stype.Particle != null)
1131 WriteParticleComplexContent (xtw, ns, stype.Particle);
1134 if (stype.ContentModel is XmlSchemaSimpleContent)
1135 WriteSimpleContent (xtw, (XmlSchemaSimpleContent)stype.ContentModel);
1136 else if (stype.ContentModel is XmlSchemaComplexContent)
1137 WriteComplexContent (xtw, ns, (XmlSchemaComplexContent)stype.ContentModel);
1141 void WriteAttributes (XmlTextWriter xtw, XmlSchemaObjectCollection atts, XmlSchemaAnyAttribute anyat)
1143 foreach (XmlSchemaObject at in atts)
1145 if (at is XmlSchemaAttribute)
1148 XmlSchemaAttribute attr = (XmlSchemaAttribute)at;
1149 XmlSchemaAttribute refAttr = attr;
1151 // refAttr.Form; TODO
1153 if (!attr.RefName.IsEmpty) {
1154 refAttr = FindRefAttribute (attr.RefName);
1155 if (refAttr == null) throw new InvalidOperationException ("Global attribute not found: " + attr.RefName);
1159 if (!refAttr.SchemaTypeName.IsEmpty) val = FindBuiltInType (refAttr.SchemaTypeName);
1160 else val = FindBuiltInType ((XmlSchemaSimpleType) refAttr.SchemaType);
1162 xtw.WriteAttributeString (refAttr.Name, val);
1164 else if (at is XmlSchemaAttributeGroupRef)
1166 XmlSchemaAttributeGroupRef gref = (XmlSchemaAttributeGroupRef)at;
1167 XmlSchemaAttributeGroup grp = (XmlSchemaAttributeGroup) schemas.Find (gref.RefName, typeof(XmlSchemaAttributeGroup));
1168 WriteAttributes (xtw, grp.Attributes, grp.AnyAttribute);
1173 xtw.WriteAttributeString ("custom-attribute","value");
1176 void WriteParticleComplexContent (XmlTextWriter xtw, string ns, XmlSchemaParticle particle)
1178 WriteParticleContent (xtw, ns, particle, false);
1181 void WriteParticleContent (XmlTextWriter xtw, string ns, XmlSchemaParticle particle, bool multiValue)
1183 if (particle is XmlSchemaGroupRef)
1184 particle = GetRefGroupParticle ((XmlSchemaGroupRef)particle);
1186 if (particle.MaxOccurs > 1) multiValue = true;
1188 if (particle is XmlSchemaSequence) {
1189 WriteSequenceContent (xtw, ns, ((XmlSchemaSequence)particle).Items, multiValue);
1191 else if (particle is XmlSchemaChoice) {
1192 if (((XmlSchemaChoice)particle).Items.Count == 1)
1193 WriteSequenceContent (xtw, ns, ((XmlSchemaChoice)particle).Items, multiValue);
1195 WriteChoiceContent (xtw, ns, (XmlSchemaChoice)particle, multiValue);
1197 else if (particle is XmlSchemaAll) {
1198 WriteSequenceContent (xtw, ns, ((XmlSchemaAll)particle).Items, multiValue);
1202 void WriteSequenceContent (XmlTextWriter xtw, string ns, XmlSchemaObjectCollection items, bool multiValue)
1204 foreach (XmlSchemaObject item in items)
1205 WriteContentItem (xtw, ns, item, multiValue);
1208 void WriteContentItem (XmlTextWriter xtw, string ns, XmlSchemaObject item, bool multiValue)
1210 if (item is XmlSchemaGroupRef)
1211 item = GetRefGroupParticle ((XmlSchemaGroupRef)item);
1213 if (item is XmlSchemaElement)
1215 XmlSchemaElement elem = (XmlSchemaElement) item;
1216 XmlSchemaElement refElem;
1217 if (!elem.RefName.IsEmpty) refElem = FindRefElement (elem);
1218 else refElem = elem;
1220 int num = (elem.MaxOccurs == 1 && !multiValue) ? 1 : 2;
1221 for (int n=0; n<num; n++)
1223 if (currentUse == SoapBindingUse.Literal)
1224 WriteElementSample (xtw, ns, refElem);
1226 WriteRefTypeSample (xtw, ns, refElem);
1229 else if (item is XmlSchemaAny)
1231 xtw.WriteString (GetLiteral ("xml"));
1233 else if (item is XmlSchemaParticle) {
1234 WriteParticleContent (xtw, ns, (XmlSchemaParticle)item, multiValue);
1238 void WriteChoiceContent (XmlTextWriter xtw, string ns, XmlSchemaChoice choice, bool multiValue)
1240 foreach (XmlSchemaObject item in choice.Items)
1241 WriteContentItem (xtw, ns, item, multiValue);
1244 void WriteSimpleContent (XmlTextWriter xtw, XmlSchemaSimpleContent content)
1246 XmlSchemaSimpleContentExtension ext = content.Content as XmlSchemaSimpleContentExtension;
1248 WriteAttributes (xtw, ext.Attributes, ext.AnyAttribute);
1250 XmlQualifiedName qname = GetContentBaseType (content.Content);
1251 xtw.WriteString (GetLiteral (FindBuiltInType (qname)));
1254 string FindBuiltInType (XmlQualifiedName qname)
1256 if (qname.Namespace == XmlSchema.Namespace)
1259 XmlSchemaComplexType ct = FindComplexTyype (qname);
1262 XmlSchemaSimpleContent sc = ct.ContentModel as XmlSchemaSimpleContent;
1263 if (sc == null) throw new InvalidOperationException ("Invalid schema");
1264 return FindBuiltInType (GetContentBaseType (sc.Content));
1267 XmlSchemaSimpleType st = (XmlSchemaSimpleType) schemas.Find (qname, typeof(XmlSchemaSimpleType));
1269 return FindBuiltInType (st);
1271 throw new InvalidOperationException ("Definition of type " + qname + " not found");
1274 string FindBuiltInType (XmlSchemaSimpleType st)
1276 if (st.Content is XmlSchemaSimpleTypeRestriction) {
1277 return FindBuiltInType (GetContentBaseType (st.Content));
1279 else if (st.Content is XmlSchemaSimpleTypeList) {
1280 string s = FindBuiltInType (GetContentBaseType (st.Content));
1281 return s + " " + s + " ...";
1283 else if (st.Content is XmlSchemaSimpleTypeUnion)
1285 //Check if all types of the union are equal. If not, then will use anyType.
1286 XmlSchemaSimpleTypeUnion uni = (XmlSchemaSimpleTypeUnion) st.Content;
1287 string utype = null;
1289 // Anonymous types are unique
1290 if (uni.BaseTypes.Count != 0 && uni.MemberTypes.Length != 0)
1293 foreach (XmlQualifiedName mt in uni.MemberTypes)
1295 string qn = FindBuiltInType (mt);
1296 if (utype != null && qn != utype) return "string";
1306 XmlQualifiedName GetContentBaseType (XmlSchemaObject ob)
1308 if (ob is XmlSchemaSimpleContentExtension)
1309 return ((XmlSchemaSimpleContentExtension)ob).BaseTypeName;
1310 else if (ob is XmlSchemaSimpleContentRestriction)
1311 return ((XmlSchemaSimpleContentRestriction)ob).BaseTypeName;
1312 else if (ob is XmlSchemaSimpleTypeRestriction)
1313 return ((XmlSchemaSimpleTypeRestriction)ob).BaseTypeName;
1314 else if (ob is XmlSchemaSimpleTypeList)
1315 return ((XmlSchemaSimpleTypeList)ob).ItemTypeName;
1320 void WriteComplexContent (XmlTextWriter xtw, string ns, XmlSchemaComplexContent content)
1322 XmlQualifiedName qname;
1324 XmlSchemaComplexContentExtension ext = content.Content as XmlSchemaComplexContentExtension;
1325 if (ext != null) qname = ext.BaseTypeName;
1327 XmlSchemaComplexContentRestriction rest = (XmlSchemaComplexContentRestriction)content.Content;
1328 qname = rest.BaseTypeName;
1329 if (qname == arrayType) {
1330 ParseArrayType (rest, out qname);
1331 XmlSchemaElement elem = new XmlSchemaElement ();
1333 elem.SchemaTypeName = qname;
1335 xtw.WriteAttributeString ("arrayType", SoapEncodingNamespace, qname.Name + "[2]");
1336 WriteContentItem (xtw, ns, elem, true);
1341 // Add base map members to this map
1342 XmlSchemaComplexType ctype = FindComplexTyype (qname);
1343 WriteComplexTypeAttributes (xtw, ctype);
1346 // Add the members of this map
1347 WriteAttributes (xtw, ext.Attributes, ext.AnyAttribute);
1348 if (ext.Particle != null)
1349 WriteParticleComplexContent (xtw, ns, ext.Particle);
1352 WriteComplexTypeElements (xtw, ns, ctype);
1355 void ParseArrayType (XmlSchemaComplexContentRestriction rest, out XmlQualifiedName qtype)
1357 XmlSchemaAttribute arrayTypeAt = FindArrayAttribute (rest.Attributes);
1358 XmlAttribute[] uatts = arrayTypeAt.UnhandledAttributes;
1359 if (uatts == null || uatts.Length == 0) throw new InvalidOperationException ("arrayType attribute not specified in array declaration");
1361 XmlAttribute xat = null;
1362 foreach (XmlAttribute at in uatts)
1363 if (at.LocalName == "arrayType" && at.NamespaceURI == WsdlNamespace)
1364 { xat = at; break; }
1367 throw new InvalidOperationException ("arrayType attribute not specified in array declaration");
1369 string arrayType = xat.Value;
1371 int i = arrayType.LastIndexOf (":");
1372 if (i == -1) ns = "";
1373 else ns = arrayType.Substring (0,i);
1375 int j = arrayType.IndexOf ("[", i+1);
1376 if (j == -1) throw new InvalidOperationException ("Cannot parse WSDL array type: " + arrayType);
1377 type = arrayType.Substring (i+1);
1378 type = type.Substring (0, type.Length-2);
1380 qtype = new XmlQualifiedName (type, ns);
1383 XmlSchemaAttribute FindArrayAttribute (XmlSchemaObjectCollection atts)
1385 foreach (object ob in atts)
1387 XmlSchemaAttribute att = ob as XmlSchemaAttribute;
1388 if (att != null && att.RefName == arrayTypeRefName) return att;
1390 XmlSchemaAttributeGroupRef gref = ob as XmlSchemaAttributeGroupRef;
1393 XmlSchemaAttributeGroup grp = (XmlSchemaAttributeGroup) schemas.Find (gref.RefName, typeof(XmlSchemaAttributeGroup));
1394 att = FindArrayAttribute (grp.Attributes);
1395 if (att != null) return att;
1401 void WriteSimpleTypeSample (XmlTextWriter xtw, XmlSchemaSimpleType stype)
1403 xtw.WriteString (GetLiteral (FindBuiltInType (stype)));
1406 XmlSchemaParticle GetRefGroupParticle (XmlSchemaGroupRef refGroup)
1408 XmlSchemaGroup grp = (XmlSchemaGroup) schemas.Find (refGroup.RefName, typeof (XmlSchemaGroup));
1409 return grp.Particle;
1412 XmlSchemaElement FindRefElement (XmlSchemaElement elem)
1414 if (elem.RefName.Namespace == XmlSchema.Namespace)
1416 if (anyElement != null) return anyElement;
1417 anyElement = new XmlSchemaElement ();
1418 anyElement.Name = "any";
1419 anyElement.SchemaTypeName = anyType;
1422 return (XmlSchemaElement) schemas.Find (elem.RefName, typeof(XmlSchemaElement));
1425 XmlSchemaAttribute FindRefAttribute (XmlQualifiedName refName)
1427 if (refName.Namespace == XmlSchema.Namespace)
1429 XmlSchemaAttribute at = new XmlSchemaAttribute ();
1430 at.Name = refName.Name;
1431 at.SchemaTypeName = new XmlQualifiedName ("string",XmlSchema.Namespace);
1434 return (XmlSchemaAttribute) schemas.Find (refName, typeof(XmlSchemaAttribute));
1437 void WriteRefTypeSample (XmlTextWriter xtw, string ns, XmlSchemaElement elem)
1439 if (elem.SchemaTypeName.Namespace == XmlSchema.Namespace || schemas.Find (elem.SchemaTypeName, typeof(XmlSchemaSimpleType)) != null)
1440 WriteElementSample (xtw, ns, elem);
1443 xtw.WriteStartElement (elem.Name, ns);
1444 xtw.WriteAttributeString ("href", "#id" + (queue.Count+1));
1445 xtw.WriteEndElement ();
1446 queue.Add (new EncodedType (ns, elem));
1450 void WriteQueuedTypeSamples (XmlTextWriter xtw)
1452 for (int n=0; n<queue.Count; n++)
1454 EncodedType ec = (EncodedType) queue[n];
1455 XmlSchemaComplexType st = FindComplexTyype (ec.Element.SchemaTypeName);
1456 WriteComplexTypeSample (xtw, st, ec.Element.SchemaTypeName, n+1);
1460 XmlSchemaComplexType FindComplexTyype (XmlQualifiedName qname)
1462 if (qname.Name.IndexOf ("[]") != -1)
1464 XmlSchemaComplexType stype = new XmlSchemaComplexType ();
1465 stype.ContentModel = new XmlSchemaComplexContent ();
1467 XmlSchemaComplexContentRestriction res = new XmlSchemaComplexContentRestriction ();
1468 stype.ContentModel.Content = res;
1469 res.BaseTypeName = arrayType;
1471 XmlSchemaAttribute att = new XmlSchemaAttribute ();
1472 att.RefName = arrayTypeRefName;
1473 res.Attributes.Add (att);
1475 XmlAttribute xat = document.CreateAttribute ("arrayType", WsdlNamespace);
1476 xat.Value = qname.Namespace + ":" + qname.Name;
1477 att.UnhandledAttributes = new XmlAttribute[] {xat};
1481 return (XmlSchemaComplexType) schemas.Find (qname, typeof(XmlSchemaComplexType));
1484 string GetQualifiedNameString (XmlTextWriter xtw, XmlQualifiedName qname)
1486 string pref = xtw.LookupPrefix (qname.Namespace);
1487 if (pref != null) return pref + ":" + qname.Name;
1489 xtw.WriteAttributeString ("xmlns", "q1", null, qname.Namespace);
1490 return "q1:" + qname.Name;
1493 protected virtual string GetLiteral (string s)
1498 void GetOperationFormat (OperationBinding obin, out SoapBindingStyle style, out SoapBindingUse use)
1500 style = SoapBindingStyle.Document;
1501 use = SoapBindingUse.Literal;
1502 SoapOperationBinding sob = obin.Extensions.Find (typeof(SoapOperationBinding)) as SoapOperationBinding;
1505 SoapBodyBinding sbb = obin.Input.Extensions.Find (typeof(SoapBodyBinding)) as SoapBodyBinding;
1518 <head runat="server">
1519 <link rel="alternate" type="text/xml" href="<%=Request.FilePath%>?disco"/>
1521 <title><%=WebServiceName%> Web Service</title>
1522 <style type="text/css">
1523 BODY { font-family: Arial; margin-left: 20px; margin-top: 20px; font-size: x-small}
1524 TABLE { font-size: x-small }
1525 .title { color:dimgray; font-family: Arial; font-size:20pt; font-weight:900}
1526 .operationTitle { color:dimgray; font-family: Arial; font-size:15pt; font-weight:900}
1527 .method { font-size: x-small }
1528 .bindingLabel { font-size: x-small; font-weight:bold; color:darkgray; line-height:8pt; display:block; margin-bottom:3px }
1529 .label { font-size: small; font-weight:bold; color:darkgray }
1530 .paramTable { font-size: x-small }
1531 .paramTable TR { background-color: gainsboro }
1532 .paramFormTable { font-size: x-small; padding: 10px; background-color: gainsboro }
1533 .paramFormTable TR { background-color: gainsboro }
1534 .paramInput { border: solid 1px gray }
1535 .button {border: solid 1px gray }
1536 .smallSeparator { height:3px; overflow:hidden }
1537 .panel { background-color:whitesmoke; border: solid 1px silver; border-top: solid 1px silver }
1538 .codePanel { background-color: white; font-size:x-small; padding:7px; border:solid 1px silver}
1539 .code-xml { font-size:10pt; font-family:courier }
1540 .code-cs { font-size:10pt; font-family:courier }
1541 .code-vb { font-size:10pt; font-family:courier }
1542 .tabLabelOn { font-weight:bold }
1543 .tabLabelOff {color: darkgray }
1544 .literal-placeholder {color: darkblue; font-weight:bold}
1545 A:link { color: black; }
1546 A:visited { color: black; }
1547 A:active { color: black; }
1548 A:hover { color: blue }
1551 <script language="javascript" type="text/javascript">
1553 function getXML (command, url, qs) {
1554 if (url == "" || url.substring (0, 4) != "http")
1557 var post_data = null;
1559 req.onreadystatechange = stateChange;
1560 if (command == "GET") {
1561 url = url + "?" + qs;
1565 req.open (command, url, true);
1566 if (command == "POST")
1567 req.setRequestHeader ("Content-Type", "application/x-www-form-urlencoded");
1568 req.send (post_data);
1571 function stateChange () {
1572 if (req.readyState == 4) {
1573 var node = document.getElementById("testresult_div");
1575 if (req.status == 200) {
1576 node.innerHTML = "<div class='code-xml'>" + formatXml (req.responseText) + "</div>";
1578 var ht = "<b style='color: red'>" + formatXml (req.status + " - " + req.statusText) + "</b>";
1579 if (req.responseText != "")
1580 ht = ht + "\n<div class='code-xml'>" + formatXml (req.responseText) + "</div>";
1581 node.innerHTML = ht;
1587 function formatXml (text)
1590 text = text.replace (re, " ");
1593 text = text.replace (re, " ");
1595 re = /\<\s*(\/?)\s*(.*?)\s*(\/?)\s*\>/g;
1596 text = text.replace (re,"{blue:<$1}{maroon:$2}{blue:$3>}");
1598 re = /{(\w*):(.*?)}/g;
1599 text = text.replace (re,"<span style='color:$1'>$2</span>");
1602 text = text.replace (re,"\"<span style='color:purple'>$1</span>\"");
1605 text = text.replace (re, "<br/>");
1610 function getReq () {
1611 if (window.XMLHttpRequest) {
1612 return new XMLHttpRequest(); // Firefox, Safari, ...
1613 } else if (window.ActiveXObject) {
1614 return new ActiveXObject("Microsoft.XMLHTTP");
1618 function clearForm ()
1620 document.getElementById("testFormResult").style.display="none";
1627 <div class="title" style="margin-left:20px">
1628 <span class="label">Web Service</span><br>
1633 **********************************************************
1637 <table border="0" width="100%" cellpadding="15px" cellspacing="15px">
1638 <tr valign="top"><td width="150px" class="panel">
1639 <div style="width:150px"></div>
1640 <a class="method" href='<%=PageName%>'>Overview</a><br>
1641 <div class="smallSeparator"></div>
1642 <a class="method" href='<%=PageName + "?" + GetPageContext("wsdl")%>'>Service Description</a>
1643 <div class="smallSeparator"></div>
1644 <a class="method" href='<%=PageName + "?" + GetPageContext("proxy")%>'>Client proxy</a>
1646 <asp:repeater id="BindingsRepeater" runat=server>
1647 <itemtemplate name="itemtemplate">
1648 <span class="bindingLabel"><%#FormatBindingName(DataBinder.Eval(Container.DataItem, "Name").ToString())%></span>
1649 <asp:repeater id="OperationsRepeater" runat=server datasource='<%# ((Binding)Container.DataItem).Operations %>'>
1651 <a class="method" href="<%=PageName%>?<%=GetTabContext("op",null)%>op=<%#GetOpName(Container.DataItem)%>&bnd=<%#DataBinder.Eval(Container.DataItem, "Binding.Name")%>"><%#GetOpName(Container.DataItem)%></a>
1652 <div class="smallSeparator"></div>
1659 </td><td class="panel">
1661 <% if (CurrentPage == "main") {%>
1664 **********************************************************
1665 Web service overview
1668 <p class="label">Web Service Overview</p>
1669 <%=WebServiceDescription%>
1671 <% if (ProfileViolations != null && ProfileViolations.Count > 0) { %>
1672 <p class="label">Basic Profile Conformance</p>
1673 This web service does not conform to WS-I Basic Profile v1.1
1675 Response.Write ("<ul>");
1676 foreach (BasicProfileViolation vio in ProfileViolations) {
1677 Response.Write ("<li><b>" + vio.NormativeStatement + "</b>: " + vio.Details);
1678 Response.Write ("<ul>");
1679 foreach (string ele in vio.Elements)
1680 Response.Write ("<li>" + ele + "</li>");
1681 Response.Write ("</ul>");
1682 Response.Write ("</li>");
1684 Response.Write ("</ul>");
1687 <%} if (DefaultBinding == null) {%>
1688 This service does not contain any public web method.
1689 <%} else if (CurrentPage == "op") {%>
1692 **********************************************************
1693 Operation description
1696 <span class="operationTitle"><%=CurrentOperationName%></span>
1701 <% if (CurrentTab == "main") { %>
1702 <span class="label">Input Parameters</span>
1703 <div class="smallSeparator"></div>
1704 <% if (InParams.Count == 0) { %>
1705 No input parameters<br>
1707 <table class="paramTable" cellspacing="1" cellpadding="5">
1708 <asp:repeater id="InputParamsRepeater" runat=server>
1711 <td width="150"><%#DataBinder.Eval(Container.DataItem, "Name")%></td>
1712 <td width="150"><%#DataBinder.Eval(Container.DataItem, "Type")%></td>
1720 <% if (OutParams.Count > 0) { %>
1721 <span class="label">Output Parameters</span>
1722 <div class="smallSeparator"></div>
1723 <table class="paramTable" cellspacing="1" cellpadding="5">
1724 <asp:repeater id="OutputParamsRepeater" runat=server>
1727 <td width="150"><%#DataBinder.Eval(Container.DataItem, "Name")%></td>
1728 <td width="150"><%#DataBinder.Eval(Container.DataItem, "Type")%></td>
1736 <span class="label">Remarks</span>
1737 <div class="smallSeparator"></div>
1738 <%=OperationDocumentation%>
1740 <span class="label">Technical information</span>
1741 <div class="smallSeparator"></div>
1742 Format: <%=CurrentOperationFormat%>
1743 <br>Supported protocols: <%=CurrentOperationProtocols%>
1747 **********************************************************
1748 Operation description - Test form
1751 <% if (CurrentTab == "test") {
1752 if (CurrentOperationSupportsTest) {%>
1753 Enter values for the parameters and click the 'Invoke' button to test this method:<br><br>
1754 <form action="<%=PageName%>" method="GET">
1755 <input type="hidden" name="page" value="<%=CurrentPage%>">
1756 <input type="hidden" name="tab" value="<%=CurrentTab%>">
1757 <input type="hidden" name="op" value="<%=CurrentOperationName%>">
1758 <input type="hidden" name="bnd" value="<%=CurrentOperationBinding%>">
1759 <input type="hidden" name="ext" value="testform">
1760 <table class="paramFormTable" cellspacing="0" cellpadding="3">
1761 <asp:repeater id="InputFormParamsRepeater" runat=server>
1764 <td><%#DataBinder.Eval(Container.DataItem, "Name")%>: </td>
1765 <td width="150"><input class="paramInput" type="text" size="20" name="<%#DataBinder.Eval(Container.DataItem, "Name")%>"></td>
1769 <tr><td></td><td><input class="button" type="submit" value="Invoke"> <input class="button" type="button" onclick="clearForm()" value="Clear"></td></tr>
1772 <div id="testFormResult" style="display:<%= (HasFormResult?"block":"none") %>">
1773 The web service returned the following result:<br/><br/>
1774 <div class="codePanel" id="testresult_div">
1776 <script language="javascript">
1777 getXML ("<%= GetOrPost () %>", "<%= GetTestResultUrl () %>", "<%= GetQS () %>");
1781 The test form is not available for this operation because it has parameters with a complex structure.
1786 **********************************************************
1787 Operation description - Message Layout
1790 <% if (CurrentTab == "msg") { %>
1792 The following are sample SOAP requests and responses for each protocol supported by this method:
1795 <% if (IsOperationSupported ("Soap")) { %>
1796 <span class="label">Soap</span>
1798 <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("Soap", true)%></div></div>
1800 <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("Soap", false)%></div></div>
1803 <% if (IsOperationSupported ("HttpGet")) { %>
1804 <span class="label">HTTP Get</span>
1806 <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("HttpGet", true)%></div></div>
1808 <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("HttpGet", false)%></div></div>
1811 <% if (IsOperationSupported ("HttpPost")) { %>
1812 <span class="label">HTTP Post</span>
1814 <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("HttpPost", true)%></div></div>
1816 <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("HttpPost", false)%></div></div>
1821 <%} else if (CurrentPage == "proxy") {%>
1823 **********************************************************
1826 <form action="<%=PageName%>" name="langForm" method="GET">
1827 Select the language for which you want to generate a proxy
1828 <input type="hidden" name="page" value="<%=CurrentPage%>">
1829 <SELECT name="lang" onchange="langForm.submit()">
1830 <%=GetOptionSel("cs",CurrentLanguage)%>C#</option>
1831 <%=GetOptionSel("vb",CurrentLanguage)%>Visual Basic</option>
1836 <span class="label"><%=CurrentProxytName%></span>
1837 <a href="<%=PageName + "?code=" + CurrentLanguage%>">Download</a>
1839 <div class="codePanel">
1840 <div class="code-<%=CurrentLanguage%>"><%=GetProxyCode ()%></div>
1842 <%} else if (CurrentPage == "wsdl") {%>
1844 **********************************************************
1847 <% if (descriptions.Count > 1 || schemas.Count > 1) {%>
1848 The description of this web service is composed by several documents. Click on the document you want to see:
1852 for (int n=0; n<descriptions.Count; n++)
1853 Response.Write ("<li><a href='" + PageName + "?" + GetPageContext(null) + "doctype=wsdl&docind=" + n + "'>WSDL document " + descriptions[n].TargetNamespace + "</a></li>");
1854 for (int n=0; n<schemas.Count; n++)
1855 Response.Write ("<li><a href='" + PageName + "?" + GetPageContext(null) + "doctype=schema&docind=" + n + "'>Xml Schema " + schemas[n].TargetNamespace + "</a></li>");
1862 <span class="label"><%=CurrentDocumentName%></span>
1863 <a href="<%=PageName + "?" + CurrentDocType + "=" + CurrentDocInd %>">Download</a>
1865 <div class="codePanel">
1866 <div class="code-xml"><%=GenerateDocument ()%></div>
1871 <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
1873 <td width="20px"></td>