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.RegularExpressions" %>
28 <%@ Assembly name="System.Web.Services" %>
29 <%@ Page debug="true" %>
32 <script language="C#" runat="server">
34 ServiceDescriptionCollection descriptions;
37 string WebServiceName;
38 string WebServiceDescription;
41 string DefaultBinding;
42 ArrayList ServiceProtocols;
44 string CurrentOperationName;
45 string CurrentOperationBinding;
46 string OperationDocumentation;
47 string CurrentOperationFormat;
48 bool CurrentOperationSupportsTest;
51 string CurrentOperationProtocols;
52 int CodeTextColumns = 95;
54 void Page_Load(object sender, EventArgs e)
56 descriptions = (ServiceDescriptionCollection) Context.Items["wsdls"];
57 schemas = (XmlSchemas) Context.Items["schemas"];
59 ServiceDescription desc = descriptions [0];
60 if (schemas.Count == 0) schemas = desc.Types.Schemas;
62 Service service = desc.Services[0];
63 WebServiceName = service.Name;
64 DefaultBinding = desc.Bindings[0].Name;
65 WebServiceDescription = service.Documentation;
66 ServiceProtocols = FindServiceProtocols (null);
68 CurrentOperationName = Request.QueryString["op"];
69 CurrentOperationBinding = Request.QueryString["bnd"];
70 if (CurrentOperationName != null) BuildOperationInfo ();
72 PageName = HttpUtility.UrlEncode (Path.GetFileName(Request.Path), Encoding.UTF8);
74 ArrayList list = new ArrayList ();
75 foreach (ServiceDescription sd in descriptions) {
76 foreach (Binding bin in sd.Bindings)
77 if (bin.Extensions.Find (typeof(SoapBinding)) != null) list.Add (bin);
80 BindingsRepeater.DataSource = list;
84 void BuildOperationInfo ()
86 InParams = new ArrayList ();
87 OutParams = new ArrayList ();
89 Port port = FindPort (CurrentOperationBinding, null);
90 Binding binding = descriptions.GetBinding (port.Binding);
92 PortType portType = descriptions.GetPortType (binding.Type);
93 Operation oper = FindOperation (portType, CurrentOperationName);
95 OperationDocumentation = oper.Documentation;
96 if (OperationDocumentation == null || OperationDocumentation == "")
97 OperationDocumentation = "No additional remarks";
99 foreach (OperationMessage opm in oper.Messages)
101 if (opm is OperationInput)
102 BuildParameters (InParams, opm);
103 else if (opm is OperationOutput)
104 BuildParameters (OutParams, opm);
107 // Protocols supported by the operation
108 CurrentOperationProtocols = "";
109 ArrayList prots = FindServiceProtocols (CurrentOperationName);
110 for (int n=0; n<prots.Count; n++) {
111 if (n != 0) CurrentOperationProtocols += ", ";
112 CurrentOperationProtocols += (string) prots[n];
115 CurrentOperationSupportsTest = prots.Contains ("HttpGet") || prots.Contains ("HttpPost");
118 OperationBinding obin = FindOperation (binding, CurrentOperationName);
120 CurrentOperationFormat = GetOperationFormat (obin);
122 InputParamsRepeater.DataSource = InParams;
123 InputFormParamsRepeater.DataSource = InParams;
124 OutputParamsRepeater.DataSource = OutParams;
127 void BuildParameters (ArrayList list, OperationMessage opm)
129 Message msg = descriptions.GetMessage (opm.Message);
130 if (msg.Parts.Count > 0 && msg.Parts[0].Name == "parameters")
132 MessagePart part = msg.Parts[0];
133 XmlSchemaComplexType ctype;
134 if (part.Element == XmlQualifiedName.Empty)
136 ctype = (XmlSchemaComplexType) schemas.Find (part.Type, typeof(XmlSchemaComplexType));
140 XmlSchemaElement elem = (XmlSchemaElement) schemas.Find (part.Element, typeof(XmlSchemaElement));
141 ctype = (XmlSchemaComplexType) elem.SchemaType;
143 XmlSchemaSequence seq = ctype.Particle as XmlSchemaSequence;
144 if (seq == null) return;
146 foreach (XmlSchemaObject ob in seq.Items)
148 Parameter p = new Parameter();
149 p.Description = "No additional remarks";
151 if (ob is XmlSchemaElement)
153 XmlSchemaElement selem = GetRefElement ((XmlSchemaElement)ob);
155 p.Type = selem.SchemaTypeName.Name;
167 foreach (MessagePart part in msg.Parts)
169 Parameter p = new Parameter ();
170 p.Description = "No additional remarks";
172 if (part.Element == XmlQualifiedName.Empty)
173 p.Type = part.Type.Name;
176 XmlSchemaElement elem = (XmlSchemaElement) schemas.Find (part.Element, typeof(XmlSchemaElement));
177 p.Type = elem.SchemaTypeName.Name;
184 string GetOperationFormat (OperationBinding obin)
187 SoapOperationBinding sob = obin.Extensions.Find (typeof(SoapOperationBinding)) as SoapOperationBinding;
189 format = sob.Style.ToString ();
190 SoapBodyBinding sbb = obin.Input.Extensions.Find (typeof(SoapBodyBinding)) as SoapBodyBinding;
192 format += " / " + sbb.Use;
197 XmlSchemaElement GetRefElement (XmlSchemaElement elem)
199 if (!elem.RefName.IsEmpty)
200 return (XmlSchemaElement) schemas.Find (elem.RefName, typeof(XmlSchemaElement));
205 ArrayList FindServiceProtocols(string operName)
207 ArrayList table = new ArrayList ();
208 Service service = descriptions[0].Services[0];
209 foreach (Port port in service.Ports)
212 Binding bin = descriptions.GetBinding (port.Binding);
213 if (bin.Extensions.Find (typeof(SoapBinding)) != null)
217 HttpBinding hb = (HttpBinding) bin.Extensions.Find (typeof(HttpBinding));
218 if (hb != null && hb.Verb == "POST") prot = "HttpPost";
219 else if (hb != null && hb.Verb == "GET") prot = "HttpGet";
222 if (prot != null && operName != null)
224 if (FindOperation (bin, operName) == null)
228 if (prot != null && !table.Contains (prot))
234 Port FindPort (string portName, string protocol)
236 Service service = descriptions[0].Services[0];
237 foreach (Port port in service.Ports)
239 if (portName == null)
241 Binding binding = descriptions.GetBinding (port.Binding);
242 if (GetProtocol (binding) == protocol) return port;
244 else if (port.Name == portName)
250 string GetProtocol (Binding binding)
252 if (binding.Extensions.Find (typeof(SoapBinding)) != null) return "Soap";
253 HttpBinding hb = (HttpBinding) binding.Extensions.Find (typeof(HttpBinding));
254 if (hb == null) return "";
255 if (hb.Verb == "POST") return "HttpPost";
256 if (hb.Verb == "GET") return "HttpGet";
261 Operation FindOperation (PortType portType, string name)
263 foreach (Operation oper in portType.Operations) {
264 if (oper.Messages.Input.Name != null) {
265 if (oper.Messages.Input.Name == name) return oper;
268 if (oper.Name == name) return oper;
274 OperationBinding FindOperation (Binding binding, string name)
276 foreach (OperationBinding oper in binding.Operations) {
277 if (oper.Input.Name != null) {
278 if (oper.Input.Name == name) return oper;
281 if (oper.Name == name) return oper;
287 string FormatBindingName (string name)
289 if (name == DefaultBinding) return "Methods";
290 else return "Methods for binding<br>" + name;
293 string GetOpName (object op)
295 OperationBinding ob = op as OperationBinding;
296 if (ob == null) return "";
297 if (ob.Input.Name != null) return ob.Input.Name;
303 get { return Request.QueryString ["ext"] == "testform"; }
306 string GetTestResult ()
308 if (!HasFormResult) return null;
312 for (int n=0; n<Request.QueryString.Count; n++)
315 if (qs != "") qs += "&";
316 qs += Request.QueryString.GetKey(n) + "=" + Request.QueryString [n];
318 if (Request.QueryString.GetKey(n) == "ext") fill = true;
321 string location = null;
322 ServiceDescription desc = descriptions [0];
323 Service service = desc.Services[0];
324 foreach (Port port in service.Ports)
325 if (port.Name == CurrentOperationBinding)
327 SoapAddressBinding sbi = (SoapAddressBinding) port.Extensions.Find (typeof(SoapAddressBinding));
329 location = sbi.Location;
332 if (location == null)
333 return "Could not locate web service";
337 WebRequest req = WebRequest.Create (location + "/" + CurrentOperationName + "?" + qs);
338 WebResponse resp = req.GetResponse();
339 StreamReader sr = new StreamReader (resp.GetResponseStream());
340 string s = sr.ReadToEnd ();
342 return "<div class='code-xml'>" + ColorizeXml(WrapText(s,CodeTextColumns)) + "</div>";
346 string res = "<b style='color:red'>" + ex.Message + "</b>";
347 WebException wex = ex as WebException;
350 WebResponse resp = wex.Response;
352 StreamReader sr = new StreamReader (resp.GetResponseStream());
353 string s = sr.ReadToEnd ();
355 res += "<div class='code-xml'>" + ColorizeXml(WrapText(s,CodeTextColumns)) + "</div>";
362 string GenerateOperationMessages (string protocol, bool generateInput)
364 if (!IsOperationSupported (protocol)) return "";
367 if (protocol != "Soap") port = FindPort (null, protocol);
368 else port = FindPort (CurrentOperationBinding, null);
370 Binding binding = descriptions.GetBinding (port.Binding);
371 OperationBinding obin = FindOperation (binding, CurrentOperationName);
372 PortType portType = descriptions.GetPortType (binding.Type);
373 Operation oper = FindOperation (portType, CurrentOperationName);
375 HtmlSampleGenerator sg = new HtmlSampleGenerator (descriptions, schemas);
376 string txt = sg.GenerateMessage (port, obin, oper, protocol, generateInput);
377 if (protocol == "Soap") txt = WrapText (txt,CodeTextColumns);
378 txt = ColorizeXml (txt);
379 txt = txt.Replace ("@placeholder!","<span class='literal-placeholder'>");
380 txt = txt.Replace ("!placeholder@","</span>");
384 bool IsOperationSupported (string protocol)
386 if (CurrentPage != "op" || CurrentTab != "msg") return false;
387 if (protocol == "Soap") return true;
389 Port port = FindPort (null, protocol);
390 if (port == null) return false;
391 Binding binding = descriptions.GetBinding (port.Binding);
392 if (binding == null) return false;
393 return FindOperation (binding, CurrentOperationName) != null;
397 // Proxy code generation
400 string GetProxyCode ()
402 CodeNamespace codeNamespace = new CodeNamespace();
403 CodeCompileUnit codeUnit = new CodeCompileUnit();
405 codeUnit.Namespaces.Add (codeNamespace);
407 ServiceDescriptionImporter importer = new ServiceDescriptionImporter();
409 foreach (ServiceDescription sd in descriptions)
410 importer.AddServiceDescription(sd, null, null);
412 foreach (XmlSchema sc in schemas)
413 importer.Schemas.Add (sc);
415 importer.Import(codeNamespace, codeUnit);
417 string langId = Request.QueryString ["lang"];
418 if (langId == null || langId == "") langId = "cs";
419 CodeDomProvider provider = GetProvider (langId);
420 ICodeGenerator generator = provider.CreateGenerator();
421 CodeGeneratorOptions options = new CodeGeneratorOptions();
423 StringWriter sw = new StringWriter ();
424 generator.GenerateCodeFromCompileUnit(codeUnit, sw, options);
426 return Colorize (WrapText (sw.ToString (), CodeTextColumns), langId);
429 public string CurrentLanguage
432 string langId = Request.QueryString ["lang"];
433 if (langId == null || langId == "") langId = "cs";
438 public string CurrentProxytName
441 string lan = CurrentLanguage == "cs" ? "C#" : "Visual Basic";
442 return lan + " Client Proxy";
446 private CodeDomProvider GetProvider(string langId)
448 switch (langId.ToUpper())
450 case "CS": return new CSharpCodeProvider();
451 case "VB": return new VBCodeProvider();
452 default: return null;
457 // Document generation
460 string GenerateDocument ()
462 StringWriter sw = new StringWriter ();
464 if (CurrentDocType == "wsdl")
465 descriptions [CurrentDocInd].Write (sw);
466 else if (CurrentDocType == "schema")
467 schemas [CurrentDocInd].Write (sw);
469 return Colorize (WrapText (sw.ToString (), CodeTextColumns), "xml");
472 public string CurrentDocType
474 get { return Request.QueryString ["doctype"] != null ? Request.QueryString ["doctype"] : "wsdl"; }
477 public int CurrentDocInd
479 get { return Request.QueryString ["docind"] != null ? int.Parse (Request.QueryString ["docind"]) : 0; }
482 public string CurrentDocumentName
485 if (CurrentDocType == "wsdl")
486 return "WSDL document for namespace \"" + descriptions [CurrentDocInd].TargetNamespace + "\"";
488 return "Xml Schema for namespace \"" + schemas [CurrentDocInd].TargetNamespace + "\"";
496 bool firstTab = true;
497 ArrayList disabledTabs = new ArrayList ();
501 get { return Request.QueryString["tab"] != null ? Request.QueryString["tab"] : "main" ; }
506 get { return Request.QueryString["page"] != null ? Request.QueryString["page"] : "main" ; }
511 if (CurrentOperationName != null)
513 WriteTab ("main","Overview");
514 WriteTab ("test","Test Form");
515 WriteTab ("msg","Message Layout");
519 void WriteTab (string id, string label)
521 if (!firstTab) Response.Write(" | ");
524 string cname = CurrentTab == id ? "tabLabelOn" : "tabLabelOff";
525 Response.Write ("<a href='" + PageName + "?" + GetPageContext(null) + GetDataContext() + "tab=" + id + "' style='text-decoration:none'>");
526 Response.Write ("<span class='" + cname + "'>" + label + "</span>");
527 Response.Write ("</a>");
530 string GetTabContext (string pag, string tab)
532 if (tab == null) tab = CurrentTab;
533 if (pag == null) pag = CurrentPage;
534 if (pag != CurrentPage) tab = "main";
535 return "page=" + pag + "&tab=" + tab + "&";
538 string GetPageContext (string pag)
540 if (pag == null) pag = CurrentPage;
541 return "page=" + pag + "&";
554 static string keywords_cs =
555 "(\\babstract\\b|\\bevent\\b|\\bnew\\b|\\bstruct\\b|\\bas\\b|\\bexplicit\\b|\\bnull\\b|\\bswitch\\b|\\bbase\\b|\\bextern\\b|" +
556 "\\bobject\\b|\\bthis\\b|\\bbool\\b|\\bfalse\\b|\\boperator\\b|\\bthrow\\b|\\bbreak\\b|\\bfinally\\b|\\bout\\b|\\btrue\\b|" +
557 "\\bbyte\\b|\\bfixed\\b|\\boverride\\b|\\btry\\b|\\bcase\\b|\\bfloat\\b|\\bparams\\b|\\btypeof\\b|\\bcatch\\b|\\bfor\\b|" +
558 "\\bprivate\\b|\\buint\\b|\\bchar\\b|\\bforeach\\b|\\bprotected\\b|\\bulong\\b|\\bchecked\\b|\\bgoto\\b|\\bpublic\\b|" +
559 "\\bunchecked\\b|\\bclass\\b|\\bif\\b|\\breadonly\\b|\\bunsafe\\b|\\bconst\\b|\\bimplicit\\b|\\bref\\b|\\bushort\\b|" +
560 "\\bcontinue\\b|\\bin\\b|\\breturn\\b|\\busing\\b|\\bdecimal\\b|\\bint\\b|\\bsbyte\\b|\\bvirtual\\b|\\bdefault\\b|" +
561 "\\binterface\\b|\\bsealed\\b|\\bvolatile\\b|\\bdelegate\\b|\\binternal\\b|\\bshort\\b|\\bvoid\\b|\\bdo\\b|\\bis\\b|" +
562 "\\bsizeof\\b|\\bwhile\\b|\\bdouble\\b|\\block\\b|\\bstackalloc\\b|\\belse\\b|\\blong\\b|\\bstatic\\b|\\benum\\b|" +
563 "\\bnamespace\\b|\\bstring\\b)";
565 static string keywords_vb =
566 "(\\bAddHandler\\b|\\bAddressOf\\b|\\bAlias\\b|\\bAnd\\b|\\bAndAlso\\b|\\bAnsi\\b|\\bAs\\b|\\bAssembly\\b|" +
567 "\\bAuto\\b|\\bBoolean\\b|\\bByRef\\b|\\bByte\\b|\\bByVal\\b|\\bCall\\b|\\bCase\\b|\\bCatch\\b|" +
568 "\\bCBool\\b|\\bCByte\\b|\\bCChar\\b|\\bCDate\\b|\\bCDec\\b|\\bCDbl\\b|\\bChar\\b|\\bCInt\\b|" +
569 "\\bClass\\b|\\bCLng\\b|\\bCObj\\b|\\bConst\\b|\\bCShort\\b|\\bCSng\\b|\\bCStr\\b|\\bCType\\b|" +
570 "\\bDate\\b|\\bDecimal\\b|\\bDeclare\\b|\\bDefault\\b|\\bDelegate\\b|\\bDim\\b|\\bDirectCast\\b|\\bDo\\b|" +
571 "\\bDouble\\b|\\bEach\\b|\\bElse\\b|\\bElseIf\\b|\\bEnd\\b|\\bEnum\\b|\\bErase\\b|\\bError\\b|" +
572 "\\bEvent\\b|\\bExit\\b|\\bFalse\\b|\\bFinally\\b|\\bFor\\b|\\bFriend\\b|\\bFunction\\b|\\bGet\\b|" +
573 "\\bGetType\\b|\\bGoSub\\b|\\bGoTo\\b|\\bHandles\\b|\\bIf\\b|\\bImplements\\b|\\bImports\\b|\\bIn\\b|" +
574 "\\bInherits\\b|\\bInteger\\b|\\bInterface\\b|\\bIs\\b|\\bLet\\b|\\bLib\\b|\\bLike\\b|\\bLong\\b|" +
575 "\\bLoop\\b|\\bMe\\b|\\bMod\\b|\\bModule\\b|\\bMustInherit\\b|\\bMustOverride\\b|\\bMyBase\\b|\\bMyClass\\b|" +
576 "\\bNamespace\\b|\\bNew\\b|\\bNext\\b|\\bNot\\b|\\bNothing\\b|\\bNotInheritable\\b|\\bNotOverridable\\b|\\bObject\\b|" +
577 "\\bOn\\b|\\bOption\\b|\\bOptional\\b|\\bOr\\b|\\bOrElse\\b|\\bOverloads\\b|\\bOverridable\\b|\\bOverrides\\b|" +
578 "\\bParamArray\\b|\\bPreserve\\b|\\bPrivate\\b|\\bProperty\\b|\\bProtected\\b|\\bPublic\\b|\\bRaiseEvent\\b|\\bReadOnly\\b|" +
579 "\\bReDim\\b|\\bREM\\b|\\bRemoveHandler\\b|\\bResume\\b|\\bReturn\\b|\\bSelect\\b|\\bSet\\b|\\bShadows\\b|" +
580 "\\bShared\\b|\\bShort\\b|\\bSingle\\b|\\bStatic\\b|\\bStep\\b|\\bStop\\b|\\bString\\b|\\bStructure\\b|" +
581 "\\bSub\\b|\\bSyncLock\\b|\\bThen\\b|\\bThrow\\b|\\bTo\\b|\\bTrue\\b|\\bTry\\b|\\bTypeOf\\b|" +
582 "\\bUnicode\\b|\\bUntil\\b|\\bVariant\\b|\\bWhen\\b|\\bWhile\\b|\\bWith\\b|\\bWithEvents\\b|\\bWriteOnly\\b|\\bXor\\b)";
584 string Colorize (string text, string lang)
586 if (lang == "xml") return ColorizeXml (text);
587 else if (lang == "cs") return ColorizeCs (text);
588 else if (lang == "vb") return ColorizeVb (text);
592 string ColorizeXml (string text)
594 text = text.Replace (" ", " ");
595 Regex re = new Regex ("\r\n|\r|\n");
596 text = re.Replace (text, "_br_");
598 re = new Regex ("<\\s*(\\/?)\\s*([\\s\\S]*?)\\s*(\\/?)\\s*>");
599 text = re.Replace (text,"{blue:<$1}{maroon:$2}{blue:$3>}");
601 re = new Regex ("\\{(\\w*):([\\s\\S]*?)\\}");
602 text = re.Replace (text,"<span style='color:$1'>$2</span>");
604 re = new Regex ("\"(.*?)\"");
605 text = re.Replace (text,"\"<span style='color:purple'>$1</span>\"");
608 text = text.Replace ("\t", " ");
609 text = text.Replace ("_br_", "<br>");
613 string ColorizeCs (string text)
615 text = text.Replace (" ", " ");
617 text = text.Replace ("<", "<");
618 text = text.Replace (">", ">");
620 Regex re = new Regex ("\"((((?!\").)|\\\")*?)\"");
621 text = re.Replace (text,"<span style='color:purple'>\"$1\"</span>");
623 re = new Regex ("//(((.(?!\"</span>))|\"(((?!\").)*)\"</span>)*)(\r|\n|\r\n)");
624 text = re.Replace (text,"<span style='color:green'>//$1</span><br/>");
626 re = new Regex (keywords_cs);
627 text = re.Replace (text,"<span style='color:blue'>$1</span>");
629 text = text.Replace ("\t"," ");
630 text = text.Replace ("\n","<br/>");
635 string ColorizeVb (string text)
637 text = text.Replace (" ", " ");
639 /* Regex re = new Regex ("\"((((?!\").)|\\\")*?)\"");
640 text = re.Replace (text,"<span style='color:purple'>\"$1\"</span>");
642 re = new Regex ("'(((.(?!\"\\<\\/span\\>))|\"(((?!\").)*)\"\\<\\/span\\>)*)(\r|\n|\r\n)");
643 text = re.Replace (text,"<span style='color:green'>//$1</span><br/>");
645 re = new Regex (keywords_vb);
646 text = re.Replace (text,"<span style='color:blue'>$1</span>");
648 text = text.Replace ("\t"," ");
649 text = text.Replace ("\n","<br/>");
654 // Helper methods and classes
657 string GetDataContext ()
659 return "op=" + CurrentOperationName + "&bnd=" + CurrentOperationBinding + "&";
662 string GetOptionSel (string v1, string v2)
664 string op = "<option ";
665 if (v1 == v2) op += "selected ";
666 return op + "value='" + v1 + "'>";
669 string WrapText (string text, int maxChars)
671 text = text.Replace(" />","/>");
673 string linspace = null;
677 bool inquotes = false;
679 string sublineIndent = "";
680 System.Text.StringBuilder sb = new System.Text.StringBuilder ();
681 for (int n=0; n<text.Length; n++)
685 if (c=='\r' || c=='\n' || n==text.Length-1)
687 sb.Append (linspace + sublineIndent + text.Substring (linstart, n-linstart+1));
697 if (lastc==',' || lastc=='(')
699 if (!inquotes) breakpos = n;
702 if (lincount > maxChars && breakpos >= linstart)
704 if (linspace != null)
705 sb.Append (linspace + sublineIndent);
706 sb.Append (text.Substring (linstart, breakpos-linstart));
709 lincount = linspace.Length + sublineIndent.Length + (n-breakpos);
713 if (c==' ' || c=='\t')
720 inquotes = !inquotes;
723 if (linspace == null) {
724 linspace = text.Substring (linstart, n-linstart);
731 return sb.ToString ();
740 public string Name { get { return name; } set { name = value; } }
741 public string Type { get { return type; } set { type = value; } }
742 public string Description { get { return description; } set { description = value; } }
745 public class HtmlSampleGenerator: SampleGenerator
747 public HtmlSampleGenerator (ServiceDescriptionCollection services, XmlSchemas schemas)
748 : base (services, schemas)
752 protected override string GetLiteral (string s)
754 return "@placeholder!" + s + "!placeholder@";
759 public class SampleGenerator
761 protected ServiceDescriptionCollection descriptions;
762 protected XmlSchemas schemas;
763 XmlSchemaElement anyElement;
765 SoapBindingUse currentUse;
766 XmlDocument document = new XmlDocument ();
768 static readonly XmlQualifiedName anyType = new XmlQualifiedName ("anyType",XmlSchema.Namespace);
769 static readonly XmlQualifiedName arrayType = new XmlQualifiedName ("Array","http://schemas.xmlsoap.org/soap/encoding/");
770 static readonly XmlQualifiedName arrayTypeRefName = new XmlQualifiedName ("arrayType","http://schemas.xmlsoap.org/soap/encoding/");
771 const string SoapEnvelopeNamespace = "http://schemas.xmlsoap.org/soap/envelope/";
772 const string WsdlNamespace = "http://schemas.xmlsoap.org/wsdl/";
773 const string SoapEncodingNamespace = "http://schemas.xmlsoap.org/soap/encoding/";
777 public EncodedType (string ns, XmlSchemaElement elem) { Namespace = ns; Element = elem; }
778 public string Namespace;
779 public XmlSchemaElement Element;
782 public SampleGenerator (ServiceDescriptionCollection services, XmlSchemas schemas)
784 descriptions = services;
785 this.schemas = schemas;
786 queue = new ArrayList ();
789 public string GenerateMessage (Port port, OperationBinding obin, Operation oper, string protocol, bool generateInput)
791 OperationMessage msg = null;
792 foreach (OperationMessage opm in oper.Messages)
794 if (opm is OperationInput && generateInput) msg = opm;
795 else if (opm is OperationOutput && !generateInput) msg = opm;
797 if (msg == null) return null;
800 case "Soap": return GenerateHttpSoapMessage (port, obin, oper, msg);
801 case "HttpGet": return GenerateHttpGetMessage (port, obin, oper, msg);
802 case "HttpPost": return GenerateHttpPostMessage (port, obin, oper, msg);
804 return "Unknown protocol";
807 public string GenerateHttpSoapMessage (Port port, OperationBinding obin, Operation oper, OperationMessage msg)
811 if (msg is OperationInput)
813 SoapAddressBinding sab = port.Extensions.Find (typeof(SoapAddressBinding)) as SoapAddressBinding;
814 SoapOperationBinding sob = obin.Extensions.Find (typeof(SoapOperationBinding)) as SoapOperationBinding;
815 req += "POST " + new Uri (sab.Location).AbsolutePath + "\n";
816 req += "SOAPAction: " + sob.SoapAction + "\n";
817 req += "Content-Type: text/xml; charset=utf-8\n";
818 req += "Content-Length: " + GetLiteral ("string") + "\n";
819 req += "Host: " + GetLiteral ("string") + "\n\n";
823 req += "HTTP/1.0 200 OK\n";
824 req += "Content-Type: text/xml; charset=utf-8\n";
825 req += "Content-Length: " + GetLiteral ("string") + "\n\n";
828 req += GenerateSoapMessage (obin, oper, msg);
832 public string GenerateHttpGetMessage (Port port, OperationBinding obin, Operation oper, OperationMessage msg)
836 if (msg is OperationInput)
838 HttpAddressBinding sab = port.Extensions.Find (typeof(HttpAddressBinding)) as HttpAddressBinding;
839 HttpOperationBinding sob = obin.Extensions.Find (typeof(HttpOperationBinding)) as HttpOperationBinding;
840 string location = new Uri (sab.Location).AbsolutePath + sob.Location + "?" + BuildQueryString (msg);
841 req += "GET " + location + "\n";
842 req += "Host: " + GetLiteral ("string");
846 req += "HTTP/1.0 200 OK\n";
847 req += "Content-Type: text/xml; charset=utf-8\n";
848 req += "Content-Length: " + GetLiteral ("string") + "\n\n";
850 MimeXmlBinding mxb = (MimeXmlBinding) obin.Output.Extensions.Find (typeof(MimeXmlBinding)) as MimeXmlBinding;
851 if (mxb == null) return req;
853 Message message = descriptions.GetMessage (msg.Message);
854 XmlQualifiedName ename = null;
855 foreach (MessagePart part in message.Parts)
856 if (part.Name == mxb.Part) ename = part.Element;
858 if (ename == null) return req + GetLiteral("string");
860 StringWriter sw = new StringWriter ();
861 XmlTextWriter xtw = new XmlTextWriter (sw);
862 xtw.Formatting = Formatting.Indented;
863 currentUse = SoapBindingUse.Literal;
864 WriteRootElementSample (xtw, ename);
866 req += sw.ToString ();
872 public string GenerateHttpPostMessage (Port port, OperationBinding obin, Operation oper, OperationMessage msg)
876 if (msg is OperationInput)
878 HttpAddressBinding sab = port.Extensions.Find (typeof(HttpAddressBinding)) as HttpAddressBinding;
879 HttpOperationBinding sob = obin.Extensions.Find (typeof(HttpOperationBinding)) as HttpOperationBinding;
880 string location = new Uri (sab.Location).AbsolutePath + sob.Location;
881 req += "POST " + location + "\n";
882 req += "Content-Type: application/x-www-form-urlencoded\n";
883 req += "Content-Length: " + GetLiteral ("string") + "\n";
884 req += "Host: " + GetLiteral ("string") + "\n\n";
885 req += BuildQueryString (msg);
887 else return GenerateHttpGetMessage (port, obin, oper, msg);
892 string BuildQueryString (OperationMessage opm)
895 Message msg = descriptions.GetMessage (opm.Message);
896 foreach (MessagePart part in msg.Parts)
898 if (s.Length != 0) s += "&";
899 s += part.Name + "=" + GetLiteral (part.Type.Name);
904 public string GenerateSoapMessage (OperationBinding obin, Operation oper, OperationMessage msg)
906 SoapOperationBinding sob = obin.Extensions.Find (typeof(SoapOperationBinding)) as SoapOperationBinding;
907 SoapBindingStyle style = (sob != null) ? sob.Style : SoapBindingStyle.Document;
909 MessageBinding msgbin = (msg is OperationInput) ? (MessageBinding) obin.Input : (MessageBinding)obin.Output;
910 SoapBodyBinding sbb = msgbin.Extensions.Find (typeof(SoapBodyBinding)) as SoapBodyBinding;
911 SoapBindingUse bodyUse = (sbb != null) ? sbb.Use : SoapBindingUse.Literal;
913 StringWriter sw = new StringWriter ();
914 XmlTextWriter xtw = new XmlTextWriter (sw);
915 xtw.Formatting = Formatting.Indented;
917 xtw.WriteStartDocument ();
918 xtw.WriteStartElement ("soap", "Envelope", SoapEnvelopeNamespace);
919 xtw.WriteAttributeString ("xmlns", "xsi", null, XmlSchema.InstanceNamespace);
920 xtw.WriteAttributeString ("xmlns", "xsd", null, XmlSchema.Namespace);
922 if (bodyUse == SoapBindingUse.Encoded)
924 xtw.WriteAttributeString ("xmlns", "soapenc", null, SoapEncodingNamespace);
925 xtw.WriteAttributeString ("xmlns", "tns", null, msg.Message.Namespace);
929 foreach (object ob in msgbin.Extensions)
931 SoapHeaderBinding hb = ob as SoapHeaderBinding;
932 if (hb == null) continue;
934 xtw.WriteStartElement ("soap", "Header", SoapEnvelopeNamespace);
935 WriteHeader (xtw, hb);
936 xtw.WriteEndElement ();
940 xtw.WriteStartElement ("soap", "Body", SoapEnvelopeNamespace);
942 currentUse = bodyUse;
943 WriteBody (xtw, oper, msg, sbb, style);
945 xtw.WriteEndElement ();
946 xtw.WriteEndElement ();
948 return sw.ToString ();
951 void WriteHeader (XmlTextWriter xtw, SoapHeaderBinding header)
953 Message msg = descriptions.GetMessage (header.Message);
954 if (msg == null) throw new InvalidOperationException ("Message " + header.Message + " not found");
955 MessagePart part = msg.Parts [header.Part];
956 if (part == null) throw new InvalidOperationException ("Message part " + header.Part + " not found in message " + header.Message);
958 currentUse = header.Use;
960 if (currentUse == SoapBindingUse.Literal)
961 WriteRootElementSample (xtw, part.Element);
963 WriteTypeSample (xtw, part.Type);
966 void WriteBody (XmlTextWriter xtw, Operation oper, OperationMessage opm, SoapBodyBinding sbb, SoapBindingStyle style)
968 Message msg = descriptions.GetMessage (opm.Message);
969 if (msg.Parts.Count > 0 && msg.Parts[0].Name == "parameters")
971 MessagePart part = msg.Parts[0];
972 if (part.Element == XmlQualifiedName.Empty)
973 WriteTypeSample (xtw, part.Type);
975 WriteRootElementSample (xtw, part.Element);
979 string elemName = oper.Name;
981 if (opm is OperationOutput) elemName += "Response";
983 if (style == SoapBindingStyle.Rpc) {
984 xtw.WriteStartElement (elemName, sbb.Namespace);
988 foreach (MessagePart part in msg.Parts)
990 if (part.Element == XmlQualifiedName.Empty)
992 XmlSchemaElement elem = new XmlSchemaElement ();
993 elem.SchemaTypeName = part.Type;
994 elem.Name = part.Name;
995 WriteElementSample (xtw, ns, elem);
998 WriteRootElementSample (xtw, part.Element);
1001 if (style == SoapBindingStyle.Rpc)
1002 xtw.WriteEndElement ();
1004 WriteQueuedTypeSamples (xtw);
1007 void WriteRootElementSample (XmlTextWriter xtw, XmlQualifiedName qname)
1009 XmlSchemaElement elem = (XmlSchemaElement) schemas.Find (qname, typeof(XmlSchemaElement));
1010 if (elem == null) throw new InvalidOperationException ("Element not found: " + qname);
1011 WriteElementSample (xtw, qname.Namespace, elem);
1014 void WriteElementSample (XmlTextWriter xtw, string ns, XmlSchemaElement elem)
1016 bool sharedAnnType = false;
1017 XmlQualifiedName root;
1019 if (!elem.RefName.IsEmpty) {
1020 XmlSchemaElement refElem = FindRefElement (elem);
1021 if (refElem == null) throw new InvalidOperationException ("Global element not found: " + elem.RefName);
1022 root = elem.RefName;
1024 sharedAnnType = true;
1027 root = new XmlQualifiedName (elem.Name, ns);
1029 if (!elem.SchemaTypeName.IsEmpty)
1031 XmlSchemaComplexType st = FindComplexTyype (elem.SchemaTypeName);
1033 WriteComplexTypeSample (xtw, st, root);
1036 xtw.WriteStartElement (root.Name, root.Namespace);
1037 if (currentUse == SoapBindingUse.Encoded)
1038 xtw.WriteAttributeString ("type", XmlSchema.InstanceNamespace, GetQualifiedNameString (xtw, elem.SchemaTypeName));
1039 xtw.WriteString (GetLiteral (FindBuiltInType (elem.SchemaTypeName)));
1040 xtw.WriteEndElement ();
1043 else if (elem.SchemaType == null)
1045 xtw.WriteStartElement ("any");
1046 xtw.WriteEndElement ();
1049 WriteComplexTypeSample (xtw, (XmlSchemaComplexType) elem.SchemaType, root);
1052 void WriteTypeSample (XmlTextWriter xtw, XmlQualifiedName qname)
1054 XmlSchemaComplexType ctype = FindComplexTyype (qname);
1055 if (ctype != null) {
1056 WriteComplexTypeSample (xtw, ctype, qname);
1060 XmlSchemaSimpleType stype = (XmlSchemaSimpleType) schemas.Find (qname, typeof(XmlSchemaSimpleType));
1061 if (stype != null) {
1062 WriteSimpleTypeSample (xtw, stype);
1066 xtw.WriteString (GetLiteral (FindBuiltInType (qname)));
1067 throw new InvalidOperationException ("Type not found: " + qname);
1070 void WriteComplexTypeSample (XmlTextWriter xtw, XmlSchemaComplexType stype, XmlQualifiedName rootName)
1072 WriteComplexTypeSample (xtw, stype, rootName, -1);
1075 void WriteComplexTypeSample (XmlTextWriter xtw, XmlSchemaComplexType stype, XmlQualifiedName rootName, int id)
1077 string ns = rootName.Namespace;
1079 if (rootName.Name.IndexOf ("[]") != -1) rootName = arrayType;
1081 if (currentUse == SoapBindingUse.Encoded) {
1082 string pref = xtw.LookupPrefix (rootName.Namespace);
1083 if (pref == null) pref = "q1";
1084 xtw.WriteStartElement (pref, rootName.Name, rootName.Namespace);
1088 xtw.WriteStartElement (rootName.Name, rootName.Namespace);
1092 xtw.WriteAttributeString ("id", "id" + id);
1093 if (rootName != arrayType)
1094 xtw.WriteAttributeString ("type", XmlSchema.InstanceNamespace, GetQualifiedNameString (xtw, rootName));
1097 WriteComplexTypeAttributes (xtw, stype);
1098 WriteComplexTypeElements (xtw, ns, stype);
1100 xtw.WriteEndElement ();
1103 void WriteComplexTypeAttributes (XmlTextWriter xtw, XmlSchemaComplexType stype)
1105 WriteAttributes (xtw, stype.Attributes, stype.AnyAttribute);
1108 void WriteComplexTypeElements (XmlTextWriter xtw, string ns, XmlSchemaComplexType stype)
1110 if (stype.Particle != null)
1111 WriteParticleComplexContent (xtw, ns, stype.Particle);
1114 if (stype.ContentModel is XmlSchemaSimpleContent)
1115 WriteSimpleContent (xtw, (XmlSchemaSimpleContent)stype.ContentModel);
1116 else if (stype.ContentModel is XmlSchemaComplexContent)
1117 WriteComplexContent (xtw, ns, (XmlSchemaComplexContent)stype.ContentModel);
1121 void WriteAttributes (XmlTextWriter xtw, XmlSchemaObjectCollection atts, XmlSchemaAnyAttribute anyat)
1123 foreach (XmlSchemaObject at in atts)
1125 if (at is XmlSchemaAttribute)
1128 XmlSchemaAttribute attr = (XmlSchemaAttribute)at;
1129 XmlSchemaAttribute refAttr = attr;
1131 // refAttr.Form; TODO
1133 if (!attr.RefName.IsEmpty) {
1134 refAttr = FindRefAttribute (attr.RefName);
1135 if (refAttr == null) throw new InvalidOperationException ("Global attribute not found: " + attr.RefName);
1139 if (!refAttr.SchemaTypeName.IsEmpty) val = FindBuiltInType (refAttr.SchemaTypeName);
1140 else val = FindBuiltInType ((XmlSchemaSimpleType) refAttr.SchemaType);
1142 xtw.WriteAttributeString (refAttr.Name, val);
1144 else if (at is XmlSchemaAttributeGroupRef)
1146 XmlSchemaAttributeGroupRef gref = (XmlSchemaAttributeGroupRef)at;
1147 XmlSchemaAttributeGroup grp = (XmlSchemaAttributeGroup) schemas.Find (gref.RefName, typeof(XmlSchemaAttributeGroup));
1148 WriteAttributes (xtw, grp.Attributes, grp.AnyAttribute);
1153 xtw.WriteAttributeString ("custom-attribute","value");
1156 void WriteParticleComplexContent (XmlTextWriter xtw, string ns, XmlSchemaParticle particle)
1158 WriteParticleContent (xtw, ns, particle, false);
1161 void WriteParticleContent (XmlTextWriter xtw, string ns, XmlSchemaParticle particle, bool multiValue)
1163 if (particle is XmlSchemaGroupRef)
1164 particle = GetRefGroupParticle ((XmlSchemaGroupRef)particle);
1166 if (particle.MaxOccurs > 1) multiValue = true;
1168 if (particle is XmlSchemaSequence) {
1169 WriteSequenceContent (xtw, ns, ((XmlSchemaSequence)particle).Items, multiValue);
1171 else if (particle is XmlSchemaChoice) {
1172 if (((XmlSchemaChoice)particle).Items.Count == 1)
1173 WriteSequenceContent (xtw, ns, ((XmlSchemaChoice)particle).Items, multiValue);
1175 WriteChoiceContent (xtw, ns, (XmlSchemaChoice)particle, multiValue);
1177 else if (particle is XmlSchemaAll) {
1178 WriteSequenceContent (xtw, ns, ((XmlSchemaAll)particle).Items, multiValue);
1182 void WriteSequenceContent (XmlTextWriter xtw, string ns, XmlSchemaObjectCollection items, bool multiValue)
1184 foreach (XmlSchemaObject item in items)
1185 WriteContentItem (xtw, ns, item, multiValue);
1188 void WriteContentItem (XmlTextWriter xtw, string ns, XmlSchemaObject item, bool multiValue)
1190 if (item is XmlSchemaGroupRef)
1191 item = GetRefGroupParticle ((XmlSchemaGroupRef)item);
1193 if (item is XmlSchemaElement)
1195 XmlSchemaElement elem = (XmlSchemaElement) item;
1196 XmlSchemaElement refElem;
1197 if (!elem.RefName.IsEmpty) refElem = FindRefElement (elem);
1198 else refElem = elem;
1200 int num = (elem.MaxOccurs == 1 && !multiValue) ? 1 : 2;
1201 for (int n=0; n<num; n++)
1203 if (currentUse == SoapBindingUse.Literal)
1204 WriteElementSample (xtw, ns, refElem);
1206 WriteRefTypeSample (xtw, ns, refElem);
1209 else if (item is XmlSchemaAny)
1211 xtw.WriteStartElement ("any"); xtw.WriteEndElement ();
1213 xtw.WriteStartElement ("any"); xtw.WriteEndElement ();
1216 else if (item is XmlSchemaParticle) {
1217 WriteParticleContent (xtw, ns, (XmlSchemaParticle)item, multiValue);
1221 void WriteChoiceContent (XmlTextWriter xtw, string ns, XmlSchemaChoice choice, bool multiValue)
1223 foreach (XmlSchemaObject item in choice.Items)
1224 WriteContentItem (xtw, ns, item, multiValue);
1227 void WriteSimpleContent (XmlTextWriter xtw, XmlSchemaSimpleContent content)
1229 XmlSchemaSimpleContentExtension ext = content.Content as XmlSchemaSimpleContentExtension;
1231 WriteAttributes (xtw, ext.Attributes, ext.AnyAttribute);
1233 XmlQualifiedName qname = GetContentBaseType (content.Content);
1234 xtw.WriteString (GetLiteral (FindBuiltInType (qname)));
1237 string FindBuiltInType (XmlQualifiedName qname)
1239 if (qname.Namespace == XmlSchema.Namespace)
1242 XmlSchemaComplexType ct = FindComplexTyype (qname);
1245 XmlSchemaSimpleContent sc = ct.ContentModel as XmlSchemaSimpleContent;
1246 if (sc == null) throw new InvalidOperationException ("Invalid schema");
1247 return FindBuiltInType (GetContentBaseType (sc.Content));
1250 XmlSchemaSimpleType st = (XmlSchemaSimpleType) schemas.Find (qname, typeof(XmlSchemaSimpleType));
1252 return FindBuiltInType (st);
1254 throw new InvalidOperationException ("Definition of type " + qname + " not found");
1257 string FindBuiltInType (XmlSchemaSimpleType st)
1259 if (st.Content is XmlSchemaSimpleTypeRestriction) {
1260 return FindBuiltInType (GetContentBaseType (st.Content));
1262 else if (st.Content is XmlSchemaSimpleTypeList) {
1263 string s = FindBuiltInType (GetContentBaseType (st.Content));
1264 return s + " " + s + " ...";
1266 else if (st.Content is XmlSchemaSimpleTypeUnion)
1268 // Check if all types of the union are equal. If not, then will use anyType.
1269 XmlSchemaSimpleTypeUnion uni = (XmlSchemaSimpleTypeUnion) st.Content;
1270 string utype = null;
1272 // Anonymous types are unique
1273 if (uni.BaseTypes.Count != 0 && uni.MemberTypes.Length != 0)
1276 foreach (XmlQualifiedName mt in uni.MemberTypes)
1278 string qn = FindBuiltInType (mt);
1279 if (utype != null && qn != utype) return "string";
1289 XmlQualifiedName GetContentBaseType (XmlSchemaObject ob)
1291 if (ob is XmlSchemaSimpleContentExtension)
1292 return ((XmlSchemaSimpleContentExtension)ob).BaseTypeName;
1293 else if (ob is XmlSchemaSimpleContentRestriction)
1294 return ((XmlSchemaSimpleContentRestriction)ob).BaseTypeName;
1295 else if (ob is XmlSchemaSimpleTypeRestriction)
1296 return ((XmlSchemaSimpleTypeRestriction)ob).BaseTypeName;
1297 else if (ob is XmlSchemaSimpleTypeList)
1298 return ((XmlSchemaSimpleTypeList)ob).ItemTypeName;
1303 void WriteComplexContent (XmlTextWriter xtw, string ns, XmlSchemaComplexContent content)
1305 XmlQualifiedName qname;
1307 XmlSchemaComplexContentExtension ext = content.Content as XmlSchemaComplexContentExtension;
1308 if (ext != null) qname = ext.BaseTypeName;
1310 XmlSchemaComplexContentRestriction rest = (XmlSchemaComplexContentRestriction)content.Content;
1311 qname = rest.BaseTypeName;
1312 if (qname == arrayType) {
1313 ParseArrayType (rest, out qname);
1314 XmlSchemaElement elem = new XmlSchemaElement ();
1316 elem.SchemaTypeName = qname;
1318 xtw.WriteAttributeString ("arrayType", SoapEncodingNamespace, qname.Name + "[2]");
1319 WriteContentItem (xtw, ns, elem, true);
1324 // Add base map members to this map
1325 XmlSchemaComplexType ctype = FindComplexTyype (qname);
1326 WriteComplexTypeAttributes (xtw, ctype);
1329 // Add the members of this map
1330 WriteAttributes (xtw, ext.Attributes, ext.AnyAttribute);
1331 if (ext.Particle != null)
1332 WriteParticleComplexContent (xtw, ns, ext.Particle);
1335 WriteComplexTypeElements (xtw, ns, ctype);
1338 void ParseArrayType (XmlSchemaComplexContentRestriction rest, out XmlQualifiedName qtype)
1340 XmlSchemaAttribute arrayTypeAt = FindArrayAttribute (rest.Attributes);
1341 XmlAttribute[] uatts = arrayTypeAt.UnhandledAttributes;
1342 if (uatts == null || uatts.Length == 0) throw new InvalidOperationException ("arrayType attribute not specified in array declaration");
1344 XmlAttribute xat = null;
1345 foreach (XmlAttribute at in uatts)
1346 if (at.LocalName == "arrayType" && at.NamespaceURI == WsdlNamespace)
1347 { xat = at; break; }
1350 throw new InvalidOperationException ("arrayType attribute not specified in array declaration");
1352 string arrayType = xat.Value;
1354 int i = arrayType.LastIndexOf (":");
1355 if (i == -1) ns = "";
1356 else ns = arrayType.Substring (0,i);
1358 int j = arrayType.IndexOf ("[", i+1);
1359 if (j == -1) throw new InvalidOperationException ("Cannot parse WSDL array type: " + arrayType);
1360 type = arrayType.Substring (i+1);
1361 type = type.Substring (0, type.Length-2);
1363 qtype = new XmlQualifiedName (type, ns);
1366 XmlSchemaAttribute FindArrayAttribute (XmlSchemaObjectCollection atts)
1368 foreach (object ob in atts)
1370 XmlSchemaAttribute att = ob as XmlSchemaAttribute;
1371 if (att != null && att.RefName == arrayTypeRefName) return att;
1373 XmlSchemaAttributeGroupRef gref = ob as XmlSchemaAttributeGroupRef;
1376 XmlSchemaAttributeGroup grp = (XmlSchemaAttributeGroup) schemas.Find (gref.RefName, typeof(XmlSchemaAttributeGroup));
1377 att = FindArrayAttribute (grp.Attributes);
1378 if (att != null) return att;
1384 void WriteSimpleTypeSample (XmlTextWriter xtw, XmlSchemaSimpleType stype)
1386 xtw.WriteString (GetLiteral (FindBuiltInType (stype)));
1389 XmlSchemaParticle GetRefGroupParticle (XmlSchemaGroupRef refGroup)
1391 XmlSchemaGroup grp = (XmlSchemaGroup) schemas.Find (refGroup.RefName, typeof (XmlSchemaGroup));
1392 return grp.Particle;
1395 XmlSchemaElement FindRefElement (XmlSchemaElement elem)
1397 if (elem.RefName.Namespace == XmlSchema.Namespace)
1399 if (anyElement != null) return anyElement;
1400 anyElement = new XmlSchemaElement ();
1401 anyElement.Name = "any";
1402 anyElement.SchemaTypeName = anyType;
1405 return (XmlSchemaElement) schemas.Find (elem.RefName, typeof(XmlSchemaElement));
1408 XmlSchemaAttribute FindRefAttribute (XmlQualifiedName refName)
1410 if (refName.Namespace == XmlSchema.Namespace)
1412 XmlSchemaAttribute at = new XmlSchemaAttribute ();
1413 at.Name = refName.Name;
1414 at.SchemaTypeName = new XmlQualifiedName ("string",XmlSchema.Namespace);
1417 return (XmlSchemaAttribute) schemas.Find (refName, typeof(XmlSchemaAttribute));
1420 void WriteRefTypeSample (XmlTextWriter xtw, string ns, XmlSchemaElement elem)
1422 if (elem.SchemaTypeName.Namespace == XmlSchema.Namespace || schemas.Find (elem.SchemaTypeName, typeof(XmlSchemaSimpleType)) != null)
1423 WriteElementSample (xtw, ns, elem);
1426 xtw.WriteStartElement (elem.Name, ns);
1427 xtw.WriteAttributeString ("href", "#id" + (queue.Count+1));
1428 xtw.WriteEndElement ();
1429 queue.Add (new EncodedType (ns, elem));
1433 void WriteQueuedTypeSamples (XmlTextWriter xtw)
1435 for (int n=0; n<queue.Count; n++)
1437 EncodedType ec = (EncodedType) queue[n];
1438 XmlSchemaComplexType st = FindComplexTyype (ec.Element.SchemaTypeName);
1439 WriteComplexTypeSample (xtw, st, ec.Element.SchemaTypeName, n+1);
1443 XmlSchemaComplexType FindComplexTyype (XmlQualifiedName qname)
1445 if (qname.Name.IndexOf ("[]") != -1)
1447 XmlSchemaComplexType stype = new XmlSchemaComplexType ();
1448 stype.ContentModel = new XmlSchemaComplexContent ();
1450 XmlSchemaComplexContentRestriction res = new XmlSchemaComplexContentRestriction ();
1451 stype.ContentModel.Content = res;
1452 res.BaseTypeName = arrayType;
1454 XmlSchemaAttribute att = new XmlSchemaAttribute ();
1455 att.RefName = arrayTypeRefName;
1456 res.Attributes.Add (att);
1458 XmlAttribute xat = document.CreateAttribute ("arrayType", WsdlNamespace);
1459 xat.Value = qname.Namespace + ":" + qname.Name;
1460 att.UnhandledAttributes = new XmlAttribute[] {xat};
1464 return (XmlSchemaComplexType) schemas.Find (qname, typeof(XmlSchemaComplexType));
1467 string GetQualifiedNameString (XmlTextWriter xtw, XmlQualifiedName qname)
1469 string pref = xtw.LookupPrefix (qname.Namespace);
1470 if (pref != null) return pref + ":" + qname.Name;
1472 xtw.WriteAttributeString ("xmlns", "q1", null, qname.Namespace);
1473 return "q1:" + qname.Name;
1476 protected virtual string GetLiteral (string s)
1481 void GetOperationFormat (OperationBinding obin, out SoapBindingStyle style, out SoapBindingUse use)
1483 style = SoapBindingStyle.Document;
1484 use = SoapBindingUse.Literal;
1485 SoapOperationBinding sob = obin.Extensions.Find (typeof(SoapOperationBinding)) as SoapOperationBinding;
1488 SoapBodyBinding sbb = obin.Input.Extensions.Find (typeof(SoapBodyBinding)) as SoapBodyBinding;
1502 <link rel="alternate" type="text/xml" href="<%=Request.FilePath%>?disco"/>
1504 <title><%=WebServiceName%> Web Service</title>
1505 <style type="text/css">
1506 BODY { font-family: Arial; margin-left: 20px; margin-top: 20px; font-size: x-small}
1507 TABLE { font-size: x-small }
1508 .title { color:dimgray; font-family: Arial; font-size:20pt; font-weight:900}
1509 .operationTitle { color:dimgray; font-family: Arial; font-size:15pt; font-weight:900}
1510 .method { font-size: x-small }
1511 .bindingLabel { font-size: x-small; font-weight:bold; color:darkgray; line-height:8pt; display:block; margin-bottom:3px }
1512 .label { font-size: small; font-weight:bold; color:darkgray }
1513 .paramTable { font-size: x-small }
1514 .paramTable TR { background-color: gainsboro }
1515 .paramFormTable { font-size: x-small; padding: 10px; background-color: gainsboro }
1516 .paramFormTable TR { background-color: gainsboro }
1517 .paramInput { border: solid 1px gray }
1518 .button {border: solid 1px gray }
1519 .smallSeparator { height:3px; overflow:hidden }
1520 .panel { background-color:whitesmoke; border: solid 1px silver; border-top: solid 1px silver }
1521 .codePanel { background-color: white; font-size:x-small; padding:7px; border:solid 1px silver}
1522 .code-xml { font-size:10pt; font-family:courier }
1523 .code-cs { font-size:10pt; font-family:courier }
1524 .code-vb { font-size:10pt; font-family:courier }
1525 .tabLabelOn { font-weight:bold }
1526 .tabLabelOff {color: darkgray }
1527 .literal-placeholder {color: darkblue; font-weight:bold}
1528 A:link { color: black; }
1529 A:visited { color: black; }
1530 A:active { color: black; }
1531 A:hover { color: blue }
1535 function clearForm ()
1537 document.getElementById("testFormResult").style.display="none";
1544 <div class="title" style="margin-left:20px">
1545 <span class="label">Web Service</span><br>
1550 **********************************************************
1554 <table border="0" width="100%" cellpadding="15px" cellspacing="15px">
1555 <tr valign="top"><td width="150px" class="panel">
1556 <div style="width:150px"></div>
1557 <a class="method" href='<%=PageName%>'>Overview</a><br>
1558 <div class="smallSeparator"></div>
1559 <a class="method" href='<%=PageName + "?" + GetPageContext("wsdl")%>'>Service Description</a>
1560 <div class="smallSeparator"></div>
1561 <a class="method" href='<%=PageName + "?" + GetPageContext("proxy")%>'>Client proxy</a>
1563 <asp:repeater id="BindingsRepeater" runat=server>
1564 <itemtemplate name="itemtemplate">
1565 <span class="bindingLabel"><%#FormatBindingName(DataBinder.Eval(Container.DataItem, "Name").ToString())%></span>
1566 <asp:repeater id="OperationsRepeater" runat=server datasource='<%# ((Binding)Container.DataItem).Operations %>'>
1568 <a class="method" href="<%#PageName%>?<%#GetTabContext("op",null)%>op=<%#GetOpName(Container.DataItem)%>&bnd=<%#DataBinder.Eval(Container.DataItem, "Binding.Name")%>"><%#GetOpName(Container.DataItem)%></a>
1569 <div class="smallSeparator"></div>
1576 </td><td class="panel">
1578 <% if (CurrentPage == "main") {%>
1581 **********************************************************
1582 Web service overview
1585 <p class="label">Web Service Overview</p>
1586 <%#WebServiceDescription%>
1588 <%} if (CurrentPage == "op") {%>
1591 **********************************************************
1592 Operation description
1595 <span class="operationTitle"><%#CurrentOperationName%></span>
1600 <% if (CurrentTab == "main") { %>
1601 <span class="label">Input Parameters</span>
1602 <div class="smallSeparator"></div>
1603 <% if (InParams.Count == 0) { %>
1604 No input parameters<br>
1606 <table class="paramTable" cellspacing="1" cellpadding="5">
1607 <asp:repeater id="InputParamsRepeater" runat=server>
1610 <td width="150"><%#DataBinder.Eval(Container.DataItem, "Name")%></td>
1611 <td width="150"><%#DataBinder.Eval(Container.DataItem, "Type")%></td>
1619 <% if (OutParams.Count > 0) { %>
1620 <span class="label">Output Parameters</span>
1621 <div class="smallSeparator"></div>
1622 <table class="paramTable" cellspacing="1" cellpadding="5">
1623 <asp:repeater id="OutputParamsRepeater" runat=server>
1626 <td width="150"><%#DataBinder.Eval(Container.DataItem, "Name")%></td>
1627 <td width="150"><%#DataBinder.Eval(Container.DataItem, "Type")%></td>
1635 <span class="label">Remarks</span>
1636 <div class="smallSeparator"></div>
1637 <%#OperationDocumentation%>
1639 <span class="label">Technical information</span>
1640 <div class="smallSeparator"></div>
1641 Format: <%#CurrentOperationFormat%>
1642 <br>Supported protocols: <%#CurrentOperationProtocols%>
1646 **********************************************************
1647 Operation description - Test form
1650 <% if (CurrentTab == "test") {
1651 if (CurrentOperationSupportsTest) {%>
1652 Enter values for the parameters and click the 'Invoke' button to test this method:<br><br>
1653 <form action="<%#PageName%>" method="GET">
1654 <input type="hidden" name="page" value="<%#CurrentPage%>">
1655 <input type="hidden" name="tab" value="<%#CurrentTab%>">
1656 <input type="hidden" name="op" value="<%#CurrentOperationName%>">
1657 <input type="hidden" name="bnd" value="<%#CurrentOperationBinding%>">
1658 <input type="hidden" name="ext" value="testform">
1659 <table class="paramFormTable" cellspacing="0" cellpadding="3">
1660 <asp:repeater id="InputFormParamsRepeater" runat=server>
1663 <td><%#DataBinder.Eval(Container.DataItem, "Name")%>: </td>
1664 <td width="150"><input class="paramInput" type="text" size="20" name="<%#DataBinder.Eval(Container.DataItem, "Name")%>"></td>
1668 <tr><td></td><td><input class="button" type="submit" value="Invoke"> <input class="button" type="button" onclick="clearForm()" value="Clear"></td></tr>
1671 <div id="testFormResult" style="display:<%# (HasFormResult?"block":"none") %>">
1672 The web service returned the following result:<br/><br/>
1673 <div class="codePanel"><%#GetTestResult()%></div>
1676 The test form is not available for this operation because it has parameters with a complex structure.
1681 **********************************************************
1682 Operation description - Message Layout
1685 <% if (CurrentTab == "msg") { %>
1687 The following are sample SOAP requests and responses for each protocol supported by this method:
1690 <% if (IsOperationSupported ("Soap")) { %>
1691 <span class="label">Soap</span>
1693 <div class="codePanel"><div class="code-xml"><%#GenerateOperationMessages ("Soap", true)%></div></div>
1695 <div class="codePanel"><div class="code-xml"><%#GenerateOperationMessages ("Soap", false)%></div></div>
1698 <% if (IsOperationSupported ("HttpGet")) { %>
1699 <span class="label">HTTP Get</span>
1701 <div class="codePanel"><div class="code-xml"><%#GenerateOperationMessages ("HttpGet", true)%></div></div>
1703 <div class="codePanel"><div class="code-xml"><%#GenerateOperationMessages ("HttpGet", false)%></div></div>
1706 <% if (IsOperationSupported ("HttpPost")) { %>
1707 <span class="label">HTTP Post</span>
1709 <div class="codePanel"><div class="code-xml"><%#GenerateOperationMessages ("HttpPost", true)%></div></div>
1711 <div class="codePanel"><div class="code-xml"><%#GenerateOperationMessages ("HttpPost", false)%></div></div>
1718 <% if (CurrentPage == "proxy") {%>
1720 **********************************************************
1723 <form action="<%#PageName%>" name="langForm" method="GET">
1724 Select the language for which you want to generate a proxy
1725 <input type="hidden" name="page" value="<%#CurrentPage%>">
1726 <SELECT name="lang" onchange="langForm.submit()">
1727 <%#GetOptionSel("cs",CurrentLanguage)%>C#</option>
1728 <%#GetOptionSel("vb",CurrentLanguage)%>Visual Basic</option>
1733 <span class="label"><%#CurrentProxytName%></span>
1734 <a href="<%#PageName + "?code=" + CurrentLanguage%>">Download</a>
1736 <div class="codePanel">
1737 <div class="code-<%#CurrentLanguage%>"><%#GetProxyCode ()%></div>
1741 <% if (CurrentPage == "wsdl") {%>
1743 **********************************************************
1746 <% if (descriptions.Count > 1 || schemas.Count > 1) {%>
1747 The description of this web service is composed by several documents. Click on the document you want to see:
1751 for (int n=0; n<descriptions.Count; n++)
1752 Response.Write ("<li><a href='" + PageName + "?" + GetPageContext(null) + "doctype=wsdl&docind=" + n + "'>WSDL document " + descriptions[n].TargetNamespace + "</a></li>");
1753 for (int n=0; n<schemas.Count; n++)
1754 Response.Write ("<li><a href='" + PageName + "?" + GetPageContext(null) + "doctype=schema&docind=" + n + "'>Xml Schema " + schemas[n].TargetNamespace + "</a></li>");
1761 <span class="label"><%#CurrentDocumentName%></span>
1762 <a href="<%=PageName + "?" + CurrentDocType + "=" + CurrentDocInd %>">Download</a>
1764 <div class="codePanel">
1765 <div class="code-xml"><%#GenerateDocument ()%></div>
1770 <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
1772 <td withd="20px"></td>