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)
332 string GetTestResult ()
334 if (!HasFormResult) return null;
338 for (int n=0; n<Request.QueryString.Count; n++)
341 if (qs != "") qs += "&";
342 qs += Request.QueryString.GetKey(n) + "=" + Server.UrlEncode (Request.QueryString [n]);
344 if (Request.QueryString.GetKey(n) == "ext") fill = true;
347 string location = null;
348 ServiceDescription desc = descriptions [0];
349 Service service = desc.Services[0];
350 foreach (Port port in service.Ports)
351 if (port.Name == CurrentOperationBinding)
353 SoapAddressBinding sbi = (SoapAddressBinding) port.Extensions.Find (typeof(SoapAddressBinding));
355 location = sbi.Location;
358 if (location == null)
359 return "Could not locate web service";
363 string url = location + "/" + CurrentOperationName;
364 Uri uri = new Uri (url);
366 if (CurrentOperationProtocols.IndexOf ("HttpGet") < 0) {
367 req = WebRequest.Create (url);
369 if (!String.IsNullOrEmpty (qs)) {
370 req.ContentType = "application/x-www-form-urlencoded";
371 byte [] postBuffer = Encoding.UTF8.GetBytes (qs);
372 req.ContentLength = postBuffer.Length;
373 using (Stream requestStream = req.GetRequestStream())
374 requestStream.Write (postBuffer, 0, postBuffer.Length);
378 req = WebRequest.Create (url + "?" + qs);
379 if (url.StartsWith ("https:"))
380 ServicePointManager.CertificatePolicy = new NoCheckCertificatePolicy ();
381 HttpCookieCollection cookies = Request.Cookies;
382 int last = cookies.Count;
384 CookieContainer container = new CookieContainer ();
385 for (int i = 0; i < last; i++) {
386 HttpCookie hcookie = cookies [i];
387 Cookie cookie = new Cookie (hcookie.Name, hcookie.Value, hcookie.Path, hcookie.Domain);
388 container.Add (uri, cookie);
390 ((HttpWebRequest) req).CookieContainer = container;
392 WebResponse resp = req.GetResponse();
393 StreamReader sr = new StreamReader (resp.GetResponseStream());
394 string s = sr.ReadToEnd ();
396 return "<div class='code-xml'>" + ColorizeXml(WrapText(s,CodeTextColumns)) + "</div>";
400 string res = "<b style='color:red'>" + ex.Message + "</b>";
401 WebException wex = ex as WebException;
404 WebResponse resp = wex.Response;
406 StreamReader sr = new StreamReader (resp.GetResponseStream());
407 string s = sr.ReadToEnd ();
409 res += "<div class='code-xml'>" + ColorizeXml(WrapText(s,CodeTextColumns)) + "</div>";
416 string GenerateOperationMessages (string protocol, bool generateInput)
418 if (!IsOperationSupported (protocol)) return "";
421 if (protocol != "Soap") port = FindPort (null, protocol);
422 else port = FindPort (CurrentOperationBinding, null);
424 Binding binding = descriptions.GetBinding (port.Binding);
425 OperationBinding obin = FindOperation (binding, CurrentOperationName);
426 PortType portType = descriptions.GetPortType (binding.Type);
427 Operation oper = FindOperation (portType, CurrentOperationName);
429 HtmlSampleGenerator sg = new HtmlSampleGenerator (descriptions, schemas);
430 string txt = sg.GenerateMessage (port, obin, oper, protocol, generateInput);
431 if (protocol == "Soap") txt = WrapText (txt,CodeTextColumns);
432 txt = ColorizeXml (txt);
433 txt = txt.Replace ("@placeholder!","<span class='literal-placeholder'>");
434 txt = txt.Replace ("!placeholder@","</span>");
438 bool IsOperationSupported (string protocol)
440 if (CurrentPage != "op" || CurrentTab != "msg") return false;
441 if (protocol == "Soap") return true;
443 Port port = FindPort (null, protocol);
444 if (port == null) return false;
445 Binding binding = descriptions.GetBinding (port.Binding);
446 if (binding == null) return false;
447 return FindOperation (binding, CurrentOperationName) != null;
451 // Proxy code generation
454 string GetProxyCode ()
456 CodeNamespace codeNamespace = new CodeNamespace();
457 CodeCompileUnit codeUnit = new CodeCompileUnit();
459 codeUnit.Namespaces.Add (codeNamespace);
461 ServiceDescriptionImporter importer = new ServiceDescriptionImporter();
463 foreach (ServiceDescription sd in descriptions)
464 importer.AddServiceDescription(sd, null, null);
466 foreach (XmlSchema sc in schemas)
467 importer.Schemas.Add (sc);
469 importer.Import(codeNamespace, codeUnit);
471 string langId = Request.QueryString ["lang"];
472 if (langId == null || langId == "") langId = "cs";
473 CodeDomProvider provider = GetProvider (langId);
474 ICodeGenerator generator = provider.CreateGenerator();
475 CodeGeneratorOptions options = new CodeGeneratorOptions();
477 StringWriter sw = new StringWriter ();
478 generator.GenerateCodeFromCompileUnit(codeUnit, sw, options);
480 return Colorize (WrapText (sw.ToString (), CodeTextColumns), langId);
483 public string CurrentLanguage
486 string langId = Request.QueryString ["lang"];
487 if (langId == null || langId == "") langId = "cs";
492 public string CurrentProxytName
495 string lan = CurrentLanguage == "cs" ? "C#" : "Visual Basic";
496 return lan + " Client Proxy";
500 private CodeDomProvider GetProvider(string langId)
502 switch (langId.ToUpper())
504 case "CS": return new CSharpCodeProvider();
505 case "VB": return new VBCodeProvider();
506 default: return null;
511 // Document generation
514 string GenerateDocument ()
516 StringWriter sw = new StringWriter ();
518 if (CurrentDocType == "wsdl")
519 descriptions [CurrentDocInd].Write (sw);
520 else if (CurrentDocType == "schema")
521 schemas [CurrentDocInd].Write (sw);
523 return Colorize (WrapText (sw.ToString (), CodeTextColumns), "xml");
526 public string CurrentDocType
528 get { return Request.QueryString ["doctype"] != null ? Request.QueryString ["doctype"] : "wsdl"; }
531 public int CurrentDocInd
533 get { return Request.QueryString ["docind"] != null ? int.Parse (Request.QueryString ["docind"]) : 0; }
536 public string CurrentDocumentName
539 if (CurrentDocType == "wsdl")
540 return "WSDL document for namespace \"" + descriptions [CurrentDocInd].TargetNamespace + "\"";
542 return "Xml Schema for namespace \"" + schemas [CurrentDocInd].TargetNamespace + "\"";
550 bool firstTab = true;
551 ArrayList disabledTabs = new ArrayList ();
555 get { return Request.QueryString["tab"] != null ? Request.QueryString["tab"] : "main" ; }
560 get { return Request.QueryString["page"] != null ? Request.QueryString["page"] : "main" ; }
565 if (CurrentOperationName != null)
567 WriteTab ("main","Overview");
568 WriteTab ("test","Test Form");
569 WriteTab ("msg","Message Layout");
573 void WriteTab (string id, string label)
575 if (!firstTab) Response.Write(" | ");
578 string cname = CurrentTab == id ? "tabLabelOn" : "tabLabelOff";
579 Response.Write ("<a href='" + PageName + "?" + GetPageContext(null) + GetDataContext() + "tab=" + id + "' style='text-decoration:none'>");
580 Response.Write ("<span class='" + cname + "'>" + label + "</span>");
581 Response.Write ("</a>");
584 string GetTabContext (string pag, string tab)
586 if (tab == null) tab = CurrentTab;
587 if (pag == null) pag = CurrentPage;
588 if (pag != CurrentPage) tab = "main";
589 return "page=" + pag + "&tab=" + tab + "&";
592 string GetPageContext (string pag)
594 if (pag == null) pag = CurrentPage;
595 return "page=" + pag + "&";
608 static string keywords_cs =
609 "(\\babstract\\b|\\bevent\\b|\\bnew\\b|\\bstruct\\b|\\bas\\b|\\bexplicit\\b|\\bnull\\b|\\bswitch\\b|\\bbase\\b|\\bextern\\b|" +
610 "\\bobject\\b|\\bthis\\b|\\bbool\\b|\\bfalse\\b|\\boperator\\b|\\bthrow\\b|\\bbreak\\b|\\bfinally\\b|\\bout\\b|\\btrue\\b|" +
611 "\\bbyte\\b|\\bfixed\\b|\\boverride\\b|\\btry\\b|\\bcase\\b|\\bfloat\\b|\\bparams\\b|\\btypeof\\b|\\bcatch\\b|\\bfor\\b|" +
612 "\\bprivate\\b|\\buint\\b|\\bchar\\b|\\bforeach\\b|\\bprotected\\b|\\bulong\\b|\\bchecked\\b|\\bgoto\\b|\\bpublic\\b|" +
613 "\\bunchecked\\b|\\bclass\\b|\\bif\\b|\\breadonly\\b|\\bunsafe\\b|\\bconst\\b|\\bimplicit\\b|\\bref\\b|\\bushort\\b|" +
614 "\\bcontinue\\b|\\bin\\b|\\breturn\\b|\\busing\\b|\\bdecimal\\b|\\bint\\b|\\bsbyte\\b|\\bvirtual\\b|\\bdefault\\b|" +
615 "\\binterface\\b|\\bsealed\\b|\\bvolatile\\b|\\bdelegate\\b|\\binternal\\b|\\bshort\\b|\\bvoid\\b|\\bdo\\b|\\bis\\b|" +
616 "\\bsizeof\\b|\\bwhile\\b|\\bdouble\\b|\\block\\b|\\bstackalloc\\b|\\belse\\b|\\blong\\b|\\bstatic\\b|\\benum\\b|" +
617 "\\bnamespace\\b|\\bstring\\b)";
619 static string keywords_vb =
620 "(\\bAddHandler\\b|\\bAddressOf\\b|\\bAlias\\b|\\bAnd\\b|\\bAndAlso\\b|\\bAnsi\\b|\\bAs\\b|\\bAssembly\\b|" +
621 "\\bAuto\\b|\\bBoolean\\b|\\bByRef\\b|\\bByte\\b|\\bByVal\\b|\\bCall\\b|\\bCase\\b|\\bCatch\\b|" +
622 "\\bCBool\\b|\\bCByte\\b|\\bCChar\\b|\\bCDate\\b|\\bCDec\\b|\\bCDbl\\b|\\bChar\\b|\\bCInt\\b|" +
623 "\\bClass\\b|\\bCLng\\b|\\bCObj\\b|\\bConst\\b|\\bCShort\\b|\\bCSng\\b|\\bCStr\\b|\\bCType\\b|" +
624 "\\bDate\\b|\\bDecimal\\b|\\bDeclare\\b|\\bDefault\\b|\\bDelegate\\b|\\bDim\\b|\\bDirectCast\\b|\\bDo\\b|" +
625 "\\bDouble\\b|\\bEach\\b|\\bElse\\b|\\bElseIf\\b|\\bEnd\\b|\\bEnum\\b|\\bErase\\b|\\bError\\b|" +
626 "\\bEvent\\b|\\bExit\\b|\\bFalse\\b|\\bFinally\\b|\\bFor\\b|\\bFriend\\b|\\bFunction\\b|\\bGet\\b|" +
627 "\\bGetType\\b|\\bGoSub\\b|\\bGoTo\\b|\\bHandles\\b|\\bIf\\b|\\bImplements\\b|\\bImports\\b|\\bIn\\b|" +
628 "\\bInherits\\b|\\bInteger\\b|\\bInterface\\b|\\bIs\\b|\\bLet\\b|\\bLib\\b|\\bLike\\b|\\bLong\\b|" +
629 "\\bLoop\\b|\\bMe\\b|\\bMod\\b|\\bModule\\b|\\bMustInherit\\b|\\bMustOverride\\b|\\bMyBase\\b|\\bMyClass\\b|" +
630 "\\bNamespace\\b|\\bNew\\b|\\bNext\\b|\\bNot\\b|\\bNothing\\b|\\bNotInheritable\\b|\\bNotOverridable\\b|\\bObject\\b|" +
631 "\\bOn\\b|\\bOption\\b|\\bOptional\\b|\\bOr\\b|\\bOrElse\\b|\\bOverloads\\b|\\bOverridable\\b|\\bOverrides\\b|" +
632 "\\bParamArray\\b|\\bPreserve\\b|\\bPrivate\\b|\\bProperty\\b|\\bProtected\\b|\\bPublic\\b|\\bRaiseEvent\\b|\\bReadOnly\\b|" +
633 "\\bReDim\\b|\\bREM\\b|\\bRemoveHandler\\b|\\bResume\\b|\\bReturn\\b|\\bSelect\\b|\\bSet\\b|\\bShadows\\b|" +
634 "\\bShared\\b|\\bShort\\b|\\bSingle\\b|\\bStatic\\b|\\bStep\\b|\\bStop\\b|\\bString\\b|\\bStructure\\b|" +
635 "\\bSub\\b|\\bSyncLock\\b|\\bThen\\b|\\bThrow\\b|\\bTo\\b|\\bTrue\\b|\\bTry\\b|\\bTypeOf\\b|" +
636 "\\bUnicode\\b|\\bUntil\\b|\\bVariant\\b|\\bWhen\\b|\\bWhile\\b|\\bWith\\b|\\bWithEvents\\b|\\bWriteOnly\\b|\\bXor\\b)";
638 string Colorize (string text, string lang)
640 if (lang == "xml") return ColorizeXml (text);
641 else if (lang == "cs") return ColorizeCs (text);
642 else if (lang == "vb") return ColorizeVb (text);
646 string ColorizeXml (string text)
648 text = text.Replace (" ", " ");
649 Regex re = new Regex ("\r\n|\r|\n");
650 text = re.Replace (text, "_br_");
652 re = new Regex ("<\\s*(\\/?)\\s*([\\s\\S]*?)\\s*(\\/?)\\s*>");
653 text = re.Replace (text,"{blue:<$1}{maroon:$2}{blue:$3>}");
655 re = new Regex ("\\{(\\w*):([\\s\\S]*?)\\}");
656 text = re.Replace (text,"<span style='color:$1'>$2</span>");
658 re = new Regex ("\"(.*?)\"");
659 text = re.Replace (text,"\"<span style='color:purple'>$1</span>\"");
662 text = text.Replace ("\t", " ");
663 text = text.Replace ("_br_", "<br>");
667 string ColorizeCs (string text)
669 text = text.Replace (" ", " ");
671 text = text.Replace ("<", "<");
672 text = text.Replace (">", ">");
674 Regex re = new Regex ("\"((((?!\").)|\\\")*?)\"");
675 text = re.Replace (text,"<span style='color:purple'>\"$1\"</span>");
677 re = new Regex ("//(((.(?!\"</span>))|\"(((?!\").)*)\"</span>)*)(\r|\n|\r\n)");
678 text = re.Replace (text,"<span style='color:green'>//$1</span><br/>");
680 re = new Regex (keywords_cs);
681 text = re.Replace (text,"<span style='color:blue'>$1</span>");
683 text = text.Replace ("\t"," ");
684 text = text.Replace ("\n","<br/>");
689 string ColorizeVb (string text)
691 text = text.Replace (" ", " ");
693 /* Regex re = new Regex ("\"((((?!\").)|\\\")*?)\"");
694 text = re.Replace (text,"<span style='color:purple'>\"$1\"</span>");
696 re = new Regex ("'(((.(?!\"\\<\\/span\\>))|\"(((?!\").)*)\"\\<\\/span\\>)*)(\r|\n|\r\n)");
697 text = re.Replace (text,"<span style='color:green'>//$1</span><br/>");
699 re = new Regex (keywords_vb);
700 text = re.Replace (text,"<span style='color:blue'>$1</span>");
702 text = text.Replace ("\t"," ");
703 text = text.Replace ("\n","<br/>");
708 // Helper methods and classes
711 string GetDataContext ()
713 return "op=" + CurrentOperationName + "&bnd=" + CurrentOperationBinding + "&";
716 string GetOptionSel (string v1, string v2)
718 string op = "<option ";
719 if (v1 == v2) op += "selected ";
720 return op + "value='" + v1 + "'>";
723 string WrapText (string text, int maxChars)
725 text = text.Replace(" />","/>");
727 string linspace = null;
731 bool inquotes = false;
733 string sublineIndent = "";
734 System.Text.StringBuilder sb = new System.Text.StringBuilder ();
735 for (int n=0; n<text.Length; n++)
739 if (c=='\r' || c=='\n' || n==text.Length-1)
741 sb.Append (linspace + sublineIndent + text.Substring (linstart, n-linstart+1));
751 if (lastc==',' || lastc=='(')
753 if (!inquotes) breakpos = n;
756 if (lincount > maxChars && breakpos >= linstart)
758 if (linspace != null)
759 sb.Append (linspace + sublineIndent);
760 sb.Append (text.Substring (linstart, breakpos-linstart));
763 lincount = linspace.Length + sublineIndent.Length + (n-breakpos);
767 if (c==' ' || c=='\t')
774 inquotes = !inquotes;
777 if (linspace == null) {
778 linspace = text.Substring (linstart, n-linstart);
785 return sb.ToString ();
794 public string Name { get { return name; } set { name = value; } }
795 public string Type { get { return type; } set { type = value; } }
796 public string Description { get { return description; } set { description = value; } }
799 public class HtmlSampleGenerator: SampleGenerator
801 public HtmlSampleGenerator (ServiceDescriptionCollection services, XmlSchemas schemas)
802 : base (services, schemas)
806 protected override string GetLiteral (string s)
808 return "@placeholder!" + s + "!placeholder@";
813 public class SampleGenerator
815 protected ServiceDescriptionCollection descriptions;
816 protected XmlSchemas schemas;
817 XmlSchemaElement anyElement;
819 SoapBindingUse currentUse;
820 XmlDocument document = new XmlDocument ();
822 static readonly XmlQualifiedName anyType = new XmlQualifiedName ("anyType",XmlSchema.Namespace);
823 static readonly XmlQualifiedName arrayType = new XmlQualifiedName ("Array","http://schemas.xmlsoap.org/soap/encoding/");
824 static readonly XmlQualifiedName arrayTypeRefName = new XmlQualifiedName ("arrayType","http://schemas.xmlsoap.org/soap/encoding/");
825 const string SoapEnvelopeNamespace = "http://schemas.xmlsoap.org/soap/envelope/";
826 const string WsdlNamespace = "http://schemas.xmlsoap.org/wsdl/";
827 const string SoapEncodingNamespace = "http://schemas.xmlsoap.org/soap/encoding/";
831 public EncodedType (string ns, XmlSchemaElement elem) { Namespace = ns; Element = elem; }
832 public string Namespace;
833 public XmlSchemaElement Element;
836 public SampleGenerator (ServiceDescriptionCollection services, XmlSchemas schemas)
838 descriptions = services;
839 this.schemas = schemas;
840 queue = new ArrayList ();
843 public string GenerateMessage (Port port, OperationBinding obin, Operation oper, string protocol, bool generateInput)
845 OperationMessage msg = null;
846 foreach (OperationMessage opm in oper.Messages)
848 if (opm is OperationInput && generateInput) msg = opm;
849 else if (opm is OperationOutput && !generateInput) msg = opm;
851 if (msg == null) return null;
854 case "Soap": return GenerateHttpSoapMessage (port, obin, oper, msg);
855 case "HttpGet": return GenerateHttpGetMessage (port, obin, oper, msg);
856 case "HttpPost": return GenerateHttpPostMessage (port, obin, oper, msg);
858 return "Unknown protocol";
861 public string GenerateHttpSoapMessage (Port port, OperationBinding obin, Operation oper, OperationMessage msg)
865 if (msg is OperationInput)
867 SoapAddressBinding sab = port.Extensions.Find (typeof(SoapAddressBinding)) as SoapAddressBinding;
868 SoapOperationBinding sob = obin.Extensions.Find (typeof(SoapOperationBinding)) as SoapOperationBinding;
869 req += "POST " + new Uri (sab.Location).AbsolutePath + "\n";
870 req += "SOAPAction: " + sob.SoapAction + "\n";
871 req += "Content-Type: text/xml; charset=utf-8\n";
872 req += "Content-Length: " + GetLiteral ("string") + "\n";
873 req += "Host: " + GetLiteral ("string") + "\n\n";
877 req += "HTTP/1.0 200 OK\n";
878 req += "Content-Type: text/xml; charset=utf-8\n";
879 req += "Content-Length: " + GetLiteral ("string") + "\n\n";
882 req += GenerateSoapMessage (obin, oper, msg);
886 public string GenerateHttpGetMessage (Port port, OperationBinding obin, Operation oper, OperationMessage msg)
890 if (msg is OperationInput)
892 HttpAddressBinding sab = port.Extensions.Find (typeof(HttpAddressBinding)) as HttpAddressBinding;
893 HttpOperationBinding sob = obin.Extensions.Find (typeof(HttpOperationBinding)) as HttpOperationBinding;
894 string location = new Uri (sab.Location).AbsolutePath + sob.Location + "?" + BuildQueryString (msg);
895 req += "GET " + location + "\n";
896 req += "Host: " + GetLiteral ("string");
900 req += "HTTP/1.0 200 OK\n";
901 req += "Content-Type: text/xml; charset=utf-8\n";
902 req += "Content-Length: " + GetLiteral ("string") + "\n\n";
904 MimeXmlBinding mxb = (MimeXmlBinding) obin.Output.Extensions.Find (typeof(MimeXmlBinding)) as MimeXmlBinding;
905 if (mxb == null) return req;
907 Message message = descriptions.GetMessage (msg.Message);
908 XmlQualifiedName ename = null;
909 foreach (MessagePart part in message.Parts)
910 if (part.Name == mxb.Part) ename = part.Element;
912 if (ename == null) return req + GetLiteral("string");
914 StringWriter sw = new StringWriter ();
915 XmlTextWriter xtw = new XmlTextWriter (sw);
916 xtw.Formatting = Formatting.Indented;
917 currentUse = SoapBindingUse.Literal;
918 WriteRootElementSample (xtw, ename);
920 req += sw.ToString ();
926 public string GenerateHttpPostMessage (Port port, OperationBinding obin, Operation oper, OperationMessage msg)
930 if (msg is OperationInput)
932 HttpAddressBinding sab = port.Extensions.Find (typeof(HttpAddressBinding)) as HttpAddressBinding;
933 HttpOperationBinding sob = obin.Extensions.Find (typeof(HttpOperationBinding)) as HttpOperationBinding;
934 string location = new Uri (sab.Location).AbsolutePath + sob.Location;
935 req += "POST " + location + "\n";
936 req += "Content-Type: application/x-www-form-urlencoded\n";
937 req += "Content-Length: " + GetLiteral ("string") + "\n";
938 req += "Host: " + GetLiteral ("string") + "\n\n";
939 req += BuildQueryString (msg);
941 else return GenerateHttpGetMessage (port, obin, oper, msg);
946 string BuildQueryString (OperationMessage opm)
949 Message msg = descriptions.GetMessage (opm.Message);
950 foreach (MessagePart part in msg.Parts)
952 if (s.Length != 0) s += "&";
953 s += part.Name + "=" + GetLiteral (part.Type.Name);
958 public string GenerateSoapMessage (OperationBinding obin, Operation oper, OperationMessage msg)
960 SoapOperationBinding sob = obin.Extensions.Find (typeof(SoapOperationBinding)) as SoapOperationBinding;
961 SoapBindingStyle style = (sob != null) ? sob.Style : SoapBindingStyle.Document;
963 MessageBinding msgbin = (msg is OperationInput) ? (MessageBinding) obin.Input : (MessageBinding)obin.Output;
964 SoapBodyBinding sbb = msgbin.Extensions.Find (typeof(SoapBodyBinding)) as SoapBodyBinding;
965 SoapBindingUse bodyUse = (sbb != null) ? sbb.Use : SoapBindingUse.Literal;
967 StringWriter sw = new StringWriter ();
968 XmlTextWriter xtw = new XmlTextWriter (sw);
969 xtw.Formatting = Formatting.Indented;
971 xtw.WriteStartDocument ();
972 xtw.WriteStartElement ("soap", "Envelope", SoapEnvelopeNamespace);
973 xtw.WriteAttributeString ("xmlns", "xsi", null, XmlSchema.InstanceNamespace);
974 xtw.WriteAttributeString ("xmlns", "xsd", null, XmlSchema.Namespace);
976 if (bodyUse == SoapBindingUse.Encoded)
978 xtw.WriteAttributeString ("xmlns", "soapenc", null, SoapEncodingNamespace);
979 xtw.WriteAttributeString ("xmlns", "tns", null, msg.Message.Namespace);
984 bool writtenHeader = false;
985 foreach (object ob in msgbin.Extensions)
987 SoapHeaderBinding hb = ob as SoapHeaderBinding;
988 if (hb == null) continue;
990 if (!writtenHeader) {
991 xtw.WriteStartElement ("soap", "Header", SoapEnvelopeNamespace);
992 writtenHeader = true;
995 WriteHeader (xtw, hb);
999 xtw.WriteEndElement ();
1002 xtw.WriteStartElement ("soap", "Body", SoapEnvelopeNamespace);
1004 currentUse = bodyUse;
1005 WriteBody (xtw, oper, msg, sbb, style);
1007 xtw.WriteEndElement ();
1008 xtw.WriteEndElement ();
1010 return sw.ToString ();
1013 void WriteHeader (XmlTextWriter xtw, SoapHeaderBinding header)
1015 Message msg = descriptions.GetMessage (header.Message);
1016 if (msg == null) throw new InvalidOperationException ("Message " + header.Message + " not found");
1017 MessagePart part = msg.Parts [header.Part];
1018 if (part == null) throw new InvalidOperationException ("Message part " + header.Part + " not found in message " + header.Message);
1020 currentUse = header.Use;
1022 if (currentUse == SoapBindingUse.Literal)
1023 WriteRootElementSample (xtw, part.Element);
1025 WriteTypeSample (xtw, part.Type);
1028 void WriteBody (XmlTextWriter xtw, Operation oper, OperationMessage opm, SoapBodyBinding sbb, SoapBindingStyle style)
1030 Message msg = descriptions.GetMessage (opm.Message);
1031 if (msg.Parts.Count > 0 && msg.Parts[0].Name == "parameters")
1033 MessagePart part = msg.Parts[0];
1034 if (part.Element == XmlQualifiedName.Empty)
1035 WriteTypeSample (xtw, part.Type);
1037 WriteRootElementSample (xtw, part.Element);
1041 string elemName = oper.Name;
1043 if (opm is OperationOutput) elemName += "Response";
1045 if (style == SoapBindingStyle.Rpc) {
1046 xtw.WriteStartElement (elemName, sbb.Namespace);
1050 foreach (MessagePart part in msg.Parts)
1052 if (part.Element == XmlQualifiedName.Empty)
1054 XmlSchemaElement elem = new XmlSchemaElement ();
1055 elem.SchemaTypeName = part.Type;
1056 elem.Name = part.Name;
1057 WriteElementSample (xtw, ns, elem);
1060 WriteRootElementSample (xtw, part.Element);
1063 if (style == SoapBindingStyle.Rpc)
1064 xtw.WriteEndElement ();
1066 WriteQueuedTypeSamples (xtw);
1069 void WriteRootElementSample (XmlTextWriter xtw, XmlQualifiedName qname)
1071 XmlSchemaElement elem = (XmlSchemaElement) schemas.Find (qname, typeof(XmlSchemaElement));
1072 if (elem == null) throw new InvalidOperationException ("Element not found: " + qname);
1073 WriteElementSample (xtw, qname.Namespace, elem);
1076 void WriteElementSample (XmlTextWriter xtw, string ns, XmlSchemaElement elem)
1078 bool sharedAnnType = false;
1079 XmlQualifiedName root;
1081 if (!elem.RefName.IsEmpty) {
1082 XmlSchemaElement refElem = FindRefElement (elem);
1083 if (refElem == null) throw new InvalidOperationException ("Global element not found: " + elem.RefName);
1084 root = elem.RefName;
1086 sharedAnnType = true;
1089 root = new XmlQualifiedName (elem.Name, ns);
1091 if (!elem.SchemaTypeName.IsEmpty)
1093 XmlSchemaComplexType st = FindComplexTyype (elem.SchemaTypeName);
1095 WriteComplexTypeSample (xtw, st, root);
1098 xtw.WriteStartElement (root.Name, root.Namespace);
1099 if (currentUse == SoapBindingUse.Encoded)
1100 xtw.WriteAttributeString ("type", XmlSchema.InstanceNamespace, GetQualifiedNameString (xtw, elem.SchemaTypeName));
1101 xtw.WriteString (GetLiteral (FindBuiltInType (elem.SchemaTypeName)));
1102 xtw.WriteEndElement ();
1105 else if (elem.SchemaType == null)
1107 xtw.WriteStartElement ("any");
1108 xtw.WriteEndElement ();
1111 WriteComplexTypeSample (xtw, (XmlSchemaComplexType) elem.SchemaType, root);
1114 void WriteTypeSample (XmlTextWriter xtw, XmlQualifiedName qname)
1116 XmlSchemaComplexType ctype = FindComplexTyype (qname);
1117 if (ctype != null) {
1118 WriteComplexTypeSample (xtw, ctype, qname);
1122 XmlSchemaSimpleType stype = (XmlSchemaSimpleType) schemas.Find (qname, typeof(XmlSchemaSimpleType));
1123 if (stype != null) {
1124 WriteSimpleTypeSample (xtw, stype);
1128 xtw.WriteString (GetLiteral (FindBuiltInType (qname)));
1129 throw new InvalidOperationException ("Type not found: " + qname);
1132 void WriteComplexTypeSample (XmlTextWriter xtw, XmlSchemaComplexType stype, XmlQualifiedName rootName)
1134 WriteComplexTypeSample (xtw, stype, rootName, -1);
1137 void WriteComplexTypeSample (XmlTextWriter xtw, XmlSchemaComplexType stype, XmlQualifiedName rootName, int id)
1139 string ns = rootName.Namespace;
1141 if (rootName.Name.IndexOf ("[]") != -1) rootName = arrayType;
1143 if (currentUse == SoapBindingUse.Encoded) {
1144 string pref = xtw.LookupPrefix (rootName.Namespace);
1145 if (pref == null) pref = "q1";
1146 xtw.WriteStartElement (pref, rootName.Name, rootName.Namespace);
1150 xtw.WriteStartElement (rootName.Name, rootName.Namespace);
1154 xtw.WriteAttributeString ("id", "id" + id);
1155 if (rootName != arrayType)
1156 xtw.WriteAttributeString ("type", XmlSchema.InstanceNamespace, GetQualifiedNameString (xtw, rootName));
1159 WriteComplexTypeAttributes (xtw, stype);
1160 WriteComplexTypeElements (xtw, ns, stype);
1162 xtw.WriteEndElement ();
1165 void WriteComplexTypeAttributes (XmlTextWriter xtw, XmlSchemaComplexType stype)
1167 WriteAttributes (xtw, stype.Attributes, stype.AnyAttribute);
1170 void WriteComplexTypeElements (XmlTextWriter xtw, string ns, XmlSchemaComplexType stype)
1172 if (stype.Particle != null)
1173 WriteParticleComplexContent (xtw, ns, stype.Particle);
1176 if (stype.ContentModel is XmlSchemaSimpleContent)
1177 WriteSimpleContent (xtw, (XmlSchemaSimpleContent)stype.ContentModel);
1178 else if (stype.ContentModel is XmlSchemaComplexContent)
1179 WriteComplexContent (xtw, ns, (XmlSchemaComplexContent)stype.ContentModel);
1183 void WriteAttributes (XmlTextWriter xtw, XmlSchemaObjectCollection atts, XmlSchemaAnyAttribute anyat)
1185 foreach (XmlSchemaObject at in atts)
1187 if (at is XmlSchemaAttribute)
1190 XmlSchemaAttribute attr = (XmlSchemaAttribute)at;
1191 XmlSchemaAttribute refAttr = attr;
1193 // refAttr.Form; TODO
1195 if (!attr.RefName.IsEmpty) {
1196 refAttr = FindRefAttribute (attr.RefName);
1197 if (refAttr == null) throw new InvalidOperationException ("Global attribute not found: " + attr.RefName);
1201 if (!refAttr.SchemaTypeName.IsEmpty) val = FindBuiltInType (refAttr.SchemaTypeName);
1202 else val = FindBuiltInType ((XmlSchemaSimpleType) refAttr.SchemaType);
1204 xtw.WriteAttributeString (refAttr.Name, val);
1206 else if (at is XmlSchemaAttributeGroupRef)
1208 XmlSchemaAttributeGroupRef gref = (XmlSchemaAttributeGroupRef)at;
1209 XmlSchemaAttributeGroup grp = (XmlSchemaAttributeGroup) schemas.Find (gref.RefName, typeof(XmlSchemaAttributeGroup));
1210 WriteAttributes (xtw, grp.Attributes, grp.AnyAttribute);
1215 xtw.WriteAttributeString ("custom-attribute","value");
1218 void WriteParticleComplexContent (XmlTextWriter xtw, string ns, XmlSchemaParticle particle)
1220 WriteParticleContent (xtw, ns, particle, false);
1223 void WriteParticleContent (XmlTextWriter xtw, string ns, XmlSchemaParticle particle, bool multiValue)
1225 if (particle is XmlSchemaGroupRef)
1226 particle = GetRefGroupParticle ((XmlSchemaGroupRef)particle);
1228 if (particle.MaxOccurs > 1) multiValue = true;
1230 if (particle is XmlSchemaSequence) {
1231 WriteSequenceContent (xtw, ns, ((XmlSchemaSequence)particle).Items, multiValue);
1233 else if (particle is XmlSchemaChoice) {
1234 if (((XmlSchemaChoice)particle).Items.Count == 1)
1235 WriteSequenceContent (xtw, ns, ((XmlSchemaChoice)particle).Items, multiValue);
1237 WriteChoiceContent (xtw, ns, (XmlSchemaChoice)particle, multiValue);
1239 else if (particle is XmlSchemaAll) {
1240 WriteSequenceContent (xtw, ns, ((XmlSchemaAll)particle).Items, multiValue);
1244 void WriteSequenceContent (XmlTextWriter xtw, string ns, XmlSchemaObjectCollection items, bool multiValue)
1246 foreach (XmlSchemaObject item in items)
1247 WriteContentItem (xtw, ns, item, multiValue);
1250 void WriteContentItem (XmlTextWriter xtw, string ns, XmlSchemaObject item, bool multiValue)
1252 if (item is XmlSchemaGroupRef)
1253 item = GetRefGroupParticle ((XmlSchemaGroupRef)item);
1255 if (item is XmlSchemaElement)
1257 XmlSchemaElement elem = (XmlSchemaElement) item;
1258 XmlSchemaElement refElem;
1259 if (!elem.RefName.IsEmpty) refElem = FindRefElement (elem);
1260 else refElem = elem;
1262 int num = (elem.MaxOccurs == 1 && !multiValue) ? 1 : 2;
1263 for (int n=0; n<num; n++)
1265 if (currentUse == SoapBindingUse.Literal)
1266 WriteElementSample (xtw, ns, refElem);
1268 WriteRefTypeSample (xtw, ns, refElem);
1271 else if (item is XmlSchemaAny)
1273 xtw.WriteString (GetLiteral ("xml"));
1275 else if (item is XmlSchemaParticle) {
1276 WriteParticleContent (xtw, ns, (XmlSchemaParticle)item, multiValue);
1280 void WriteChoiceContent (XmlTextWriter xtw, string ns, XmlSchemaChoice choice, bool multiValue)
1282 foreach (XmlSchemaObject item in choice.Items)
1283 WriteContentItem (xtw, ns, item, multiValue);
1286 void WriteSimpleContent (XmlTextWriter xtw, XmlSchemaSimpleContent content)
1288 XmlSchemaSimpleContentExtension ext = content.Content as XmlSchemaSimpleContentExtension;
1290 WriteAttributes (xtw, ext.Attributes, ext.AnyAttribute);
1292 XmlQualifiedName qname = GetContentBaseType (content.Content);
1293 xtw.WriteString (GetLiteral (FindBuiltInType (qname)));
1296 string FindBuiltInType (XmlQualifiedName qname)
1298 if (qname.Namespace == XmlSchema.Namespace)
1301 XmlSchemaComplexType ct = FindComplexTyype (qname);
1304 XmlSchemaSimpleContent sc = ct.ContentModel as XmlSchemaSimpleContent;
1305 if (sc == null) throw new InvalidOperationException ("Invalid schema");
1306 return FindBuiltInType (GetContentBaseType (sc.Content));
1309 XmlSchemaSimpleType st = (XmlSchemaSimpleType) schemas.Find (qname, typeof(XmlSchemaSimpleType));
1311 return FindBuiltInType (st);
1313 throw new InvalidOperationException ("Definition of type " + qname + " not found");
1316 string FindBuiltInType (XmlSchemaSimpleType st)
1318 if (st.Content is XmlSchemaSimpleTypeRestriction) {
1319 return FindBuiltInType (GetContentBaseType (st.Content));
1321 else if (st.Content is XmlSchemaSimpleTypeList) {
1322 string s = FindBuiltInType (GetContentBaseType (st.Content));
1323 return s + " " + s + " ...";
1325 else if (st.Content is XmlSchemaSimpleTypeUnion)
1327 //Check if all types of the union are equal. If not, then will use anyType.
1328 XmlSchemaSimpleTypeUnion uni = (XmlSchemaSimpleTypeUnion) st.Content;
1329 string utype = null;
1331 // Anonymous types are unique
1332 if (uni.BaseTypes.Count != 0 && uni.MemberTypes.Length != 0)
1335 foreach (XmlQualifiedName mt in uni.MemberTypes)
1337 string qn = FindBuiltInType (mt);
1338 if (utype != null && qn != utype) return "string";
1348 XmlQualifiedName GetContentBaseType (XmlSchemaObject ob)
1350 if (ob is XmlSchemaSimpleContentExtension)
1351 return ((XmlSchemaSimpleContentExtension)ob).BaseTypeName;
1352 else if (ob is XmlSchemaSimpleContentRestriction)
1353 return ((XmlSchemaSimpleContentRestriction)ob).BaseTypeName;
1354 else if (ob is XmlSchemaSimpleTypeRestriction)
1355 return ((XmlSchemaSimpleTypeRestriction)ob).BaseTypeName;
1356 else if (ob is XmlSchemaSimpleTypeList)
1357 return ((XmlSchemaSimpleTypeList)ob).ItemTypeName;
1362 void WriteComplexContent (XmlTextWriter xtw, string ns, XmlSchemaComplexContent content)
1364 XmlQualifiedName qname;
1366 XmlSchemaComplexContentExtension ext = content.Content as XmlSchemaComplexContentExtension;
1367 if (ext != null) qname = ext.BaseTypeName;
1369 XmlSchemaComplexContentRestriction rest = (XmlSchemaComplexContentRestriction)content.Content;
1370 qname = rest.BaseTypeName;
1371 if (qname == arrayType) {
1372 ParseArrayType (rest, out qname);
1373 XmlSchemaElement elem = new XmlSchemaElement ();
1375 elem.SchemaTypeName = qname;
1377 xtw.WriteAttributeString ("arrayType", SoapEncodingNamespace, qname.Name + "[2]");
1378 WriteContentItem (xtw, ns, elem, true);
1383 // Add base map members to this map
1384 XmlSchemaComplexType ctype = FindComplexTyype (qname);
1385 WriteComplexTypeAttributes (xtw, ctype);
1388 // Add the members of this map
1389 WriteAttributes (xtw, ext.Attributes, ext.AnyAttribute);
1390 if (ext.Particle != null)
1391 WriteParticleComplexContent (xtw, ns, ext.Particle);
1394 WriteComplexTypeElements (xtw, ns, ctype);
1397 void ParseArrayType (XmlSchemaComplexContentRestriction rest, out XmlQualifiedName qtype)
1399 XmlSchemaAttribute arrayTypeAt = FindArrayAttribute (rest.Attributes);
1400 XmlAttribute[] uatts = arrayTypeAt.UnhandledAttributes;
1401 if (uatts == null || uatts.Length == 0) throw new InvalidOperationException ("arrayType attribute not specified in array declaration");
1403 XmlAttribute xat = null;
1404 foreach (XmlAttribute at in uatts)
1405 if (at.LocalName == "arrayType" && at.NamespaceURI == WsdlNamespace)
1406 { xat = at; break; }
1409 throw new InvalidOperationException ("arrayType attribute not specified in array declaration");
1411 string arrayType = xat.Value;
1413 int i = arrayType.LastIndexOf (":");
1414 if (i == -1) ns = "";
1415 else ns = arrayType.Substring (0,i);
1417 int j = arrayType.IndexOf ("[", i+1);
1418 if (j == -1) throw new InvalidOperationException ("Cannot parse WSDL array type: " + arrayType);
1419 type = arrayType.Substring (i+1);
1420 type = type.Substring (0, type.Length-2);
1422 qtype = new XmlQualifiedName (type, ns);
1425 XmlSchemaAttribute FindArrayAttribute (XmlSchemaObjectCollection atts)
1427 foreach (object ob in atts)
1429 XmlSchemaAttribute att = ob as XmlSchemaAttribute;
1430 if (att != null && att.RefName == arrayTypeRefName) return att;
1432 XmlSchemaAttributeGroupRef gref = ob as XmlSchemaAttributeGroupRef;
1435 XmlSchemaAttributeGroup grp = (XmlSchemaAttributeGroup) schemas.Find (gref.RefName, typeof(XmlSchemaAttributeGroup));
1436 att = FindArrayAttribute (grp.Attributes);
1437 if (att != null) return att;
1443 void WriteSimpleTypeSample (XmlTextWriter xtw, XmlSchemaSimpleType stype)
1445 xtw.WriteString (GetLiteral (FindBuiltInType (stype)));
1448 XmlSchemaParticle GetRefGroupParticle (XmlSchemaGroupRef refGroup)
1450 XmlSchemaGroup grp = (XmlSchemaGroup) schemas.Find (refGroup.RefName, typeof (XmlSchemaGroup));
1451 return grp.Particle;
1454 XmlSchemaElement FindRefElement (XmlSchemaElement elem)
1456 if (elem.RefName.Namespace == XmlSchema.Namespace)
1458 if (anyElement != null) return anyElement;
1459 anyElement = new XmlSchemaElement ();
1460 anyElement.Name = "any";
1461 anyElement.SchemaTypeName = anyType;
1464 return (XmlSchemaElement) schemas.Find (elem.RefName, typeof(XmlSchemaElement));
1467 XmlSchemaAttribute FindRefAttribute (XmlQualifiedName refName)
1469 if (refName.Namespace == XmlSchema.Namespace)
1471 XmlSchemaAttribute at = new XmlSchemaAttribute ();
1472 at.Name = refName.Name;
1473 at.SchemaTypeName = new XmlQualifiedName ("string",XmlSchema.Namespace);
1476 return (XmlSchemaAttribute) schemas.Find (refName, typeof(XmlSchemaAttribute));
1479 void WriteRefTypeSample (XmlTextWriter xtw, string ns, XmlSchemaElement elem)
1481 if (elem.SchemaTypeName.Namespace == XmlSchema.Namespace || schemas.Find (elem.SchemaTypeName, typeof(XmlSchemaSimpleType)) != null)
1482 WriteElementSample (xtw, ns, elem);
1485 xtw.WriteStartElement (elem.Name, ns);
1486 xtw.WriteAttributeString ("href", "#id" + (queue.Count+1));
1487 xtw.WriteEndElement ();
1488 queue.Add (new EncodedType (ns, elem));
1492 void WriteQueuedTypeSamples (XmlTextWriter xtw)
1494 for (int n=0; n<queue.Count; n++)
1496 EncodedType ec = (EncodedType) queue[n];
1497 XmlSchemaComplexType st = FindComplexTyype (ec.Element.SchemaTypeName);
1498 WriteComplexTypeSample (xtw, st, ec.Element.SchemaTypeName, n+1);
1502 XmlSchemaComplexType FindComplexTyype (XmlQualifiedName qname)
1504 if (qname.Name.IndexOf ("[]") != -1)
1506 XmlSchemaComplexType stype = new XmlSchemaComplexType ();
1507 stype.ContentModel = new XmlSchemaComplexContent ();
1509 XmlSchemaComplexContentRestriction res = new XmlSchemaComplexContentRestriction ();
1510 stype.ContentModel.Content = res;
1511 res.BaseTypeName = arrayType;
1513 XmlSchemaAttribute att = new XmlSchemaAttribute ();
1514 att.RefName = arrayTypeRefName;
1515 res.Attributes.Add (att);
1517 XmlAttribute xat = document.CreateAttribute ("arrayType", WsdlNamespace);
1518 xat.Value = qname.Namespace + ":" + qname.Name;
1519 att.UnhandledAttributes = new XmlAttribute[] {xat};
1523 return (XmlSchemaComplexType) schemas.Find (qname, typeof(XmlSchemaComplexType));
1526 string GetQualifiedNameString (XmlTextWriter xtw, XmlQualifiedName qname)
1528 string pref = xtw.LookupPrefix (qname.Namespace);
1529 if (pref != null) return pref + ":" + qname.Name;
1531 xtw.WriteAttributeString ("xmlns", "q1", null, qname.Namespace);
1532 return "q1:" + qname.Name;
1535 protected virtual string GetLiteral (string s)
1540 void GetOperationFormat (OperationBinding obin, out SoapBindingStyle style, out SoapBindingUse use)
1542 style = SoapBindingStyle.Document;
1543 use = SoapBindingUse.Literal;
1544 SoapOperationBinding sob = obin.Extensions.Find (typeof(SoapOperationBinding)) as SoapOperationBinding;
1547 SoapBodyBinding sbb = obin.Input.Extensions.Find (typeof(SoapBodyBinding)) as SoapBodyBinding;
1561 <link rel="alternate" type="text/xml" href="<%=Request.FilePath%>?disco"/>
1563 <title><%=WebServiceName%> Web Service</title>
1564 <style type="text/css">
1565 BODY { font-family: Arial; margin-left: 20px; margin-top: 20px; font-size: x-small}
1566 TABLE { font-size: x-small }
1567 .title { color:dimgray; font-family: Arial; font-size:20pt; font-weight:900}
1568 .operationTitle { color:dimgray; font-family: Arial; font-size:15pt; font-weight:900}
1569 .method { font-size: x-small }
1570 .bindingLabel { font-size: x-small; font-weight:bold; color:darkgray; line-height:8pt; display:block; margin-bottom:3px }
1571 .label { font-size: small; font-weight:bold; color:darkgray }
1572 .paramTable { font-size: x-small }
1573 .paramTable TR { background-color: gainsboro }
1574 .paramFormTable { font-size: x-small; padding: 10px; background-color: gainsboro }
1575 .paramFormTable TR { background-color: gainsboro }
1576 .paramInput { border: solid 1px gray }
1577 .button {border: solid 1px gray }
1578 .smallSeparator { height:3px; overflow:hidden }
1579 .panel { background-color:whitesmoke; border: solid 1px silver; border-top: solid 1px silver }
1580 .codePanel { background-color: white; font-size:x-small; padding:7px; border:solid 1px silver}
1581 .code-xml { font-size:10pt; font-family:courier }
1582 .code-cs { font-size:10pt; font-family:courier }
1583 .code-vb { font-size:10pt; font-family:courier }
1584 .tabLabelOn { font-weight:bold }
1585 .tabLabelOff {color: darkgray }
1586 .literal-placeholder {color: darkblue; font-weight:bold}
1587 A:link { color: black; }
1588 A:visited { color: black; }
1589 A:active { color: black; }
1590 A:hover { color: blue }
1594 function clearForm ()
1596 document.getElementById("testFormResult").style.display="none";
1603 <div class="title" style="margin-left:20px">
1604 <span class="label">Web Service</span><br>
1609 **********************************************************
1613 <table border="0" width="100%" cellpadding="15px" cellspacing="15px">
1614 <tr valign="top"><td width="150px" class="panel">
1615 <div style="width:150px"></div>
1616 <a class="method" href='<%=PageName%>'>Overview</a><br>
1617 <div class="smallSeparator"></div>
1618 <a class="method" href='<%=PageName + "?" + GetPageContext("wsdl")%>'>Service Description</a>
1619 <div class="smallSeparator"></div>
1620 <a class="method" href='<%=PageName + "?" + GetPageContext("proxy")%>'>Client proxy</a>
1622 <asp:repeater id="BindingsRepeater" runat=server>
1623 <itemtemplate name="itemtemplate">
1624 <span class="bindingLabel"><%#FormatBindingName(DataBinder.Eval(Container.DataItem, "Name").ToString())%></span>
1625 <asp:repeater id="OperationsRepeater" runat=server datasource='<%# ((Binding)Container.DataItem).Operations %>'>
1627 <a class="method" href="<%=PageName%>?<%=GetTabContext("op",null)%>op=<%#GetOpName(Container.DataItem)%>&bnd=<%#DataBinder.Eval(Container.DataItem, "Binding.Name")%>"><%#GetOpName(Container.DataItem)%></a>
1628 <div class="smallSeparator"></div>
1635 </td><td class="panel">
1637 <% if (CurrentPage == "main") {%>
1640 **********************************************************
1641 Web service overview
1644 <p class="label">Web Service Overview</p>
1645 <%=WebServiceDescription%>
1647 <% if (ProfileViolations.Count > 0) { %>
1648 <p class="label">Basic Profile Conformance</p>
1649 This web service does not conform to WS-I Basic Profile v1.1
1651 Response.Write ("<ul>");
1652 foreach (BasicProfileViolation vio in ProfileViolations) {
1653 Response.Write ("<li><b>" + vio.NormativeStatement + "</b>: " + vio.Details);
1654 Response.Write ("<ul>");
1655 foreach (string ele in vio.Elements)
1656 Response.Write ("<li>" + ele + "</li>");
1657 Response.Write ("</ul>");
1658 Response.Write ("</li>");
1660 Response.Write ("</ul>");
1663 <%} if (DefaultBinding == null) {%>
1664 This service does not contain any public web method.
1665 <%} else if (CurrentPage == "op") {%>
1668 **********************************************************
1669 Operation description
1672 <span class="operationTitle"><%=CurrentOperationName%></span>
1677 <% if (CurrentTab == "main") { %>
1678 <span class="label">Input Parameters</span>
1679 <div class="smallSeparator"></div>
1680 <% if (InParams.Count == 0) { %>
1681 No input parameters<br>
1683 <table class="paramTable" cellspacing="1" cellpadding="5">
1684 <asp:repeater id="InputParamsRepeater" runat=server>
1687 <td width="150"><%#DataBinder.Eval(Container.DataItem, "Name")%></td>
1688 <td width="150"><%#DataBinder.Eval(Container.DataItem, "Type")%></td>
1696 <% if (OutParams.Count > 0) { %>
1697 <span class="label">Output Parameters</span>
1698 <div class="smallSeparator"></div>
1699 <table class="paramTable" cellspacing="1" cellpadding="5">
1700 <asp:repeater id="OutputParamsRepeater" runat=server>
1703 <td width="150"><%#DataBinder.Eval(Container.DataItem, "Name")%></td>
1704 <td width="150"><%#DataBinder.Eval(Container.DataItem, "Type")%></td>
1712 <span class="label">Remarks</span>
1713 <div class="smallSeparator"></div>
1714 <%=OperationDocumentation%>
1716 <span class="label">Technical information</span>
1717 <div class="smallSeparator"></div>
1718 Format: <%=CurrentOperationFormat%>
1719 <br>Supported protocols: <%=CurrentOperationProtocols%>
1723 **********************************************************
1724 Operation description - Test form
1727 <% if (CurrentTab == "test") {
1728 if (CurrentOperationSupportsTest) {%>
1729 Enter values for the parameters and click the 'Invoke' button to test this method:<br><br>
1730 <form action="<%=PageName%>" method="GET">
1731 <input type="hidden" name="page" value="<%=CurrentPage%>">
1732 <input type="hidden" name="tab" value="<%=CurrentTab%>">
1733 <input type="hidden" name="op" value="<%=CurrentOperationName%>">
1734 <input type="hidden" name="bnd" value="<%=CurrentOperationBinding%>">
1735 <input type="hidden" name="ext" value="testform">
1736 <table class="paramFormTable" cellspacing="0" cellpadding="3">
1737 <asp:repeater id="InputFormParamsRepeater" runat=server>
1740 <td><%#DataBinder.Eval(Container.DataItem, "Name")%>: </td>
1741 <td width="150"><input class="paramInput" type="text" size="20" name="<%#DataBinder.Eval(Container.DataItem, "Name")%>"></td>
1745 <tr><td></td><td><input class="button" type="submit" value="Invoke"> <input class="button" type="button" onclick="clearForm()" value="Clear"></td></tr>
1748 <div id="testFormResult" style="display:<%= (HasFormResult?"block":"none") %>">
1749 The web service returned the following result:<br/><br/>
1750 <div class="codePanel"><%=GetTestResult()%></div>
1753 The test form is not available for this operation because it has parameters with a complex structure.
1758 **********************************************************
1759 Operation description - Message Layout
1762 <% if (CurrentTab == "msg") { %>
1764 The following are sample SOAP requests and responses for each protocol supported by this method:
1767 <% if (IsOperationSupported ("Soap")) { %>
1768 <span class="label">Soap</span>
1770 <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("Soap", true)%></div></div>
1772 <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("Soap", false)%></div></div>
1775 <% if (IsOperationSupported ("HttpGet")) { %>
1776 <span class="label">HTTP Get</span>
1778 <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("HttpGet", true)%></div></div>
1780 <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("HttpGet", false)%></div></div>
1783 <% if (IsOperationSupported ("HttpPost")) { %>
1784 <span class="label">HTTP Post</span>
1786 <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("HttpPost", true)%></div></div>
1788 <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("HttpPost", false)%></div></div>
1793 <%} else if (CurrentPage == "proxy") {%>
1795 **********************************************************
1798 <form action="<%=PageName%>" name="langForm" method="GET">
1799 Select the language for which you want to generate a proxy
1800 <input type="hidden" name="page" value="<%=CurrentPage%>">
1801 <SELECT name="lang" onchange="langForm.submit()">
1802 <%=GetOptionSel("cs",CurrentLanguage)%>C#</option>
1803 <%=GetOptionSel("vb",CurrentLanguage)%>Visual Basic</option>
1808 <span class="label"><%=CurrentProxytName%></span>
1809 <a href="<%=PageName + "?code=" + CurrentLanguage%>">Download</a>
1811 <div class="codePanel">
1812 <div class="code-<%=CurrentLanguage%>"><%=GetProxyCode ()%></div>
1814 <%} else if (CurrentPage == "wsdl") {%>
1816 **********************************************************
1819 <% if (descriptions.Count > 1 || schemas.Count > 1) {%>
1820 The description of this web service is composed by several documents. Click on the document you want to see:
1824 for (int n=0; n<descriptions.Count; n++)
1825 Response.Write ("<li><a href='" + PageName + "?" + GetPageContext(null) + "doctype=wsdl&docind=" + n + "'>WSDL document " + descriptions[n].TargetNamespace + "</a></li>");
1826 for (int n=0; n<schemas.Count; n++)
1827 Response.Write ("<li><a href='" + PageName + "?" + GetPageContext(null) + "doctype=schema&docind=" + n + "'>Xml Schema " + schemas[n].TargetNamespace + "</a></li>");
1834 <span class="label"><%=CurrentDocumentName%></span>
1835 <a href="<%=PageName + "?" + CurrentDocType + "=" + CurrentDocInd %>">Download</a>
1837 <div class="codePanel">
1838 <div class="code-xml"><%=GenerateDocument ()%></div>
1843 <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
1845 <td width="20px"></td>