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.Description" %>
18 <%@ Import Namespace="System" %>
19 <%@ Import Namespace="System.Net" %>
20 <%@ Import Namespace="System.Globalization" %>
21 <%@ Import Namespace="System.Resources" %>
22 <%@ Import Namespace="System.Diagnostics" %>
23 <%@ Import Namespace="System.CodeDom" %>
24 <%@ Import Namespace="System.CodeDom.Compiler" %>
25 <%@ Import Namespace="Microsoft.CSharp" %>
26 <%@ Import Namespace="Microsoft.VisualBasic" %>
27 <%@ Import Namespace="System.Text" %>
28 <%@ Import Namespace="System.Text.RegularExpressions" %>
29 <%@ Import Namespace="System.Security.Cryptography.X509Certificates" %>
30 <%@ Assembly name="System.Web.Services" %>
31 <%@ Page debug="true" %>
34 <script language="C#" runat="server">
36 ServiceDescriptionCollection descriptions;
39 string WebServiceName;
40 string WebServiceDescription;
43 string DefaultBinding;
44 ArrayList ServiceProtocols;
46 string CurrentOperationName;
47 string CurrentOperationBinding;
48 string OperationDocumentation;
49 string CurrentOperationFormat;
50 bool CurrentOperationSupportsTest;
53 string CurrentOperationProtocols;
54 int CodeTextColumns = 95;
56 void Page_Load(object sender, EventArgs e)
58 descriptions = (ServiceDescriptionCollection) Context.Items["wsdls"];
59 schemas = (XmlSchemas) Context.Items["schemas"];
61 ServiceDescription desc = descriptions [0];
62 if (schemas.Count == 0) schemas = desc.Types.Schemas;
64 Service service = desc.Services[0];
65 WebServiceName = service.Name;
66 if (desc.Bindings.Count == 0)
69 DefaultBinding = desc.Bindings[0].Name;
70 WebServiceDescription = service.Documentation;
71 ServiceProtocols = FindServiceProtocols (null);
73 CurrentOperationName = Request.QueryString["op"];
74 CurrentOperationBinding = Request.QueryString["bnd"];
75 if (CurrentOperationName != null) BuildOperationInfo ();
77 PageName = HttpUtility.UrlEncode (Path.GetFileName(Request.Path), Encoding.UTF8);
79 ArrayList list = new ArrayList ();
80 foreach (ServiceDescription sd in descriptions) {
81 foreach (Binding bin in sd.Bindings)
82 if (bin.Extensions.Find (typeof(SoapBinding)) != null) list.Add (bin);
85 BindingsRepeater.DataSource = list;
89 void BuildOperationInfo ()
91 InParams = new ArrayList ();
92 OutParams = new ArrayList ();
94 Port port = FindPort (CurrentOperationBinding, null);
95 Binding binding = descriptions.GetBinding (port.Binding);
97 PortType portType = descriptions.GetPortType (binding.Type);
98 Operation oper = FindOperation (portType, CurrentOperationName);
100 OperationDocumentation = oper.Documentation;
101 if (OperationDocumentation == null || OperationDocumentation == "")
102 OperationDocumentation = "No additional remarks";
104 foreach (OperationMessage opm in oper.Messages)
106 if (opm is OperationInput)
107 BuildParameters (InParams, opm);
108 else if (opm is OperationOutput)
109 BuildParameters (OutParams, opm);
112 // Protocols supported by the operation
113 CurrentOperationProtocols = "";
114 ArrayList prots = FindServiceProtocols (CurrentOperationName);
115 for (int n=0; n<prots.Count; n++) {
116 if (n != 0) CurrentOperationProtocols += ", ";
117 CurrentOperationProtocols += (string) prots[n];
120 CurrentOperationSupportsTest = prots.Contains ("HttpGet") || prots.Contains ("HttpPost");
123 OperationBinding obin = FindOperation (binding, CurrentOperationName);
125 CurrentOperationFormat = GetOperationFormat (obin);
127 InputParamsRepeater.DataSource = InParams;
128 InputFormParamsRepeater.DataSource = InParams;
129 OutputParamsRepeater.DataSource = OutParams;
132 void BuildParameters (ArrayList list, OperationMessage opm)
134 Message msg = descriptions.GetMessage (opm.Message);
135 if (msg.Parts.Count > 0 && msg.Parts[0].Name == "parameters")
137 MessagePart part = msg.Parts[0];
138 XmlSchemaComplexType ctype;
139 if (part.Element == XmlQualifiedName.Empty)
141 ctype = (XmlSchemaComplexType) schemas.Find (part.Type, typeof(XmlSchemaComplexType));
145 XmlSchemaElement elem = (XmlSchemaElement) schemas.Find (part.Element, typeof(XmlSchemaElement));
146 ctype = (XmlSchemaComplexType) elem.SchemaType;
148 XmlSchemaSequence seq = ctype.Particle as XmlSchemaSequence;
149 if (seq == null) return;
151 foreach (XmlSchemaObject ob in seq.Items)
153 Parameter p = new Parameter();
154 p.Description = "No additional remarks";
156 if (ob is XmlSchemaElement)
158 XmlSchemaElement selem = GetRefElement ((XmlSchemaElement)ob);
160 p.Type = selem.SchemaTypeName.Name;
172 foreach (MessagePart part in msg.Parts)
174 Parameter p = new Parameter ();
175 p.Description = "No additional remarks";
177 if (part.Element == XmlQualifiedName.Empty)
178 p.Type = part.Type.Name;
181 XmlSchemaElement elem = (XmlSchemaElement) schemas.Find (part.Element, typeof(XmlSchemaElement));
182 p.Type = elem.SchemaTypeName.Name;
189 string GetOperationFormat (OperationBinding obin)
192 SoapOperationBinding sob = obin.Extensions.Find (typeof(SoapOperationBinding)) as SoapOperationBinding;
194 format = sob.Style.ToString ();
195 SoapBodyBinding sbb = obin.Input.Extensions.Find (typeof(SoapBodyBinding)) as SoapBodyBinding;
197 format += " / " + sbb.Use;
202 XmlSchemaElement GetRefElement (XmlSchemaElement elem)
204 if (!elem.RefName.IsEmpty)
205 return (XmlSchemaElement) schemas.Find (elem.RefName, typeof(XmlSchemaElement));
210 ArrayList FindServiceProtocols(string operName)
212 ArrayList table = new ArrayList ();
213 Service service = descriptions[0].Services[0];
214 foreach (Port port in service.Ports)
217 Binding bin = descriptions.GetBinding (port.Binding);
218 if (bin.Extensions.Find (typeof(SoapBinding)) != null)
222 HttpBinding hb = (HttpBinding) bin.Extensions.Find (typeof(HttpBinding));
223 if (hb != null && hb.Verb == "POST") prot = "HttpPost";
224 else if (hb != null && hb.Verb == "GET") prot = "HttpGet";
227 if (prot != null && operName != null)
229 if (FindOperation (bin, operName) == null)
233 if (prot != null && !table.Contains (prot))
239 Port FindPort (string portName, string protocol)
241 Service service = descriptions[0].Services[0];
242 foreach (Port port in service.Ports)
244 if (portName == null)
246 Binding binding = descriptions.GetBinding (port.Binding);
247 if (GetProtocol (binding) == protocol) return port;
249 else if (port.Name == portName)
255 string GetProtocol (Binding binding)
257 if (binding.Extensions.Find (typeof(SoapBinding)) != null) return "Soap";
258 HttpBinding hb = (HttpBinding) binding.Extensions.Find (typeof(HttpBinding));
259 if (hb == null) return "";
260 if (hb.Verb == "POST") return "HttpPost";
261 if (hb.Verb == "GET") return "HttpGet";
266 Operation FindOperation (PortType portType, string name)
268 foreach (Operation oper in portType.Operations) {
269 if (oper.Messages.Input.Name != null) {
270 if (oper.Messages.Input.Name == name) return oper;
273 if (oper.Name == name) return oper;
279 OperationBinding FindOperation (Binding binding, string name)
281 foreach (OperationBinding oper in binding.Operations) {
282 if (oper.Input.Name != null) {
283 if (oper.Input.Name == name) return oper;
286 if (oper.Name == name) return oper;
292 string FormatBindingName (string name)
294 if (name == DefaultBinding) return "Methods";
295 else return "Methods for binding<br>" + name;
298 string GetOpName (object op)
300 OperationBinding ob = op as OperationBinding;
301 if (ob == null) return "";
302 if (ob.Input.Name != null) return ob.Input.Name;
308 get { return Request.QueryString ["ext"] == "testform"; }
311 class NoCheckCertificatePolicy : ICertificatePolicy {
312 public bool CheckValidationResult (ServicePoint a, X509Certificate b, WebRequest c, int d)
318 string GetTestResult ()
320 if (!HasFormResult) return null;
324 for (int n=0; n<Request.QueryString.Count; n++)
327 if (qs != "") qs += "&";
328 qs += Request.QueryString.GetKey(n) + "=" + Server.UrlEncode (Request.QueryString [n]);
330 if (Request.QueryString.GetKey(n) == "ext") fill = true;
333 string location = null;
334 ServiceDescription desc = descriptions [0];
335 Service service = desc.Services[0];
336 foreach (Port port in service.Ports)
337 if (port.Name == CurrentOperationBinding)
339 SoapAddressBinding sbi = (SoapAddressBinding) port.Extensions.Find (typeof(SoapAddressBinding));
341 location = sbi.Location;
344 if (location == null)
345 return "Could not locate web service";
349 string url = location + "/" + CurrentOperationName;
350 Uri uri = new Uri (url);
352 if (CurrentOperationProtocols.IndexOf ("HttpGet") < 0) {
353 req = WebRequest.Create (url);
355 if (qs != null && qs.Length > 0) {
356 byte [] postBuffer = Encoding.UTF8.GetBytes (qs);
357 req.ContentLength = postBuffer.Length;
358 using (Stream requestStream = req.GetRequestStream ())
359 requestStream.Write (postBuffer, 0, postBuffer.Length);
363 req = WebRequest.Create (url + "?" + qs);
364 if (url.StartsWith ("https:"))
365 ServicePointManager.CertificatePolicy = new NoCheckCertificatePolicy ();
366 HttpCookieCollection cookies = Request.Cookies;
367 int last = cookies.Count;
369 CookieContainer container = new CookieContainer ();
370 for (int i = 0; i < last; i++) {
371 HttpCookie hcookie = cookies [i];
372 Cookie cookie = new Cookie (hcookie.Name, hcookie.Value, hcookie.Path, hcookie.Domain);
373 container.Add (uri, cookie);
375 ((HttpWebRequest) req).CookieContainer = container;
377 WebResponse resp = req.GetResponse();
378 StreamReader sr = new StreamReader (resp.GetResponseStream());
379 string s = sr.ReadToEnd ();
381 return "<div class='code-xml'>" + ColorizeXml(WrapText(s,CodeTextColumns)) + "</div>";
385 string res = "<b style='color:red'>" + ex.Message + "</b>";
386 WebException wex = ex as WebException;
389 WebResponse resp = wex.Response;
391 StreamReader sr = new StreamReader (resp.GetResponseStream());
392 string s = sr.ReadToEnd ();
394 res += "<div class='code-xml'>" + ColorizeXml(WrapText(s,CodeTextColumns)) + "</div>";
401 string GenerateOperationMessages (string protocol, bool generateInput)
403 if (!IsOperationSupported (protocol)) return "";
406 if (protocol != "Soap") port = FindPort (null, protocol);
407 else port = FindPort (CurrentOperationBinding, null);
409 Binding binding = descriptions.GetBinding (port.Binding);
410 OperationBinding obin = FindOperation (binding, CurrentOperationName);
411 PortType portType = descriptions.GetPortType (binding.Type);
412 Operation oper = FindOperation (portType, CurrentOperationName);
414 HtmlSampleGenerator sg = new HtmlSampleGenerator (descriptions, schemas);
415 string txt = sg.GenerateMessage (port, obin, oper, protocol, generateInput);
416 if (protocol == "Soap") txt = WrapText (txt,CodeTextColumns);
417 txt = ColorizeXml (txt);
418 txt = txt.Replace ("@placeholder!","<span class='literal-placeholder'>");
419 txt = txt.Replace ("!placeholder@","</span>");
423 bool IsOperationSupported (string protocol)
425 if (CurrentPage != "op" || CurrentTab != "msg") return false;
426 if (protocol == "Soap") return true;
428 Port port = FindPort (null, protocol);
429 if (port == null) return false;
430 Binding binding = descriptions.GetBinding (port.Binding);
431 if (binding == null) return false;
432 return FindOperation (binding, CurrentOperationName) != null;
436 // Proxy code generation
439 string GetProxyCode ()
441 CodeNamespace codeNamespace = new CodeNamespace();
442 CodeCompileUnit codeUnit = new CodeCompileUnit();
444 codeUnit.Namespaces.Add (codeNamespace);
446 ServiceDescriptionImporter importer = new ServiceDescriptionImporter();
448 foreach (ServiceDescription sd in descriptions)
449 importer.AddServiceDescription(sd, null, null);
451 foreach (XmlSchema sc in schemas)
452 importer.Schemas.Add (sc);
454 importer.Import(codeNamespace, codeUnit);
456 string langId = Request.QueryString ["lang"];
457 if (langId == null || langId == "") langId = "cs";
458 CodeDomProvider provider = GetProvider (langId);
459 ICodeGenerator generator = provider.CreateGenerator();
460 CodeGeneratorOptions options = new CodeGeneratorOptions();
462 StringWriter sw = new StringWriter ();
463 generator.GenerateCodeFromCompileUnit(codeUnit, sw, options);
465 return Colorize (WrapText (sw.ToString (), CodeTextColumns), langId);
468 public string CurrentLanguage
471 string langId = Request.QueryString ["lang"];
472 if (langId == null || langId == "") langId = "cs";
477 public string CurrentProxytName
480 string lan = CurrentLanguage == "cs" ? "C#" : "Visual Basic";
481 return lan + " Client Proxy";
485 private CodeDomProvider GetProvider(string langId)
487 switch (langId.ToUpper())
489 case "CS": return new CSharpCodeProvider();
490 case "VB": return new VBCodeProvider();
491 default: return null;
496 // Document generation
499 string GenerateDocument ()
501 StringWriter sw = new StringWriter ();
503 if (CurrentDocType == "wsdl")
504 descriptions [CurrentDocInd].Write (sw);
505 else if (CurrentDocType == "schema")
506 schemas [CurrentDocInd].Write (sw);
508 return Colorize (WrapText (sw.ToString (), CodeTextColumns), "xml");
511 public string CurrentDocType
513 get { return Request.QueryString ["doctype"] != null ? Request.QueryString ["doctype"] : "wsdl"; }
516 public int CurrentDocInd
518 get { return Request.QueryString ["docind"] != null ? int.Parse (Request.QueryString ["docind"]) : 0; }
521 public string CurrentDocumentName
524 if (CurrentDocType == "wsdl")
525 return "WSDL document for namespace \"" + descriptions [CurrentDocInd].TargetNamespace + "\"";
527 return "Xml Schema for namespace \"" + schemas [CurrentDocInd].TargetNamespace + "\"";
535 bool firstTab = true;
536 ArrayList disabledTabs = new ArrayList ();
540 get { return Request.QueryString["tab"] != null ? Request.QueryString["tab"] : "main" ; }
545 get { return Request.QueryString["page"] != null ? Request.QueryString["page"] : "main" ; }
550 if (CurrentOperationName != null)
552 WriteTab ("main","Overview");
553 WriteTab ("test","Test Form");
554 WriteTab ("msg","Message Layout");
558 void WriteTab (string id, string label)
560 if (!firstTab) Response.Write(" | ");
563 string cname = CurrentTab == id ? "tabLabelOn" : "tabLabelOff";
564 Response.Write ("<a href='" + PageName + "?" + GetPageContext(null) + GetDataContext() + "tab=" + id + "' style='text-decoration:none'>");
565 Response.Write ("<span class='" + cname + "'>" + label + "</span>");
566 Response.Write ("</a>");
569 string GetTabContext (string pag, string tab)
571 if (tab == null) tab = CurrentTab;
572 if (pag == null) pag = CurrentPage;
573 if (pag != CurrentPage) tab = "main";
574 return "page=" + pag + "&tab=" + tab + "&";
577 string GetPageContext (string pag)
579 if (pag == null) pag = CurrentPage;
580 return "page=" + pag + "&";
593 static string keywords_cs =
594 "(\\babstract\\b|\\bevent\\b|\\bnew\\b|\\bstruct\\b|\\bas\\b|\\bexplicit\\b|\\bnull\\b|\\bswitch\\b|\\bbase\\b|\\bextern\\b|" +
595 "\\bobject\\b|\\bthis\\b|\\bbool\\b|\\bfalse\\b|\\boperator\\b|\\bthrow\\b|\\bbreak\\b|\\bfinally\\b|\\bout\\b|\\btrue\\b|" +
596 "\\bbyte\\b|\\bfixed\\b|\\boverride\\b|\\btry\\b|\\bcase\\b|\\bfloat\\b|\\bparams\\b|\\btypeof\\b|\\bcatch\\b|\\bfor\\b|" +
597 "\\bprivate\\b|\\buint\\b|\\bchar\\b|\\bforeach\\b|\\bprotected\\b|\\bulong\\b|\\bchecked\\b|\\bgoto\\b|\\bpublic\\b|" +
598 "\\bunchecked\\b|\\bclass\\b|\\bif\\b|\\breadonly\\b|\\bunsafe\\b|\\bconst\\b|\\bimplicit\\b|\\bref\\b|\\bushort\\b|" +
599 "\\bcontinue\\b|\\bin\\b|\\breturn\\b|\\busing\\b|\\bdecimal\\b|\\bint\\b|\\bsbyte\\b|\\bvirtual\\b|\\bdefault\\b|" +
600 "\\binterface\\b|\\bsealed\\b|\\bvolatile\\b|\\bdelegate\\b|\\binternal\\b|\\bshort\\b|\\bvoid\\b|\\bdo\\b|\\bis\\b|" +
601 "\\bsizeof\\b|\\bwhile\\b|\\bdouble\\b|\\block\\b|\\bstackalloc\\b|\\belse\\b|\\blong\\b|\\bstatic\\b|\\benum\\b|" +
602 "\\bnamespace\\b|\\bstring\\b)";
604 static string keywords_vb =
605 "(\\bAddHandler\\b|\\bAddressOf\\b|\\bAlias\\b|\\bAnd\\b|\\bAndAlso\\b|\\bAnsi\\b|\\bAs\\b|\\bAssembly\\b|" +
606 "\\bAuto\\b|\\bBoolean\\b|\\bByRef\\b|\\bByte\\b|\\bByVal\\b|\\bCall\\b|\\bCase\\b|\\bCatch\\b|" +
607 "\\bCBool\\b|\\bCByte\\b|\\bCChar\\b|\\bCDate\\b|\\bCDec\\b|\\bCDbl\\b|\\bChar\\b|\\bCInt\\b|" +
608 "\\bClass\\b|\\bCLng\\b|\\bCObj\\b|\\bConst\\b|\\bCShort\\b|\\bCSng\\b|\\bCStr\\b|\\bCType\\b|" +
609 "\\bDate\\b|\\bDecimal\\b|\\bDeclare\\b|\\bDefault\\b|\\bDelegate\\b|\\bDim\\b|\\bDirectCast\\b|\\bDo\\b|" +
610 "\\bDouble\\b|\\bEach\\b|\\bElse\\b|\\bElseIf\\b|\\bEnd\\b|\\bEnum\\b|\\bErase\\b|\\bError\\b|" +
611 "\\bEvent\\b|\\bExit\\b|\\bFalse\\b|\\bFinally\\b|\\bFor\\b|\\bFriend\\b|\\bFunction\\b|\\bGet\\b|" +
612 "\\bGetType\\b|\\bGoSub\\b|\\bGoTo\\b|\\bHandles\\b|\\bIf\\b|\\bImplements\\b|\\bImports\\b|\\bIn\\b|" +
613 "\\bInherits\\b|\\bInteger\\b|\\bInterface\\b|\\bIs\\b|\\bLet\\b|\\bLib\\b|\\bLike\\b|\\bLong\\b|" +
614 "\\bLoop\\b|\\bMe\\b|\\bMod\\b|\\bModule\\b|\\bMustInherit\\b|\\bMustOverride\\b|\\bMyBase\\b|\\bMyClass\\b|" +
615 "\\bNamespace\\b|\\bNew\\b|\\bNext\\b|\\bNot\\b|\\bNothing\\b|\\bNotInheritable\\b|\\bNotOverridable\\b|\\bObject\\b|" +
616 "\\bOn\\b|\\bOption\\b|\\bOptional\\b|\\bOr\\b|\\bOrElse\\b|\\bOverloads\\b|\\bOverridable\\b|\\bOverrides\\b|" +
617 "\\bParamArray\\b|\\bPreserve\\b|\\bPrivate\\b|\\bProperty\\b|\\bProtected\\b|\\bPublic\\b|\\bRaiseEvent\\b|\\bReadOnly\\b|" +
618 "\\bReDim\\b|\\bREM\\b|\\bRemoveHandler\\b|\\bResume\\b|\\bReturn\\b|\\bSelect\\b|\\bSet\\b|\\bShadows\\b|" +
619 "\\bShared\\b|\\bShort\\b|\\bSingle\\b|\\bStatic\\b|\\bStep\\b|\\bStop\\b|\\bString\\b|\\bStructure\\b|" +
620 "\\bSub\\b|\\bSyncLock\\b|\\bThen\\b|\\bThrow\\b|\\bTo\\b|\\bTrue\\b|\\bTry\\b|\\bTypeOf\\b|" +
621 "\\bUnicode\\b|\\bUntil\\b|\\bVariant\\b|\\bWhen\\b|\\bWhile\\b|\\bWith\\b|\\bWithEvents\\b|\\bWriteOnly\\b|\\bXor\\b)";
623 string Colorize (string text, string lang)
625 if (lang == "xml") return ColorizeXml (text);
626 else if (lang == "cs") return ColorizeCs (text);
627 else if (lang == "vb") return ColorizeVb (text);
631 string ColorizeXml (string text)
633 text = text.Replace (" ", " ");
634 Regex re = new Regex ("\r\n|\r|\n");
635 text = re.Replace (text, "_br_");
637 re = new Regex ("<\\s*(\\/?)\\s*([\\s\\S]*?)\\s*(\\/?)\\s*>");
638 text = re.Replace (text,"{blue:<$1}{maroon:$2}{blue:$3>}");
640 re = new Regex ("\\{(\\w*):([\\s\\S]*?)\\}");
641 text = re.Replace (text,"<span style='color:$1'>$2</span>");
643 re = new Regex ("\"(.*?)\"");
644 text = re.Replace (text,"\"<span style='color:purple'>$1</span>\"");
647 text = text.Replace ("\t", " ");
648 text = text.Replace ("_br_", "<br>");
652 string ColorizeCs (string text)
654 text = text.Replace (" ", " ");
656 text = text.Replace ("<", "<");
657 text = text.Replace (">", ">");
659 Regex re = new Regex ("\"((((?!\").)|\\\")*?)\"");
660 text = re.Replace (text,"<span style='color:purple'>\"$1\"</span>");
662 re = new Regex ("//(((.(?!\"</span>))|\"(((?!\").)*)\"</span>)*)(\r|\n|\r\n)");
663 text = re.Replace (text,"<span style='color:green'>//$1</span><br/>");
665 re = new Regex (keywords_cs);
666 text = re.Replace (text,"<span style='color:blue'>$1</span>");
668 text = text.Replace ("\t"," ");
669 text = text.Replace ("\n","<br/>");
674 string ColorizeVb (string text)
676 text = text.Replace (" ", " ");
678 /* Regex re = new Regex ("\"((((?!\").)|\\\")*?)\"");
679 text = re.Replace (text,"<span style='color:purple'>\"$1\"</span>");
681 re = new Regex ("'(((.(?!\"\\<\\/span\\>))|\"(((?!\").)*)\"\\<\\/span\\>)*)(\r|\n|\r\n)");
682 text = re.Replace (text,"<span style='color:green'>//$1</span><br/>");
684 re = new Regex (keywords_vb);
685 text = re.Replace (text,"<span style='color:blue'>$1</span>");
687 text = text.Replace ("\t"," ");
688 text = text.Replace ("\n","<br/>");
693 // Helper methods and classes
696 string GetDataContext ()
698 return "op=" + CurrentOperationName + "&bnd=" + CurrentOperationBinding + "&";
701 string GetOptionSel (string v1, string v2)
703 string op = "<option ";
704 if (v1 == v2) op += "selected ";
705 return op + "value='" + v1 + "'>";
708 string WrapText (string text, int maxChars)
710 text = text.Replace(" />","/>");
712 string linspace = null;
716 bool inquotes = false;
718 string sublineIndent = "";
719 System.Text.StringBuilder sb = new System.Text.StringBuilder ();
720 for (int n=0; n<text.Length; n++)
724 if (c=='\r' || c=='\n' || n==text.Length-1)
726 sb.Append (linspace + sublineIndent + text.Substring (linstart, n-linstart+1));
736 if (lastc==',' || lastc=='(')
738 if (!inquotes) breakpos = n;
741 if (lincount > maxChars && breakpos >= linstart)
743 if (linspace != null)
744 sb.Append (linspace + sublineIndent);
745 sb.Append (text.Substring (linstart, breakpos-linstart));
748 lincount = linspace.Length + sublineIndent.Length + (n-breakpos);
752 if (c==' ' || c=='\t')
759 inquotes = !inquotes;
762 if (linspace == null) {
763 linspace = text.Substring (linstart, n-linstart);
770 return sb.ToString ();
779 public string Name { get { return name; } set { name = value; } }
780 public string Type { get { return type; } set { type = value; } }
781 public string Description { get { return description; } set { description = value; } }
784 public class HtmlSampleGenerator: SampleGenerator
786 public HtmlSampleGenerator (ServiceDescriptionCollection services, XmlSchemas schemas)
787 : base (services, schemas)
791 protected override string GetLiteral (string s)
793 return "@placeholder!" + s + "!placeholder@";
798 public class SampleGenerator
800 protected ServiceDescriptionCollection descriptions;
801 protected XmlSchemas schemas;
802 XmlSchemaElement anyElement;
804 SoapBindingUse currentUse;
805 XmlDocument document = new XmlDocument ();
807 static readonly XmlQualifiedName anyType = new XmlQualifiedName ("anyType",XmlSchema.Namespace);
808 static readonly XmlQualifiedName arrayType = new XmlQualifiedName ("Array","http://schemas.xmlsoap.org/soap/encoding/");
809 static readonly XmlQualifiedName arrayTypeRefName = new XmlQualifiedName ("arrayType","http://schemas.xmlsoap.org/soap/encoding/");
810 const string SoapEnvelopeNamespace = "http://schemas.xmlsoap.org/soap/envelope/";
811 const string WsdlNamespace = "http://schemas.xmlsoap.org/wsdl/";
812 const string SoapEncodingNamespace = "http://schemas.xmlsoap.org/soap/encoding/";
816 public EncodedType (string ns, XmlSchemaElement elem) { Namespace = ns; Element = elem; }
817 public string Namespace;
818 public XmlSchemaElement Element;
821 public SampleGenerator (ServiceDescriptionCollection services, XmlSchemas schemas)
823 descriptions = services;
824 this.schemas = schemas;
825 queue = new ArrayList ();
828 public string GenerateMessage (Port port, OperationBinding obin, Operation oper, string protocol, bool generateInput)
830 OperationMessage msg = null;
831 foreach (OperationMessage opm in oper.Messages)
833 if (opm is OperationInput && generateInput) msg = opm;
834 else if (opm is OperationOutput && !generateInput) msg = opm;
836 if (msg == null) return null;
839 case "Soap": return GenerateHttpSoapMessage (port, obin, oper, msg);
840 case "HttpGet": return GenerateHttpGetMessage (port, obin, oper, msg);
841 case "HttpPost": return GenerateHttpPostMessage (port, obin, oper, msg);
843 return "Unknown protocol";
846 public string GenerateHttpSoapMessage (Port port, OperationBinding obin, Operation oper, OperationMessage msg)
850 if (msg is OperationInput)
852 SoapAddressBinding sab = port.Extensions.Find (typeof(SoapAddressBinding)) as SoapAddressBinding;
853 SoapOperationBinding sob = obin.Extensions.Find (typeof(SoapOperationBinding)) as SoapOperationBinding;
854 req += "POST " + new Uri (sab.Location).AbsolutePath + "\n";
855 req += "SOAPAction: " + sob.SoapAction + "\n";
856 req += "Content-Type: text/xml; charset=utf-8\n";
857 req += "Content-Length: " + GetLiteral ("string") + "\n";
858 req += "Host: " + GetLiteral ("string") + "\n\n";
862 req += "HTTP/1.0 200 OK\n";
863 req += "Content-Type: text/xml; charset=utf-8\n";
864 req += "Content-Length: " + GetLiteral ("string") + "\n\n";
867 req += GenerateSoapMessage (obin, oper, msg);
871 public string GenerateHttpGetMessage (Port port, OperationBinding obin, Operation oper, OperationMessage msg)
875 if (msg is OperationInput)
877 HttpAddressBinding sab = port.Extensions.Find (typeof(HttpAddressBinding)) as HttpAddressBinding;
878 HttpOperationBinding sob = obin.Extensions.Find (typeof(HttpOperationBinding)) as HttpOperationBinding;
879 string location = new Uri (sab.Location).AbsolutePath + sob.Location + "?" + BuildQueryString (msg);
880 req += "GET " + location + "\n";
881 req += "Host: " + GetLiteral ("string");
885 req += "HTTP/1.0 200 OK\n";
886 req += "Content-Type: text/xml; charset=utf-8\n";
887 req += "Content-Length: " + GetLiteral ("string") + "\n\n";
889 MimeXmlBinding mxb = (MimeXmlBinding) obin.Output.Extensions.Find (typeof(MimeXmlBinding)) as MimeXmlBinding;
890 if (mxb == null) return req;
892 Message message = descriptions.GetMessage (msg.Message);
893 XmlQualifiedName ename = null;
894 foreach (MessagePart part in message.Parts)
895 if (part.Name == mxb.Part) ename = part.Element;
897 if (ename == null) return req + GetLiteral("string");
899 StringWriter sw = new StringWriter ();
900 XmlTextWriter xtw = new XmlTextWriter (sw);
901 xtw.Formatting = Formatting.Indented;
902 currentUse = SoapBindingUse.Literal;
903 WriteRootElementSample (xtw, ename);
905 req += sw.ToString ();
911 public string GenerateHttpPostMessage (Port port, OperationBinding obin, Operation oper, OperationMessage msg)
915 if (msg is OperationInput)
917 HttpAddressBinding sab = port.Extensions.Find (typeof(HttpAddressBinding)) as HttpAddressBinding;
918 HttpOperationBinding sob = obin.Extensions.Find (typeof(HttpOperationBinding)) as HttpOperationBinding;
919 string location = new Uri (sab.Location).AbsolutePath + sob.Location;
920 req += "POST " + location + "\n";
921 req += "Content-Type: application/x-www-form-urlencoded\n";
922 req += "Content-Length: " + GetLiteral ("string") + "\n";
923 req += "Host: " + GetLiteral ("string") + "\n\n";
924 req += BuildQueryString (msg);
926 else return GenerateHttpGetMessage (port, obin, oper, msg);
931 string BuildQueryString (OperationMessage opm)
934 Message msg = descriptions.GetMessage (opm.Message);
935 foreach (MessagePart part in msg.Parts)
937 if (s.Length != 0) s += "&";
938 s += part.Name + "=" + GetLiteral (part.Type.Name);
943 public string GenerateSoapMessage (OperationBinding obin, Operation oper, OperationMessage msg)
945 SoapOperationBinding sob = obin.Extensions.Find (typeof(SoapOperationBinding)) as SoapOperationBinding;
946 SoapBindingStyle style = (sob != null) ? sob.Style : SoapBindingStyle.Document;
948 MessageBinding msgbin = (msg is OperationInput) ? (MessageBinding) obin.Input : (MessageBinding)obin.Output;
949 SoapBodyBinding sbb = msgbin.Extensions.Find (typeof(SoapBodyBinding)) as SoapBodyBinding;
950 SoapBindingUse bodyUse = (sbb != null) ? sbb.Use : SoapBindingUse.Literal;
952 StringWriter sw = new StringWriter ();
953 XmlTextWriter xtw = new XmlTextWriter (sw);
954 xtw.Formatting = Formatting.Indented;
956 xtw.WriteStartDocument ();
957 xtw.WriteStartElement ("soap", "Envelope", SoapEnvelopeNamespace);
958 xtw.WriteAttributeString ("xmlns", "xsi", null, XmlSchema.InstanceNamespace);
959 xtw.WriteAttributeString ("xmlns", "xsd", null, XmlSchema.Namespace);
961 if (bodyUse == SoapBindingUse.Encoded)
963 xtw.WriteAttributeString ("xmlns", "soapenc", null, SoapEncodingNamespace);
964 xtw.WriteAttributeString ("xmlns", "tns", null, msg.Message.Namespace);
969 bool writtenHeader = false;
970 foreach (object ob in msgbin.Extensions)
972 SoapHeaderBinding hb = ob as SoapHeaderBinding;
973 if (hb == null) continue;
975 if (!writtenHeader) {
976 xtw.WriteStartElement ("soap", "Header", SoapEnvelopeNamespace);
977 writtenHeader = true;
980 WriteHeader (xtw, hb);
984 xtw.WriteEndElement ();
987 xtw.WriteStartElement ("soap", "Body", SoapEnvelopeNamespace);
989 currentUse = bodyUse;
990 WriteBody (xtw, oper, msg, sbb, style);
992 xtw.WriteEndElement ();
993 xtw.WriteEndElement ();
995 return sw.ToString ();
998 void WriteHeader (XmlTextWriter xtw, SoapHeaderBinding header)
1000 Message msg = descriptions.GetMessage (header.Message);
1001 if (msg == null) throw new InvalidOperationException ("Message " + header.Message + " not found");
1002 MessagePart part = msg.Parts [header.Part];
1003 if (part == null) throw new InvalidOperationException ("Message part " + header.Part + " not found in message " + header.Message);
1005 currentUse = header.Use;
1007 if (currentUse == SoapBindingUse.Literal)
1008 WriteRootElementSample (xtw, part.Element);
1010 WriteTypeSample (xtw, part.Type);
1013 void WriteBody (XmlTextWriter xtw, Operation oper, OperationMessage opm, SoapBodyBinding sbb, SoapBindingStyle style)
1015 Message msg = descriptions.GetMessage (opm.Message);
1016 if (msg.Parts.Count > 0 && msg.Parts[0].Name == "parameters")
1018 MessagePart part = msg.Parts[0];
1019 if (part.Element == XmlQualifiedName.Empty)
1020 WriteTypeSample (xtw, part.Type);
1022 WriteRootElementSample (xtw, part.Element);
1026 string elemName = oper.Name;
1028 if (opm is OperationOutput) elemName += "Response";
1030 if (style == SoapBindingStyle.Rpc) {
1031 xtw.WriteStartElement (elemName, sbb.Namespace);
1035 foreach (MessagePart part in msg.Parts)
1037 if (part.Element == XmlQualifiedName.Empty)
1039 XmlSchemaElement elem = new XmlSchemaElement ();
1040 elem.SchemaTypeName = part.Type;
1041 elem.Name = part.Name;
1042 WriteElementSample (xtw, ns, elem);
1045 WriteRootElementSample (xtw, part.Element);
1048 if (style == SoapBindingStyle.Rpc)
1049 xtw.WriteEndElement ();
1051 WriteQueuedTypeSamples (xtw);
1054 void WriteRootElementSample (XmlTextWriter xtw, XmlQualifiedName qname)
1056 XmlSchemaElement elem = (XmlSchemaElement) schemas.Find (qname, typeof(XmlSchemaElement));
1057 if (elem == null) throw new InvalidOperationException ("Element not found: " + qname);
1058 WriteElementSample (xtw, qname.Namespace, elem);
1061 void WriteElementSample (XmlTextWriter xtw, string ns, XmlSchemaElement elem)
1063 bool sharedAnnType = false;
1064 XmlQualifiedName root;
1066 if (!elem.RefName.IsEmpty) {
1067 XmlSchemaElement refElem = FindRefElement (elem);
1068 if (refElem == null) throw new InvalidOperationException ("Global element not found: " + elem.RefName);
1069 root = elem.RefName;
1071 sharedAnnType = true;
1074 root = new XmlQualifiedName (elem.Name, ns);
1076 if (!elem.SchemaTypeName.IsEmpty)
1078 XmlSchemaComplexType st = FindComplexTyype (elem.SchemaTypeName);
1080 WriteComplexTypeSample (xtw, st, root);
1083 xtw.WriteStartElement (root.Name, root.Namespace);
1084 if (currentUse == SoapBindingUse.Encoded)
1085 xtw.WriteAttributeString ("type", XmlSchema.InstanceNamespace, GetQualifiedNameString (xtw, elem.SchemaTypeName));
1086 xtw.WriteString (GetLiteral (FindBuiltInType (elem.SchemaTypeName)));
1087 xtw.WriteEndElement ();
1090 else if (elem.SchemaType == null)
1092 xtw.WriteStartElement ("any");
1093 xtw.WriteEndElement ();
1096 WriteComplexTypeSample (xtw, (XmlSchemaComplexType) elem.SchemaType, root);
1099 void WriteTypeSample (XmlTextWriter xtw, XmlQualifiedName qname)
1101 XmlSchemaComplexType ctype = FindComplexTyype (qname);
1102 if (ctype != null) {
1103 WriteComplexTypeSample (xtw, ctype, qname);
1107 XmlSchemaSimpleType stype = (XmlSchemaSimpleType) schemas.Find (qname, typeof(XmlSchemaSimpleType));
1108 if (stype != null) {
1109 WriteSimpleTypeSample (xtw, stype);
1113 xtw.WriteString (GetLiteral (FindBuiltInType (qname)));
1114 throw new InvalidOperationException ("Type not found: " + qname);
1117 void WriteComplexTypeSample (XmlTextWriter xtw, XmlSchemaComplexType stype, XmlQualifiedName rootName)
1119 WriteComplexTypeSample (xtw, stype, rootName, -1);
1122 void WriteComplexTypeSample (XmlTextWriter xtw, XmlSchemaComplexType stype, XmlQualifiedName rootName, int id)
1124 string ns = rootName.Namespace;
1126 if (rootName.Name.IndexOf ("[]") != -1) rootName = arrayType;
1128 if (currentUse == SoapBindingUse.Encoded) {
1129 string pref = xtw.LookupPrefix (rootName.Namespace);
1130 if (pref == null) pref = "q1";
1131 xtw.WriteStartElement (pref, rootName.Name, rootName.Namespace);
1135 xtw.WriteStartElement (rootName.Name, rootName.Namespace);
1139 xtw.WriteAttributeString ("id", "id" + id);
1140 if (rootName != arrayType)
1141 xtw.WriteAttributeString ("type", XmlSchema.InstanceNamespace, GetQualifiedNameString (xtw, rootName));
1144 WriteComplexTypeAttributes (xtw, stype);
1145 WriteComplexTypeElements (xtw, ns, stype);
1147 xtw.WriteEndElement ();
1150 void WriteComplexTypeAttributes (XmlTextWriter xtw, XmlSchemaComplexType stype)
1152 WriteAttributes (xtw, stype.Attributes, stype.AnyAttribute);
1155 void WriteComplexTypeElements (XmlTextWriter xtw, string ns, XmlSchemaComplexType stype)
1157 if (stype.Particle != null)
1158 WriteParticleComplexContent (xtw, ns, stype.Particle);
1161 if (stype.ContentModel is XmlSchemaSimpleContent)
1162 WriteSimpleContent (xtw, (XmlSchemaSimpleContent)stype.ContentModel);
1163 else if (stype.ContentModel is XmlSchemaComplexContent)
1164 WriteComplexContent (xtw, ns, (XmlSchemaComplexContent)stype.ContentModel);
1168 void WriteAttributes (XmlTextWriter xtw, XmlSchemaObjectCollection atts, XmlSchemaAnyAttribute anyat)
1170 foreach (XmlSchemaObject at in atts)
1172 if (at is XmlSchemaAttribute)
1175 XmlSchemaAttribute attr = (XmlSchemaAttribute)at;
1176 XmlSchemaAttribute refAttr = attr;
1178 // refAttr.Form; TODO
1180 if (!attr.RefName.IsEmpty) {
1181 refAttr = FindRefAttribute (attr.RefName);
1182 if (refAttr == null) throw new InvalidOperationException ("Global attribute not found: " + attr.RefName);
1186 if (!refAttr.SchemaTypeName.IsEmpty) val = FindBuiltInType (refAttr.SchemaTypeName);
1187 else val = FindBuiltInType ((XmlSchemaSimpleType) refAttr.SchemaType);
1189 xtw.WriteAttributeString (refAttr.Name, val);
1191 else if (at is XmlSchemaAttributeGroupRef)
1193 XmlSchemaAttributeGroupRef gref = (XmlSchemaAttributeGroupRef)at;
1194 XmlSchemaAttributeGroup grp = (XmlSchemaAttributeGroup) schemas.Find (gref.RefName, typeof(XmlSchemaAttributeGroup));
1195 WriteAttributes (xtw, grp.Attributes, grp.AnyAttribute);
1200 xtw.WriteAttributeString ("custom-attribute","value");
1203 void WriteParticleComplexContent (XmlTextWriter xtw, string ns, XmlSchemaParticle particle)
1205 WriteParticleContent (xtw, ns, particle, false);
1208 void WriteParticleContent (XmlTextWriter xtw, string ns, XmlSchemaParticle particle, bool multiValue)
1210 if (particle is XmlSchemaGroupRef)
1211 particle = GetRefGroupParticle ((XmlSchemaGroupRef)particle);
1213 if (particle.MaxOccurs > 1) multiValue = true;
1215 if (particle is XmlSchemaSequence) {
1216 WriteSequenceContent (xtw, ns, ((XmlSchemaSequence)particle).Items, multiValue);
1218 else if (particle is XmlSchemaChoice) {
1219 if (((XmlSchemaChoice)particle).Items.Count == 1)
1220 WriteSequenceContent (xtw, ns, ((XmlSchemaChoice)particle).Items, multiValue);
1222 WriteChoiceContent (xtw, ns, (XmlSchemaChoice)particle, multiValue);
1224 else if (particle is XmlSchemaAll) {
1225 WriteSequenceContent (xtw, ns, ((XmlSchemaAll)particle).Items, multiValue);
1229 void WriteSequenceContent (XmlTextWriter xtw, string ns, XmlSchemaObjectCollection items, bool multiValue)
1231 foreach (XmlSchemaObject item in items)
1232 WriteContentItem (xtw, ns, item, multiValue);
1235 void WriteContentItem (XmlTextWriter xtw, string ns, XmlSchemaObject item, bool multiValue)
1237 if (item is XmlSchemaGroupRef)
1238 item = GetRefGroupParticle ((XmlSchemaGroupRef)item);
1240 if (item is XmlSchemaElement)
1242 XmlSchemaElement elem = (XmlSchemaElement) item;
1243 XmlSchemaElement refElem;
1244 if (!elem.RefName.IsEmpty) refElem = FindRefElement (elem);
1245 else refElem = elem;
1247 int num = (elem.MaxOccurs == 1 && !multiValue) ? 1 : 2;
1248 for (int n=0; n<num; n++)
1250 if (currentUse == SoapBindingUse.Literal)
1251 WriteElementSample (xtw, ns, refElem);
1253 WriteRefTypeSample (xtw, ns, refElem);
1256 else if (item is XmlSchemaAny)
1258 xtw.WriteString (GetLiteral ("xml"));
1260 else if (item is XmlSchemaParticle) {
1261 WriteParticleContent (xtw, ns, (XmlSchemaParticle)item, multiValue);
1265 void WriteChoiceContent (XmlTextWriter xtw, string ns, XmlSchemaChoice choice, bool multiValue)
1267 foreach (XmlSchemaObject item in choice.Items)
1268 WriteContentItem (xtw, ns, item, multiValue);
1271 void WriteSimpleContent (XmlTextWriter xtw, XmlSchemaSimpleContent content)
1273 XmlSchemaSimpleContentExtension ext = content.Content as XmlSchemaSimpleContentExtension;
1275 WriteAttributes (xtw, ext.Attributes, ext.AnyAttribute);
1277 XmlQualifiedName qname = GetContentBaseType (content.Content);
1278 xtw.WriteString (GetLiteral (FindBuiltInType (qname)));
1281 string FindBuiltInType (XmlQualifiedName qname)
1283 if (qname.Namespace == XmlSchema.Namespace)
1286 XmlSchemaComplexType ct = FindComplexTyype (qname);
1289 XmlSchemaSimpleContent sc = ct.ContentModel as XmlSchemaSimpleContent;
1290 if (sc == null) throw new InvalidOperationException ("Invalid schema");
1291 return FindBuiltInType (GetContentBaseType (sc.Content));
1294 XmlSchemaSimpleType st = (XmlSchemaSimpleType) schemas.Find (qname, typeof(XmlSchemaSimpleType));
1296 return FindBuiltInType (st);
1298 throw new InvalidOperationException ("Definition of type " + qname + " not found");
1301 string FindBuiltInType (XmlSchemaSimpleType st)
1303 if (st.Content is XmlSchemaSimpleTypeRestriction) {
1304 return FindBuiltInType (GetContentBaseType (st.Content));
1306 else if (st.Content is XmlSchemaSimpleTypeList) {
1307 string s = FindBuiltInType (GetContentBaseType (st.Content));
1308 return s + " " + s + " ...";
1310 else if (st.Content is XmlSchemaSimpleTypeUnion)
1312 //Check if all types of the union are equal. If not, then will use anyType.
1313 XmlSchemaSimpleTypeUnion uni = (XmlSchemaSimpleTypeUnion) st.Content;
1314 string utype = null;
1316 // Anonymous types are unique
1317 if (uni.BaseTypes.Count != 0 && uni.MemberTypes.Length != 0)
1320 foreach (XmlQualifiedName mt in uni.MemberTypes)
1322 string qn = FindBuiltInType (mt);
1323 if (utype != null && qn != utype) return "string";
1333 XmlQualifiedName GetContentBaseType (XmlSchemaObject ob)
1335 if (ob is XmlSchemaSimpleContentExtension)
1336 return ((XmlSchemaSimpleContentExtension)ob).BaseTypeName;
1337 else if (ob is XmlSchemaSimpleContentRestriction)
1338 return ((XmlSchemaSimpleContentRestriction)ob).BaseTypeName;
1339 else if (ob is XmlSchemaSimpleTypeRestriction)
1340 return ((XmlSchemaSimpleTypeRestriction)ob).BaseTypeName;
1341 else if (ob is XmlSchemaSimpleTypeList)
1342 return ((XmlSchemaSimpleTypeList)ob).ItemTypeName;
1347 void WriteComplexContent (XmlTextWriter xtw, string ns, XmlSchemaComplexContent content)
1349 XmlQualifiedName qname;
1351 XmlSchemaComplexContentExtension ext = content.Content as XmlSchemaComplexContentExtension;
1352 if (ext != null) qname = ext.BaseTypeName;
1354 XmlSchemaComplexContentRestriction rest = (XmlSchemaComplexContentRestriction)content.Content;
1355 qname = rest.BaseTypeName;
1356 if (qname == arrayType) {
1357 ParseArrayType (rest, out qname);
1358 XmlSchemaElement elem = new XmlSchemaElement ();
1360 elem.SchemaTypeName = qname;
1362 xtw.WriteAttributeString ("arrayType", SoapEncodingNamespace, qname.Name + "[2]");
1363 WriteContentItem (xtw, ns, elem, true);
1368 // Add base map members to this map
1369 XmlSchemaComplexType ctype = FindComplexTyype (qname);
1370 WriteComplexTypeAttributes (xtw, ctype);
1373 // Add the members of this map
1374 WriteAttributes (xtw, ext.Attributes, ext.AnyAttribute);
1375 if (ext.Particle != null)
1376 WriteParticleComplexContent (xtw, ns, ext.Particle);
1379 WriteComplexTypeElements (xtw, ns, ctype);
1382 void ParseArrayType (XmlSchemaComplexContentRestriction rest, out XmlQualifiedName qtype)
1384 XmlSchemaAttribute arrayTypeAt = FindArrayAttribute (rest.Attributes);
1385 XmlAttribute[] uatts = arrayTypeAt.UnhandledAttributes;
1386 if (uatts == null || uatts.Length == 0) throw new InvalidOperationException ("arrayType attribute not specified in array declaration");
1388 XmlAttribute xat = null;
1389 foreach (XmlAttribute at in uatts)
1390 if (at.LocalName == "arrayType" && at.NamespaceURI == WsdlNamespace)
1391 { xat = at; break; }
1394 throw new InvalidOperationException ("arrayType attribute not specified in array declaration");
1396 string arrayType = xat.Value;
1398 int i = arrayType.LastIndexOf (":");
1399 if (i == -1) ns = "";
1400 else ns = arrayType.Substring (0,i);
1402 int j = arrayType.IndexOf ("[", i+1);
1403 if (j == -1) throw new InvalidOperationException ("Cannot parse WSDL array type: " + arrayType);
1404 type = arrayType.Substring (i+1);
1405 type = type.Substring (0, type.Length-2);
1407 qtype = new XmlQualifiedName (type, ns);
1410 XmlSchemaAttribute FindArrayAttribute (XmlSchemaObjectCollection atts)
1412 foreach (object ob in atts)
1414 XmlSchemaAttribute att = ob as XmlSchemaAttribute;
1415 if (att != null && att.RefName == arrayTypeRefName) return att;
1417 XmlSchemaAttributeGroupRef gref = ob as XmlSchemaAttributeGroupRef;
1420 XmlSchemaAttributeGroup grp = (XmlSchemaAttributeGroup) schemas.Find (gref.RefName, typeof(XmlSchemaAttributeGroup));
1421 att = FindArrayAttribute (grp.Attributes);
1422 if (att != null) return att;
1428 void WriteSimpleTypeSample (XmlTextWriter xtw, XmlSchemaSimpleType stype)
1430 xtw.WriteString (GetLiteral (FindBuiltInType (stype)));
1433 XmlSchemaParticle GetRefGroupParticle (XmlSchemaGroupRef refGroup)
1435 XmlSchemaGroup grp = (XmlSchemaGroup) schemas.Find (refGroup.RefName, typeof (XmlSchemaGroup));
1436 return grp.Particle;
1439 XmlSchemaElement FindRefElement (XmlSchemaElement elem)
1441 if (elem.RefName.Namespace == XmlSchema.Namespace)
1443 if (anyElement != null) return anyElement;
1444 anyElement = new XmlSchemaElement ();
1445 anyElement.Name = "any";
1446 anyElement.SchemaTypeName = anyType;
1449 return (XmlSchemaElement) schemas.Find (elem.RefName, typeof(XmlSchemaElement));
1452 XmlSchemaAttribute FindRefAttribute (XmlQualifiedName refName)
1454 if (refName.Namespace == XmlSchema.Namespace)
1456 XmlSchemaAttribute at = new XmlSchemaAttribute ();
1457 at.Name = refName.Name;
1458 at.SchemaTypeName = new XmlQualifiedName ("string",XmlSchema.Namespace);
1461 return (XmlSchemaAttribute) schemas.Find (refName, typeof(XmlSchemaAttribute));
1464 void WriteRefTypeSample (XmlTextWriter xtw, string ns, XmlSchemaElement elem)
1466 if (elem.SchemaTypeName.Namespace == XmlSchema.Namespace || schemas.Find (elem.SchemaTypeName, typeof(XmlSchemaSimpleType)) != null)
1467 WriteElementSample (xtw, ns, elem);
1470 xtw.WriteStartElement (elem.Name, ns);
1471 xtw.WriteAttributeString ("href", "#id" + (queue.Count+1));
1472 xtw.WriteEndElement ();
1473 queue.Add (new EncodedType (ns, elem));
1477 void WriteQueuedTypeSamples (XmlTextWriter xtw)
1479 for (int n=0; n<queue.Count; n++)
1481 EncodedType ec = (EncodedType) queue[n];
1482 XmlSchemaComplexType st = FindComplexTyype (ec.Element.SchemaTypeName);
1483 WriteComplexTypeSample (xtw, st, ec.Element.SchemaTypeName, n+1);
1487 XmlSchemaComplexType FindComplexTyype (XmlQualifiedName qname)
1489 if (qname.Name.IndexOf ("[]") != -1)
1491 XmlSchemaComplexType stype = new XmlSchemaComplexType ();
1492 stype.ContentModel = new XmlSchemaComplexContent ();
1494 XmlSchemaComplexContentRestriction res = new XmlSchemaComplexContentRestriction ();
1495 stype.ContentModel.Content = res;
1496 res.BaseTypeName = arrayType;
1498 XmlSchemaAttribute att = new XmlSchemaAttribute ();
1499 att.RefName = arrayTypeRefName;
1500 res.Attributes.Add (att);
1502 XmlAttribute xat = document.CreateAttribute ("arrayType", WsdlNamespace);
1503 xat.Value = qname.Namespace + ":" + qname.Name;
1504 att.UnhandledAttributes = new XmlAttribute[] {xat};
1508 return (XmlSchemaComplexType) schemas.Find (qname, typeof(XmlSchemaComplexType));
1511 string GetQualifiedNameString (XmlTextWriter xtw, XmlQualifiedName qname)
1513 string pref = xtw.LookupPrefix (qname.Namespace);
1514 if (pref != null) return pref + ":" + qname.Name;
1516 xtw.WriteAttributeString ("xmlns", "q1", null, qname.Namespace);
1517 return "q1:" + qname.Name;
1520 protected virtual string GetLiteral (string s)
1525 void GetOperationFormat (OperationBinding obin, out SoapBindingStyle style, out SoapBindingUse use)
1527 style = SoapBindingStyle.Document;
1528 use = SoapBindingUse.Literal;
1529 SoapOperationBinding sob = obin.Extensions.Find (typeof(SoapOperationBinding)) as SoapOperationBinding;
1532 SoapBodyBinding sbb = obin.Input.Extensions.Find (typeof(SoapBodyBinding)) as SoapBodyBinding;
1546 <link rel="alternate" type="text/xml" href="<%=Request.FilePath%>?disco"/>
1548 <title><%=WebServiceName%> Web Service</title>
1549 <style type="text/css">
1550 BODY { font-family: Arial; margin-left: 20px; margin-top: 20px; font-size: x-small}
1551 TABLE { font-size: x-small }
1552 .title { color:dimgray; font-family: Arial; font-size:20pt; font-weight:900}
1553 .operationTitle { color:dimgray; font-family: Arial; font-size:15pt; font-weight:900}
1554 .method { font-size: x-small }
1555 .bindingLabel { font-size: x-small; font-weight:bold; color:darkgray; line-height:8pt; display:block; margin-bottom:3px }
1556 .label { font-size: small; font-weight:bold; color:darkgray }
1557 .paramTable { font-size: x-small }
1558 .paramTable TR { background-color: gainsboro }
1559 .paramFormTable { font-size: x-small; padding: 10px; background-color: gainsboro }
1560 .paramFormTable TR { background-color: gainsboro }
1561 .paramInput { border: solid 1px gray }
1562 .button {border: solid 1px gray }
1563 .smallSeparator { height:3px; overflow:hidden }
1564 .panel { background-color:whitesmoke; border: solid 1px silver; border-top: solid 1px silver }
1565 .codePanel { background-color: white; font-size:x-small; padding:7px; border:solid 1px silver}
1566 .code-xml { font-size:10pt; font-family:courier }
1567 .code-cs { font-size:10pt; font-family:courier }
1568 .code-vb { font-size:10pt; font-family:courier }
1569 .tabLabelOn { font-weight:bold }
1570 .tabLabelOff {color: darkgray }
1571 .literal-placeholder {color: darkblue; font-weight:bold}
1572 A:link { color: black; }
1573 A:visited { color: black; }
1574 A:active { color: black; }
1575 A:hover { color: blue }
1579 function clearForm ()
1581 document.getElementById("testFormResult").style.display="none";
1588 <div class="title" style="margin-left:20px">
1589 <span class="label">Web Service</span><br>
1594 **********************************************************
1598 <table border="0" width="100%" cellpadding="15px" cellspacing="15px">
1599 <tr valign="top"><td width="150px" class="panel">
1600 <div style="width:150px"></div>
1601 <a class="method" href='<%=PageName%>'>Overview</a><br>
1602 <div class="smallSeparator"></div>
1603 <a class="method" href='<%=PageName + "?" + GetPageContext("wsdl")%>'>Service Description</a>
1604 <div class="smallSeparator"></div>
1605 <a class="method" href='<%=PageName + "?" + GetPageContext("proxy")%>'>Client proxy</a>
1607 <asp:repeater id="BindingsRepeater" runat=server>
1608 <itemtemplate name="itemtemplate">
1609 <span class="bindingLabel"><%#FormatBindingName(DataBinder.Eval(Container.DataItem, "Name").ToString())%></span>
1610 <asp:repeater id="OperationsRepeater" runat=server datasource='<%# ((Binding)Container.DataItem).Operations %>'>
1612 <a class="method" href="<%=PageName%>?<%=GetTabContext("op",null)%>op=<%#GetOpName(Container.DataItem)%>&bnd=<%#DataBinder.Eval(Container.DataItem, "Binding.Name")%>"><%#GetOpName(Container.DataItem)%></a>
1613 <div class="smallSeparator"></div>
1620 </td><td class="panel">
1622 <% if (CurrentPage == "main") {%>
1625 **********************************************************
1626 Web service overview
1629 <p class="label">Web Service Overview</p>
1630 <%=WebServiceDescription%>
1632 <%} if (DefaultBinding == null) {%>
1633 This service does not contain any public web method.
1634 <%} else if (CurrentPage == "op") {%>
1637 **********************************************************
1638 Operation description
1641 <span class="operationTitle"><%=CurrentOperationName%></span>
1646 <% if (CurrentTab == "main") { %>
1647 <span class="label">Input Parameters</span>
1648 <div class="smallSeparator"></div>
1649 <% if (InParams.Count == 0) { %>
1650 No input parameters<br>
1652 <table class="paramTable" cellspacing="1" cellpadding="5">
1653 <asp:repeater id="InputParamsRepeater" runat=server>
1656 <td width="150"><%#DataBinder.Eval(Container.DataItem, "Name")%></td>
1657 <td width="150"><%#DataBinder.Eval(Container.DataItem, "Type")%></td>
1665 <% if (OutParams.Count > 0) { %>
1666 <span class="label">Output Parameters</span>
1667 <div class="smallSeparator"></div>
1668 <table class="paramTable" cellspacing="1" cellpadding="5">
1669 <asp:repeater id="OutputParamsRepeater" runat=server>
1672 <td width="150"><%#DataBinder.Eval(Container.DataItem, "Name")%></td>
1673 <td width="150"><%#DataBinder.Eval(Container.DataItem, "Type")%></td>
1681 <span class="label">Remarks</span>
1682 <div class="smallSeparator"></div>
1683 <%=OperationDocumentation%>
1685 <span class="label">Technical information</span>
1686 <div class="smallSeparator"></div>
1687 Format: <%=CurrentOperationFormat%>
1688 <br>Supported protocols: <%=CurrentOperationProtocols%>
1692 **********************************************************
1693 Operation description - Test form
1696 <% if (CurrentTab == "test") {
1697 if (CurrentOperationSupportsTest) {%>
1698 Enter values for the parameters and click the 'Invoke' button to test this method:<br><br>
1699 <form action="<%=PageName%>" method="GET">
1700 <input type="hidden" name="page" value="<%=CurrentPage%>">
1701 <input type="hidden" name="tab" value="<%=CurrentTab%>">
1702 <input type="hidden" name="op" value="<%=CurrentOperationName%>">
1703 <input type="hidden" name="bnd" value="<%=CurrentOperationBinding%>">
1704 <input type="hidden" name="ext" value="testform">
1705 <table class="paramFormTable" cellspacing="0" cellpadding="3">
1706 <asp:repeater id="InputFormParamsRepeater" runat=server>
1709 <td><%#DataBinder.Eval(Container.DataItem, "Name")%>: </td>
1710 <td width="150"><input class="paramInput" type="text" size="20" name="<%#DataBinder.Eval(Container.DataItem, "Name")%>"></td>
1714 <tr><td></td><td><input class="button" type="submit" value="Invoke"> <input class="button" type="button" onclick="clearForm()" value="Clear"></td></tr>
1717 <div id="testFormResult" style="display:<%= (HasFormResult?"block":"none") %>">
1718 The web service returned the following result:<br/><br/>
1719 <div class="codePanel"><%=GetTestResult()%></div>
1722 The test form is not available for this operation because it has parameters with a complex structure.
1727 **********************************************************
1728 Operation description - Message Layout
1731 <% if (CurrentTab == "msg") { %>
1733 The following are sample SOAP requests and responses for each protocol supported by this method:
1736 <% if (IsOperationSupported ("Soap")) { %>
1737 <span class="label">Soap</span>
1739 <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("Soap", true)%></div></div>
1741 <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("Soap", false)%></div></div>
1744 <% if (IsOperationSupported ("HttpGet")) { %>
1745 <span class="label">HTTP Get</span>
1747 <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("HttpGet", true)%></div></div>
1749 <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("HttpGet", false)%></div></div>
1752 <% if (IsOperationSupported ("HttpPost")) { %>
1753 <span class="label">HTTP Post</span>
1755 <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("HttpPost", true)%></div></div>
1757 <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("HttpPost", false)%></div></div>
1762 <%} else if (CurrentPage == "proxy") {%>
1764 **********************************************************
1767 <form action="<%=PageName%>" name="langForm" method="GET">
1768 Select the language for which you want to generate a proxy
1769 <input type="hidden" name="page" value="<%=CurrentPage%>">
1770 <SELECT name="lang" onchange="langForm.submit()">
1771 <%=GetOptionSel("cs",CurrentLanguage)%>C#</option>
1772 <%=GetOptionSel("vb",CurrentLanguage)%>Visual Basic</option>
1777 <span class="label"><%=CurrentProxytName%></span>
1778 <a href="<%=PageName + "?code=" + CurrentLanguage%>">Download</a>
1780 <div class="codePanel">
1781 <div class="code-<%=CurrentLanguage%>"><%=GetProxyCode ()%></div>
1783 <%} else if (CurrentPage == "wsdl") {%>
1785 **********************************************************
1788 <% if (descriptions.Count > 1 || schemas.Count > 1) {%>
1789 The description of this web service is composed by several documents. Click on the document you want to see:
1793 for (int n=0; n<descriptions.Count; n++)
1794 Response.Write ("<li><a href='" + PageName + "?" + GetPageContext(null) + "doctype=wsdl&docind=" + n + "'>WSDL document " + descriptions[n].TargetNamespace + "</a></li>");
1795 for (int n=0; n<schemas.Count; n++)
1796 Response.Write ("<li><a href='" + PageName + "?" + GetPageContext(null) + "doctype=schema&docind=" + n + "'>Xml Schema " + schemas[n].TargetNamespace + "</a></li>");
1803 <span class="label"><%=CurrentDocumentName%></span>
1804 <a href="<%=PageName + "?" + CurrentDocType + "=" + CurrentDocInd %>">Download</a>
1806 <div class="codePanel">
1807 <div class="code-xml"><%=GenerateDocument ()%></div>
1812 <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
1814 <td width="20px"></td>