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="javascript" type="text/javascript">
39 function getXML (command, url, qs) {
40 if (url == "" || url.substring (0, 4) != "http")
45 req.onreadystatechange = stateChange;
46 if (command == "GET") {
51 req.open (command, url, true);
52 if (command == "POST")
53 req.setRequestHeader ("Content-Type", "application/x-www-form-urlencoded");
57 function stateChange () {
58 if (req.readyState == 4) {
59 var node = document.getElementById("testresult_div");
61 if (req.status == 200) {
62 node.innerHTML = "<div class='code-xml'>" + formatXml (req.responseText) + "</div>";
64 var ht = "<b style='color: red'>" + formatXml (req.status + " - " + req.statusText) + "</b>";
65 if (req.responseText != "")
66 ht = ht + "\n<div class='code-xml'>" + formatXml (req.responseText) + "</div>";
73 function formatXml (text)
76 text = text.replace (re, " ");
79 text = text.replace (re, " ");
81 re = /\<\s*(\/?)\s*(.*?)\s*(\/?)\s*\>/g;
82 text = text.replace (re,"{blue:<$1}{maroon:$2}{blue:$3>}");
84 re = /{(\w*):(.*?)}/g;
85 text = text.replace (re,"<span style='color:$1'>$2</span>");
88 text = text.replace (re,"\"<span style='color:purple'>$1</span>\"");
91 text = text.replace (re, "<br/>");
97 if (window.XMLHttpRequest) {
98 return new XMLHttpRequest(); // Firefox, Safari, ...
99 } else if (window.ActiveXObject) {
100 return new ActiveXObject("Microsoft.XMLHTTP");
104 <script language="C#" runat="server">
106 ServiceDescriptionCollection descriptions;
109 string WebServiceName;
110 string WebServiceDescription;
113 string DefaultBinding;
114 ArrayList ServiceProtocols;
116 string CurrentOperationName;
117 string CurrentOperationBinding;
118 string OperationDocumentation;
119 string CurrentOperationFormat;
120 bool CurrentOperationSupportsTest;
123 string CurrentOperationProtocols;
124 int CodeTextColumns = 95;
125 BasicProfileViolationCollection ProfileViolations;
127 void Page_Load(object sender, EventArgs e)
129 descriptions = (ServiceDescriptionCollection) Context.Items["wsdls"];
130 schemas = (XmlSchemas) Context.Items["schemas"];
132 ServiceDescription desc = descriptions [0];
133 if (schemas.Count == 0) schemas = desc.Types.Schemas;
135 Service service = desc.Services[0];
136 WebServiceName = service.Name;
137 if (desc.Bindings.Count == 0)
140 DefaultBinding = desc.Bindings[0].Name;
141 WebServiceDescription = service.Documentation;
142 if (WebServiceDescription == "" || WebServiceDescription == null)
143 WebServiceDescription = "Description has not been provided";
144 ServiceProtocols = FindServiceProtocols (null);
146 CurrentOperationName = Request.QueryString["op"];
147 CurrentOperationBinding = Request.QueryString["bnd"];
148 if (CurrentOperationName != null) BuildOperationInfo ();
150 PageName = HttpUtility.UrlEncode (Path.GetFileName(Request.Path), Encoding.UTF8);
152 ArrayList list = new ArrayList ();
153 foreach (ServiceDescription sd in descriptions) {
154 foreach (Binding bin in sd.Bindings)
155 if (bin.Extensions.Find (typeof(SoapBinding)) != null) list.Add (bin);
158 BindingsRepeater.DataSource = list;
161 ProfileViolations = new BasicProfileViolationCollection ();
162 foreach (WsiProfilesElement claims in ((WebServicesSection) WebConfigurationManager.GetSection("system.web/webServices")).ConformanceWarnings)
163 if (claims.Name != WsiProfiles.None)
164 WebServicesInteroperability.CheckConformance (claims.Name, descriptions, ProfileViolations);
167 void BuildOperationInfo ()
169 InParams = new ArrayList ();
170 OutParams = new ArrayList ();
172 Port port = FindPort (CurrentOperationBinding, null);
173 Binding binding = descriptions.GetBinding (port.Binding);
175 PortType portType = descriptions.GetPortType (binding.Type);
176 Operation oper = FindOperation (portType, CurrentOperationName);
178 OperationDocumentation = oper.Documentation;
179 if (OperationDocumentation == null || OperationDocumentation == "")
180 OperationDocumentation = "No additional remarks";
182 foreach (OperationMessage opm in oper.Messages)
184 if (opm is OperationInput)
185 BuildParameters (InParams, opm);
186 else if (opm is OperationOutput)
187 BuildParameters (OutParams, opm);
190 // Protocols supported by the operation
191 CurrentOperationProtocols = "";
192 ArrayList prots = FindServiceProtocols (CurrentOperationName);
193 for (int n=0; n<prots.Count; n++) {
194 if (n != 0) CurrentOperationProtocols += ", ";
195 CurrentOperationProtocols += (string) prots[n];
198 WebServiceProtocols testProtocols = WebServiceProtocols.HttpGet | WebServiceProtocols.HttpPost;
199 if (Context.Request.IsLocal)
200 testProtocols |= WebServiceProtocols.HttpPostLocalhost;
201 CurrentOperationSupportsTest = (WebServicesSection.Current.EnabledProtocols & testProtocols) != 0;
204 OperationBinding obin = FindOperation (binding, CurrentOperationName);
206 CurrentOperationFormat = GetOperationFormat (obin);
208 InputParamsRepeater.DataSource = InParams;
209 InputFormParamsRepeater.DataSource = InParams;
210 OutputParamsRepeater.DataSource = OutParams;
213 void BuildParameters (ArrayList list, OperationMessage opm)
215 Message msg = descriptions.GetMessage (opm.Message);
216 if (msg.Parts.Count > 0 && msg.Parts[0].Name == "parameters")
218 MessagePart part = msg.Parts[0];
219 XmlSchemaComplexType ctype;
220 if (part.Element == XmlQualifiedName.Empty)
222 ctype = (XmlSchemaComplexType) schemas.Find (part.Type, typeof(XmlSchemaComplexType));
226 XmlSchemaElement elem = (XmlSchemaElement) schemas.Find (part.Element, typeof(XmlSchemaElement));
227 ctype = (XmlSchemaComplexType) elem.SchemaType;
229 XmlSchemaSequence seq = ctype.Particle as XmlSchemaSequence;
230 if (seq == null) return;
232 foreach (XmlSchemaObject ob in seq.Items)
234 Parameter p = new Parameter();
235 p.Description = "No additional remarks";
237 if (ob is XmlSchemaElement)
239 XmlSchemaElement selem = GetRefElement ((XmlSchemaElement)ob);
241 p.Type = selem.SchemaTypeName.Name;
253 foreach (MessagePart part in msg.Parts)
255 Parameter p = new Parameter ();
256 p.Description = "No additional remarks";
258 if (part.Element == XmlQualifiedName.Empty)
259 p.Type = part.Type.Name;
262 XmlSchemaElement elem = (XmlSchemaElement) schemas.Find (part.Element, typeof(XmlSchemaElement));
263 p.Type = elem.SchemaTypeName.Name;
270 string GetOperationFormat (OperationBinding obin)
273 SoapOperationBinding sob = obin.Extensions.Find (typeof(SoapOperationBinding)) as SoapOperationBinding;
275 format = sob.Style.ToString ();
276 SoapBodyBinding sbb = obin.Input.Extensions.Find (typeof(SoapBodyBinding)) as SoapBodyBinding;
278 format += " / " + sbb.Use;
283 XmlSchemaElement GetRefElement (XmlSchemaElement elem)
285 if (!elem.RefName.IsEmpty)
286 return (XmlSchemaElement) schemas.Find (elem.RefName, typeof(XmlSchemaElement));
291 ArrayList FindServiceProtocols(string operName)
293 ArrayList table = new ArrayList ();
294 Service service = descriptions[0].Services[0];
295 foreach (Port port in service.Ports)
298 Binding bin = descriptions.GetBinding (port.Binding);
299 if (bin.Extensions.Find (typeof(SoapBinding)) != null)
303 HttpBinding hb = (HttpBinding) bin.Extensions.Find (typeof(HttpBinding));
304 if (hb != null && hb.Verb == "POST") prot = "HttpPost";
305 else if (hb != null && hb.Verb == "GET") prot = "HttpGet";
308 if (prot != null && operName != null)
310 if (FindOperation (bin, operName) == null)
314 if (prot != null && !table.Contains (prot))
320 Port FindPort (string portName, string protocol)
322 Service service = descriptions[0].Services[0];
323 foreach (Port port in service.Ports)
325 if (portName == null)
327 Binding binding = descriptions.GetBinding (port.Binding);
328 if (GetProtocol (binding) == protocol) return port;
330 else if (port.Name == portName)
336 string GetProtocol (Binding binding)
338 if (binding.Extensions.Find (typeof(SoapBinding)) != null) return "Soap";
339 HttpBinding hb = (HttpBinding) binding.Extensions.Find (typeof(HttpBinding));
340 if (hb == null) return "";
341 if (hb.Verb == "POST") return "HttpPost";
342 if (hb.Verb == "GET") return "HttpGet";
347 Operation FindOperation (PortType portType, string name)
349 foreach (Operation oper in portType.Operations) {
350 if (oper.Messages.Input.Name != null) {
351 if (oper.Messages.Input.Name == name) return oper;
354 if (oper.Name == name) return oper;
360 OperationBinding FindOperation (Binding binding, string name)
362 foreach (OperationBinding oper in binding.Operations) {
363 if (oper.Input.Name != null) {
364 if (oper.Input.Name == name) return oper;
367 if (oper.Name == name) return oper;
373 string FormatBindingName (string name)
375 if (name == DefaultBinding) return "Methods";
376 else return "Methods for binding<br>" + name;
379 string GetOpName (object op)
381 OperationBinding ob = op as OperationBinding;
382 if (ob == null) return "";
383 if (ob.Input.Name != null) return ob.Input.Name;
389 get { return Request.QueryString ["ext"] == "testform"; }
392 class NoCheckCertificatePolicy : ICertificatePolicy {
393 public bool CheckValidationResult (ServicePoint a, X509Certificate b, WebRequest c, int d)
401 return (CurrentOperationProtocols.IndexOf ("HttpGet") >= 0) ? "GET" : "POST";
408 NameValueCollection query_string = Request.QueryString;
409 for (int n = 0; n < query_string.Count; n++) {
411 if (qs != "") qs += "&";
412 qs += query_string.GetKey(n) + "=" + Server.UrlEncode (query_string [n]);
414 if (query_string.GetKey(n) == "ext") fill = true;
420 string GetTestResultUrl ()
422 if (!HasFormResult) return "";
424 string location = null;
425 ServiceDescription desc = descriptions [0];
426 Service service = desc.Services[0];
427 foreach (Port port in service.Ports)
428 if (port.Name == CurrentOperationBinding)
430 SoapAddressBinding sbi = (SoapAddressBinding) port.Extensions.Find (typeof(SoapAddressBinding));
432 location = sbi.Location;
435 if (location == null)
436 return "Could not locate web service";
438 return location + "/" + CurrentOperationName;
441 string GenerateOperationMessages (string protocol, bool generateInput)
443 if (!IsOperationSupported (protocol)) return "";
446 if (protocol != "Soap") port = FindPort (null, protocol);
447 else port = FindPort (CurrentOperationBinding, null);
449 Binding binding = descriptions.GetBinding (port.Binding);
450 OperationBinding obin = FindOperation (binding, CurrentOperationName);
451 PortType portType = descriptions.GetPortType (binding.Type);
452 Operation oper = FindOperation (portType, CurrentOperationName);
454 HtmlSampleGenerator sg = new HtmlSampleGenerator (descriptions, schemas);
455 string txt = sg.GenerateMessage (port, obin, oper, protocol, generateInput);
456 if (protocol == "Soap") txt = WrapText (txt,CodeTextColumns);
457 txt = ColorizeXml (txt);
458 txt = txt.Replace ("@placeholder!","<span class='literal-placeholder'>");
459 txt = txt.Replace ("!placeholder@","</span>");
463 bool IsOperationSupported (string protocol)
465 if (CurrentPage != "op" || CurrentTab != "msg") return false;
466 if (protocol == "Soap") return true;
468 Port port = FindPort (null, protocol);
469 if (port == null) return false;
470 Binding binding = descriptions.GetBinding (port.Binding);
471 if (binding == null) return false;
472 return FindOperation (binding, CurrentOperationName) != null;
476 // Proxy code generation
479 string GetProxyCode ()
481 CodeNamespace codeNamespace = new CodeNamespace();
482 CodeCompileUnit codeUnit = new CodeCompileUnit();
484 codeUnit.Namespaces.Add (codeNamespace);
486 ServiceDescriptionImporter importer = new ServiceDescriptionImporter();
488 foreach (ServiceDescription sd in descriptions)
489 importer.AddServiceDescription(sd, null, null);
491 foreach (XmlSchema sc in schemas)
492 importer.Schemas.Add (sc);
494 importer.Import(codeNamespace, codeUnit);
496 string langId = Request.QueryString ["lang"];
497 if (langId == null || langId == "") langId = "cs";
498 CodeDomProvider provider = GetProvider (langId);
499 ICodeGenerator generator = provider.CreateGenerator();
500 CodeGeneratorOptions options = new CodeGeneratorOptions();
502 StringWriter sw = new StringWriter ();
503 generator.GenerateCodeFromCompileUnit(codeUnit, sw, options);
505 return Colorize (WrapText (sw.ToString (), CodeTextColumns), langId);
508 public string CurrentLanguage
511 string langId = Request.QueryString ["lang"];
512 if (langId == null || langId == "") langId = "cs";
517 public string CurrentProxytName
520 string lan = CurrentLanguage == "cs" ? "C#" : "Visual Basic";
521 return lan + " Client Proxy";
525 private CodeDomProvider GetProvider(string langId)
527 switch (langId.ToUpper())
529 case "CS": return new CSharpCodeProvider();
530 case "VB": return new VBCodeProvider();
531 default: return null;
536 // Document generation
539 string GenerateDocument ()
541 StringWriter sw = new StringWriter ();
543 if (CurrentDocType == "wsdl")
544 descriptions [CurrentDocInd].Write (sw);
545 else if (CurrentDocType == "schema")
546 schemas [CurrentDocInd].Write (sw);
548 return Colorize (WrapText (sw.ToString (), CodeTextColumns), "xml");
551 public string CurrentDocType
553 get { return Request.QueryString ["doctype"] != null ? Request.QueryString ["doctype"] : "wsdl"; }
556 public int CurrentDocInd
558 get { return Request.QueryString ["docind"] != null ? int.Parse (Request.QueryString ["docind"]) : 0; }
561 public string CurrentDocumentName
564 if (CurrentDocType == "wsdl")
565 return "WSDL document for namespace \"" + descriptions [CurrentDocInd].TargetNamespace + "\"";
567 return "Xml Schema for namespace \"" + schemas [CurrentDocInd].TargetNamespace + "\"";
575 bool firstTab = true;
576 ArrayList disabledTabs = new ArrayList ();
580 get { return Request.QueryString["tab"] != null ? Request.QueryString["tab"] : "main" ; }
585 get { return Request.QueryString["page"] != null ? Request.QueryString["page"] : "main" ; }
590 if (CurrentOperationName != null)
592 WriteTab ("main","Overview");
593 WriteTab ("test","Test Form");
594 WriteTab ("msg","Message Layout");
598 void WriteTab (string id, string label)
600 if (!firstTab) Response.Write(" | ");
603 string cname = CurrentTab == id ? "tabLabelOn" : "tabLabelOff";
604 Response.Write ("<a href='" + PageName + "?" + GetPageContext(null) + GetDataContext() + "tab=" + id + "' style='text-decoration:none'>");
605 Response.Write ("<span class='" + cname + "'>" + label + "</span>");
606 Response.Write ("</a>");
609 string GetTabContext (string pag, string tab)
611 if (tab == null) tab = CurrentTab;
612 if (pag == null) pag = CurrentPage;
613 if (pag != CurrentPage) tab = "main";
614 return "page=" + pag + "&tab=" + tab + "&";
617 string GetPageContext (string pag)
619 if (pag == null) pag = CurrentPage;
620 return "page=" + pag + "&";
633 static string keywords_cs =
634 "(\\babstract\\b|\\bevent\\b|\\bnew\\b|\\bstruct\\b|\\bas\\b|\\bexplicit\\b|\\bnull\\b|\\bswitch\\b|\\bbase\\b|\\bextern\\b|" +
635 "\\bobject\\b|\\bthis\\b|\\bbool\\b|\\bfalse\\b|\\boperator\\b|\\bthrow\\b|\\bbreak\\b|\\bfinally\\b|\\bout\\b|\\btrue\\b|" +
636 "\\bbyte\\b|\\bfixed\\b|\\boverride\\b|\\btry\\b|\\bcase\\b|\\bfloat\\b|\\bparams\\b|\\btypeof\\b|\\bcatch\\b|\\bfor\\b|" +
637 "\\bprivate\\b|\\buint\\b|\\bchar\\b|\\bforeach\\b|\\bprotected\\b|\\bulong\\b|\\bchecked\\b|\\bgoto\\b|\\bpublic\\b|" +
638 "\\bunchecked\\b|\\bclass\\b|\\bif\\b|\\breadonly\\b|\\bunsafe\\b|\\bconst\\b|\\bimplicit\\b|\\bref\\b|\\bushort\\b|" +
639 "\\bcontinue\\b|\\bin\\b|\\breturn\\b|\\busing\\b|\\bdecimal\\b|\\bint\\b|\\bsbyte\\b|\\bvirtual\\b|\\bdefault\\b|" +
640 "\\binterface\\b|\\bsealed\\b|\\bvolatile\\b|\\bdelegate\\b|\\binternal\\b|\\bshort\\b|\\bvoid\\b|\\bdo\\b|\\bis\\b|" +
641 "\\bsizeof\\b|\\bwhile\\b|\\bdouble\\b|\\block\\b|\\bstackalloc\\b|\\belse\\b|\\blong\\b|\\bstatic\\b|\\benum\\b|" +
642 "\\bnamespace\\b|\\bstring\\b)";
644 static string keywords_vb =
645 "(\\bAddHandler\\b|\\bAddressOf\\b|\\bAlias\\b|\\bAnd\\b|\\bAndAlso\\b|\\bAnsi\\b|\\bAs\\b|\\bAssembly\\b|" +
646 "\\bAuto\\b|\\bBoolean\\b|\\bByRef\\b|\\bByte\\b|\\bByVal\\b|\\bCall\\b|\\bCase\\b|\\bCatch\\b|" +
647 "\\bCBool\\b|\\bCByte\\b|\\bCChar\\b|\\bCDate\\b|\\bCDec\\b|\\bCDbl\\b|\\bChar\\b|\\bCInt\\b|" +
648 "\\bClass\\b|\\bCLng\\b|\\bCObj\\b|\\bConst\\b|\\bCShort\\b|\\bCSng\\b|\\bCStr\\b|\\bCType\\b|" +
649 "\\bDate\\b|\\bDecimal\\b|\\bDeclare\\b|\\bDefault\\b|\\bDelegate\\b|\\bDim\\b|\\bDirectCast\\b|\\bDo\\b|" +
650 "\\bDouble\\b|\\bEach\\b|\\bElse\\b|\\bElseIf\\b|\\bEnd\\b|\\bEnum\\b|\\bErase\\b|\\bError\\b|" +
651 "\\bEvent\\b|\\bExit\\b|\\bFalse\\b|\\bFinally\\b|\\bFor\\b|\\bFriend\\b|\\bFunction\\b|\\bGet\\b|" +
652 "\\bGetType\\b|\\bGoSub\\b|\\bGoTo\\b|\\bHandles\\b|\\bIf\\b|\\bImplements\\b|\\bImports\\b|\\bIn\\b|" +
653 "\\bInherits\\b|\\bInteger\\b|\\bInterface\\b|\\bIs\\b|\\bLet\\b|\\bLib\\b|\\bLike\\b|\\bLong\\b|" +
654 "\\bLoop\\b|\\bMe\\b|\\bMod\\b|\\bModule\\b|\\bMustInherit\\b|\\bMustOverride\\b|\\bMyBase\\b|\\bMyClass\\b|" +
655 "\\bNamespace\\b|\\bNew\\b|\\bNext\\b|\\bNot\\b|\\bNothing\\b|\\bNotInheritable\\b|\\bNotOverridable\\b|\\bObject\\b|" +
656 "\\bOn\\b|\\bOption\\b|\\bOptional\\b|\\bOr\\b|\\bOrElse\\b|\\bOverloads\\b|\\bOverridable\\b|\\bOverrides\\b|" +
657 "\\bParamArray\\b|\\bPreserve\\b|\\bPrivate\\b|\\bProperty\\b|\\bProtected\\b|\\bPublic\\b|\\bRaiseEvent\\b|\\bReadOnly\\b|" +
658 "\\bReDim\\b|\\bREM\\b|\\bRemoveHandler\\b|\\bResume\\b|\\bReturn\\b|\\bSelect\\b|\\bSet\\b|\\bShadows\\b|" +
659 "\\bShared\\b|\\bShort\\b|\\bSingle\\b|\\bStatic\\b|\\bStep\\b|\\bStop\\b|\\bString\\b|\\bStructure\\b|" +
660 "\\bSub\\b|\\bSyncLock\\b|\\bThen\\b|\\bThrow\\b|\\bTo\\b|\\bTrue\\b|\\bTry\\b|\\bTypeOf\\b|" +
661 "\\bUnicode\\b|\\bUntil\\b|\\bVariant\\b|\\bWhen\\b|\\bWhile\\b|\\bWith\\b|\\bWithEvents\\b|\\bWriteOnly\\b|\\bXor\\b)";
663 string Colorize (string text, string lang)
665 if (lang == "xml") return ColorizeXml (text);
666 else if (lang == "cs") return ColorizeCs (text);
667 else if (lang == "vb") return ColorizeVb (text);
671 string ColorizeXml (string text)
673 text = text.Replace (" ", " ");
674 Regex re = new Regex ("\r\n|\r|\n");
675 text = re.Replace (text, "_br_");
677 re = new Regex ("<\\s*(\\/?)\\s*([\\s\\S]*?)\\s*(\\/?)\\s*>");
678 text = re.Replace (text,"{blue:<$1}{maroon:$2}{blue:$3>}");
680 re = new Regex ("\\{(\\w*):([\\s\\S]*?)\\}");
681 text = re.Replace (text,"<span style='color:$1'>$2</span>");
683 re = new Regex ("\"(.*?)\"");
684 text = re.Replace (text,"\"<span style='color:purple'>$1</span>\"");
687 text = text.Replace ("\t", " ");
688 text = text.Replace ("_br_", "<br>");
692 string ColorizeCs (string text)
694 text = text.Replace (" ", " ");
696 text = text.Replace ("<", "<");
697 text = text.Replace (">", ">");
699 Regex re = new Regex ("\"((((?!\").)|\\\")*?)\"");
700 text = re.Replace (text,"<span style='color:purple'>\"$1\"</span>");
702 re = new Regex ("//(((.(?!\"</span>))|\"(((?!\").)*)\"</span>)*)(\r|\n|\r\n)");
703 text = re.Replace (text,"<span style='color:green'>//$1</span><br/>");
705 re = new Regex (keywords_cs);
706 text = re.Replace (text,"<span style='color:blue'>$1</span>");
708 text = text.Replace ("\t"," ");
709 text = text.Replace ("\n","<br/>");
714 string ColorizeVb (string text)
716 text = text.Replace (" ", " ");
718 /* Regex re = new Regex ("\"((((?!\").)|\\\")*?)\"");
719 text = re.Replace (text,"<span style='color:purple'>\"$1\"</span>");
721 re = new Regex ("'(((.(?!\"\\<\\/span\\>))|\"(((?!\").)*)\"\\<\\/span\\>)*)(\r|\n|\r\n)");
722 text = re.Replace (text,"<span style='color:green'>//$1</span><br/>");
724 re = new Regex (keywords_vb);
725 text = re.Replace (text,"<span style='color:blue'>$1</span>");
727 text = text.Replace ("\t"," ");
728 text = text.Replace ("\n","<br/>");
733 // Helper methods and classes
736 string GetDataContext ()
738 return "op=" + CurrentOperationName + "&bnd=" + CurrentOperationBinding + "&";
741 string GetOptionSel (string v1, string v2)
743 string op = "<option ";
744 if (v1 == v2) op += "selected ";
745 return op + "value='" + v1 + "'>";
748 string WrapText (string text, int maxChars)
750 text = text.Replace(" />","/>");
752 string linspace = null;
756 bool inquotes = false;
758 string sublineIndent = "";
759 System.Text.StringBuilder sb = new System.Text.StringBuilder ();
760 for (int n=0; n<text.Length; n++)
764 if (c=='\r' || c=='\n' || n==text.Length-1)
766 sb.Append (linspace + sublineIndent + text.Substring (linstart, n-linstart+1));
776 if (lastc==',' || lastc=='(')
778 if (!inquotes) breakpos = n;
781 if (lincount > maxChars && breakpos >= linstart)
783 if (linspace != null)
784 sb.Append (linspace + sublineIndent);
785 sb.Append (text.Substring (linstart, breakpos-linstart));
788 lincount = linspace.Length + sublineIndent.Length + (n-breakpos);
792 if (c==' ' || c=='\t')
799 inquotes = !inquotes;
802 if (linspace == null) {
803 linspace = text.Substring (linstart, n-linstart);
810 return sb.ToString ();
819 public string Name { get { return name; } set { name = value; } }
820 public string Type { get { return type; } set { type = value; } }
821 public string Description { get { return description; } set { description = value; } }
824 public class HtmlSampleGenerator: SampleGenerator
826 public HtmlSampleGenerator (ServiceDescriptionCollection services, XmlSchemas schemas)
827 : base (services, schemas)
831 protected override string GetLiteral (string s)
833 return "@placeholder!" + s + "!placeholder@";
838 public class SampleGenerator
840 protected ServiceDescriptionCollection descriptions;
841 protected XmlSchemas schemas;
842 XmlSchemaElement anyElement;
844 SoapBindingUse currentUse;
845 XmlDocument document = new XmlDocument ();
847 static readonly XmlQualifiedName anyType = new XmlQualifiedName ("anyType",XmlSchema.Namespace);
848 static readonly XmlQualifiedName arrayType = new XmlQualifiedName ("Array","http://schemas.xmlsoap.org/soap/encoding/");
849 static readonly XmlQualifiedName arrayTypeRefName = new XmlQualifiedName ("arrayType","http://schemas.xmlsoap.org/soap/encoding/");
850 const string SoapEnvelopeNamespace = "http://schemas.xmlsoap.org/soap/envelope/";
851 const string WsdlNamespace = "http://schemas.xmlsoap.org/wsdl/";
852 const string SoapEncodingNamespace = "http://schemas.xmlsoap.org/soap/encoding/";
856 public EncodedType (string ns, XmlSchemaElement elem) { Namespace = ns; Element = elem; }
857 public string Namespace;
858 public XmlSchemaElement Element;
861 public SampleGenerator (ServiceDescriptionCollection services, XmlSchemas schemas)
863 descriptions = services;
864 this.schemas = schemas;
865 queue = new ArrayList ();
868 public string GenerateMessage (Port port, OperationBinding obin, Operation oper, string protocol, bool generateInput)
870 OperationMessage msg = null;
871 foreach (OperationMessage opm in oper.Messages)
873 if (opm is OperationInput && generateInput) msg = opm;
874 else if (opm is OperationOutput && !generateInput) msg = opm;
876 if (msg == null) return null;
879 case "Soap": return GenerateHttpSoapMessage (port, obin, oper, msg);
880 case "HttpGet": return GenerateHttpGetMessage (port, obin, oper, msg);
881 case "HttpPost": return GenerateHttpPostMessage (port, obin, oper, msg);
883 return "Unknown protocol";
886 public string GenerateHttpSoapMessage (Port port, OperationBinding obin, Operation oper, OperationMessage msg)
890 if (msg is OperationInput)
892 SoapAddressBinding sab = port.Extensions.Find (typeof(SoapAddressBinding)) as SoapAddressBinding;
893 SoapOperationBinding sob = obin.Extensions.Find (typeof(SoapOperationBinding)) as SoapOperationBinding;
894 req += "POST " + new Uri (sab.Location).AbsolutePath + "\n";
895 req += "SOAPAction: " + sob.SoapAction + "\n";
896 req += "Content-Type: text/xml; charset=utf-8\n";
897 req += "Content-Length: " + GetLiteral ("string") + "\n";
898 req += "Host: " + GetLiteral ("string") + "\n\n";
902 req += "HTTP/1.0 200 OK\n";
903 req += "Content-Type: text/xml; charset=utf-8\n";
904 req += "Content-Length: " + GetLiteral ("string") + "\n\n";
907 req += GenerateSoapMessage (obin, oper, msg);
911 public string GenerateHttpGetMessage (Port port, OperationBinding obin, Operation oper, OperationMessage msg)
915 if (msg is OperationInput)
917 HttpAddressBinding sab = port.Extensions.Find (typeof(HttpAddressBinding)) as HttpAddressBinding;
918 HttpOperationBinding sob = obin.Extensions.Find (typeof(HttpOperationBinding)) as HttpOperationBinding;
919 string location = new Uri (sab.Location).AbsolutePath + sob.Location + "?" + BuildQueryString (msg);
920 req += "GET " + location + "\n";
921 req += "Host: " + GetLiteral ("string");
925 req += "HTTP/1.0 200 OK\n";
926 req += "Content-Type: text/xml; charset=utf-8\n";
927 req += "Content-Length: " + GetLiteral ("string") + "\n\n";
929 MimeXmlBinding mxb = (MimeXmlBinding) obin.Output.Extensions.Find (typeof(MimeXmlBinding)) as MimeXmlBinding;
930 if (mxb == null) return req;
932 Message message = descriptions.GetMessage (msg.Message);
933 XmlQualifiedName ename = null;
934 foreach (MessagePart part in message.Parts)
935 if (part.Name == mxb.Part) ename = part.Element;
937 if (ename == null) return req + GetLiteral("string");
939 StringWriter sw = new StringWriter ();
940 XmlTextWriter xtw = new XmlTextWriter (sw);
941 xtw.Formatting = Formatting.Indented;
942 currentUse = SoapBindingUse.Literal;
943 WriteRootElementSample (xtw, ename);
945 req += sw.ToString ();
951 public string GenerateHttpPostMessage (Port port, OperationBinding obin, Operation oper, OperationMessage msg)
955 if (msg is OperationInput)
957 HttpAddressBinding sab = port.Extensions.Find (typeof(HttpAddressBinding)) as HttpAddressBinding;
958 HttpOperationBinding sob = obin.Extensions.Find (typeof(HttpOperationBinding)) as HttpOperationBinding;
959 string location = new Uri (sab.Location).AbsolutePath + sob.Location;
960 req += "POST " + location + "\n";
961 req += "Content-Type: application/x-www-form-urlencoded\n";
962 req += "Content-Length: " + GetLiteral ("string") + "\n";
963 req += "Host: " + GetLiteral ("string") + "\n\n";
964 req += BuildQueryString (msg);
966 else return GenerateHttpGetMessage (port, obin, oper, msg);
971 string BuildQueryString (OperationMessage opm)
974 Message msg = descriptions.GetMessage (opm.Message);
975 foreach (MessagePart part in msg.Parts)
977 if (s.Length != 0) s += "&";
978 s += part.Name + "=" + GetLiteral (part.Type.Name);
983 public string GenerateSoapMessage (OperationBinding obin, Operation oper, OperationMessage msg)
985 SoapOperationBinding sob = obin.Extensions.Find (typeof(SoapOperationBinding)) as SoapOperationBinding;
986 SoapBindingStyle style = (sob != null) ? sob.Style : SoapBindingStyle.Document;
988 MessageBinding msgbin = (msg is OperationInput) ? (MessageBinding) obin.Input : (MessageBinding)obin.Output;
989 SoapBodyBinding sbb = msgbin.Extensions.Find (typeof(SoapBodyBinding)) as SoapBodyBinding;
990 SoapBindingUse bodyUse = (sbb != null) ? sbb.Use : SoapBindingUse.Literal;
992 StringWriter sw = new StringWriter ();
993 XmlTextWriter xtw = new XmlTextWriter (sw);
994 xtw.Formatting = Formatting.Indented;
996 xtw.WriteStartDocument ();
997 xtw.WriteStartElement ("soap", "Envelope", SoapEnvelopeNamespace);
998 xtw.WriteAttributeString ("xmlns", "xsi", null, XmlSchema.InstanceNamespace);
999 xtw.WriteAttributeString ("xmlns", "xsd", null, XmlSchema.Namespace);
1001 if (bodyUse == SoapBindingUse.Encoded)
1003 xtw.WriteAttributeString ("xmlns", "soapenc", null, SoapEncodingNamespace);
1004 xtw.WriteAttributeString ("xmlns", "tns", null, msg.Message.Namespace);
1007 // Serialize headers
1009 bool writtenHeader = false;
1010 foreach (object ob in msgbin.Extensions)
1012 SoapHeaderBinding hb = ob as SoapHeaderBinding;
1013 if (hb == null) continue;
1015 if (!writtenHeader) {
1016 xtw.WriteStartElement ("soap", "Header", SoapEnvelopeNamespace);
1017 writtenHeader = true;
1020 WriteHeader (xtw, hb);
1024 xtw.WriteEndElement ();
1027 xtw.WriteStartElement ("soap", "Body", SoapEnvelopeNamespace);
1029 currentUse = bodyUse;
1030 WriteBody (xtw, oper, msg, sbb, style);
1032 xtw.WriteEndElement ();
1033 xtw.WriteEndElement ();
1035 return sw.ToString ();
1038 void WriteHeader (XmlTextWriter xtw, SoapHeaderBinding header)
1040 Message msg = descriptions.GetMessage (header.Message);
1041 if (msg == null) throw new InvalidOperationException ("Message " + header.Message + " not found");
1042 MessagePart part = msg.Parts [header.Part];
1043 if (part == null) throw new InvalidOperationException ("Message part " + header.Part + " not found in message " + header.Message);
1045 currentUse = header.Use;
1047 if (currentUse == SoapBindingUse.Literal)
1048 WriteRootElementSample (xtw, part.Element);
1050 WriteTypeSample (xtw, part.Type);
1053 void WriteBody (XmlTextWriter xtw, Operation oper, OperationMessage opm, SoapBodyBinding sbb, SoapBindingStyle style)
1055 Message msg = descriptions.GetMessage (opm.Message);
1056 if (msg.Parts.Count > 0 && msg.Parts[0].Name == "parameters")
1058 MessagePart part = msg.Parts[0];
1059 if (part.Element == XmlQualifiedName.Empty)
1060 WriteTypeSample (xtw, part.Type);
1062 WriteRootElementSample (xtw, part.Element);
1066 string elemName = oper.Name;
1068 if (opm is OperationOutput) elemName += "Response";
1070 if (style == SoapBindingStyle.Rpc) {
1071 xtw.WriteStartElement (elemName, sbb.Namespace);
1075 foreach (MessagePart part in msg.Parts)
1077 if (part.Element == XmlQualifiedName.Empty)
1079 XmlSchemaElement elem = new XmlSchemaElement ();
1080 elem.SchemaTypeName = part.Type;
1081 elem.Name = part.Name;
1082 WriteElementSample (xtw, ns, elem);
1085 WriteRootElementSample (xtw, part.Element);
1088 if (style == SoapBindingStyle.Rpc)
1089 xtw.WriteEndElement ();
1091 WriteQueuedTypeSamples (xtw);
1094 void WriteRootElementSample (XmlTextWriter xtw, XmlQualifiedName qname)
1096 XmlSchemaElement elem = (XmlSchemaElement) schemas.Find (qname, typeof(XmlSchemaElement));
1097 if (elem == null) throw new InvalidOperationException ("Element not found: " + qname);
1098 WriteElementSample (xtw, qname.Namespace, elem);
1101 void WriteElementSample (XmlTextWriter xtw, string ns, XmlSchemaElement elem)
1103 bool sharedAnnType = false;
1104 XmlQualifiedName root;
1106 if (!elem.RefName.IsEmpty) {
1107 XmlSchemaElement refElem = FindRefElement (elem);
1108 if (refElem == null) throw new InvalidOperationException ("Global element not found: " + elem.RefName);
1109 root = elem.RefName;
1111 sharedAnnType = true;
1114 root = new XmlQualifiedName (elem.Name, ns);
1116 if (!elem.SchemaTypeName.IsEmpty)
1118 XmlSchemaComplexType st = FindComplexTyype (elem.SchemaTypeName);
1120 WriteComplexTypeSample (xtw, st, root);
1123 xtw.WriteStartElement (root.Name, root.Namespace);
1124 if (currentUse == SoapBindingUse.Encoded)
1125 xtw.WriteAttributeString ("type", XmlSchema.InstanceNamespace, GetQualifiedNameString (xtw, elem.SchemaTypeName));
1126 xtw.WriteString (GetLiteral (FindBuiltInType (elem.SchemaTypeName)));
1127 xtw.WriteEndElement ();
1130 else if (elem.SchemaType == null)
1132 xtw.WriteStartElement ("any");
1133 xtw.WriteEndElement ();
1136 WriteComplexTypeSample (xtw, (XmlSchemaComplexType) elem.SchemaType, root);
1139 void WriteTypeSample (XmlTextWriter xtw, XmlQualifiedName qname)
1141 XmlSchemaComplexType ctype = FindComplexTyype (qname);
1142 if (ctype != null) {
1143 WriteComplexTypeSample (xtw, ctype, qname);
1147 XmlSchemaSimpleType stype = (XmlSchemaSimpleType) schemas.Find (qname, typeof(XmlSchemaSimpleType));
1148 if (stype != null) {
1149 WriteSimpleTypeSample (xtw, stype);
1153 xtw.WriteString (GetLiteral (FindBuiltInType (qname)));
1154 throw new InvalidOperationException ("Type not found: " + qname);
1157 void WriteComplexTypeSample (XmlTextWriter xtw, XmlSchemaComplexType stype, XmlQualifiedName rootName)
1159 WriteComplexTypeSample (xtw, stype, rootName, -1);
1162 void WriteComplexTypeSample (XmlTextWriter xtw, XmlSchemaComplexType stype, XmlQualifiedName rootName, int id)
1164 string ns = rootName.Namespace;
1166 if (rootName.Name.IndexOf ("[]") != -1) rootName = arrayType;
1168 if (currentUse == SoapBindingUse.Encoded) {
1169 string pref = xtw.LookupPrefix (rootName.Namespace);
1170 if (pref == null) pref = "q1";
1171 xtw.WriteStartElement (pref, rootName.Name, rootName.Namespace);
1175 xtw.WriteStartElement (rootName.Name, rootName.Namespace);
1179 xtw.WriteAttributeString ("id", "id" + id);
1180 if (rootName != arrayType)
1181 xtw.WriteAttributeString ("type", XmlSchema.InstanceNamespace, GetQualifiedNameString (xtw, rootName));
1184 WriteComplexTypeAttributes (xtw, stype);
1185 WriteComplexTypeElements (xtw, ns, stype);
1187 xtw.WriteEndElement ();
1190 void WriteComplexTypeAttributes (XmlTextWriter xtw, XmlSchemaComplexType stype)
1192 WriteAttributes (xtw, stype.Attributes, stype.AnyAttribute);
1195 void WriteComplexTypeElements (XmlTextWriter xtw, string ns, XmlSchemaComplexType stype)
1197 if (stype.Particle != null)
1198 WriteParticleComplexContent (xtw, ns, stype.Particle);
1201 if (stype.ContentModel is XmlSchemaSimpleContent)
1202 WriteSimpleContent (xtw, (XmlSchemaSimpleContent)stype.ContentModel);
1203 else if (stype.ContentModel is XmlSchemaComplexContent)
1204 WriteComplexContent (xtw, ns, (XmlSchemaComplexContent)stype.ContentModel);
1208 void WriteAttributes (XmlTextWriter xtw, XmlSchemaObjectCollection atts, XmlSchemaAnyAttribute anyat)
1210 foreach (XmlSchemaObject at in atts)
1212 if (at is XmlSchemaAttribute)
1215 XmlSchemaAttribute attr = (XmlSchemaAttribute)at;
1216 XmlSchemaAttribute refAttr = attr;
1218 // refAttr.Form; TODO
1220 if (!attr.RefName.IsEmpty) {
1221 refAttr = FindRefAttribute (attr.RefName);
1222 if (refAttr == null) throw new InvalidOperationException ("Global attribute not found: " + attr.RefName);
1226 if (!refAttr.SchemaTypeName.IsEmpty) val = FindBuiltInType (refAttr.SchemaTypeName);
1227 else val = FindBuiltInType ((XmlSchemaSimpleType) refAttr.SchemaType);
1229 xtw.WriteAttributeString (refAttr.Name, val);
1231 else if (at is XmlSchemaAttributeGroupRef)
1233 XmlSchemaAttributeGroupRef gref = (XmlSchemaAttributeGroupRef)at;
1234 XmlSchemaAttributeGroup grp = (XmlSchemaAttributeGroup) schemas.Find (gref.RefName, typeof(XmlSchemaAttributeGroup));
1235 WriteAttributes (xtw, grp.Attributes, grp.AnyAttribute);
1240 xtw.WriteAttributeString ("custom-attribute","value");
1243 void WriteParticleComplexContent (XmlTextWriter xtw, string ns, XmlSchemaParticle particle)
1245 WriteParticleContent (xtw, ns, particle, false);
1248 void WriteParticleContent (XmlTextWriter xtw, string ns, XmlSchemaParticle particle, bool multiValue)
1250 if (particle is XmlSchemaGroupRef)
1251 particle = GetRefGroupParticle ((XmlSchemaGroupRef)particle);
1253 if (particle.MaxOccurs > 1) multiValue = true;
1255 if (particle is XmlSchemaSequence) {
1256 WriteSequenceContent (xtw, ns, ((XmlSchemaSequence)particle).Items, multiValue);
1258 else if (particle is XmlSchemaChoice) {
1259 if (((XmlSchemaChoice)particle).Items.Count == 1)
1260 WriteSequenceContent (xtw, ns, ((XmlSchemaChoice)particle).Items, multiValue);
1262 WriteChoiceContent (xtw, ns, (XmlSchemaChoice)particle, multiValue);
1264 else if (particle is XmlSchemaAll) {
1265 WriteSequenceContent (xtw, ns, ((XmlSchemaAll)particle).Items, multiValue);
1269 void WriteSequenceContent (XmlTextWriter xtw, string ns, XmlSchemaObjectCollection items, bool multiValue)
1271 foreach (XmlSchemaObject item in items)
1272 WriteContentItem (xtw, ns, item, multiValue);
1275 void WriteContentItem (XmlTextWriter xtw, string ns, XmlSchemaObject item, bool multiValue)
1277 if (item is XmlSchemaGroupRef)
1278 item = GetRefGroupParticle ((XmlSchemaGroupRef)item);
1280 if (item is XmlSchemaElement)
1282 XmlSchemaElement elem = (XmlSchemaElement) item;
1283 XmlSchemaElement refElem;
1284 if (!elem.RefName.IsEmpty) refElem = FindRefElement (elem);
1285 else refElem = elem;
1287 int num = (elem.MaxOccurs == 1 && !multiValue) ? 1 : 2;
1288 for (int n=0; n<num; n++)
1290 if (currentUse == SoapBindingUse.Literal)
1291 WriteElementSample (xtw, ns, refElem);
1293 WriteRefTypeSample (xtw, ns, refElem);
1296 else if (item is XmlSchemaAny)
1298 xtw.WriteString (GetLiteral ("xml"));
1300 else if (item is XmlSchemaParticle) {
1301 WriteParticleContent (xtw, ns, (XmlSchemaParticle)item, multiValue);
1305 void WriteChoiceContent (XmlTextWriter xtw, string ns, XmlSchemaChoice choice, bool multiValue)
1307 foreach (XmlSchemaObject item in choice.Items)
1308 WriteContentItem (xtw, ns, item, multiValue);
1311 void WriteSimpleContent (XmlTextWriter xtw, XmlSchemaSimpleContent content)
1313 XmlSchemaSimpleContentExtension ext = content.Content as XmlSchemaSimpleContentExtension;
1315 WriteAttributes (xtw, ext.Attributes, ext.AnyAttribute);
1317 XmlQualifiedName qname = GetContentBaseType (content.Content);
1318 xtw.WriteString (GetLiteral (FindBuiltInType (qname)));
1321 string FindBuiltInType (XmlQualifiedName qname)
1323 if (qname.Namespace == XmlSchema.Namespace)
1326 XmlSchemaComplexType ct = FindComplexTyype (qname);
1329 XmlSchemaSimpleContent sc = ct.ContentModel as XmlSchemaSimpleContent;
1330 if (sc == null) throw new InvalidOperationException ("Invalid schema");
1331 return FindBuiltInType (GetContentBaseType (sc.Content));
1334 XmlSchemaSimpleType st = (XmlSchemaSimpleType) schemas.Find (qname, typeof(XmlSchemaSimpleType));
1336 return FindBuiltInType (st);
1338 throw new InvalidOperationException ("Definition of type " + qname + " not found");
1341 string FindBuiltInType (XmlSchemaSimpleType st)
1343 if (st.Content is XmlSchemaSimpleTypeRestriction) {
1344 return FindBuiltInType (GetContentBaseType (st.Content));
1346 else if (st.Content is XmlSchemaSimpleTypeList) {
1347 string s = FindBuiltInType (GetContentBaseType (st.Content));
1348 return s + " " + s + " ...";
1350 else if (st.Content is XmlSchemaSimpleTypeUnion)
1352 //Check if all types of the union are equal. If not, then will use anyType.
1353 XmlSchemaSimpleTypeUnion uni = (XmlSchemaSimpleTypeUnion) st.Content;
1354 string utype = null;
1356 // Anonymous types are unique
1357 if (uni.BaseTypes.Count != 0 && uni.MemberTypes.Length != 0)
1360 foreach (XmlQualifiedName mt in uni.MemberTypes)
1362 string qn = FindBuiltInType (mt);
1363 if (utype != null && qn != utype) return "string";
1373 XmlQualifiedName GetContentBaseType (XmlSchemaObject ob)
1375 if (ob is XmlSchemaSimpleContentExtension)
1376 return ((XmlSchemaSimpleContentExtension)ob).BaseTypeName;
1377 else if (ob is XmlSchemaSimpleContentRestriction)
1378 return ((XmlSchemaSimpleContentRestriction)ob).BaseTypeName;
1379 else if (ob is XmlSchemaSimpleTypeRestriction)
1380 return ((XmlSchemaSimpleTypeRestriction)ob).BaseTypeName;
1381 else if (ob is XmlSchemaSimpleTypeList)
1382 return ((XmlSchemaSimpleTypeList)ob).ItemTypeName;
1387 void WriteComplexContent (XmlTextWriter xtw, string ns, XmlSchemaComplexContent content)
1389 XmlQualifiedName qname;
1391 XmlSchemaComplexContentExtension ext = content.Content as XmlSchemaComplexContentExtension;
1392 if (ext != null) qname = ext.BaseTypeName;
1394 XmlSchemaComplexContentRestriction rest = (XmlSchemaComplexContentRestriction)content.Content;
1395 qname = rest.BaseTypeName;
1396 if (qname == arrayType) {
1397 ParseArrayType (rest, out qname);
1398 XmlSchemaElement elem = new XmlSchemaElement ();
1400 elem.SchemaTypeName = qname;
1402 xtw.WriteAttributeString ("arrayType", SoapEncodingNamespace, qname.Name + "[2]");
1403 WriteContentItem (xtw, ns, elem, true);
1408 // Add base map members to this map
1409 XmlSchemaComplexType ctype = FindComplexTyype (qname);
1410 WriteComplexTypeAttributes (xtw, ctype);
1413 // Add the members of this map
1414 WriteAttributes (xtw, ext.Attributes, ext.AnyAttribute);
1415 if (ext.Particle != null)
1416 WriteParticleComplexContent (xtw, ns, ext.Particle);
1419 WriteComplexTypeElements (xtw, ns, ctype);
1422 void ParseArrayType (XmlSchemaComplexContentRestriction rest, out XmlQualifiedName qtype)
1424 XmlSchemaAttribute arrayTypeAt = FindArrayAttribute (rest.Attributes);
1425 XmlAttribute[] uatts = arrayTypeAt.UnhandledAttributes;
1426 if (uatts == null || uatts.Length == 0) throw new InvalidOperationException ("arrayType attribute not specified in array declaration");
1428 XmlAttribute xat = null;
1429 foreach (XmlAttribute at in uatts)
1430 if (at.LocalName == "arrayType" && at.NamespaceURI == WsdlNamespace)
1431 { xat = at; break; }
1434 throw new InvalidOperationException ("arrayType attribute not specified in array declaration");
1436 string arrayType = xat.Value;
1438 int i = arrayType.LastIndexOf (":");
1439 if (i == -1) ns = "";
1440 else ns = arrayType.Substring (0,i);
1442 int j = arrayType.IndexOf ("[", i+1);
1443 if (j == -1) throw new InvalidOperationException ("Cannot parse WSDL array type: " + arrayType);
1444 type = arrayType.Substring (i+1);
1445 type = type.Substring (0, type.Length-2);
1447 qtype = new XmlQualifiedName (type, ns);
1450 XmlSchemaAttribute FindArrayAttribute (XmlSchemaObjectCollection atts)
1452 foreach (object ob in atts)
1454 XmlSchemaAttribute att = ob as XmlSchemaAttribute;
1455 if (att != null && att.RefName == arrayTypeRefName) return att;
1457 XmlSchemaAttributeGroupRef gref = ob as XmlSchemaAttributeGroupRef;
1460 XmlSchemaAttributeGroup grp = (XmlSchemaAttributeGroup) schemas.Find (gref.RefName, typeof(XmlSchemaAttributeGroup));
1461 att = FindArrayAttribute (grp.Attributes);
1462 if (att != null) return att;
1468 void WriteSimpleTypeSample (XmlTextWriter xtw, XmlSchemaSimpleType stype)
1470 xtw.WriteString (GetLiteral (FindBuiltInType (stype)));
1473 XmlSchemaParticle GetRefGroupParticle (XmlSchemaGroupRef refGroup)
1475 XmlSchemaGroup grp = (XmlSchemaGroup) schemas.Find (refGroup.RefName, typeof (XmlSchemaGroup));
1476 return grp.Particle;
1479 XmlSchemaElement FindRefElement (XmlSchemaElement elem)
1481 if (elem.RefName.Namespace == XmlSchema.Namespace)
1483 if (anyElement != null) return anyElement;
1484 anyElement = new XmlSchemaElement ();
1485 anyElement.Name = "any";
1486 anyElement.SchemaTypeName = anyType;
1489 return (XmlSchemaElement) schemas.Find (elem.RefName, typeof(XmlSchemaElement));
1492 XmlSchemaAttribute FindRefAttribute (XmlQualifiedName refName)
1494 if (refName.Namespace == XmlSchema.Namespace)
1496 XmlSchemaAttribute at = new XmlSchemaAttribute ();
1497 at.Name = refName.Name;
1498 at.SchemaTypeName = new XmlQualifiedName ("string",XmlSchema.Namespace);
1501 return (XmlSchemaAttribute) schemas.Find (refName, typeof(XmlSchemaAttribute));
1504 void WriteRefTypeSample (XmlTextWriter xtw, string ns, XmlSchemaElement elem)
1506 if (elem.SchemaTypeName.Namespace == XmlSchema.Namespace || schemas.Find (elem.SchemaTypeName, typeof(XmlSchemaSimpleType)) != null)
1507 WriteElementSample (xtw, ns, elem);
1510 xtw.WriteStartElement (elem.Name, ns);
1511 xtw.WriteAttributeString ("href", "#id" + (queue.Count+1));
1512 xtw.WriteEndElement ();
1513 queue.Add (new EncodedType (ns, elem));
1517 void WriteQueuedTypeSamples (XmlTextWriter xtw)
1519 for (int n=0; n<queue.Count; n++)
1521 EncodedType ec = (EncodedType) queue[n];
1522 XmlSchemaComplexType st = FindComplexTyype (ec.Element.SchemaTypeName);
1523 WriteComplexTypeSample (xtw, st, ec.Element.SchemaTypeName, n+1);
1527 XmlSchemaComplexType FindComplexTyype (XmlQualifiedName qname)
1529 if (qname.Name.IndexOf ("[]") != -1)
1531 XmlSchemaComplexType stype = new XmlSchemaComplexType ();
1532 stype.ContentModel = new XmlSchemaComplexContent ();
1534 XmlSchemaComplexContentRestriction res = new XmlSchemaComplexContentRestriction ();
1535 stype.ContentModel.Content = res;
1536 res.BaseTypeName = arrayType;
1538 XmlSchemaAttribute att = new XmlSchemaAttribute ();
1539 att.RefName = arrayTypeRefName;
1540 res.Attributes.Add (att);
1542 XmlAttribute xat = document.CreateAttribute ("arrayType", WsdlNamespace);
1543 xat.Value = qname.Namespace + ":" + qname.Name;
1544 att.UnhandledAttributes = new XmlAttribute[] {xat};
1548 return (XmlSchemaComplexType) schemas.Find (qname, typeof(XmlSchemaComplexType));
1551 string GetQualifiedNameString (XmlTextWriter xtw, XmlQualifiedName qname)
1553 string pref = xtw.LookupPrefix (qname.Namespace);
1554 if (pref != null) return pref + ":" + qname.Name;
1556 xtw.WriteAttributeString ("xmlns", "q1", null, qname.Namespace);
1557 return "q1:" + qname.Name;
1560 protected virtual string GetLiteral (string s)
1565 void GetOperationFormat (OperationBinding obin, out SoapBindingStyle style, out SoapBindingUse use)
1567 style = SoapBindingStyle.Document;
1568 use = SoapBindingUse.Literal;
1569 SoapOperationBinding sob = obin.Extensions.Find (typeof(SoapOperationBinding)) as SoapOperationBinding;
1572 SoapBodyBinding sbb = obin.Input.Extensions.Find (typeof(SoapBodyBinding)) as SoapBodyBinding;
1585 <head runat="server">
1586 <link rel="alternate" type="text/xml" href="<%=Request.FilePath%>?disco"/>
1588 <title><%=WebServiceName%> Web Service</title>
1589 <style type="text/css">
1590 BODY { font-family: Arial; margin-left: 20px; margin-top: 20px; font-size: x-small}
1591 TABLE { font-size: x-small }
1592 .title { color:dimgray; font-family: Arial; font-size:20pt; font-weight:900}
1593 .operationTitle { color:dimgray; font-family: Arial; font-size:15pt; font-weight:900}
1594 .method { font-size: x-small }
1595 .bindingLabel { font-size: x-small; font-weight:bold; color:darkgray; line-height:8pt; display:block; margin-bottom:3px }
1596 .label { font-size: small; font-weight:bold; color:darkgray }
1597 .paramTable { font-size: x-small }
1598 .paramTable TR { background-color: gainsboro }
1599 .paramFormTable { font-size: x-small; padding: 10px; background-color: gainsboro }
1600 .paramFormTable TR { background-color: gainsboro }
1601 .paramInput { border: solid 1px gray }
1602 .button {border: solid 1px gray }
1603 .smallSeparator { height:3px; overflow:hidden }
1604 .panel { background-color:whitesmoke; border: solid 1px silver; border-top: solid 1px silver }
1605 .codePanel { background-color: white; font-size:x-small; padding:7px; border:solid 1px silver}
1606 .code-xml { font-size:10pt; font-family:courier }
1607 .code-cs { font-size:10pt; font-family:courier }
1608 .code-vb { font-size:10pt; font-family:courier }
1609 .tabLabelOn { font-weight:bold }
1610 .tabLabelOff {color: darkgray }
1611 .literal-placeholder {color: darkblue; font-weight:bold}
1612 A:link { color: black; }
1613 A:visited { color: black; }
1614 A:active { color: black; }
1615 A:hover { color: blue }
1619 function clearForm ()
1621 document.getElementById("testFormResult").style.display="none";
1628 <div class="title" style="margin-left:20px">
1629 <span class="label">Web Service</span><br>
1634 **********************************************************
1638 <table border="0" width="100%" cellpadding="15px" cellspacing="15px">
1639 <tr valign="top"><td width="150px" class="panel">
1640 <div style="width:150px"></div>
1641 <a class="method" href='<%=PageName%>'>Overview</a><br>
1642 <div class="smallSeparator"></div>
1643 <a class="method" href='<%=PageName + "?" + GetPageContext("wsdl")%>'>Service Description</a>
1644 <div class="smallSeparator"></div>
1645 <a class="method" href='<%=PageName + "?" + GetPageContext("proxy")%>'>Client proxy</a>
1647 <asp:repeater id="BindingsRepeater" runat=server>
1648 <itemtemplate name="itemtemplate">
1649 <span class="bindingLabel"><%#FormatBindingName(DataBinder.Eval(Container.DataItem, "Name").ToString())%></span>
1650 <asp:repeater id="OperationsRepeater" runat=server datasource='<%# ((Binding)Container.DataItem).Operations %>'>
1652 <a class="method" href="<%=PageName%>?<%=GetTabContext("op",null)%>op=<%#GetOpName(Container.DataItem)%>&bnd=<%#DataBinder.Eval(Container.DataItem, "Binding.Name")%>"><%#GetOpName(Container.DataItem)%></a>
1653 <div class="smallSeparator"></div>
1660 </td><td class="panel">
1662 <% if (CurrentPage == "main") {%>
1665 **********************************************************
1666 Web service overview
1669 <p class="label">Web Service Overview</p>
1670 <%=WebServiceDescription%>
1672 <% if (ProfileViolations != null && ProfileViolations.Count > 0) { %>
1673 <p class="label">Basic Profile Conformance</p>
1674 This web service does not conform to WS-I Basic Profile v1.1
1676 Response.Write ("<ul>");
1677 foreach (BasicProfileViolation vio in ProfileViolations) {
1678 Response.Write ("<li><b>" + vio.NormativeStatement + "</b>: " + vio.Details);
1679 Response.Write ("<ul>");
1680 foreach (string ele in vio.Elements)
1681 Response.Write ("<li>" + ele + "</li>");
1682 Response.Write ("</ul>");
1683 Response.Write ("</li>");
1685 Response.Write ("</ul>");
1688 <%} if (DefaultBinding == null) {%>
1689 This service does not contain any public web method.
1690 <%} else if (CurrentPage == "op") {%>
1693 **********************************************************
1694 Operation description
1697 <span class="operationTitle"><%=CurrentOperationName%></span>
1702 <% if (CurrentTab == "main") { %>
1703 <span class="label">Input Parameters</span>
1704 <div class="smallSeparator"></div>
1705 <% if (InParams.Count == 0) { %>
1706 No input parameters<br>
1708 <table class="paramTable" cellspacing="1" cellpadding="5">
1709 <asp:repeater id="InputParamsRepeater" runat=server>
1712 <td width="150"><%#DataBinder.Eval(Container.DataItem, "Name")%></td>
1713 <td width="150"><%#DataBinder.Eval(Container.DataItem, "Type")%></td>
1721 <% if (OutParams.Count > 0) { %>
1722 <span class="label">Output Parameters</span>
1723 <div class="smallSeparator"></div>
1724 <table class="paramTable" cellspacing="1" cellpadding="5">
1725 <asp:repeater id="OutputParamsRepeater" runat=server>
1728 <td width="150"><%#DataBinder.Eval(Container.DataItem, "Name")%></td>
1729 <td width="150"><%#DataBinder.Eval(Container.DataItem, "Type")%></td>
1737 <span class="label">Remarks</span>
1738 <div class="smallSeparator"></div>
1739 <%=OperationDocumentation%>
1741 <span class="label">Technical information</span>
1742 <div class="smallSeparator"></div>
1743 Format: <%=CurrentOperationFormat%>
1744 <br>Supported protocols: <%=CurrentOperationProtocols%>
1748 **********************************************************
1749 Operation description - Test form
1752 <% if (CurrentTab == "test") {
1753 if (CurrentOperationSupportsTest) {%>
1754 Enter values for the parameters and click the 'Invoke' button to test this method:<br><br>
1755 <form action="<%=PageName%>" method="GET">
1756 <input type="hidden" name="page" value="<%=CurrentPage%>">
1757 <input type="hidden" name="tab" value="<%=CurrentTab%>">
1758 <input type="hidden" name="op" value="<%=CurrentOperationName%>">
1759 <input type="hidden" name="bnd" value="<%=CurrentOperationBinding%>">
1760 <input type="hidden" name="ext" value="testform">
1761 <table class="paramFormTable" cellspacing="0" cellpadding="3">
1762 <asp:repeater id="InputFormParamsRepeater" runat=server>
1765 <td><%#DataBinder.Eval(Container.DataItem, "Name")%>: </td>
1766 <td width="150"><input class="paramInput" type="text" size="20" name="<%#DataBinder.Eval(Container.DataItem, "Name")%>"></td>
1770 <tr><td></td><td><input class="button" type="submit" value="Invoke"> <input class="button" type="button" onclick="clearForm()" value="Clear"></td></tr>
1773 <div id="testFormResult" style="display:<%= (HasFormResult?"block":"none") %>">
1774 The web service returned the following result:<br/><br/>
1775 <div class="codePanel" id="testresult_div">
1777 <script language="javascript">
1778 getXML ("<%= GetOrPost () %>", "<%= GetTestResultUrl () %>", "<%= GetQS () %>");
1782 The test form is not available for this operation because it has parameters with a complex structure.
1787 **********************************************************
1788 Operation description - Message Layout
1791 <% if (CurrentTab == "msg") { %>
1793 The following are sample SOAP requests and responses for each protocol supported by this method:
1796 <% if (IsOperationSupported ("Soap")) { %>
1797 <span class="label">Soap</span>
1799 <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("Soap", true)%></div></div>
1801 <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("Soap", false)%></div></div>
1804 <% if (IsOperationSupported ("HttpGet")) { %>
1805 <span class="label">HTTP Get</span>
1807 <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("HttpGet", true)%></div></div>
1809 <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("HttpGet", false)%></div></div>
1812 <% if (IsOperationSupported ("HttpPost")) { %>
1813 <span class="label">HTTP Post</span>
1815 <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("HttpPost", true)%></div></div>
1817 <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("HttpPost", false)%></div></div>
1822 <%} else if (CurrentPage == "proxy") {%>
1824 **********************************************************
1827 <form action="<%=PageName%>" name="langForm" method="GET">
1828 Select the language for which you want to generate a proxy
1829 <input type="hidden" name="page" value="<%=CurrentPage%>">
1830 <SELECT name="lang" onchange="langForm.submit()">
1831 <%=GetOptionSel("cs",CurrentLanguage)%>C#</option>
1832 <%=GetOptionSel("vb",CurrentLanguage)%>Visual Basic</option>
1837 <span class="label"><%=CurrentProxytName%></span>
1838 <a href="<%=PageName + "?code=" + CurrentLanguage%>">Download</a>
1840 <div class="codePanel">
1841 <div class="code-<%=CurrentLanguage%>"><%=GetProxyCode ()%></div>
1843 <%} else if (CurrentPage == "wsdl") {%>
1845 **********************************************************
1848 <% if (descriptions.Count > 1 || schemas.Count > 1) {%>
1849 The description of this web service is composed by several documents. Click on the document you want to see:
1853 for (int n=0; n<descriptions.Count; n++)
1854 Response.Write ("<li><a href='" + PageName + "?" + GetPageContext(null) + "doctype=wsdl&docind=" + n + "'>WSDL document " + descriptions[n].TargetNamespace + "</a></li>");
1855 for (int n=0; n<schemas.Count; n++)
1856 Response.Write ("<li><a href='" + PageName + "?" + GetPageContext(null) + "doctype=schema&docind=" + n + "'>Xml Schema " + schemas[n].TargetNamespace + "</a></li>");
1863 <span class="label"><%=CurrentDocumentName%></span>
1864 <a href="<%=PageName + "?" + CurrentDocType + "=" + CurrentDocInd %>">Download</a>
1866 <div class="codePanel">
1867 <div class="code-xml"><%=GenerateDocument ()%></div>
1872 <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
1874 <td width="20px"></td>