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 if (desc.Bindings.Count == 0)
67 DefaultBinding = desc.Bindings[0].Name;
68 WebServiceDescription = service.Documentation;
69 ServiceProtocols = FindServiceProtocols (null);
71 CurrentOperationName = Request.QueryString["op"];
72 CurrentOperationBinding = Request.QueryString["bnd"];
73 if (CurrentOperationName != null) BuildOperationInfo ();
75 PageName = HttpUtility.UrlEncode (Path.GetFileName(Request.Path), Encoding.UTF8);
77 ArrayList list = new ArrayList ();
78 foreach (ServiceDescription sd in descriptions) {
79 foreach (Binding bin in sd.Bindings)
80 if (bin.Extensions.Find (typeof(SoapBinding)) != null) list.Add (bin);
83 BindingsRepeater.DataSource = list;
87 void BuildOperationInfo ()
89 InParams = new ArrayList ();
90 OutParams = new ArrayList ();
92 Port port = FindPort (CurrentOperationBinding, null);
93 Binding binding = descriptions.GetBinding (port.Binding);
95 PortType portType = descriptions.GetPortType (binding.Type);
96 Operation oper = FindOperation (portType, CurrentOperationName);
98 OperationDocumentation = oper.Documentation;
99 if (OperationDocumentation == null || OperationDocumentation == "")
100 OperationDocumentation = "No additional remarks";
102 foreach (OperationMessage opm in oper.Messages)
104 if (opm is OperationInput)
105 BuildParameters (InParams, opm);
106 else if (opm is OperationOutput)
107 BuildParameters (OutParams, opm);
110 // Protocols supported by the operation
111 CurrentOperationProtocols = "";
112 ArrayList prots = FindServiceProtocols (CurrentOperationName);
113 for (int n=0; n<prots.Count; n++) {
114 if (n != 0) CurrentOperationProtocols += ", ";
115 CurrentOperationProtocols += (string) prots[n];
118 CurrentOperationSupportsTest = prots.Contains ("HttpGet") || prots.Contains ("HttpPost");
121 OperationBinding obin = FindOperation (binding, CurrentOperationName);
123 CurrentOperationFormat = GetOperationFormat (obin);
125 InputParamsRepeater.DataSource = InParams;
126 InputFormParamsRepeater.DataSource = InParams;
127 OutputParamsRepeater.DataSource = OutParams;
130 void BuildParameters (ArrayList list, OperationMessage opm)
132 Message msg = descriptions.GetMessage (opm.Message);
133 if (msg.Parts.Count > 0 && msg.Parts[0].Name == "parameters")
135 MessagePart part = msg.Parts[0];
136 XmlSchemaComplexType ctype;
137 if (part.Element == XmlQualifiedName.Empty)
139 ctype = (XmlSchemaComplexType) schemas.Find (part.Type, typeof(XmlSchemaComplexType));
143 XmlSchemaElement elem = (XmlSchemaElement) schemas.Find (part.Element, typeof(XmlSchemaElement));
144 ctype = (XmlSchemaComplexType) elem.SchemaType;
146 XmlSchemaSequence seq = ctype.Particle as XmlSchemaSequence;
147 if (seq == null) return;
149 foreach (XmlSchemaObject ob in seq.Items)
151 Parameter p = new Parameter();
152 p.Description = "No additional remarks";
154 if (ob is XmlSchemaElement)
156 XmlSchemaElement selem = GetRefElement ((XmlSchemaElement)ob);
158 p.Type = selem.SchemaTypeName.Name;
170 foreach (MessagePart part in msg.Parts)
172 Parameter p = new Parameter ();
173 p.Description = "No additional remarks";
175 if (part.Element == XmlQualifiedName.Empty)
176 p.Type = part.Type.Name;
179 XmlSchemaElement elem = (XmlSchemaElement) schemas.Find (part.Element, typeof(XmlSchemaElement));
180 p.Type = elem.SchemaTypeName.Name;
187 string GetOperationFormat (OperationBinding obin)
190 SoapOperationBinding sob = obin.Extensions.Find (typeof(SoapOperationBinding)) as SoapOperationBinding;
192 format = sob.Style.ToString ();
193 SoapBodyBinding sbb = obin.Input.Extensions.Find (typeof(SoapBodyBinding)) as SoapBodyBinding;
195 format += " / " + sbb.Use;
200 XmlSchemaElement GetRefElement (XmlSchemaElement elem)
202 if (!elem.RefName.IsEmpty)
203 return (XmlSchemaElement) schemas.Find (elem.RefName, typeof(XmlSchemaElement));
208 ArrayList FindServiceProtocols(string operName)
210 ArrayList table = new ArrayList ();
211 Service service = descriptions[0].Services[0];
212 foreach (Port port in service.Ports)
215 Binding bin = descriptions.GetBinding (port.Binding);
216 if (bin.Extensions.Find (typeof(SoapBinding)) != null)
220 HttpBinding hb = (HttpBinding) bin.Extensions.Find (typeof(HttpBinding));
221 if (hb != null && hb.Verb == "POST") prot = "HttpPost";
222 else if (hb != null && hb.Verb == "GET") prot = "HttpGet";
225 if (prot != null && operName != null)
227 if (FindOperation (bin, operName) == null)
231 if (prot != null && !table.Contains (prot))
237 Port FindPort (string portName, string protocol)
239 Service service = descriptions[0].Services[0];
240 foreach (Port port in service.Ports)
242 if (portName == null)
244 Binding binding = descriptions.GetBinding (port.Binding);
245 if (GetProtocol (binding) == protocol) return port;
247 else if (port.Name == portName)
253 string GetProtocol (Binding binding)
255 if (binding.Extensions.Find (typeof(SoapBinding)) != null) return "Soap";
256 HttpBinding hb = (HttpBinding) binding.Extensions.Find (typeof(HttpBinding));
257 if (hb == null) return "";
258 if (hb.Verb == "POST") return "HttpPost";
259 if (hb.Verb == "GET") return "HttpGet";
264 Operation FindOperation (PortType portType, string name)
266 foreach (Operation oper in portType.Operations) {
267 if (oper.Messages.Input.Name != null) {
268 if (oper.Messages.Input.Name == name) return oper;
271 if (oper.Name == name) return oper;
277 OperationBinding FindOperation (Binding binding, string name)
279 foreach (OperationBinding oper in binding.Operations) {
280 if (oper.Input.Name != null) {
281 if (oper.Input.Name == name) return oper;
284 if (oper.Name == name) return oper;
290 string FormatBindingName (string name)
292 if (name == DefaultBinding) return "Methods";
293 else return "Methods for binding<br>" + name;
296 string GetOpName (object op)
298 OperationBinding ob = op as OperationBinding;
299 if (ob == null) return "";
300 if (ob.Input.Name != null) return ob.Input.Name;
306 get { return Request.QueryString ["ext"] == "testform"; }
309 string GetTestResult ()
311 if (!HasFormResult) return null;
315 for (int n=0; n<Request.QueryString.Count; n++)
318 if (qs != "") qs += "&";
319 qs += Request.QueryString.GetKey(n) + "=" + Server.UrlEncode (Request.QueryString [n]);
321 if (Request.QueryString.GetKey(n) == "ext") fill = true;
324 string location = null;
325 ServiceDescription desc = descriptions [0];
326 Service service = desc.Services[0];
327 foreach (Port port in service.Ports)
328 if (port.Name == CurrentOperationBinding)
330 SoapAddressBinding sbi = (SoapAddressBinding) port.Extensions.Find (typeof(SoapAddressBinding));
332 location = sbi.Location;
335 if (location == null)
336 return "Could not locate web service";
340 string url = location + "/" + HttpUtility.UrlEncode( CurrentOperationName );
341 Uri uri = new Uri (url);
342 WebRequest req = WebRequest.Create (url + ".invoke?" + qs);
343 HttpCookieCollection cookies = Request.Cookies;
344 int last = cookies.Count;
346 CookieContainer container = new CookieContainer ();
347 for (int i = 0; i < last; i++) {
348 HttpCookie hcookie = cookies [i];
349 Cookie cookie = new Cookie (hcookie.Name, hcookie.Value, hcookie.Path, hcookie.Domain);
350 container.Add (uri, cookie);
352 ((HttpWebRequest) req).CookieContainer = container;
354 WebResponse resp = req.GetResponse();
355 StreamReader sr = new StreamReader (resp.GetResponseStream());
356 string s = sr.ReadToEnd ();
358 return "<div class='code-xml'>" + ColorizeXml(WrapText(s,CodeTextColumns)) + "</div>";
362 string res = "<b style='color:red'>" + ex.Message + "<br/>" + ex.StackTrace.Replace("\n", "<br/>") + "</b>";
363 WebException wex = ex as WebException;
366 WebResponse resp = wex.Response;
368 StreamReader sr = new StreamReader (resp.GetResponseStream());
369 string s = sr.ReadToEnd ();
371 res += "<div class='code-xml'>" + ColorizeXml(WrapText(s,CodeTextColumns)) + "</div>";
378 string GenerateOperationMessages (string protocol, bool generateInput)
380 if (!IsOperationSupported (protocol)) return "";
383 if (protocol != "Soap") port = FindPort (null, protocol);
384 else port = FindPort (CurrentOperationBinding, null);
386 Binding binding = descriptions.GetBinding (port.Binding);
387 OperationBinding obin = FindOperation (binding, CurrentOperationName);
388 PortType portType = descriptions.GetPortType (binding.Type);
389 Operation oper = FindOperation (portType, CurrentOperationName);
391 HtmlSampleGenerator sg = new HtmlSampleGenerator (descriptions, schemas);
392 string txt = sg.GenerateMessage (port, obin, oper, protocol, generateInput);
393 if (protocol == "Soap") txt = WrapText (txt,CodeTextColumns);
394 txt = ColorizeXml (txt);
395 txt = txt.Replace ("@placeholder!","<span class='literal-placeholder'>");
396 txt = txt.Replace ("!placeholder@","</span>");
400 bool IsOperationSupported (string protocol)
402 if (CurrentPage != "op" || CurrentTab != "msg") return false;
403 if (protocol == "Soap") return true;
405 Port port = FindPort (null, protocol);
406 if (port == null) return false;
407 Binding binding = descriptions.GetBinding (port.Binding);
408 if (binding == null) return false;
409 return FindOperation (binding, CurrentOperationName) != null;
413 // Proxy code generation
416 string GetProxyCode ()
418 return "Proxy code generation is not yet supported.";
421 public string CurrentLanguage
424 string langId = Request.QueryString ["lang"];
425 if (langId == null || langId == "") langId = "cs";
430 public string CurrentProxytName
433 string lan = CurrentLanguage == "cs" ? "C#" : "Visual Basic";
434 return lan + " Client Proxy";
440 // Document generation
443 string GenerateDocument ()
445 StringWriter sw = new StringWriter ();
447 if (CurrentDocType == "wsdl")
448 descriptions [CurrentDocInd].Write (sw);
449 else if (CurrentDocType == "schema")
450 schemas [CurrentDocInd].Write (sw);
452 return Colorize (WrapText (sw.ToString (), CodeTextColumns), "xml");
455 public string CurrentDocType
457 get { return Request.QueryString ["doctype"] != null ? Request.QueryString ["doctype"] : "wsdl"; }
460 public int CurrentDocInd
462 get { return Request.QueryString ["docind"] != null ? int.Parse (Request.QueryString ["docind"]) : 0; }
465 public string CurrentDocumentName
468 if (CurrentDocType == "wsdl")
469 return "WSDL document for namespace \"" + descriptions [CurrentDocInd].TargetNamespace + "\"";
471 return "Xml Schema for namespace \"" + schemas [CurrentDocInd].TargetNamespace + "\"";
479 bool firstTab = true;
480 ArrayList disabledTabs = new ArrayList ();
484 get { return Request.QueryString["tab"] != null ? Request.QueryString["tab"] : "main" ; }
489 get { return Request.QueryString["page"] != null ? Request.QueryString["page"] : "main" ; }
494 if (CurrentOperationName != null)
496 WriteTab ("main","Overview");
497 WriteTab ("test","Test Form");
498 WriteTab ("msg","Message Layout");
502 void WriteTab (string id, string label)
504 if (!firstTab) Response.Write(" | ");
507 string cname = CurrentTab == id ? "tabLabelOn" : "tabLabelOff";
508 Response.Write ("<a href='" + PageName + "?" + GetPageContext(null) + GetDataContext() + "tab=" + id + "' style='text-decoration:none'>");
509 Response.Write ("<span class='" + cname + "'>" + label + "</span>");
510 Response.Write ("</a>");
513 string GetTabContext (string pag, string tab)
515 if (tab == null) tab = CurrentTab;
516 if (pag == null) pag = CurrentPage;
517 if (pag != CurrentPage) tab = "main";
518 return "page=" + pag + "&tab=" + tab + "&";
521 string GetPageContext (string pag)
523 if (pag == null) pag = CurrentPage;
524 return "page=" + pag + "&";
537 static string keywords_cs =
538 "(\\babstract\\b|\\bevent\\b|\\bnew\\b|\\bstruct\\b|\\bas\\b|\\bexplicit\\b|\\bnull\\b|\\bswitch\\b|\\bbase\\b|\\bextern\\b|" +
539 "\\bobject\\b|\\bthis\\b|\\bbool\\b|\\bfalse\\b|\\boperator\\b|\\bthrow\\b|\\bbreak\\b|\\bfinally\\b|\\bout\\b|\\btrue\\b|" +
540 "\\bbyte\\b|\\bfixed\\b|\\boverride\\b|\\btry\\b|\\bcase\\b|\\bfloat\\b|\\bparams\\b|\\btypeof\\b|\\bcatch\\b|\\bfor\\b|" +
541 "\\bprivate\\b|\\buint\\b|\\bchar\\b|\\bforeach\\b|\\bprotected\\b|\\bulong\\b|\\bchecked\\b|\\bgoto\\b|\\bpublic\\b|" +
542 "\\bunchecked\\b|\\bclass\\b|\\bif\\b|\\breadonly\\b|\\bunsafe\\b|\\bconst\\b|\\bimplicit\\b|\\bref\\b|\\bushort\\b|" +
543 "\\bcontinue\\b|\\bin\\b|\\breturn\\b|\\busing\\b|\\bdecimal\\b|\\bint\\b|\\bsbyte\\b|\\bvirtual\\b|\\bdefault\\b|" +
544 "\\binterface\\b|\\bsealed\\b|\\bvolatile\\b|\\bdelegate\\b|\\binternal\\b|\\bshort\\b|\\bvoid\\b|\\bdo\\b|\\bis\\b|" +
545 "\\bsizeof\\b|\\bwhile\\b|\\bdouble\\b|\\block\\b|\\bstackalloc\\b|\\belse\\b|\\blong\\b|\\bstatic\\b|\\benum\\b|" +
546 "\\bnamespace\\b|\\bstring\\b)";
548 static string keywords_vb =
549 "(\\bAddHandler\\b|\\bAddressOf\\b|\\bAlias\\b|\\bAnd\\b|\\bAndAlso\\b|\\bAnsi\\b|\\bAs\\b|\\bAssembly\\b|" +
550 "\\bAuto\\b|\\bBoolean\\b|\\bByRef\\b|\\bByte\\b|\\bByVal\\b|\\bCall\\b|\\bCase\\b|\\bCatch\\b|" +
551 "\\bCBool\\b|\\bCByte\\b|\\bCChar\\b|\\bCDate\\b|\\bCDec\\b|\\bCDbl\\b|\\bChar\\b|\\bCInt\\b|" +
552 "\\bClass\\b|\\bCLng\\b|\\bCObj\\b|\\bConst\\b|\\bCShort\\b|\\bCSng\\b|\\bCStr\\b|\\bCType\\b|" +
553 "\\bDate\\b|\\bDecimal\\b|\\bDeclare\\b|\\bDefault\\b|\\bDelegate\\b|\\bDim\\b|\\bDirectCast\\b|\\bDo\\b|" +
554 "\\bDouble\\b|\\bEach\\b|\\bElse\\b|\\bElseIf\\b|\\bEnd\\b|\\bEnum\\b|\\bErase\\b|\\bError\\b|" +
555 "\\bEvent\\b|\\bExit\\b|\\bFalse\\b|\\bFinally\\b|\\bFor\\b|\\bFriend\\b|\\bFunction\\b|\\bGet\\b|" +
556 "\\bGetType\\b|\\bGoSub\\b|\\bGoTo\\b|\\bHandles\\b|\\bIf\\b|\\bImplements\\b|\\bImports\\b|\\bIn\\b|" +
557 "\\bInherits\\b|\\bInteger\\b|\\bInterface\\b|\\bIs\\b|\\bLet\\b|\\bLib\\b|\\bLike\\b|\\bLong\\b|" +
558 "\\bLoop\\b|\\bMe\\b|\\bMod\\b|\\bModule\\b|\\bMustInherit\\b|\\bMustOverride\\b|\\bMyBase\\b|\\bMyClass\\b|" +
559 "\\bNamespace\\b|\\bNew\\b|\\bNext\\b|\\bNot\\b|\\bNothing\\b|\\bNotInheritable\\b|\\bNotOverridable\\b|\\bObject\\b|" +
560 "\\bOn\\b|\\bOption\\b|\\bOptional\\b|\\bOr\\b|\\bOrElse\\b|\\bOverloads\\b|\\bOverridable\\b|\\bOverrides\\b|" +
561 "\\bParamArray\\b|\\bPreserve\\b|\\bPrivate\\b|\\bProperty\\b|\\bProtected\\b|\\bPublic\\b|\\bRaiseEvent\\b|\\bReadOnly\\b|" +
562 "\\bReDim\\b|\\bREM\\b|\\bRemoveHandler\\b|\\bResume\\b|\\bReturn\\b|\\bSelect\\b|\\bSet\\b|\\bShadows\\b|" +
563 "\\bShared\\b|\\bShort\\b|\\bSingle\\b|\\bStatic\\b|\\bStep\\b|\\bStop\\b|\\bString\\b|\\bStructure\\b|" +
564 "\\bSub\\b|\\bSyncLock\\b|\\bThen\\b|\\bThrow\\b|\\bTo\\b|\\bTrue\\b|\\bTry\\b|\\bTypeOf\\b|" +
565 "\\bUnicode\\b|\\bUntil\\b|\\bVariant\\b|\\bWhen\\b|\\bWhile\\b|\\bWith\\b|\\bWithEvents\\b|\\bWriteOnly\\b|\\bXor\\b)";
567 string Colorize (string text, string lang)
569 if (lang == "xml") return ColorizeXml (text);
570 else if (lang == "cs") return ColorizeCs (text);
571 else if (lang == "vb") return ColorizeVb (text);
575 string ColorizeXml (string text)
577 text = text.Replace (" ", " ");
578 Regex re = new Regex ("\r\n|\r|\n");
579 text = re.Replace (text, "_br_");
581 re = new Regex ("<\\s*(\\/?)\\s*([\\s\\S]*?)\\s*(\\/?)\\s*>");
582 text = re.Replace (text,"{blue:<$1}{maroon:$2}{blue:$3>}");
584 re = new Regex ("\\{(\\w*):([\\s\\S]*?)\\}");
585 text = re.Replace (text,"<span style='color:$1'>$2</span>");
587 re = new Regex ("\"(.*?)\"");
588 text = re.Replace (text,"\"<span style='color:purple'>$1</span>\"");
591 text = text.Replace ("\t", " ");
592 text = text.Replace ("_br_", "<br>");
596 string ColorizeCs (string text)
598 text = text.Replace (" ", " ");
600 text = text.Replace ("<", "<");
601 text = text.Replace (">", ">");
603 Regex re = new Regex ("\"((((?!\").)|\\\")*?)\"");
604 text = re.Replace (text,"<span style='color:purple'>\"$1\"</span>");
606 re = new Regex ("//(((.(?!\"</span>))|\"(((?!\").)*)\"</span>)*)(\r|\n|\r\n)");
607 text = re.Replace (text,"<span style='color:green'>//$1</span><br/>");
609 re = new Regex (keywords_cs);
610 text = re.Replace (text,"<span style='color:blue'>$1</span>");
612 text = text.Replace ("\t"," ");
613 text = text.Replace ("\n","<br/>");
618 string ColorizeVb (string text)
620 text = text.Replace (" ", " ");
622 /* Regex re = new Regex ("\"((((?!\").)|\\\")*?)\"");
623 text = re.Replace (text,"<span style='color:purple'>\"$1\"</span>");
625 re = new Regex ("'(((.(?!\"\\<\\/span\\>))|\"(((?!\").)*)\"\\<\\/span\\>)*)(\r|\n|\r\n)");
626 text = re.Replace (text,"<span style='color:green'>//$1</span><br/>");
628 re = new Regex (keywords_vb);
629 text = re.Replace (text,"<span style='color:blue'>$1</span>");
631 text = text.Replace ("\t"," ");
632 text = text.Replace ("\n","<br/>");
637 // Helper methods and classes
640 string GetDataContext ()
642 return "op=" + CurrentOperationName + "&bnd=" + CurrentOperationBinding + "&";
645 string GetOptionSel (string v1, string v2)
647 string op = "<option ";
648 if (v1 == v2) op += "selected ";
649 return op + "value='" + v1 + "'>";
652 string WrapText (string text, int maxChars)
654 text = text.Replace(" />","/>");
656 string linspace = null;
660 bool inquotes = false;
662 string sublineIndent = "";
663 System.Text.StringBuilder sb = new System.Text.StringBuilder ();
664 for (int n=0; n<text.Length; n++)
668 if (c=='\r' || c=='\n' || n==text.Length-1)
670 sb.Append (linspace + sublineIndent + text.Substring (linstart, n-linstart+1));
680 if (lastc==',' || lastc=='(')
682 if (!inquotes) breakpos = n;
685 if (lincount > maxChars && breakpos >= linstart)
687 if (linspace != null)
688 sb.Append (linspace + sublineIndent);
689 sb.Append (text.Substring (linstart, breakpos-linstart));
692 lincount = linspace.Length + sublineIndent.Length + (n-breakpos);
696 if (c==' ' || c=='\t')
703 inquotes = !inquotes;
706 if (linspace == null) {
707 linspace = text.Substring (linstart, n-linstart);
714 return sb.ToString ();
723 public string Name { get { return name; } set { name = value; } }
724 public string Type { get { return type; } set { type = value; } }
725 public string Description { get { return description; } set { description = value; } }
728 public class HtmlSampleGenerator: SampleGenerator
730 public HtmlSampleGenerator (ServiceDescriptionCollection services, XmlSchemas schemas)
731 : base (services, schemas)
735 protected override string GetLiteral (string s)
737 return "@placeholder!" + s + "!placeholder@";
742 public class SampleGenerator
744 protected ServiceDescriptionCollection descriptions;
745 protected XmlSchemas schemas;
746 XmlSchemaElement anyElement;
748 SoapBindingUse currentUse;
749 XmlDocument document = new XmlDocument ();
751 static readonly XmlQualifiedName anyType = new XmlQualifiedName ("anyType",XmlSchema.Namespace);
752 static readonly XmlQualifiedName arrayType = new XmlQualifiedName ("Array","http://schemas.xmlsoap.org/soap/encoding/");
753 static readonly XmlQualifiedName arrayTypeRefName = new XmlQualifiedName ("arrayType","http://schemas.xmlsoap.org/soap/encoding/");
754 const string SoapEnvelopeNamespace = "http://schemas.xmlsoap.org/soap/envelope/";
755 const string WsdlNamespace = "http://schemas.xmlsoap.org/wsdl/";
756 const string SoapEncodingNamespace = "http://schemas.xmlsoap.org/soap/encoding/";
760 public EncodedType (string ns, XmlSchemaElement elem) { Namespace = ns; Element = elem; }
761 public string Namespace;
762 public XmlSchemaElement Element;
765 public SampleGenerator (ServiceDescriptionCollection services, XmlSchemas schemas)
767 descriptions = services;
768 this.schemas = schemas;
769 queue = new ArrayList ();
772 public string GenerateMessage (Port port, OperationBinding obin, Operation oper, string protocol, bool generateInput)
774 OperationMessage msg = null;
775 foreach (OperationMessage opm in oper.Messages)
777 if (opm is OperationInput && generateInput) msg = opm;
778 else if (opm is OperationOutput && !generateInput) msg = opm;
780 if (msg == null) return null;
783 case "Soap": return GenerateHttpSoapMessage (port, obin, oper, msg);
784 case "HttpGet": return GenerateHttpGetMessage (port, obin, oper, msg);
785 case "HttpPost": return GenerateHttpPostMessage (port, obin, oper, msg);
787 return "Unknown protocol";
790 public string GenerateHttpSoapMessage (Port port, OperationBinding obin, Operation oper, OperationMessage msg)
794 if (msg is OperationInput)
796 SoapAddressBinding sab = port.Extensions.Find (typeof(SoapAddressBinding)) as SoapAddressBinding;
797 SoapOperationBinding sob = obin.Extensions.Find (typeof(SoapOperationBinding)) as SoapOperationBinding;
798 req += "POST " + new Uri (sab.Location).AbsolutePath + "\n";
799 req += "SOAPAction: " + sob.SoapAction + "\n";
800 req += "Content-Type: text/xml; charset=utf-8\n";
801 req += "Content-Length: " + GetLiteral ("string") + "\n";
802 req += "Host: " + GetLiteral ("string") + "\n\n";
806 req += "HTTP/1.0 200 OK\n";
807 req += "Content-Type: text/xml; charset=utf-8\n";
808 req += "Content-Length: " + GetLiteral ("string") + "\n\n";
811 req += GenerateSoapMessage (obin, oper, msg);
815 public string GenerateHttpGetMessage (Port port, OperationBinding obin, Operation oper, OperationMessage msg)
819 if (msg is OperationInput)
821 HttpAddressBinding sab = port.Extensions.Find (typeof(HttpAddressBinding)) as HttpAddressBinding;
822 HttpOperationBinding sob = obin.Extensions.Find (typeof(HttpOperationBinding)) as HttpOperationBinding;
823 string location = new Uri (sab.Location).AbsolutePath + sob.Location + "?" + BuildQueryString (msg);
824 req += "GET " + location + "\n";
825 req += "Host: " + GetLiteral ("string");
829 req += "HTTP/1.0 200 OK\n";
830 req += "Content-Type: text/xml; charset=utf-8\n";
831 req += "Content-Length: " + GetLiteral ("string") + "\n\n";
833 MimeXmlBinding mxb = (MimeXmlBinding) obin.Output.Extensions.Find (typeof(MimeXmlBinding)) as MimeXmlBinding;
834 if (mxb == null) return req;
836 Message message = descriptions.GetMessage (msg.Message);
837 XmlQualifiedName ename = null;
838 foreach (MessagePart part in message.Parts)
839 if (part.Name == mxb.Part) ename = part.Element;
841 if (ename == null) return req + GetLiteral("string");
843 StringWriter sw = new StringWriter ();
844 XmlTextWriter xtw = new XmlTextWriter (sw);
845 xtw.Formatting = Formatting.Indented;
846 currentUse = SoapBindingUse.Literal;
847 WriteRootElementSample (xtw, ename);
849 req += sw.ToString ();
855 public string GenerateHttpPostMessage (Port port, OperationBinding obin, Operation oper, OperationMessage msg)
859 if (msg is OperationInput)
861 HttpAddressBinding sab = port.Extensions.Find (typeof(HttpAddressBinding)) as HttpAddressBinding;
862 HttpOperationBinding sob = obin.Extensions.Find (typeof(HttpOperationBinding)) as HttpOperationBinding;
863 string location = new Uri (sab.Location).AbsolutePath + sob.Location;
864 req += "POST " + location + "\n";
865 req += "Content-Type: application/x-www-form-urlencoded\n";
866 req += "Content-Length: " + GetLiteral ("string") + "\n";
867 req += "Host: " + GetLiteral ("string") + "\n\n";
868 req += BuildQueryString (msg);
870 else return GenerateHttpGetMessage (port, obin, oper, msg);
875 string BuildQueryString (OperationMessage opm)
878 Message msg = descriptions.GetMessage (opm.Message);
879 foreach (MessagePart part in msg.Parts)
881 if (s.Length != 0) s += "&";
882 s += part.Name + "=" + GetLiteral (part.Type.Name);
887 public string GenerateSoapMessage (OperationBinding obin, Operation oper, OperationMessage msg)
889 SoapOperationBinding sob = obin.Extensions.Find (typeof(SoapOperationBinding)) as SoapOperationBinding;
890 SoapBindingStyle style = (sob != null) ? sob.Style : SoapBindingStyle.Document;
892 MessageBinding msgbin = (msg is OperationInput) ? (MessageBinding) obin.Input : (MessageBinding)obin.Output;
893 SoapBodyBinding sbb = msgbin.Extensions.Find (typeof(SoapBodyBinding)) as SoapBodyBinding;
894 SoapBindingUse bodyUse = (sbb != null) ? sbb.Use : SoapBindingUse.Literal;
896 StringWriter sw = new StringWriter ();
897 XmlTextWriter xtw = new XmlTextWriter (sw);
898 xtw.Formatting = Formatting.Indented;
900 xtw.WriteStartDocument ();
901 xtw.WriteStartElement ("soap", "Envelope", SoapEnvelopeNamespace);
902 xtw.WriteAttributeString ("xmlns", "xsi", null, XmlSchema.InstanceNamespace);
903 xtw.WriteAttributeString ("xmlns", "xsd", null, XmlSchema.Namespace);
905 if (bodyUse == SoapBindingUse.Encoded)
907 xtw.WriteAttributeString ("xmlns", "soapenc", null, SoapEncodingNamespace);
908 xtw.WriteAttributeString ("xmlns", "tns", null, msg.Message.Namespace);
913 bool writtenHeader = false;
914 foreach (object ob in msgbin.Extensions)
916 SoapHeaderBinding hb = ob as SoapHeaderBinding;
917 if (hb == null) continue;
919 if (!writtenHeader) {
920 xtw.WriteStartElement ("soap", "Header", SoapEnvelopeNamespace);
921 writtenHeader = true;
924 WriteHeader (xtw, hb);
928 xtw.WriteEndElement ();
931 xtw.WriteStartElement ("soap", "Body", SoapEnvelopeNamespace);
933 currentUse = bodyUse;
934 WriteBody (xtw, oper, msg, sbb, style);
936 xtw.WriteEndElement ();
937 xtw.WriteEndElement ();
939 return sw.ToString ();
942 void WriteHeader (XmlTextWriter xtw, SoapHeaderBinding header)
944 Message msg = descriptions.GetMessage (header.Message);
945 if (msg == null) throw new InvalidOperationException ("Message " + header.Message + " not found");
946 MessagePart part = msg.Parts [header.Part];
947 if (part == null) throw new InvalidOperationException ("Message part " + header.Part + " not found in message " + header.Message);
949 currentUse = header.Use;
951 if (currentUse == SoapBindingUse.Literal)
952 WriteRootElementSample (xtw, part.Element);
954 WriteTypeSample (xtw, part.Type);
957 void WriteBody (XmlTextWriter xtw, Operation oper, OperationMessage opm, SoapBodyBinding sbb, SoapBindingStyle style)
959 Message msg = descriptions.GetMessage (opm.Message);
960 if (msg.Parts.Count > 0 && msg.Parts[0].Name == "parameters")
962 MessagePart part = msg.Parts[0];
963 if (part.Element == XmlQualifiedName.Empty)
964 WriteTypeSample (xtw, part.Type);
966 WriteRootElementSample (xtw, part.Element);
970 string elemName = oper.Name;
972 if (opm is OperationOutput) elemName += "Response";
974 if (style == SoapBindingStyle.Rpc) {
975 xtw.WriteStartElement (elemName, sbb.Namespace);
979 foreach (MessagePart part in msg.Parts)
981 if (part.Element == XmlQualifiedName.Empty)
983 XmlSchemaElement elem = new XmlSchemaElement ();
984 elem.SchemaTypeName = part.Type;
985 elem.Name = part.Name;
986 WriteElementSample (xtw, ns, elem);
989 WriteRootElementSample (xtw, part.Element);
992 if (style == SoapBindingStyle.Rpc)
993 xtw.WriteEndElement ();
995 WriteQueuedTypeSamples (xtw);
998 void WriteRootElementSample (XmlTextWriter xtw, XmlQualifiedName qname)
1000 XmlSchemaElement elem = (XmlSchemaElement) schemas.Find (qname, typeof(XmlSchemaElement));
1001 if (elem == null) throw new InvalidOperationException ("Element not found: " + qname);
1002 WriteElementSample (xtw, qname.Namespace, elem);
1005 void WriteElementSample (XmlTextWriter xtw, string ns, XmlSchemaElement elem)
1007 bool sharedAnnType = false;
1008 XmlQualifiedName root;
1010 if (!elem.RefName.IsEmpty) {
1011 XmlSchemaElement refElem = FindRefElement (elem);
1012 if (refElem == null) throw new InvalidOperationException ("Global element not found: " + elem.RefName);
1013 root = elem.RefName;
1015 sharedAnnType = true;
1018 root = new XmlQualifiedName (elem.Name, ns);
1020 if (!elem.SchemaTypeName.IsEmpty)
1022 XmlSchemaComplexType st = FindComplexTyype (elem.SchemaTypeName);
1024 WriteComplexTypeSample (xtw, st, root);
1027 xtw.WriteStartElement (root.Name, root.Namespace);
1028 if (currentUse == SoapBindingUse.Encoded)
1029 xtw.WriteAttributeString ("type", XmlSchema.InstanceNamespace, GetQualifiedNameString (xtw, elem.SchemaTypeName));
1030 xtw.WriteString (GetLiteral (FindBuiltInType (elem.SchemaTypeName)));
1031 xtw.WriteEndElement ();
1034 else if (elem.SchemaType == null)
1036 xtw.WriteStartElement ("any");
1037 xtw.WriteEndElement ();
1040 WriteComplexTypeSample (xtw, (XmlSchemaComplexType) elem.SchemaType, root);
1043 void WriteTypeSample (XmlTextWriter xtw, XmlQualifiedName qname)
1045 XmlSchemaComplexType ctype = FindComplexTyype (qname);
1046 if (ctype != null) {
1047 WriteComplexTypeSample (xtw, ctype, qname);
1051 XmlSchemaSimpleType stype = (XmlSchemaSimpleType) schemas.Find (qname, typeof(XmlSchemaSimpleType));
1052 if (stype != null) {
1053 WriteSimpleTypeSample (xtw, stype);
1057 xtw.WriteString (GetLiteral (FindBuiltInType (qname)));
1058 throw new InvalidOperationException ("Type not found: " + qname);
1061 void WriteComplexTypeSample (XmlTextWriter xtw, XmlSchemaComplexType stype, XmlQualifiedName rootName)
1063 WriteComplexTypeSample (xtw, stype, rootName, -1);
1066 void WriteComplexTypeSample (XmlTextWriter xtw, XmlSchemaComplexType stype, XmlQualifiedName rootName, int id)
1068 string ns = rootName.Namespace;
1070 if (rootName.Name.IndexOf ("[]") != -1) rootName = arrayType;
1072 if (currentUse == SoapBindingUse.Encoded) {
1073 string pref = xtw.LookupPrefix (rootName.Namespace);
1074 if (pref == null) pref = "q1";
1075 xtw.WriteStartElement (pref, rootName.Name, rootName.Namespace);
1079 xtw.WriteStartElement (rootName.Name, rootName.Namespace);
1083 xtw.WriteAttributeString ("id", "id" + id);
1084 if (rootName != arrayType)
1085 xtw.WriteAttributeString ("type", XmlSchema.InstanceNamespace, GetQualifiedNameString (xtw, rootName));
1088 WriteComplexTypeAttributes (xtw, stype);
1089 WriteComplexTypeElements (xtw, ns, stype);
1091 xtw.WriteEndElement ();
1094 void WriteComplexTypeAttributes (XmlTextWriter xtw, XmlSchemaComplexType stype)
1096 WriteAttributes (xtw, stype.Attributes, stype.AnyAttribute);
1099 void WriteComplexTypeElements (XmlTextWriter xtw, string ns, XmlSchemaComplexType stype)
1101 if (stype.Particle != null)
1102 WriteParticleComplexContent (xtw, ns, stype.Particle);
1105 if (stype.ContentModel is XmlSchemaSimpleContent)
1106 WriteSimpleContent (xtw, (XmlSchemaSimpleContent)stype.ContentModel);
1107 else if (stype.ContentModel is XmlSchemaComplexContent)
1108 WriteComplexContent (xtw, ns, (XmlSchemaComplexContent)stype.ContentModel);
1112 void WriteAttributes (XmlTextWriter xtw, XmlSchemaObjectCollection atts, XmlSchemaAnyAttribute anyat)
1114 foreach (XmlSchemaObject at in atts)
1116 if (at is XmlSchemaAttribute)
1119 XmlSchemaAttribute attr = (XmlSchemaAttribute)at;
1120 XmlSchemaAttribute refAttr = attr;
1122 // refAttr.Form; TODO
1124 if (!attr.RefName.IsEmpty) {
1125 refAttr = FindRefAttribute (attr.RefName);
1126 if (refAttr == null) throw new InvalidOperationException ("Global attribute not found: " + attr.RefName);
1130 if (!refAttr.SchemaTypeName.IsEmpty) val = FindBuiltInType (refAttr.SchemaTypeName);
1131 else val = FindBuiltInType ((XmlSchemaSimpleType) refAttr.SchemaType);
1133 xtw.WriteAttributeString (refAttr.Name, val);
1135 else if (at is XmlSchemaAttributeGroupRef)
1137 XmlSchemaAttributeGroupRef gref = (XmlSchemaAttributeGroupRef)at;
1138 XmlSchemaAttributeGroup grp = (XmlSchemaAttributeGroup) schemas.Find (gref.RefName, typeof(XmlSchemaAttributeGroup));
1139 WriteAttributes (xtw, grp.Attributes, grp.AnyAttribute);
1144 xtw.WriteAttributeString ("custom-attribute","value");
1147 void WriteParticleComplexContent (XmlTextWriter xtw, string ns, XmlSchemaParticle particle)
1149 WriteParticleContent (xtw, ns, particle, false);
1152 void WriteParticleContent (XmlTextWriter xtw, string ns, XmlSchemaParticle particle, bool multiValue)
1154 if (particle is XmlSchemaGroupRef)
1155 particle = GetRefGroupParticle ((XmlSchemaGroupRef)particle);
1157 if (particle.MaxOccurs > 1) multiValue = true;
1159 if (particle is XmlSchemaSequence) {
1160 WriteSequenceContent (xtw, ns, ((XmlSchemaSequence)particle).Items, multiValue);
1162 else if (particle is XmlSchemaChoice) {
1163 if (((XmlSchemaChoice)particle).Items.Count == 1)
1164 WriteSequenceContent (xtw, ns, ((XmlSchemaChoice)particle).Items, multiValue);
1166 WriteChoiceContent (xtw, ns, (XmlSchemaChoice)particle, multiValue);
1168 else if (particle is XmlSchemaAll) {
1169 WriteSequenceContent (xtw, ns, ((XmlSchemaAll)particle).Items, multiValue);
1173 void WriteSequenceContent (XmlTextWriter xtw, string ns, XmlSchemaObjectCollection items, bool multiValue)
1175 foreach (XmlSchemaObject item in items)
1176 WriteContentItem (xtw, ns, item, multiValue);
1179 void WriteContentItem (XmlTextWriter xtw, string ns, XmlSchemaObject item, bool multiValue)
1181 if (item is XmlSchemaGroupRef)
1182 item = GetRefGroupParticle ((XmlSchemaGroupRef)item);
1184 if (item is XmlSchemaElement)
1186 XmlSchemaElement elem = (XmlSchemaElement) item;
1187 XmlSchemaElement refElem;
1188 if (!elem.RefName.IsEmpty) refElem = FindRefElement (elem);
1189 else refElem = elem;
1191 int num = (elem.MaxOccurs == 1 && !multiValue) ? 1 : 2;
1192 for (int n=0; n<num; n++)
1194 if (currentUse == SoapBindingUse.Literal)
1195 WriteElementSample (xtw, ns, refElem);
1197 WriteRefTypeSample (xtw, ns, refElem);
1200 else if (item is XmlSchemaAny)
1202 xtw.WriteString (GetLiteral ("xml"));
1204 else if (item is XmlSchemaParticle) {
1205 WriteParticleContent (xtw, ns, (XmlSchemaParticle)item, multiValue);
1209 void WriteChoiceContent (XmlTextWriter xtw, string ns, XmlSchemaChoice choice, bool multiValue)
1211 foreach (XmlSchemaObject item in choice.Items)
1212 WriteContentItem (xtw, ns, item, multiValue);
1215 void WriteSimpleContent (XmlTextWriter xtw, XmlSchemaSimpleContent content)
1217 XmlSchemaSimpleContentExtension ext = content.Content as XmlSchemaSimpleContentExtension;
1219 WriteAttributes (xtw, ext.Attributes, ext.AnyAttribute);
1221 XmlQualifiedName qname = GetContentBaseType (content.Content);
1222 xtw.WriteString (GetLiteral (FindBuiltInType (qname)));
1225 string FindBuiltInType (XmlQualifiedName qname)
1227 if (qname.Namespace == XmlSchema.Namespace)
1230 XmlSchemaComplexType ct = FindComplexTyype (qname);
1233 XmlSchemaSimpleContent sc = ct.ContentModel as XmlSchemaSimpleContent;
1234 if (sc == null) throw new InvalidOperationException ("Invalid schema");
1235 return FindBuiltInType (GetContentBaseType (sc.Content));
1238 XmlSchemaSimpleType st = (XmlSchemaSimpleType) schemas.Find (qname, typeof(XmlSchemaSimpleType));
1240 return FindBuiltInType (st);
1242 throw new InvalidOperationException ("Definition of type " + qname + " not found");
1245 string FindBuiltInType (XmlSchemaSimpleType st)
1247 if (st.Content is XmlSchemaSimpleTypeRestriction) {
1248 return FindBuiltInType (GetContentBaseType (st.Content));
1250 else if (st.Content is XmlSchemaSimpleTypeList) {
1251 string s = FindBuiltInType (GetContentBaseType (st.Content));
1252 return s + " " + s + " ...";
1254 else if (st.Content is XmlSchemaSimpleTypeUnion)
1256 //Check if all types of the union are equal. If not, then will use anyType.
1257 XmlSchemaSimpleTypeUnion uni = (XmlSchemaSimpleTypeUnion) st.Content;
1258 string utype = null;
1260 // Anonymous types are unique
1261 if (uni.BaseTypes.Count != 0 && uni.MemberTypes.Length != 0)
1264 foreach (XmlQualifiedName mt in uni.MemberTypes)
1266 string qn = FindBuiltInType (mt);
1267 if (utype != null && qn != utype) return "string";
1277 XmlQualifiedName GetContentBaseType (XmlSchemaObject ob)
1279 if (ob is XmlSchemaSimpleContentExtension)
1280 return ((XmlSchemaSimpleContentExtension)ob).BaseTypeName;
1281 else if (ob is XmlSchemaSimpleContentRestriction)
1282 return ((XmlSchemaSimpleContentRestriction)ob).BaseTypeName;
1283 else if (ob is XmlSchemaSimpleTypeRestriction)
1284 return ((XmlSchemaSimpleTypeRestriction)ob).BaseTypeName;
1285 else if (ob is XmlSchemaSimpleTypeList)
1286 return ((XmlSchemaSimpleTypeList)ob).ItemTypeName;
1291 void WriteComplexContent (XmlTextWriter xtw, string ns, XmlSchemaComplexContent content)
1293 XmlQualifiedName qname;
1295 XmlSchemaComplexContentExtension ext = content.Content as XmlSchemaComplexContentExtension;
1296 if (ext != null) qname = ext.BaseTypeName;
1298 XmlSchemaComplexContentRestriction rest = (XmlSchemaComplexContentRestriction)content.Content;
1299 qname = rest.BaseTypeName;
1300 if (qname == arrayType) {
1301 ParseArrayType (rest, out qname);
1302 XmlSchemaElement elem = new XmlSchemaElement ();
1304 elem.SchemaTypeName = qname;
1306 xtw.WriteAttributeString ("arrayType", SoapEncodingNamespace, qname.Name + "[2]");
1307 WriteContentItem (xtw, ns, elem, true);
1312 // Add base map members to this map
1313 XmlSchemaComplexType ctype = FindComplexTyype (qname);
1314 WriteComplexTypeAttributes (xtw, ctype);
1317 // Add the members of this map
1318 WriteAttributes (xtw, ext.Attributes, ext.AnyAttribute);
1319 if (ext.Particle != null)
1320 WriteParticleComplexContent (xtw, ns, ext.Particle);
1323 WriteComplexTypeElements (xtw, ns, ctype);
1326 void ParseArrayType (XmlSchemaComplexContentRestriction rest, out XmlQualifiedName qtype)
1328 XmlSchemaAttribute arrayTypeAt = FindArrayAttribute (rest.Attributes);
1329 XmlAttribute[] uatts = arrayTypeAt.UnhandledAttributes;
1330 if (uatts == null || uatts.Length == 0) throw new InvalidOperationException ("arrayType attribute not specified in array declaration");
1332 XmlAttribute xat = null;
1333 foreach (XmlAttribute at in uatts)
1334 if (at.LocalName == "arrayType" && at.NamespaceURI == WsdlNamespace)
1335 { xat = at; break; }
1338 throw new InvalidOperationException ("arrayType attribute not specified in array declaration");
1340 string arrayType = xat.Value;
1342 int i = arrayType.LastIndexOf (":");
1343 if (i == -1) ns = "";
1344 else ns = arrayType.Substring (0,i);
1346 int j = arrayType.IndexOf ("[", i+1);
1347 if (j == -1) throw new InvalidOperationException ("Cannot parse WSDL array type: " + arrayType);
1348 type = arrayType.Substring (i+1);
1349 type = type.Substring (0, type.Length-2);
1351 qtype = new XmlQualifiedName (type, ns);
1354 XmlSchemaAttribute FindArrayAttribute (XmlSchemaObjectCollection atts)
1356 foreach (object ob in atts)
1358 XmlSchemaAttribute att = ob as XmlSchemaAttribute;
1359 if (att != null && att.RefName == arrayTypeRefName) return att;
1361 XmlSchemaAttributeGroupRef gref = ob as XmlSchemaAttributeGroupRef;
1364 XmlSchemaAttributeGroup grp = (XmlSchemaAttributeGroup) schemas.Find (gref.RefName, typeof(XmlSchemaAttributeGroup));
1365 att = FindArrayAttribute (grp.Attributes);
1366 if (att != null) return att;
1372 void WriteSimpleTypeSample (XmlTextWriter xtw, XmlSchemaSimpleType stype)
1374 xtw.WriteString (GetLiteral (FindBuiltInType (stype)));
1377 XmlSchemaParticle GetRefGroupParticle (XmlSchemaGroupRef refGroup)
1379 XmlSchemaGroup grp = (XmlSchemaGroup) schemas.Find (refGroup.RefName, typeof (XmlSchemaGroup));
1380 return grp.Particle;
1383 XmlSchemaElement FindRefElement (XmlSchemaElement elem)
1385 if (elem.RefName.Namespace == XmlSchema.Namespace)
1387 if (anyElement != null) return anyElement;
1388 anyElement = new XmlSchemaElement ();
1389 anyElement.Name = "any";
1390 anyElement.SchemaTypeName = anyType;
1393 return (XmlSchemaElement) schemas.Find (elem.RefName, typeof(XmlSchemaElement));
1396 XmlSchemaAttribute FindRefAttribute (XmlQualifiedName refName)
1398 if (refName.Namespace == XmlSchema.Namespace)
1400 XmlSchemaAttribute at = new XmlSchemaAttribute ();
1401 at.Name = refName.Name;
1402 at.SchemaTypeName = new XmlQualifiedName ("string",XmlSchema.Namespace);
1405 return (XmlSchemaAttribute) schemas.Find (refName, typeof(XmlSchemaAttribute));
1408 void WriteRefTypeSample (XmlTextWriter xtw, string ns, XmlSchemaElement elem)
1410 if (elem.SchemaTypeName.Namespace == XmlSchema.Namespace || schemas.Find (elem.SchemaTypeName, typeof(XmlSchemaSimpleType)) != null)
1411 WriteElementSample (xtw, ns, elem);
1414 xtw.WriteStartElement (elem.Name, ns);
1415 xtw.WriteAttributeString ("href", "#id" + (queue.Count+1));
1416 xtw.WriteEndElement ();
1417 queue.Add (new EncodedType (ns, elem));
1421 void WriteQueuedTypeSamples (XmlTextWriter xtw)
1423 for (int n=0; n<queue.Count; n++)
1425 EncodedType ec = (EncodedType) queue[n];
1426 XmlSchemaComplexType st = FindComplexTyype (ec.Element.SchemaTypeName);
1427 WriteComplexTypeSample (xtw, st, ec.Element.SchemaTypeName, n+1);
1431 XmlSchemaComplexType FindComplexTyype (XmlQualifiedName qname)
1433 if (qname.Name.IndexOf ("[]") != -1)
1435 XmlSchemaComplexType stype = new XmlSchemaComplexType ();
1436 stype.ContentModel = new XmlSchemaComplexContent ();
1438 XmlSchemaComplexContentRestriction res = new XmlSchemaComplexContentRestriction ();
1439 stype.ContentModel.Content = res;
1440 res.BaseTypeName = arrayType;
1442 XmlSchemaAttribute att = new XmlSchemaAttribute ();
1443 att.RefName = arrayTypeRefName;
1444 res.Attributes.Add (att);
1446 XmlAttribute xat = document.CreateAttribute ("arrayType", WsdlNamespace);
1447 xat.Value = qname.Namespace + ":" + qname.Name;
1448 att.UnhandledAttributes = new XmlAttribute[] {xat};
1452 return (XmlSchemaComplexType) schemas.Find (qname, typeof(XmlSchemaComplexType));
1455 string GetQualifiedNameString (XmlTextWriter xtw, XmlQualifiedName qname)
1457 string pref = xtw.LookupPrefix (qname.Namespace);
1458 if (pref != null) return pref + ":" + qname.Name;
1460 xtw.WriteAttributeString ("xmlns", "q1", null, qname.Namespace);
1461 return "q1:" + qname.Name;
1464 protected virtual string GetLiteral (string s)
1469 void GetOperationFormat (OperationBinding obin, out SoapBindingStyle style, out SoapBindingUse use)
1471 style = SoapBindingStyle.Document;
1472 use = SoapBindingUse.Literal;
1473 SoapOperationBinding sob = obin.Extensions.Find (typeof(SoapOperationBinding)) as SoapOperationBinding;
1476 SoapBodyBinding sbb = obin.Input.Extensions.Find (typeof(SoapBodyBinding)) as SoapBodyBinding;
1490 <link rel="alternate" type="text/xml" href="<%=Request.FilePath%>?disco"/>
1492 <title><%=WebServiceName%> Web Service</title>
1493 <style type="text/css">
1494 BODY { font-family: Arial; margin-left: 20px; margin-top: 20px; font-size: x-small}
1495 TABLE { font-size: x-small }
1496 .title { color:dimgray; font-family: Arial; font-size:20pt; font-weight:900}
1497 .operationTitle { color:dimgray; font-family: Arial; font-size:15pt; font-weight:900}
1498 .method { font-size: x-small }
1499 .bindingLabel { font-size: x-small; font-weight:bold; color:darkgray; line-height:8pt; display:block; margin-bottom:3px }
1500 .label { font-size: small; font-weight:bold; color:darkgray }
1501 .paramTable { font-size: x-small }
1502 .paramTable TR { background-color: gainsboro }
1503 .paramFormTable { font-size: x-small; padding: 10px; background-color: gainsboro }
1504 .paramFormTable TR { background-color: gainsboro }
1505 .paramInput { border: solid 1px gray }
1506 .button {border: solid 1px gray }
1507 .smallSeparator { height:3px; overflow:hidden }
1508 .panel { background-color:whitesmoke; border: solid 1px silver; border-top: solid 1px silver }
1509 .codePanel { background-color: white; font-size:x-small; padding:7px; border:solid 1px silver}
1510 .code-xml { font-size:10pt; font-family:courier }
1511 .code-cs { font-size:10pt; font-family:courier }
1512 .code-vb { font-size:10pt; font-family:courier }
1513 .tabLabelOn { font-weight:bold }
1514 .tabLabelOff {color: darkgray }
1515 .literal-placeholder {color: darkblue; font-weight:bold}
1516 A:link { color: black; }
1517 A:visited { color: black; }
1518 A:active { color: black; }
1519 A:hover { color: blue }
1523 function clearForm ()
1525 document.getElementById("testFormResult").style.display="none";
1532 <div class="title" style="margin-left:20px">
1533 <span class="label">Web Service</span><br>
1538 **********************************************************
1542 <table border="0" width="100%" cellpadding="15px" cellspacing="15px">
1543 <tr valign="top"><td width="150px" class="panel">
1544 <div style="width:150px"></div>
1545 <a class="method" href='<%=PageName%>'>Overview</a><br>
1546 <div class="smallSeparator"></div>
1547 <a class="method" href='<%=PageName + "?" + GetPageContext("wsdl")%>'>Service Description</a>
1548 <div class="smallSeparator"></div>
1549 <a class="method" href='<%=PageName + "?" + GetPageContext("proxy")%>'>Client proxy</a>
1551 <asp:repeater id="BindingsRepeater" runat=server>
1552 <itemtemplate name="itemtemplate">
1553 <span class="bindingLabel"><%#FormatBindingName(DataBinder.Eval(Container.DataItem, "Name").ToString())%></span>
1554 <asp:repeater id="OperationsRepeater" runat=server datasource='<%# ((Binding)Container.DataItem).Operations %>'>
1556 <a class="method" href="<%=PageName%>?<%=GetTabContext("op",null)%>op=<%#GetOpName(Container.DataItem)%>&bnd=<%#DataBinder.Eval(Container.DataItem, "Binding.Name")%>"><%#GetOpName(Container.DataItem)%></a>
1557 <div class="smallSeparator"></div>
1564 </td><td class="panel">
1566 <% if (CurrentPage == "main") {%>
1569 **********************************************************
1570 Web service overview
1573 <p class="label">Web Service Overview</p>
1574 <%=WebServiceDescription%>
1576 <%} if (DefaultBinding == null) {%>
1577 This service does not contain any public web method.
1578 <%} else if (CurrentPage == "op") {%>
1581 **********************************************************
1582 Operation description
1585 <span class="operationTitle"><%=CurrentOperationName%></span>
1590 <% if (CurrentTab == "main") { %>
1591 <span class="label">Input Parameters</span>
1592 <div class="smallSeparator"></div>
1593 <% if (InParams.Count == 0) { %>
1594 No input parameters<br>
1596 <table class="paramTable" cellspacing="1" cellpadding="5">
1597 <asp:repeater id="InputParamsRepeater" runat=server>
1600 <td width="150"><%#DataBinder.Eval(Container.DataItem, "Name")%></td>
1601 <td width="150"><%#DataBinder.Eval(Container.DataItem, "Type")%></td>
1609 <% if (OutParams.Count > 0) { %>
1610 <span class="label">Output Parameters</span>
1611 <div class="smallSeparator"></div>
1612 <table class="paramTable" cellspacing="1" cellpadding="5">
1613 <asp:repeater id="OutputParamsRepeater" runat=server>
1616 <td width="150"><%#DataBinder.Eval(Container.DataItem, "Name")%></td>
1617 <td width="150"><%#DataBinder.Eval(Container.DataItem, "Type")%></td>
1625 <span class="label">Remarks</span>
1626 <div class="smallSeparator"></div>
1627 <%=OperationDocumentation%>
1629 <span class="label">Technical information</span>
1630 <div class="smallSeparator"></div>
1631 Format: <%=CurrentOperationFormat%>
1632 <br>Supported protocols: <%=CurrentOperationProtocols%>
1636 **********************************************************
1637 Operation description - Test form
1640 <% if (CurrentTab == "test") {
1641 if (CurrentOperationSupportsTest) {%>
1642 Enter values for the parameters and click the 'Invoke' button to test this method:<br><br>
1643 <form action="<%=PageName%>" method="GET">
1644 <input type="hidden" name="page" value="<%=CurrentPage%>">
1645 <input type="hidden" name="tab" value="<%=CurrentTab%>">
1646 <input type="hidden" name="op" value="<%=CurrentOperationName%>">
1647 <input type="hidden" name="bnd" value="<%=CurrentOperationBinding%>">
1648 <input type="hidden" name="ext" value="testform">
1649 <table class="paramFormTable" cellspacing="0" cellpadding="3">
1650 <asp:repeater id="InputFormParamsRepeater" runat=server>
1653 <td><%#DataBinder.Eval(Container.DataItem, "Name")%>: </td>
1654 <td width="150"><input class="paramInput" type="text" size="20" name="<%#DataBinder.Eval(Container.DataItem, "Name")%>"></td>
1658 <tr><td></td><td><input class="button" type="submit" value="Invoke"> <input class="button" type="button" onclick="clearForm()" value="Clear"></td></tr>
1661 <div id="testFormResult" style="display:<%= (HasFormResult?"block":"none") %>">
1662 The web service returned the following result:<br/><br/>
1663 <div class="codePanel"><%=GetTestResult()%></div>
1666 The test form is not available for this operation because it has parameters with a complex structure.
1671 **********************************************************
1672 Operation description - Message Layout
1675 <% if (CurrentTab == "msg") { %>
1677 The following are sample SOAP requests and responses for each protocol supported by this method:
1680 <% if (IsOperationSupported ("Soap")) { %>
1681 <span class="label">Soap</span>
1683 <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("Soap", true)%></div></div>
1685 <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("Soap", false)%></div></div>
1688 <% if (IsOperationSupported ("HttpGet")) { %>
1689 <span class="label">HTTP Get</span>
1691 <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("HttpGet", true)%></div></div>
1693 <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("HttpGet", false)%></div></div>
1696 <% if (IsOperationSupported ("HttpPost")) { %>
1697 <span class="label">HTTP Post</span>
1699 <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("HttpPost", true)%></div></div>
1701 <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("HttpPost", false)%></div></div>
1706 <%} else if (CurrentPage == "proxy") {%>
1708 **********************************************************
1711 <form action="<%=PageName%>" name="langForm" method="GET">
1712 Select the language for which you want to generate a proxy
1713 <input type="hidden" name="page" value="<%=CurrentPage%>">
1714 <SELECT name="lang" onchange="langForm.submit()">
1715 <%=GetOptionSel("cs",CurrentLanguage)%>C#</option>
1716 <%=GetOptionSel("vb",CurrentLanguage)%>Visual Basic</option>
1721 <span class="label"><%=CurrentProxytName%></span>
1722 <a href="<%=PageName + "?code=" + CurrentLanguage%>">Download</a>
1724 <div class="codePanel">
1725 <div class="code-<%=CurrentLanguage%>"><%=GetProxyCode ()%></div>
1727 <%} else if (CurrentPage == "wsdl") {%>
1729 **********************************************************
1732 <% if (descriptions.Count > 1 || schemas.Count > 1) {%>
1733 The description of this web service is composed by several documents. Click on the document you want to see:
1737 for (int n=0; n<descriptions.Count; n++)
1738 Response.Write ("<li><a href='" + PageName + "?" + GetPageContext(null) + "doctype=wsdl&docind=" + n + "'>WSDL document " + descriptions[n].TargetNamespace + "</a></li>");
1739 for (int n=0; n<schemas.Count; n++)
1740 Response.Write ("<li><a href='" + PageName + "?" + GetPageContext(null) + "doctype=schema&docind=" + n + "'>Xml Schema " + schemas[n].TargetNamespace + "</a></li>");
1747 <span class="label"><%=CurrentDocumentName%></span>
1748 <a href="<%=PageName + "?" + CurrentDocType + "=" + CurrentDocInd %>">Download</a>
1750 <div class="codePanel">
1751 <div class="code-xml"><%=GenerateDocument ()%></div>
1756 <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
1758 <td width="20px"></td>