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 <%@ Assembly name="System.Web.Services" %>
33 <%@ Page debug="true" %>
36 <script language="C#" runat="server">
38 ServiceDescriptionCollection descriptions;
41 string WebServiceName;
42 string WebServiceDescription;
45 string DefaultBinding;
46 ArrayList ServiceProtocols;
48 string CurrentOperationName;
49 string CurrentOperationBinding;
50 string OperationDocumentation;
51 string CurrentOperationFormat;
52 bool CurrentOperationSupportsTest;
55 string CurrentOperationProtocols;
56 int CodeTextColumns = 95;
57 BasicProfileViolationCollection ProfileViolations;
59 void Page_Load(object sender, EventArgs e)
61 descriptions = (ServiceDescriptionCollection) Context.Items["wsdls"];
62 schemas = (XmlSchemas) Context.Items["schemas"];
64 ServiceDescription desc = descriptions [0];
65 if (schemas.Count == 0) schemas = desc.Types.Schemas;
67 Service service = desc.Services[0];
68 WebServiceName = service.Name;
69 if (desc.Bindings.Count == 0)
72 DefaultBinding = desc.Bindings[0].Name;
73 WebServiceDescription = service.Documentation;
74 if (WebServiceDescription == "" || WebServiceDescription == null)
75 WebServiceDescription = "Description has not been provided";
76 ServiceProtocols = FindServiceProtocols (null);
78 CurrentOperationName = Request.QueryString["op"];
79 CurrentOperationBinding = Request.QueryString["bnd"];
80 if (CurrentOperationName != null) BuildOperationInfo ();
82 PageName = HttpUtility.UrlEncode (Path.GetFileName(Request.Path), Encoding.UTF8);
84 ArrayList list = new ArrayList ();
85 foreach (ServiceDescription sd in descriptions) {
86 foreach (Binding bin in sd.Bindings)
87 if (bin.Extensions.Find (typeof(SoapBinding)) != null) list.Add (bin);
90 BindingsRepeater.DataSource = list;
93 ProfileViolations = new BasicProfileViolationCollection ();
94 foreach (WsiProfilesElement claims in ((WebServicesSection) WebConfigurationManager.GetSection("system.web/webServices")).ConformanceWarnings)
95 if (claims.Name != WsiProfiles.None)
96 WebServicesInteroperability.CheckConformance (claims.Name, descriptions, ProfileViolations);
99 void BuildOperationInfo ()
101 InParams = new ArrayList ();
102 OutParams = new ArrayList ();
104 Port port = FindPort (CurrentOperationBinding, null);
105 Binding binding = descriptions.GetBinding (port.Binding);
107 PortType portType = descriptions.GetPortType (binding.Type);
108 Operation oper = FindOperation (portType, CurrentOperationName);
110 OperationDocumentation = oper.Documentation;
111 if (OperationDocumentation == null || OperationDocumentation == "")
112 OperationDocumentation = "No additional remarks";
114 foreach (OperationMessage opm in oper.Messages)
116 if (opm is OperationInput)
117 BuildParameters (InParams, opm);
118 else if (opm is OperationOutput)
119 BuildParameters (OutParams, opm);
122 // Protocols supported by the operation
123 CurrentOperationProtocols = "";
124 ArrayList prots = FindServiceProtocols (CurrentOperationName);
125 for (int n=0; n<prots.Count; n++) {
126 if (n != 0) CurrentOperationProtocols += ", ";
127 CurrentOperationProtocols += (string) prots[n];
130 WebServiceProtocols testProtocols = WebServiceProtocols.HttpGet | WebServiceProtocols.HttpPost;
131 if (Context.Request.IsLocal)
132 testProtocols |= WebServiceProtocols.HttpPostLocalhost;
133 CurrentOperationSupportsTest = (WebServicesSection.Current.EnabledProtocols & testProtocols) != 0;
136 OperationBinding obin = FindOperation (binding, CurrentOperationName);
138 CurrentOperationFormat = GetOperationFormat (obin);
140 InputParamsRepeater.DataSource = InParams;
141 InputFormParamsRepeater.DataSource = InParams;
142 OutputParamsRepeater.DataSource = OutParams;
145 void BuildParameters (ArrayList list, OperationMessage opm)
147 Message msg = descriptions.GetMessage (opm.Message);
148 if (msg.Parts.Count > 0 && msg.Parts[0].Name == "parameters")
150 MessagePart part = msg.Parts[0];
151 XmlSchemaComplexType ctype;
152 if (part.Element == XmlQualifiedName.Empty)
154 ctype = (XmlSchemaComplexType) schemas.Find (part.Type, typeof(XmlSchemaComplexType));
158 XmlSchemaElement elem = (XmlSchemaElement) schemas.Find (part.Element, typeof(XmlSchemaElement));
159 ctype = (XmlSchemaComplexType) elem.SchemaType;
161 XmlSchemaSequence seq = ctype.Particle as XmlSchemaSequence;
162 if (seq == null) return;
164 foreach (XmlSchemaObject ob in seq.Items)
166 Parameter p = new Parameter();
167 p.Description = "No additional remarks";
169 if (ob is XmlSchemaElement)
171 XmlSchemaElement selem = GetRefElement ((XmlSchemaElement)ob);
173 p.Type = selem.SchemaTypeName.Name;
185 foreach (MessagePart part in msg.Parts)
187 Parameter p = new Parameter ();
188 p.Description = "No additional remarks";
190 if (part.Element == XmlQualifiedName.Empty)
191 p.Type = part.Type.Name;
194 XmlSchemaElement elem = (XmlSchemaElement) schemas.Find (part.Element, typeof(XmlSchemaElement));
195 p.Type = elem.SchemaTypeName.Name;
202 string GetOperationFormat (OperationBinding obin)
205 SoapOperationBinding sob = obin.Extensions.Find (typeof(SoapOperationBinding)) as SoapOperationBinding;
207 format = sob.Style.ToString ();
208 SoapBodyBinding sbb = obin.Input.Extensions.Find (typeof(SoapBodyBinding)) as SoapBodyBinding;
210 format += " / " + sbb.Use;
215 XmlSchemaElement GetRefElement (XmlSchemaElement elem)
217 if (!elem.RefName.IsEmpty)
218 return (XmlSchemaElement) schemas.Find (elem.RefName, typeof(XmlSchemaElement));
223 ArrayList FindServiceProtocols(string operName)
225 ArrayList table = new ArrayList ();
226 Service service = descriptions[0].Services[0];
227 foreach (Port port in service.Ports)
230 Binding bin = descriptions.GetBinding (port.Binding);
231 if (bin.Extensions.Find (typeof(SoapBinding)) != null)
235 HttpBinding hb = (HttpBinding) bin.Extensions.Find (typeof(HttpBinding));
236 if (hb != null && hb.Verb == "POST") prot = "HttpPost";
237 else if (hb != null && hb.Verb == "GET") prot = "HttpGet";
240 if (prot != null && operName != null)
242 if (FindOperation (bin, operName) == null)
246 if (prot != null && !table.Contains (prot))
252 Port FindPort (string portName, string protocol)
254 Service service = descriptions[0].Services[0];
255 foreach (Port port in service.Ports)
257 if (portName == null)
259 Binding binding = descriptions.GetBinding (port.Binding);
260 if (GetProtocol (binding) == protocol) return port;
262 else if (port.Name == portName)
268 string GetProtocol (Binding binding)
270 if (binding.Extensions.Find (typeof(SoapBinding)) != null) return "Soap";
271 HttpBinding hb = (HttpBinding) binding.Extensions.Find (typeof(HttpBinding));
272 if (hb == null) return "";
273 if (hb.Verb == "POST") return "HttpPost";
274 if (hb.Verb == "GET") return "HttpGet";
279 Operation FindOperation (PortType portType, string name)
281 foreach (Operation oper in portType.Operations) {
282 if (oper.Messages.Input.Name != null) {
283 if (oper.Messages.Input.Name == name) return oper;
286 if (oper.Name == name) return oper;
292 OperationBinding FindOperation (Binding binding, string name)
294 foreach (OperationBinding oper in binding.Operations) {
295 if (oper.Input.Name != null) {
296 if (oper.Input.Name == name) return oper;
299 if (oper.Name == name) return oper;
305 string FormatBindingName (string name)
307 if (name.EndsWith("Soap")) return "Soap 1.1";
308 else if (name.EndsWith("Soap12")) return "Soap 1.2";
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 string GetTestResult ()
327 if (!HasFormResult) return null;
331 for (int n=0; n<Request.QueryString.Count; n++)
334 if (qs != "") qs += "&";
335 qs += Request.QueryString.GetKey(n) + "=" + Server.UrlEncode (Request.QueryString [n]);
337 if (Request.QueryString.GetKey(n) == "ext") fill = true;
340 string location = null;
341 ServiceDescription desc = descriptions [0];
342 Service service = desc.Services[0];
343 foreach (Port port in service.Ports)
344 if (port.Name == CurrentOperationBinding)
346 SoapAddressBinding sbi = (SoapAddressBinding) port.Extensions.Find (typeof(SoapAddressBinding));
348 location = sbi.Location;
351 if (location == null)
352 return "Could not locate web service";
356 string url = location + "/" + CurrentOperationName;
357 Uri uri = new Uri (url);
359 if (CurrentOperationProtocols.IndexOf ("HttpGet") < 0) {
360 req = WebRequest.Create (url + ".invoke");
362 if (!String.IsNullOrEmpty (qs)) {
363 req.ContentType = "application/x-www-form-urlencoded";
364 byte [] postBuffer = Encoding.UTF8.GetBytes (qs);
365 req.ContentLength = postBuffer.Length;
366 using (Stream requestStream = req.GetRequestStream())
367 requestStream.Write (postBuffer, 0, postBuffer.Length);
371 req = WebRequest.Create (url + ".invoke?" + qs);
372 HttpCookieCollection cookies = Request.Cookies;
373 int last = cookies.Count;
375 CookieContainer container = new CookieContainer ();
376 for (int i = 0; i < last; i++) {
377 HttpCookie hcookie = cookies [i];
378 Cookie cookie = new Cookie (hcookie.Name, hcookie.Value, hcookie.Path, hcookie.Domain);
379 container.Add (uri, cookie);
381 ((HttpWebRequest) req).CookieContainer = container;
383 WebResponse resp = req.GetResponse();
384 StreamReader sr = new StreamReader (resp.GetResponseStream());
385 string s = sr.ReadToEnd ();
387 return "<div class='code-xml'>" + ColorizeXml(WrapText(s,CodeTextColumns)) + "</div>";
391 string res = "<b style='color:red'>" + ex.Message + "</b>";
392 WebException wex = ex as WebException;
395 WebResponse resp = wex.Response;
397 StreamReader sr = new StreamReader (resp.GetResponseStream());
398 string s = sr.ReadToEnd ();
400 res += "<div class='code-xml'>" + ColorizeXml(WrapText(s,CodeTextColumns)) + "</div>";
407 string GenerateOperationMessages (string protocol, bool generateInput)
409 if (!IsOperationSupported (protocol)) return "";
412 if (protocol != "Soap") port = FindPort (null, protocol);
413 else port = FindPort (CurrentOperationBinding, null);
415 Binding binding = descriptions.GetBinding (port.Binding);
416 OperationBinding obin = FindOperation (binding, CurrentOperationName);
417 PortType portType = descriptions.GetPortType (binding.Type);
418 Operation oper = FindOperation (portType, CurrentOperationName);
420 HtmlSampleGenerator sg = new HtmlSampleGenerator (descriptions, schemas);
421 string txt = sg.GenerateMessage (port, obin, oper, protocol, generateInput);
422 if (protocol == "Soap") txt = WrapText (txt,CodeTextColumns);
423 txt = ColorizeXml (txt);
424 txt = txt.Replace ("@placeholder!","<span class='literal-placeholder'>");
425 txt = txt.Replace ("!placeholder@","</span>");
429 bool IsOperationSupported (string protocol)
431 if (CurrentPage != "op" || CurrentTab != "msg") return false;
432 if (protocol == "Soap") return true;
434 Port port = FindPort (null, protocol);
435 if (port == null) return false;
436 Binding binding = descriptions.GetBinding (port.Binding);
437 if (binding == null) return false;
438 return FindOperation (binding, CurrentOperationName) != null;
442 // Proxy code generation
445 string GetProxyCode ()
447 return "Proxy code generation is not yet supported.";
450 public string CurrentLanguage
453 string langId = Request.QueryString ["lang"];
454 if (langId == null || langId == "") langId = "cs";
459 public string CurrentProxytName
462 string lan = CurrentLanguage == "cs" ? "C#" : "Visual Basic";
463 return lan + " Client Proxy";
468 // Document generation
471 string GenerateDocument ()
473 StringWriter sw = new StringWriter ();
475 if (CurrentDocType == "wsdl")
476 descriptions [CurrentDocInd].Write (sw);
477 else if (CurrentDocType == "schema")
478 schemas [CurrentDocInd].Write (sw);
480 return Colorize (WrapText (sw.ToString (), CodeTextColumns), "xml");
483 public string CurrentDocType
485 get { return Request.QueryString ["doctype"] != null ? Request.QueryString ["doctype"] : "wsdl"; }
488 public int CurrentDocInd
490 get { return Request.QueryString ["docind"] != null ? int.Parse (Request.QueryString ["docind"]) : 0; }
493 public string CurrentDocumentName
496 if (CurrentDocType == "wsdl")
497 return "WSDL document for namespace \"" + descriptions [CurrentDocInd].TargetNamespace + "\"";
499 return "Xml Schema for namespace \"" + schemas [CurrentDocInd].TargetNamespace + "\"";
507 bool firstTab = true;
508 ArrayList disabledTabs = new ArrayList ();
512 get { return Request.QueryString["tab"] != null ? Request.QueryString["tab"] : "main" ; }
517 get { return Request.QueryString["page"] != null ? Request.QueryString["page"] : "main" ; }
522 if (CurrentOperationName != null)
524 WriteTab ("main","Overview");
525 WriteTab ("test","Test Form");
526 WriteTab ("msg","Message Layout");
530 void WriteTab (string id, string label)
532 if (!firstTab) Response.Write(" | ");
535 string cname = CurrentTab == id ? "tabLabelOn" : "tabLabelOff";
536 Response.Write ("<a href='" + PageName + "?" + GetPageContext(null) + GetDataContext() + "tab=" + id + "' style='text-decoration:none'>");
537 Response.Write ("<span class='" + cname + "'>" + label + "</span>");
538 Response.Write ("</a>");
541 string GetTabContext (string pag, string tab)
543 if (tab == null) tab = CurrentTab;
544 if (pag == null) pag = CurrentPage;
545 if (pag != CurrentPage) tab = "main";
546 return "page=" + pag + "&tab=" + tab + "&";
549 string GetPageContext (string pag)
551 if (pag == null) pag = CurrentPage;
552 return "page=" + pag + "&";
565 static string keywords_cs =
566 "(\\babstract\\b|\\bevent\\b|\\bnew\\b|\\bstruct\\b|\\bas\\b|\\bexplicit\\b|\\bnull\\b|\\bswitch\\b|\\bbase\\b|\\bextern\\b|" +
567 "\\bobject\\b|\\bthis\\b|\\bbool\\b|\\bfalse\\b|\\boperator\\b|\\bthrow\\b|\\bbreak\\b|\\bfinally\\b|\\bout\\b|\\btrue\\b|" +
568 "\\bbyte\\b|\\bfixed\\b|\\boverride\\b|\\btry\\b|\\bcase\\b|\\bfloat\\b|\\bparams\\b|\\btypeof\\b|\\bcatch\\b|\\bfor\\b|" +
569 "\\bprivate\\b|\\buint\\b|\\bchar\\b|\\bforeach\\b|\\bprotected\\b|\\bulong\\b|\\bchecked\\b|\\bgoto\\b|\\bpublic\\b|" +
570 "\\bunchecked\\b|\\bclass\\b|\\bif\\b|\\breadonly\\b|\\bunsafe\\b|\\bconst\\b|\\bimplicit\\b|\\bref\\b|\\bushort\\b|" +
571 "\\bcontinue\\b|\\bin\\b|\\breturn\\b|\\busing\\b|\\bdecimal\\b|\\bint\\b|\\bsbyte\\b|\\bvirtual\\b|\\bdefault\\b|" +
572 "\\binterface\\b|\\bsealed\\b|\\bvolatile\\b|\\bdelegate\\b|\\binternal\\b|\\bshort\\b|\\bvoid\\b|\\bdo\\b|\\bis\\b|" +
573 "\\bsizeof\\b|\\bwhile\\b|\\bdouble\\b|\\block\\b|\\bstackalloc\\b|\\belse\\b|\\blong\\b|\\bstatic\\b|\\benum\\b|" +
574 "\\bnamespace\\b|\\bstring\\b)";
576 static string keywords_vb =
577 "(\\bAddHandler\\b|\\bAddressOf\\b|\\bAlias\\b|\\bAnd\\b|\\bAndAlso\\b|\\bAnsi\\b|\\bAs\\b|\\bAssembly\\b|" +
578 "\\bAuto\\b|\\bBoolean\\b|\\bByRef\\b|\\bByte\\b|\\bByVal\\b|\\bCall\\b|\\bCase\\b|\\bCatch\\b|" +
579 "\\bCBool\\b|\\bCByte\\b|\\bCChar\\b|\\bCDate\\b|\\bCDec\\b|\\bCDbl\\b|\\bChar\\b|\\bCInt\\b|" +
580 "\\bClass\\b|\\bCLng\\b|\\bCObj\\b|\\bConst\\b|\\bCShort\\b|\\bCSng\\b|\\bCStr\\b|\\bCType\\b|" +
581 "\\bDate\\b|\\bDecimal\\b|\\bDeclare\\b|\\bDefault\\b|\\bDelegate\\b|\\bDim\\b|\\bDirectCast\\b|\\bDo\\b|" +
582 "\\bDouble\\b|\\bEach\\b|\\bElse\\b|\\bElseIf\\b|\\bEnd\\b|\\bEnum\\b|\\bErase\\b|\\bError\\b|" +
583 "\\bEvent\\b|\\bExit\\b|\\bFalse\\b|\\bFinally\\b|\\bFor\\b|\\bFriend\\b|\\bFunction\\b|\\bGet\\b|" +
584 "\\bGetType\\b|\\bGoSub\\b|\\bGoTo\\b|\\bHandles\\b|\\bIf\\b|\\bImplements\\b|\\bImports\\b|\\bIn\\b|" +
585 "\\bInherits\\b|\\bInteger\\b|\\bInterface\\b|\\bIs\\b|\\bLet\\b|\\bLib\\b|\\bLike\\b|\\bLong\\b|" +
586 "\\bLoop\\b|\\bMe\\b|\\bMod\\b|\\bModule\\b|\\bMustInherit\\b|\\bMustOverride\\b|\\bMyBase\\b|\\bMyClass\\b|" +
587 "\\bNamespace\\b|\\bNew\\b|\\bNext\\b|\\bNot\\b|\\bNothing\\b|\\bNotInheritable\\b|\\bNotOverridable\\b|\\bObject\\b|" +
588 "\\bOn\\b|\\bOption\\b|\\bOptional\\b|\\bOr\\b|\\bOrElse\\b|\\bOverloads\\b|\\bOverridable\\b|\\bOverrides\\b|" +
589 "\\bParamArray\\b|\\bPreserve\\b|\\bPrivate\\b|\\bProperty\\b|\\bProtected\\b|\\bPublic\\b|\\bRaiseEvent\\b|\\bReadOnly\\b|" +
590 "\\bReDim\\b|\\bREM\\b|\\bRemoveHandler\\b|\\bResume\\b|\\bReturn\\b|\\bSelect\\b|\\bSet\\b|\\bShadows\\b|" +
591 "\\bShared\\b|\\bShort\\b|\\bSingle\\b|\\bStatic\\b|\\bStep\\b|\\bStop\\b|\\bString\\b|\\bStructure\\b|" +
592 "\\bSub\\b|\\bSyncLock\\b|\\bThen\\b|\\bThrow\\b|\\bTo\\b|\\bTrue\\b|\\bTry\\b|\\bTypeOf\\b|" +
593 "\\bUnicode\\b|\\bUntil\\b|\\bVariant\\b|\\bWhen\\b|\\bWhile\\b|\\bWith\\b|\\bWithEvents\\b|\\bWriteOnly\\b|\\bXor\\b)";
595 string Colorize (string text, string lang)
597 if (lang == "xml") return ColorizeXml (text);
598 else if (lang == "cs") return ColorizeCs (text);
599 else if (lang == "vb") return ColorizeVb (text);
603 string ColorizeXml (string text)
605 text = text.Replace (" ", " ");
606 Regex re = new Regex ("\r\n|\r|\n");
607 text = re.Replace (text, "_br_");
609 re = new Regex ("<\\s*(\\/?)\\s*([\\s\\S]*?)\\s*(\\/?)\\s*>");
610 text = re.Replace (text,"{blue:<$1}{maroon:$2}{blue:$3>}");
612 re = new Regex ("\\{(\\w*):([\\s\\S]*?)\\}");
613 text = re.Replace (text,"<span style='color:$1'>$2</span>");
615 re = new Regex ("\"(.*?)\"");
616 text = re.Replace (text,"\"<span style='color:purple'>$1</span>\"");
619 text = text.Replace ("\t", " ");
620 text = text.Replace ("_br_", "<br>");
624 string ColorizeCs (string text)
626 text = text.Replace (" ", " ");
628 text = text.Replace ("<", "<");
629 text = text.Replace (">", ">");
631 Regex re = new Regex ("\"((((?!\").)|\\\")*?)\"");
632 text = re.Replace (text,"<span style='color:purple'>\"$1\"</span>");
634 re = new Regex ("//(((.(?!\"</span>))|\"(((?!\").)*)\"</span>)*)(\r|\n|\r\n)");
635 text = re.Replace (text,"<span style='color:green'>//$1</span><br/>");
637 re = new Regex (keywords_cs);
638 text = re.Replace (text,"<span style='color:blue'>$1</span>");
640 text = text.Replace ("\t"," ");
641 text = text.Replace ("\n","<br/>");
646 string ColorizeVb (string text)
648 text = text.Replace (" ", " ");
650 /* Regex re = new Regex ("\"((((?!\").)|\\\")*?)\"");
651 text = re.Replace (text,"<span style='color:purple'>\"$1\"</span>");
653 re = new Regex ("'(((.(?!\"\\<\\/span\\>))|\"(((?!\").)*)\"\\<\\/span\\>)*)(\r|\n|\r\n)");
654 text = re.Replace (text,"<span style='color:green'>//$1</span><br/>");
656 re = new Regex (keywords_vb);
657 text = re.Replace (text,"<span style='color:blue'>$1</span>");
659 text = text.Replace ("\t"," ");
660 text = text.Replace ("\n","<br/>");
665 // Helper methods and classes
668 string GetDataContext ()
670 return "op=" + CurrentOperationName + "&bnd=" + CurrentOperationBinding + "&";
673 string GetOptionSel (string v1, string v2)
675 string op = "<option ";
676 if (v1 == v2) op += "selected ";
677 return op + "value='" + v1 + "'>";
680 string WrapText (string text, int maxChars)
682 text = text.Replace(" />","/>");
684 string linspace = null;
688 bool inquotes = false;
690 string sublineIndent = "";
691 System.Text.StringBuilder sb = new System.Text.StringBuilder ();
692 for (int n=0; n<text.Length; n++)
696 if (c=='\r' || c=='\n' || n==text.Length-1)
698 sb.Append (linspace + sublineIndent + text.Substring (linstart, n-linstart+1));
708 if (lastc==',' || lastc=='(')
710 if (!inquotes) breakpos = n;
713 if (lincount > maxChars && breakpos >= linstart)
715 if (linspace != null)
716 sb.Append (linspace + sublineIndent);
717 sb.Append (text.Substring (linstart, breakpos-linstart));
720 lincount = linspace.Length + sublineIndent.Length + (n-breakpos);
724 if (c==' ' || c=='\t')
731 inquotes = !inquotes;
734 if (linspace == null) {
735 linspace = text.Substring (linstart, n-linstart);
742 return sb.ToString ();
751 public string Name { get { return name; } set { name = value; } }
752 public string Type { get { return type; } set { type = value; } }
753 public string Description { get { return description; } set { description = value; } }
756 public class HtmlSampleGenerator: SampleGenerator
758 public HtmlSampleGenerator (ServiceDescriptionCollection services, XmlSchemas schemas)
759 : base (services, schemas)
763 protected override string GetLiteral (string s)
765 return "@placeholder!" + s + "!placeholder@";
770 public class SampleGenerator
772 protected ServiceDescriptionCollection descriptions;
773 protected XmlSchemas schemas;
774 XmlSchemaElement anyElement;
776 SoapBindingUse currentUse;
777 XmlDocument document = new XmlDocument ();
779 static readonly XmlQualifiedName anyType = new XmlQualifiedName ("anyType",XmlSchema.Namespace);
780 static readonly XmlQualifiedName arrayType = new XmlQualifiedName ("Array","http://schemas.xmlsoap.org/soap/encoding/");
781 static readonly XmlQualifiedName arrayTypeRefName = new XmlQualifiedName ("arrayType","http://schemas.xmlsoap.org/soap/encoding/");
782 const string WsdlNamespace = "http://schemas.xmlsoap.org/wsdl/";
783 const string SoapEncodingNamespace = "http://schemas.xmlsoap.org/soap/encoding/";
787 public EncodedType (string ns, XmlSchemaElement elem) { Namespace = ns; Element = elem; }
788 public string Namespace;
789 public XmlSchemaElement Element;
792 public SampleGenerator (ServiceDescriptionCollection services, XmlSchemas schemas)
794 descriptions = services;
795 this.schemas = schemas;
796 queue = new ArrayList ();
799 public string GenerateMessage (Port port, OperationBinding obin, Operation oper, string protocol, bool generateInput)
801 OperationMessage msg = null;
802 foreach (OperationMessage opm in oper.Messages)
804 if (opm is OperationInput && generateInput) msg = opm;
805 else if (opm is OperationOutput && !generateInput) msg = opm;
807 if (msg == null) return null;
810 case "Soap": return GenerateHttpSoapMessage (port, obin, oper, msg);
811 case "HttpGet": return GenerateHttpGetMessage (port, obin, oper, msg);
812 case "HttpPost": return GenerateHttpPostMessage (port, obin, oper, msg);
814 return "Unknown protocol";
817 public string GenerateHttpSoapMessage (Port port, OperationBinding obin, Operation oper, OperationMessage msg)
821 if (msg is OperationInput)
823 SoapAddressBinding sab = port.Extensions.Find (typeof(SoapAddressBinding)) as SoapAddressBinding;
824 SoapOperationBinding sob = obin.Extensions.Find (typeof(SoapOperationBinding)) as SoapOperationBinding;
825 req += "POST " + new Uri (sab.Location).AbsolutePath + "\n";
826 req += "SOAPAction: " + sob.SoapAction + "\n";
827 req += "Content-Type: text/xml; charset=utf-8\n";
828 req += "Content-Length: " + GetLiteral ("string") + "\n";
829 req += "Host: " + GetLiteral ("string") + "\n\n";
833 req += "HTTP/1.0 200 OK\n";
834 req += "Content-Type: text/xml; charset=utf-8\n";
835 req += "Content-Length: " + GetLiteral ("string") + "\n\n";
838 req += GenerateSoapMessage (obin, oper, msg);
842 public string GenerateHttpGetMessage (Port port, OperationBinding obin, Operation oper, OperationMessage msg)
846 if (msg is OperationInput)
848 HttpAddressBinding sab = port.Extensions.Find (typeof(HttpAddressBinding)) as HttpAddressBinding;
849 HttpOperationBinding sob = obin.Extensions.Find (typeof(HttpOperationBinding)) as HttpOperationBinding;
850 string location = new Uri (sab.Location).AbsolutePath + sob.Location + "?" + BuildQueryString (msg);
851 req += "GET " + location + "\n";
852 req += "Host: " + GetLiteral ("string");
856 req += "HTTP/1.0 200 OK\n";
857 req += "Content-Type: text/xml; charset=utf-8\n";
858 req += "Content-Length: " + GetLiteral ("string") + "\n\n";
860 MimeXmlBinding mxb = (MimeXmlBinding) obin.Output.Extensions.Find (typeof(MimeXmlBinding)) as MimeXmlBinding;
861 if (mxb == null) return req;
863 Message message = descriptions.GetMessage (msg.Message);
864 XmlQualifiedName ename = null;
865 foreach (MessagePart part in message.Parts)
866 if (part.Name == mxb.Part) ename = part.Element;
868 if (ename == null) return req + GetLiteral("string");
870 StringWriter sw = new StringWriter ();
871 XmlTextWriter xtw = new XmlTextWriter (sw);
872 xtw.Formatting = Formatting.Indented;
873 currentUse = SoapBindingUse.Literal;
874 WriteRootElementSample (xtw, ename);
876 req += sw.ToString ();
882 public string GenerateHttpPostMessage (Port port, OperationBinding obin, Operation oper, OperationMessage msg)
886 if (msg is OperationInput)
888 HttpAddressBinding sab = port.Extensions.Find (typeof(HttpAddressBinding)) as HttpAddressBinding;
889 HttpOperationBinding sob = obin.Extensions.Find (typeof(HttpOperationBinding)) as HttpOperationBinding;
890 string location = new Uri (sab.Location).AbsolutePath + sob.Location;
891 req += "POST " + location + "\n";
892 req += "Content-Type: application/x-www-form-urlencoded\n";
893 req += "Content-Length: " + GetLiteral ("string") + "\n";
894 req += "Host: " + GetLiteral ("string") + "\n\n";
895 req += BuildQueryString (msg);
897 else return GenerateHttpGetMessage (port, obin, oper, msg);
902 string BuildQueryString (OperationMessage opm)
905 Message msg = descriptions.GetMessage (opm.Message);
906 foreach (MessagePart part in msg.Parts)
908 if (s.Length != 0) s += "&";
909 s += part.Name + "=" + GetLiteral (part.Type.Name);
914 public string GenerateSoapMessage (OperationBinding obin, Operation oper, OperationMessage msg)
916 string SoapEnvelopeNamespace = "http://schemas.xmlsoap.org/soap/envelope/";
917 if(obin.Binding.Name.EndsWith("Soap12"))
918 SoapEnvelopeNamespace = "http://www.w3.org/2003/05/soap-envelope";
920 SoapOperationBinding sob = obin.Extensions.Find (typeof(SoapOperationBinding)) as SoapOperationBinding;
921 SoapBindingStyle style = (sob != null) ? sob.Style : SoapBindingStyle.Document;
923 MessageBinding msgbin = (msg is OperationInput) ? (MessageBinding) obin.Input : (MessageBinding)obin.Output;
924 SoapBodyBinding sbb = msgbin.Extensions.Find (typeof(SoapBodyBinding)) as SoapBodyBinding;
925 SoapBindingUse bodyUse = (sbb != null) ? sbb.Use : SoapBindingUse.Literal;
927 StringWriter sw = new StringWriter ();
928 XmlTextWriter xtw = new XmlTextWriter (sw);
929 xtw.Formatting = Formatting.Indented;
931 xtw.WriteStartDocument ();
932 xtw.WriteStartElement ("soap", "Envelope", SoapEnvelopeNamespace);
933 xtw.WriteAttributeString ("xmlns", "xsi", null, XmlSchema.InstanceNamespace);
934 xtw.WriteAttributeString ("xmlns", "xsd", null, XmlSchema.Namespace);
936 if (bodyUse == SoapBindingUse.Encoded)
938 xtw.WriteAttributeString ("xmlns", "soapenc", null, SoapEncodingNamespace);
939 xtw.WriteAttributeString ("xmlns", "tns", null, msg.Message.Namespace);
944 bool writtenHeader = false;
945 foreach (object ob in msgbin.Extensions)
947 SoapHeaderBinding hb = ob as SoapHeaderBinding;
948 if (hb == null) continue;
950 if (!writtenHeader) {
951 xtw.WriteStartElement ("soap", "Header", SoapEnvelopeNamespace);
952 writtenHeader = true;
955 WriteHeader (xtw, hb);
959 xtw.WriteEndElement ();
962 xtw.WriteStartElement ("soap", "Body", SoapEnvelopeNamespace);
964 currentUse = bodyUse;
965 WriteBody (xtw, oper, msg, sbb, style);
967 xtw.WriteEndElement ();
968 xtw.WriteEndElement ();
970 return sw.ToString ();
973 void WriteHeader (XmlTextWriter xtw, SoapHeaderBinding header)
975 Message msg = descriptions.GetMessage (header.Message);
976 if (msg == null) throw new InvalidOperationException ("Message " + header.Message + " not found");
977 MessagePart part = msg.Parts [header.Part];
978 if (part == null) throw new InvalidOperationException ("Message part " + header.Part + " not found in message " + header.Message);
980 currentUse = header.Use;
982 if (currentUse == SoapBindingUse.Literal)
983 WriteRootElementSample (xtw, part.Element);
985 WriteTypeSample (xtw, part.Type);
988 void WriteBody (XmlTextWriter xtw, Operation oper, OperationMessage opm, SoapBodyBinding sbb, SoapBindingStyle style)
990 Message msg = descriptions.GetMessage (opm.Message);
991 if (msg.Parts.Count > 0 && msg.Parts[0].Name == "parameters")
993 MessagePart part = msg.Parts[0];
994 if (part.Element == XmlQualifiedName.Empty)
995 WriteTypeSample (xtw, part.Type);
997 WriteRootElementSample (xtw, part.Element);
1001 string elemName = oper.Name;
1003 if (opm is OperationOutput) elemName += "Response";
1005 if (style == SoapBindingStyle.Rpc) {
1006 xtw.WriteStartElement (elemName, sbb.Namespace);
1010 foreach (MessagePart part in msg.Parts)
1012 if (part.Element == XmlQualifiedName.Empty)
1014 XmlSchemaElement elem = new XmlSchemaElement ();
1015 elem.SchemaTypeName = part.Type;
1016 elem.Name = part.Name;
1017 WriteElementSample (xtw, ns, elem);
1020 WriteRootElementSample (xtw, part.Element);
1023 if (style == SoapBindingStyle.Rpc)
1024 xtw.WriteEndElement ();
1026 WriteQueuedTypeSamples (xtw);
1029 void WriteRootElementSample (XmlTextWriter xtw, XmlQualifiedName qname)
1031 XmlSchemaElement elem = (XmlSchemaElement) schemas.Find (qname, typeof(XmlSchemaElement));
1032 if (elem == null) throw new InvalidOperationException ("Element not found: " + qname);
1033 WriteElementSample (xtw, qname.Namespace, elem);
1036 void WriteElementSample (XmlTextWriter xtw, string ns, XmlSchemaElement elem)
1038 bool sharedAnnType = false;
1039 XmlQualifiedName root;
1041 if (!elem.RefName.IsEmpty) {
1042 XmlSchemaElement refElem = FindRefElement (elem);
1043 if (refElem == null) throw new InvalidOperationException ("Global element not found: " + elem.RefName);
1044 root = elem.RefName;
1046 sharedAnnType = true;
1049 root = new XmlQualifiedName (elem.Name, ns);
1051 if (!elem.SchemaTypeName.IsEmpty)
1053 XmlSchemaComplexType st = FindComplexTyype (elem.SchemaTypeName);
1055 WriteComplexTypeSample (xtw, st, root);
1058 xtw.WriteStartElement (root.Name, root.Namespace);
1059 if (currentUse == SoapBindingUse.Encoded)
1060 xtw.WriteAttributeString ("type", XmlSchema.InstanceNamespace, GetQualifiedNameString (xtw, elem.SchemaTypeName));
1061 xtw.WriteString (GetLiteral (FindBuiltInType (elem.SchemaTypeName)));
1062 xtw.WriteEndElement ();
1065 else if (elem.SchemaType == null)
1067 xtw.WriteStartElement ("any");
1068 xtw.WriteEndElement ();
1071 WriteComplexTypeSample (xtw, (XmlSchemaComplexType) elem.SchemaType, root);
1074 void WriteTypeSample (XmlTextWriter xtw, XmlQualifiedName qname)
1076 XmlSchemaComplexType ctype = FindComplexTyype (qname);
1077 if (ctype != null) {
1078 WriteComplexTypeSample (xtw, ctype, qname);
1082 XmlSchemaSimpleType stype = (XmlSchemaSimpleType) schemas.Find (qname, typeof(XmlSchemaSimpleType));
1083 if (stype != null) {
1084 WriteSimpleTypeSample (xtw, stype);
1088 xtw.WriteString (GetLiteral (FindBuiltInType (qname)));
1089 throw new InvalidOperationException ("Type not found: " + qname);
1092 void WriteComplexTypeSample (XmlTextWriter xtw, XmlSchemaComplexType stype, XmlQualifiedName rootName)
1094 WriteComplexTypeSample (xtw, stype, rootName, -1);
1097 void WriteComplexTypeSample (XmlTextWriter xtw, XmlSchemaComplexType stype, XmlQualifiedName rootName, int id)
1099 string ns = rootName.Namespace;
1101 if (rootName.Name.IndexOf ("[]") != -1) rootName = arrayType;
1103 if (currentUse == SoapBindingUse.Encoded) {
1104 string pref = xtw.LookupPrefix (rootName.Namespace);
1105 if (pref == null) pref = "q1";
1106 xtw.WriteStartElement (pref, rootName.Name, rootName.Namespace);
1110 xtw.WriteStartElement (rootName.Name, rootName.Namespace);
1114 xtw.WriteAttributeString ("id", "id" + id);
1115 if (rootName != arrayType)
1116 xtw.WriteAttributeString ("type", XmlSchema.InstanceNamespace, GetQualifiedNameString (xtw, rootName));
1119 WriteComplexTypeAttributes (xtw, stype);
1120 WriteComplexTypeElements (xtw, ns, stype);
1122 xtw.WriteEndElement ();
1125 void WriteComplexTypeAttributes (XmlTextWriter xtw, XmlSchemaComplexType stype)
1127 WriteAttributes (xtw, stype.Attributes, stype.AnyAttribute);
1130 void WriteComplexTypeElements (XmlTextWriter xtw, string ns, XmlSchemaComplexType stype)
1132 if (stype.Particle != null)
1133 WriteParticleComplexContent (xtw, ns, stype.Particle);
1136 if (stype.ContentModel is XmlSchemaSimpleContent)
1137 WriteSimpleContent (xtw, (XmlSchemaSimpleContent)stype.ContentModel);
1138 else if (stype.ContentModel is XmlSchemaComplexContent)
1139 WriteComplexContent (xtw, ns, (XmlSchemaComplexContent)stype.ContentModel);
1143 void WriteAttributes (XmlTextWriter xtw, XmlSchemaObjectCollection atts, XmlSchemaAnyAttribute anyat)
1145 foreach (XmlSchemaObject at in atts)
1147 if (at is XmlSchemaAttribute)
1150 XmlSchemaAttribute attr = (XmlSchemaAttribute)at;
1151 XmlSchemaAttribute refAttr = attr;
1153 // refAttr.Form; TODO
1155 if (!attr.RefName.IsEmpty) {
1156 refAttr = FindRefAttribute (attr.RefName);
1157 if (refAttr == null) throw new InvalidOperationException ("Global attribute not found: " + attr.RefName);
1161 if (!refAttr.SchemaTypeName.IsEmpty) val = FindBuiltInType (refAttr.SchemaTypeName);
1162 else val = FindBuiltInType ((XmlSchemaSimpleType) refAttr.SchemaType);
1164 xtw.WriteAttributeString (refAttr.Name, val);
1166 else if (at is XmlSchemaAttributeGroupRef)
1168 XmlSchemaAttributeGroupRef gref = (XmlSchemaAttributeGroupRef)at;
1169 XmlSchemaAttributeGroup grp = (XmlSchemaAttributeGroup) schemas.Find (gref.RefName, typeof(XmlSchemaAttributeGroup));
1170 WriteAttributes (xtw, grp.Attributes, grp.AnyAttribute);
1175 xtw.WriteAttributeString ("custom-attribute","value");
1178 void WriteParticleComplexContent (XmlTextWriter xtw, string ns, XmlSchemaParticle particle)
1180 WriteParticleContent (xtw, ns, particle, false);
1183 void WriteParticleContent (XmlTextWriter xtw, string ns, XmlSchemaParticle particle, bool multiValue)
1185 if (particle is XmlSchemaGroupRef)
1186 particle = GetRefGroupParticle ((XmlSchemaGroupRef)particle);
1188 if (particle.MaxOccurs > 1) multiValue = true;
1190 if (particle is XmlSchemaSequence) {
1191 WriteSequenceContent (xtw, ns, ((XmlSchemaSequence)particle).Items, multiValue);
1193 else if (particle is XmlSchemaChoice) {
1194 if (((XmlSchemaChoice)particle).Items.Count == 1)
1195 WriteSequenceContent (xtw, ns, ((XmlSchemaChoice)particle).Items, multiValue);
1197 WriteChoiceContent (xtw, ns, (XmlSchemaChoice)particle, multiValue);
1199 else if (particle is XmlSchemaAll) {
1200 WriteSequenceContent (xtw, ns, ((XmlSchemaAll)particle).Items, multiValue);
1204 void WriteSequenceContent (XmlTextWriter xtw, string ns, XmlSchemaObjectCollection items, bool multiValue)
1206 foreach (XmlSchemaObject item in items)
1207 WriteContentItem (xtw, ns, item, multiValue);
1210 void WriteContentItem (XmlTextWriter xtw, string ns, XmlSchemaObject item, bool multiValue)
1212 if (item is XmlSchemaGroupRef)
1213 item = GetRefGroupParticle ((XmlSchemaGroupRef)item);
1215 if (item is XmlSchemaElement)
1217 XmlSchemaElement elem = (XmlSchemaElement) item;
1218 XmlSchemaElement refElem;
1219 if (!elem.RefName.IsEmpty) refElem = FindRefElement (elem);
1220 else refElem = elem;
1222 int num = (elem.MaxOccurs == 1 && !multiValue) ? 1 : 2;
1223 for (int n=0; n<num; n++)
1225 if (currentUse == SoapBindingUse.Literal)
1226 WriteElementSample (xtw, ns, refElem);
1228 WriteRefTypeSample (xtw, ns, refElem);
1231 else if (item is XmlSchemaAny)
1233 xtw.WriteString (GetLiteral ("xml"));
1235 else if (item is XmlSchemaParticle) {
1236 WriteParticleContent (xtw, ns, (XmlSchemaParticle)item, multiValue);
1240 void WriteChoiceContent (XmlTextWriter xtw, string ns, XmlSchemaChoice choice, bool multiValue)
1242 foreach (XmlSchemaObject item in choice.Items)
1243 WriteContentItem (xtw, ns, item, multiValue);
1246 void WriteSimpleContent (XmlTextWriter xtw, XmlSchemaSimpleContent content)
1248 XmlSchemaSimpleContentExtension ext = content.Content as XmlSchemaSimpleContentExtension;
1250 WriteAttributes (xtw, ext.Attributes, ext.AnyAttribute);
1252 XmlQualifiedName qname = GetContentBaseType (content.Content);
1253 xtw.WriteString (GetLiteral (FindBuiltInType (qname)));
1256 string FindBuiltInType (XmlQualifiedName qname)
1258 if (qname.Namespace == XmlSchema.Namespace)
1261 XmlSchemaComplexType ct = FindComplexTyype (qname);
1264 XmlSchemaSimpleContent sc = ct.ContentModel as XmlSchemaSimpleContent;
1265 if (sc == null) throw new InvalidOperationException ("Invalid schema");
1266 return FindBuiltInType (GetContentBaseType (sc.Content));
1269 XmlSchemaSimpleType st = (XmlSchemaSimpleType) schemas.Find (qname, typeof(XmlSchemaSimpleType));
1271 return FindBuiltInType (st);
1273 throw new InvalidOperationException ("Definition of type " + qname + " not found");
1276 string FindBuiltInType (XmlSchemaSimpleType st)
1278 if (st.Content is XmlSchemaSimpleTypeRestriction) {
1279 return FindBuiltInType (GetContentBaseType (st.Content));
1281 else if (st.Content is XmlSchemaSimpleTypeList) {
1282 string s = FindBuiltInType (GetContentBaseType (st.Content));
1283 return s + " " + s + " ...";
1285 else if (st.Content is XmlSchemaSimpleTypeUnion)
1287 //Check if all types of the union are equal. If not, then will use anyType.
1288 XmlSchemaSimpleTypeUnion uni = (XmlSchemaSimpleTypeUnion) st.Content;
1289 string utype = null;
1291 // Anonymous types are unique
1292 if (uni.BaseTypes.Count != 0 && uni.MemberTypes.Length != 0)
1295 foreach (XmlQualifiedName mt in uni.MemberTypes)
1297 string qn = FindBuiltInType (mt);
1298 if (utype != null && qn != utype) return "string";
1308 XmlQualifiedName GetContentBaseType (XmlSchemaObject ob)
1310 if (ob is XmlSchemaSimpleContentExtension)
1311 return ((XmlSchemaSimpleContentExtension)ob).BaseTypeName;
1312 else if (ob is XmlSchemaSimpleContentRestriction)
1313 return ((XmlSchemaSimpleContentRestriction)ob).BaseTypeName;
1314 else if (ob is XmlSchemaSimpleTypeRestriction)
1315 return ((XmlSchemaSimpleTypeRestriction)ob).BaseTypeName;
1316 else if (ob is XmlSchemaSimpleTypeList)
1317 return ((XmlSchemaSimpleTypeList)ob).ItemTypeName;
1322 void WriteComplexContent (XmlTextWriter xtw, string ns, XmlSchemaComplexContent content)
1324 XmlQualifiedName qname;
1326 XmlSchemaComplexContentExtension ext = content.Content as XmlSchemaComplexContentExtension;
1327 if (ext != null) qname = ext.BaseTypeName;
1329 XmlSchemaComplexContentRestriction rest = (XmlSchemaComplexContentRestriction)content.Content;
1330 qname = rest.BaseTypeName;
1331 if (qname == arrayType) {
1332 ParseArrayType (rest, out qname);
1333 XmlSchemaElement elem = new XmlSchemaElement ();
1335 elem.SchemaTypeName = qname;
1337 xtw.WriteAttributeString ("arrayType", SoapEncodingNamespace, qname.Name + "[2]");
1338 WriteContentItem (xtw, ns, elem, true);
1343 // Add base map members to this map
1344 XmlSchemaComplexType ctype = FindComplexTyype (qname);
1345 WriteComplexTypeAttributes (xtw, ctype);
1348 // Add the members of this map
1349 WriteAttributes (xtw, ext.Attributes, ext.AnyAttribute);
1350 if (ext.Particle != null)
1351 WriteParticleComplexContent (xtw, ns, ext.Particle);
1354 WriteComplexTypeElements (xtw, ns, ctype);
1357 void ParseArrayType (XmlSchemaComplexContentRestriction rest, out XmlQualifiedName qtype)
1359 XmlSchemaAttribute arrayTypeAt = FindArrayAttribute (rest.Attributes);
1360 XmlAttribute[] uatts = arrayTypeAt.UnhandledAttributes;
1361 if (uatts == null || uatts.Length == 0) throw new InvalidOperationException ("arrayType attribute not specified in array declaration");
1363 XmlAttribute xat = null;
1364 foreach (XmlAttribute at in uatts)
1365 if (at.LocalName == "arrayType" && at.NamespaceURI == WsdlNamespace)
1366 { xat = at; break; }
1369 throw new InvalidOperationException ("arrayType attribute not specified in array declaration");
1371 string arrayType = xat.Value;
1373 int i = arrayType.LastIndexOf (":");
1374 if (i == -1) ns = "";
1375 else ns = arrayType.Substring (0,i);
1377 int j = arrayType.IndexOf ("[", i+1);
1378 if (j == -1) throw new InvalidOperationException ("Cannot parse WSDL array type: " + arrayType);
1379 type = arrayType.Substring (i+1);
1380 type = type.Substring (0, type.Length-2);
1382 qtype = new XmlQualifiedName (type, ns);
1385 XmlSchemaAttribute FindArrayAttribute (XmlSchemaObjectCollection atts)
1387 foreach (object ob in atts)
1389 XmlSchemaAttribute att = ob as XmlSchemaAttribute;
1390 if (att != null && att.RefName == arrayTypeRefName) return att;
1392 XmlSchemaAttributeGroupRef gref = ob as XmlSchemaAttributeGroupRef;
1395 XmlSchemaAttributeGroup grp = (XmlSchemaAttributeGroup) schemas.Find (gref.RefName, typeof(XmlSchemaAttributeGroup));
1396 att = FindArrayAttribute (grp.Attributes);
1397 if (att != null) return att;
1403 void WriteSimpleTypeSample (XmlTextWriter xtw, XmlSchemaSimpleType stype)
1405 xtw.WriteString (GetLiteral (FindBuiltInType (stype)));
1408 XmlSchemaParticle GetRefGroupParticle (XmlSchemaGroupRef refGroup)
1410 XmlSchemaGroup grp = (XmlSchemaGroup) schemas.Find (refGroup.RefName, typeof (XmlSchemaGroup));
1411 return grp.Particle;
1414 XmlSchemaElement FindRefElement (XmlSchemaElement elem)
1416 if (elem.RefName.Namespace == XmlSchema.Namespace)
1418 if (anyElement != null) return anyElement;
1419 anyElement = new XmlSchemaElement ();
1420 anyElement.Name = "any";
1421 anyElement.SchemaTypeName = anyType;
1424 return (XmlSchemaElement) schemas.Find (elem.RefName, typeof(XmlSchemaElement));
1427 XmlSchemaAttribute FindRefAttribute (XmlQualifiedName refName)
1429 if (refName.Namespace == XmlSchema.Namespace)
1431 XmlSchemaAttribute at = new XmlSchemaAttribute ();
1432 at.Name = refName.Name;
1433 at.SchemaTypeName = new XmlQualifiedName ("string",XmlSchema.Namespace);
1436 return (XmlSchemaAttribute) schemas.Find (refName, typeof(XmlSchemaAttribute));
1439 void WriteRefTypeSample (XmlTextWriter xtw, string ns, XmlSchemaElement elem)
1441 if (elem.SchemaTypeName.Namespace == XmlSchema.Namespace || schemas.Find (elem.SchemaTypeName, typeof(XmlSchemaSimpleType)) != null)
1442 WriteElementSample (xtw, ns, elem);
1445 xtw.WriteStartElement (elem.Name, ns);
1446 xtw.WriteAttributeString ("href", "#id" + (queue.Count+1));
1447 xtw.WriteEndElement ();
1448 queue.Add (new EncodedType (ns, elem));
1452 void WriteQueuedTypeSamples (XmlTextWriter xtw)
1454 for (int n=0; n<queue.Count; n++)
1456 EncodedType ec = (EncodedType) queue[n];
1457 XmlSchemaComplexType st = FindComplexTyype (ec.Element.SchemaTypeName);
1458 WriteComplexTypeSample (xtw, st, ec.Element.SchemaTypeName, n+1);
1462 XmlSchemaComplexType FindComplexTyype (XmlQualifiedName qname)
1464 if (qname.Name.IndexOf ("[]") != -1)
1466 XmlSchemaComplexType stype = new XmlSchemaComplexType ();
1467 stype.ContentModel = new XmlSchemaComplexContent ();
1469 XmlSchemaComplexContentRestriction res = new XmlSchemaComplexContentRestriction ();
1470 stype.ContentModel.Content = res;
1471 res.BaseTypeName = arrayType;
1473 XmlSchemaAttribute att = new XmlSchemaAttribute ();
1474 att.RefName = arrayTypeRefName;
1475 res.Attributes.Add (att);
1477 XmlAttribute xat = document.CreateAttribute ("arrayType", WsdlNamespace);
1478 xat.Value = qname.Namespace + ":" + qname.Name;
1479 att.UnhandledAttributes = new XmlAttribute[] {xat};
1483 return (XmlSchemaComplexType) schemas.Find (qname, typeof(XmlSchemaComplexType));
1486 string GetQualifiedNameString (XmlTextWriter xtw, XmlQualifiedName qname)
1488 string pref = xtw.LookupPrefix (qname.Namespace);
1489 if (pref != null) return pref + ":" + qname.Name;
1491 xtw.WriteAttributeString ("xmlns", "q1", null, qname.Namespace);
1492 return "q1:" + qname.Name;
1495 protected virtual string GetLiteral (string s)
1500 void GetOperationFormat (OperationBinding obin, out SoapBindingStyle style, out SoapBindingUse use)
1502 style = SoapBindingStyle.Document;
1503 use = SoapBindingUse.Literal;
1504 SoapOperationBinding sob = obin.Extensions.Find (typeof(SoapOperationBinding)) as SoapOperationBinding;
1507 SoapBodyBinding sbb = obin.Input.Extensions.Find (typeof(SoapBodyBinding)) as SoapBodyBinding;
1521 <link rel="alternate" type="text/xml" href="<%=Request.FilePath%>?disco"/>
1523 <title><%=WebServiceName%> Web Service</title>
1524 <style type="text/css">
1525 BODY { font-family: Arial; margin-left: 20px; margin-top: 20px; font-size: x-small}
1526 TABLE { font-size: x-small }
1527 .title { color:dimgray; font-family: Arial; font-size:20pt; font-weight:900}
1528 .operationTitle { color:dimgray; font-family: Arial; font-size:15pt; font-weight:900}
1529 .method { font-size: x-small }
1530 .bindingLabel { font-size: medium; font-weight:bold; color:darkgray; line-height:8pt; display:block; margin-bottom:3px }
1531 .label { font-size: small; font-weight:bold; color:darkgray }
1532 .paramTable { font-size: x-small }
1533 .paramTable TR { background-color: gainsboro }
1534 .paramFormTable { font-size: x-small; padding: 10px; background-color: gainsboro }
1535 .paramFormTable TR { background-color: gainsboro }
1536 .paramInput { border: solid 1px gray }
1537 .button {border: solid 1px gray }
1538 .smallSeparator { height:3px; overflow:hidden }
1539 .panel { background-color:whitesmoke; border: solid 1px silver; border-top: solid 1px silver }
1540 .codePanel { background-color: white; font-size:x-small; padding:7px; border:solid 1px silver}
1541 .code-xml { font-size:10pt; font-family:courier }
1542 .code-cs { font-size:10pt; font-family:courier }
1543 .code-vb { font-size:10pt; font-family:courier }
1544 .tabLabelOn { font-weight:bold }
1545 .tabLabelOff {color: darkgray }
1546 .literal-placeholder {color: darkblue; font-weight:bold}
1547 A:link { color: black; }
1548 A:visited { color: black; }
1549 A:active { color: black; }
1550 A:hover { color: blue }
1554 function clearForm ()
1556 document.getElementById("testFormResult").style.display="none";
1563 <div class="title" style="margin-left:20px">
1564 <span class="label">Web Service</span><br>
1569 **********************************************************
1573 <table border="0" width="100%" cellpadding="15px" cellspacing="15px">
1574 <tr valign="top"><td width="150px" class="panel">
1575 <div style="width:150px"></div>
1576 <a class="method" href='<%=PageName%>'>Overview</a><br>
1577 <div class="smallSeparator"></div>
1578 <a class="method" href='<%=PageName + "?" + GetPageContext("wsdl")%>'>Service Description</a>
1580 <div class="smallSeparator"></div>
1581 <a class="method" href='<%=PageName + "?" + GetPageContext("proxy")%>'>Client proxy</a>
1584 <asp:repeater id="BindingsRepeater" runat=server>
1586 <span class="bindingLabel"><%#FormatBindingName(DataBinder.Eval(Container.DataItem, "Name").ToString())%></span>
1587 <asp:repeater id="OperationsRepeater" runat=server datasource='<%# ((Binding)Container.DataItem).Operations %>'>
1589 <a class="method" href="<%=PageName%>?<%=GetTabContext("op",null)%>op=<%#GetOpName(Container.DataItem)%>&bnd=<%#DataBinder.Eval(Container.DataItem, "Binding.Name")%>"><%#GetOpName(Container.DataItem)%></a>
1590 <div class="smallSeparator"></div>
1597 </td><td class="panel">
1599 <% if (CurrentPage == "main") {%>
1602 **********************************************************
1603 Web service overview
1606 <p class="label">Web Service Overview</p>
1607 <%=WebServiceDescription%>
1609 <% if (ProfileViolations.Count > 0) { %>
1610 <p class="label">Basic Profile Conformance</p>
1611 This web service does not conform to WS-I Basic Profile v1.1
1613 Response.Write ("<ul>");
1614 foreach (BasicProfileViolation vio in ProfileViolations) {
1615 Response.Write ("<li><b>" + vio.NormativeStatement + "</b>: " + vio.Details);
1616 Response.Write ("<ul>");
1617 foreach (string ele in vio.Elements)
1618 Response.Write ("<li>" + ele + "</li>");
1619 Response.Write ("</ul>");
1620 Response.Write ("</li>");
1622 Response.Write ("</ul>");
1625 <%} if (DefaultBinding == null) {%>
1626 This service does not contain any public web method.
1627 <%} else if (CurrentPage == "op") {%>
1630 **********************************************************
1631 Operation description
1634 <span class="operationTitle"><%=CurrentOperationName%></span>
1639 <% if (CurrentTab == "main") { %>
1640 <span class="label">Input Parameters</span>
1641 <div class="smallSeparator"></div>
1642 <% if (InParams.Count == 0) { %>
1643 No input parameters<br>
1645 <table class="paramTable" cellspacing="1" cellpadding="5">
1646 <asp:repeater id="InputParamsRepeater" runat=server>
1649 <td width="150"><%#DataBinder.Eval(Container.DataItem, "Name")%></td>
1650 <td width="150"><%#DataBinder.Eval(Container.DataItem, "Type")%></td>
1658 <% if (OutParams.Count > 0) { %>
1659 <span class="label">Output Parameters</span>
1660 <div class="smallSeparator"></div>
1661 <table class="paramTable" cellspacing="1" cellpadding="5">
1662 <asp:repeater id="OutputParamsRepeater" runat=server>
1665 <td width="150"><%#DataBinder.Eval(Container.DataItem, "Name")%></td>
1666 <td width="150"><%#DataBinder.Eval(Container.DataItem, "Type")%></td>
1674 <span class="label">Remarks</span>
1675 <div class="smallSeparator"></div>
1676 <%=OperationDocumentation%>
1678 <span class="label">Technical information</span>
1679 <div class="smallSeparator"></div>
1680 Format: <%=CurrentOperationFormat%>
1681 <br>Supported protocols: <%=CurrentOperationProtocols%>
1685 **********************************************************
1686 Operation description - Test form
1689 <% if (CurrentTab == "test") {
1690 if (CurrentOperationSupportsTest) {%>
1691 Enter values for the parameters and click the 'Invoke' button to test this method:<br><br>
1692 <form action="<%=PageName%>" method="GET">
1693 <input type="hidden" name="page" value="<%=CurrentPage%>">
1694 <input type="hidden" name="tab" value="<%=CurrentTab%>">
1695 <input type="hidden" name="op" value="<%=CurrentOperationName%>">
1696 <input type="hidden" name="bnd" value="<%=CurrentOperationBinding%>">
1697 <input type="hidden" name="ext" value="testform">
1698 <table class="paramFormTable" cellspacing="0" cellpadding="3">
1699 <asp:repeater id="InputFormParamsRepeater" runat=server>
1702 <td><%#DataBinder.Eval(Container.DataItem, "Name")%>: </td>
1703 <td width="150"><input class="paramInput" type="text" size="20" name="<%#DataBinder.Eval(Container.DataItem, "Name")%>"></td>
1707 <tr><td></td><td><input class="button" type="submit" value="Invoke"> <input class="button" type="button" onclick="clearForm()" value="Clear"></td></tr>
1710 <div id="testFormResult" style="display:<%= (HasFormResult?"block":"none") %>">
1711 The web service returned the following result:<br/><br/>
1712 <div class="codePanel"><%=GetTestResult()%></div>
1715 The test form is not available for this operation because it has parameters with a complex structure.
1720 **********************************************************
1721 Operation description - Message Layout
1724 <% if (CurrentTab == "msg") { %>
1726 The following are sample SOAP requests and responses for each protocol supported by this method:
1729 <% if (IsOperationSupported ("Soap")) { %>
1730 <span class="label">Soap</span>
1732 <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("Soap", true)%></div></div>
1734 <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("Soap", false)%></div></div>
1737 <% if (IsOperationSupported ("HttpGet")) { %>
1738 <span class="label">HTTP Get</span>
1740 <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("HttpGet", true)%></div></div>
1742 <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("HttpGet", false)%></div></div>
1745 <% if (IsOperationSupported ("HttpPost")) { %>
1746 <span class="label">HTTP Post</span>
1748 <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("HttpPost", true)%></div></div>
1750 <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("HttpPost", false)%></div></div>
1755 <%} else if (CurrentPage == "proxy") {%>
1757 **********************************************************
1760 <form action="<%=PageName%>" name="langForm" method="GET">
1761 Select the language for which you want to generate a proxy
1762 <input type="hidden" name="page" value="<%=CurrentPage%>">
1763 <SELECT name="lang" onchange="langForm.submit()">
1764 <%=GetOptionSel("cs",CurrentLanguage)%>C#</option>
1765 <%=GetOptionSel("vb",CurrentLanguage)%>Visual Basic</option>
1770 <span class="label"><%=CurrentProxytName%></span>
1771 <a href="<%=PageName + "?code=" + CurrentLanguage%>">Download</a>
1773 <div class="codePanel">
1774 <div class="code-<%=CurrentLanguage%>"><%=GetProxyCode ()%></div>
1776 <%} else if (CurrentPage == "wsdl") {%>
1778 **********************************************************
1781 <% if (descriptions.Count > 1 || schemas.Count > 1) {%>
1782 The description of this web service is composed by several documents. Click on the document you want to see:
1786 for (int n=0; n<descriptions.Count; n++)
1787 Response.Write ("<li><a href='" + PageName + "?" + GetPageContext(null) + "doctype=wsdl&docind=" + n + "'>WSDL document " + descriptions[n].TargetNamespace + "</a></li>");
1788 for (int n=0; n<schemas.Count; n++)
1789 Response.Write ("<li><a href='" + PageName + "?" + GetPageContext(null) + "doctype=schema&docind=" + n + "'>Xml Schema " + schemas[n].TargetNamespace + "</a></li>");
1796 <span class="label"><%=CurrentDocumentName%></span>
1797 <a href="<%=PageName + "?" + CurrentDocType + "=" + CurrentDocInd %>">Download</a>
1799 <div class="codePanel">
1800 <div class="code-xml"><%=GenerateDocument ()%></div>
1805 <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
1807 <td width="20px"></td>