DefaultWsdlHelpGenerator.aspx 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796
  1. <%--
  2. //
  3. // DefaultWsdlHelpGenerator.aspx:
  4. //
  5. // Author:
  6. // Lluis Sanchez Gual ([email protected])
  7. //
  8. // (C) 2003 Ximian, Inc. http://www.ximian.com
  9. //
  10. --%>
  11. <%@ Import Namespace="System.Collections" %>
  12. <%@ Import Namespace="System.IO" %>
  13. <%@ Import Namespace="System.Xml.Serialization" %>
  14. <%@ Import Namespace="System.Xml" %>
  15. <%@ Import Namespace="System.Xml.Schema" %>
  16. <%@ Import Namespace="System.Web.Services.Description" %>
  17. <%@ Import Namespace="System" %>
  18. <%@ Import Namespace="System.Net" %>
  19. <%@ Import Namespace="System.Globalization" %>
  20. <%@ Import Namespace="System.Resources" %>
  21. <%@ Import Namespace="System.Diagnostics" %>
  22. <%@ Import Namespace="System.CodeDom" %>
  23. <%@ Import Namespace="System.CodeDom.Compiler" %>
  24. <%@ Import Namespace="Microsoft.CSharp" %>
  25. <%@ Import Namespace="Microsoft.VisualBasic" %>
  26. <%@ Import Namespace="System.Text.RegularExpressions" %>
  27. <%@ Assembly name="System.Web.Services" %>
  28. <%@ Page debug="true" %>
  29. <html>
  30. <script language="C#" runat="server">
  31. ServiceDescriptionCollection descriptions;
  32. XmlSchemas schemas;
  33. string WebServiceName;
  34. string WebServiceDescription;
  35. string PageName;
  36. string DefaultBinding;
  37. ArrayList ServiceProtocols;
  38. string CurrentOperationName;
  39. string CurrentOperationBinding;
  40. string OperationDocumentation;
  41. string CurrentOperationFormat;
  42. bool CurrentOperationSupportsTest;
  43. ArrayList InParams;
  44. ArrayList OutParams;
  45. string CurrentOperationProtocols;
  46. int CodeTextColumns = 95;
  47. void Page_Load(object sender, EventArgs e)
  48. {
  49. descriptions = (ServiceDescriptionCollection) Context.Items["wsdls"];
  50. schemas = (XmlSchemas) Context.Items["schemas"];
  51. ServiceDescription desc = descriptions [0];
  52. if (schemas.Count == 0) schemas = desc.Types.Schemas;
  53. Service service = desc.Services[0];
  54. WebServiceName = service.Name;
  55. if (desc.Bindings.Count == 0)
  56. return;
  57. DefaultBinding = desc.Bindings[0].Name;
  58. WebServiceDescription = service.Documentation;
  59. ServiceProtocols = FindServiceProtocols (null);
  60. CurrentOperationName = Request.QueryString["op"];
  61. CurrentOperationBinding = Request.QueryString["bnd"];
  62. if (CurrentOperationName != null) BuildOperationInfo ();
  63. PageName = HttpUtility.UrlEncode (Path.GetFileName(Request.Path), Encoding.UTF8);
  64. ArrayList list = new ArrayList ();
  65. foreach (ServiceDescription sd in descriptions) {
  66. foreach (Binding bin in sd.Bindings)
  67. if (bin.Extensions.Find (typeof(SoapBinding)) != null) list.Add (bin);
  68. }
  69. BindingsRepeater.DataSource = list;
  70. Page.DataBind();
  71. }
  72. void BuildOperationInfo ()
  73. {
  74. InParams = new ArrayList ();
  75. OutParams = new ArrayList ();
  76. Port port = FindPort (CurrentOperationBinding, null);
  77. Binding binding = descriptions.GetBinding (port.Binding);
  78. PortType portType = descriptions.GetPortType (binding.Type);
  79. Operation oper = FindOperation (portType, CurrentOperationName);
  80. OperationDocumentation = oper.Documentation;
  81. if (OperationDocumentation == null || OperationDocumentation == "")
  82. OperationDocumentation = "No additional remarks";
  83. foreach (OperationMessage opm in oper.Messages)
  84. {
  85. if (opm is OperationInput)
  86. BuildParameters (InParams, opm);
  87. else if (opm is OperationOutput)
  88. BuildParameters (OutParams, opm);
  89. }
  90. // Protocols supported by the operation
  91. CurrentOperationProtocols = "";
  92. ArrayList prots = FindServiceProtocols (CurrentOperationName);
  93. for (int n=0; n<prots.Count; n++) {
  94. if (n != 0) CurrentOperationProtocols += ", ";
  95. CurrentOperationProtocols += (string) prots[n];
  96. }
  97. CurrentOperationSupportsTest = prots.Contains ("HttpGet") || prots.Contains ("HttpPost");
  98. // Operation format
  99. OperationBinding obin = FindOperation (binding, CurrentOperationName);
  100. if (obin != null)
  101. CurrentOperationFormat = GetOperationFormat (obin);
  102. InputParamsRepeater.DataSource = InParams;
  103. InputFormParamsRepeater.DataSource = InParams;
  104. OutputParamsRepeater.DataSource = OutParams;
  105. }
  106. void BuildParameters (ArrayList list, OperationMessage opm)
  107. {
  108. Message msg = descriptions.GetMessage (opm.Message);
  109. if (msg.Parts.Count > 0 && msg.Parts[0].Name == "parameters")
  110. {
  111. MessagePart part = msg.Parts[0];
  112. XmlSchemaComplexType ctype;
  113. if (part.Element == XmlQualifiedName.Empty)
  114. {
  115. ctype = (XmlSchemaComplexType) schemas.Find (part.Type, typeof(XmlSchemaComplexType));
  116. }
  117. else
  118. {
  119. XmlSchemaElement elem = (XmlSchemaElement) schemas.Find (part.Element, typeof(XmlSchemaElement));
  120. ctype = (XmlSchemaComplexType) elem.SchemaType;
  121. }
  122. XmlSchemaSequence seq = ctype.Particle as XmlSchemaSequence;
  123. if (seq == null) return;
  124. foreach (XmlSchemaObject ob in seq.Items)
  125. {
  126. Parameter p = new Parameter();
  127. p.Description = "No additional remarks";
  128. if (ob is XmlSchemaElement)
  129. {
  130. XmlSchemaElement selem = GetRefElement ((XmlSchemaElement)ob);
  131. p.Name = selem.Name;
  132. p.Type = selem.SchemaTypeName.Name;
  133. }
  134. else
  135. {
  136. p.Name = "Unknown";
  137. p.Type = "Unknown";
  138. }
  139. list.Add (p);
  140. }
  141. }
  142. else
  143. {
  144. foreach (MessagePart part in msg.Parts)
  145. {
  146. Parameter p = new Parameter ();
  147. p.Description = "No additional remarks";
  148. p.Name = part.Name;
  149. if (part.Element == XmlQualifiedName.Empty)
  150. p.Type = part.Type.Name;
  151. else
  152. {
  153. XmlSchemaElement elem = (XmlSchemaElement) schemas.Find (part.Element, typeof(XmlSchemaElement));
  154. p.Type = elem.SchemaTypeName.Name;
  155. }
  156. list.Add (p);
  157. }
  158. }
  159. }
  160. string GetOperationFormat (OperationBinding obin)
  161. {
  162. string format = "";
  163. SoapOperationBinding sob = obin.Extensions.Find (typeof(SoapOperationBinding)) as SoapOperationBinding;
  164. if (sob != null) {
  165. format = sob.Style.ToString ();
  166. SoapBodyBinding sbb = obin.Input.Extensions.Find (typeof(SoapBodyBinding)) as SoapBodyBinding;
  167. if (sbb != null)
  168. format += " / " + sbb.Use;
  169. }
  170. return format;
  171. }
  172. XmlSchemaElement GetRefElement (XmlSchemaElement elem)
  173. {
  174. if (!elem.RefName.IsEmpty)
  175. return (XmlSchemaElement) schemas.Find (elem.RefName, typeof(XmlSchemaElement));
  176. else
  177. return elem;
  178. }
  179. ArrayList FindServiceProtocols(string operName)
  180. {
  181. ArrayList table = new ArrayList ();
  182. Service service = descriptions[0].Services[0];
  183. foreach (Port port in service.Ports)
  184. {
  185. string prot = null;
  186. Binding bin = descriptions.GetBinding (port.Binding);
  187. if (bin.Extensions.Find (typeof(SoapBinding)) != null)
  188. prot = "Soap";
  189. else
  190. {
  191. HttpBinding hb = (HttpBinding) bin.Extensions.Find (typeof(HttpBinding));
  192. if (hb != null && hb.Verb == "POST") prot = "HttpPost";
  193. else if (hb != null && hb.Verb == "GET") prot = "HttpGet";
  194. }
  195. if (prot != null && operName != null)
  196. {
  197. if (FindOperation (bin, operName) == null)
  198. prot = null;
  199. }
  200. if (prot != null && !table.Contains (prot))
  201. table.Add (prot);
  202. }
  203. return table;
  204. }
  205. Port FindPort (string portName, string protocol)
  206. {
  207. Service service = descriptions[0].Services[0];
  208. foreach (Port port in service.Ports)
  209. {
  210. if (portName == null)
  211. {
  212. Binding binding = descriptions.GetBinding (port.Binding);
  213. if (GetProtocol (binding) == protocol) return port;
  214. }
  215. else if (port.Name == portName)
  216. return port;
  217. }
  218. return null;
  219. }
  220. string GetProtocol (Binding binding)
  221. {
  222. if (binding.Extensions.Find (typeof(SoapBinding)) != null) return "Soap";
  223. HttpBinding hb = (HttpBinding) binding.Extensions.Find (typeof(HttpBinding));
  224. if (hb == null) return "";
  225. if (hb.Verb == "POST") return "HttpPost";
  226. if (hb.Verb == "GET") return "HttpGet";
  227. return "";
  228. }
  229. Operation FindOperation (PortType portType, string name)
  230. {
  231. foreach (Operation oper in portType.Operations) {
  232. if (oper.Messages.Input.Name != null) {
  233. if (oper.Messages.Input.Name == name) return oper;
  234. }
  235. else
  236. if (oper.Name == name) return oper;
  237. }
  238. return null;
  239. }
  240. OperationBinding FindOperation (Binding binding, string name)
  241. {
  242. foreach (OperationBinding oper in binding.Operations) {
  243. if (oper.Input.Name != null) {
  244. if (oper.Input.Name == name) return oper;
  245. }
  246. else
  247. if (oper.Name == name) return oper;
  248. }
  249. return null;
  250. }
  251. string FormatBindingName (string name)
  252. {
  253. if (name == DefaultBinding) return "Methods";
  254. else return "Methods for binding<br>" + name;
  255. }
  256. string GetOpName (object op)
  257. {
  258. OperationBinding ob = op as OperationBinding;
  259. if (ob == null) return "";
  260. if (ob.Input.Name != null) return ob.Input.Name;
  261. else return ob.Name;
  262. }
  263. bool HasFormResult
  264. {
  265. get { return Request.QueryString ["ext"] == "testform"; }
  266. }
  267. string GetTestResult ()
  268. {
  269. if (!HasFormResult) return null;
  270. bool fill = false;
  271. string qs = "";
  272. for (int n=0; n<Request.QueryString.Count; n++)
  273. {
  274. if (fill) {
  275. if (qs != "") qs += "&";
  276. qs += Request.QueryString.GetKey(n) + "=" + Server.UrlEncode (Request.QueryString [n]);
  277. }
  278. if (Request.QueryString.GetKey(n) == "ext") fill = true;
  279. }
  280. string location = null;
  281. ServiceDescription desc = descriptions [0];
  282. Service service = desc.Services[0];
  283. foreach (Port port in service.Ports)
  284. if (port.Name == CurrentOperationBinding)
  285. {
  286. SoapAddressBinding sbi = (SoapAddressBinding) port.Extensions.Find (typeof(SoapAddressBinding));
  287. if (sbi != null)
  288. location = sbi.Location;
  289. }
  290. if (location == null)
  291. return "Could not locate web service";
  292. try
  293. {
  294. string url = location + "/" + CurrentOperationName;
  295. Uri uri = new Uri (url);
  296. WebRequest req = WebRequest.Create (url + "?" + qs);
  297. HttpCookieCollection cookies = Request.Cookies;
  298. int last = cookies.Count;
  299. if (last > 0) {
  300. CookieContainer container = new CookieContainer ();
  301. for (int i = 0; i < last; i++) {
  302. HttpCookie hcookie = cookies [i];
  303. Cookie cookie = new Cookie (hcookie.Name, hcookie.Value, hcookie.Path, hcookie.Domain);
  304. container.Add (uri, cookie);
  305. }
  306. ((HttpWebRequest) req).CookieContainer = container;
  307. }
  308. WebResponse resp = req.GetResponse();
  309. StreamReader sr = new StreamReader (resp.GetResponseStream());
  310. string s = sr.ReadToEnd ();
  311. sr.Close ();
  312. return "<div class='code-xml'>" + ColorizeXml(WrapText(s,CodeTextColumns)) + "</div>";
  313. }
  314. catch (Exception ex)
  315. {
  316. string res = "<b style='color:red'>" + ex.Message + "</b>";
  317. WebException wex = ex as WebException;
  318. if (wex != null)
  319. {
  320. WebResponse resp = wex.Response;
  321. if (resp != null) {
  322. StreamReader sr = new StreamReader (resp.GetResponseStream());
  323. string s = sr.ReadToEnd ();
  324. sr.Close ();
  325. res += "<div class='code-xml'>" + ColorizeXml(WrapText(s,CodeTextColumns)) + "</div>";
  326. }
  327. }
  328. return res;
  329. }
  330. }
  331. string GenerateOperationMessages (string protocol, bool generateInput)
  332. {
  333. if (!IsOperationSupported (protocol)) return "";
  334. Port port;
  335. if (protocol != "Soap") port = FindPort (null, protocol);
  336. else port = FindPort (CurrentOperationBinding, null);
  337. Binding binding = descriptions.GetBinding (port.Binding);
  338. OperationBinding obin = FindOperation (binding, CurrentOperationName);
  339. PortType portType = descriptions.GetPortType (binding.Type);
  340. Operation oper = FindOperation (portType, CurrentOperationName);
  341. HtmlSampleGenerator sg = new HtmlSampleGenerator (descriptions, schemas);
  342. string txt = sg.GenerateMessage (port, obin, oper, protocol, generateInput);
  343. if (protocol == "Soap") txt = WrapText (txt,CodeTextColumns);
  344. txt = ColorizeXml (txt);
  345. txt = txt.Replace ("@placeholder!","<span class='literal-placeholder'>");
  346. txt = txt.Replace ("!placeholder@","</span>");
  347. return txt;
  348. }
  349. bool IsOperationSupported (string protocol)
  350. {
  351. if (CurrentPage != "op" || CurrentTab != "msg") return false;
  352. if (protocol == "Soap") return true;
  353. Port port = FindPort (null, protocol);
  354. if (port == null) return false;
  355. Binding binding = descriptions.GetBinding (port.Binding);
  356. if (binding == null) return false;
  357. return FindOperation (binding, CurrentOperationName) != null;
  358. }
  359. //
  360. // Proxy code generation
  361. //
  362. string GetProxyCode ()
  363. {
  364. CodeNamespace codeNamespace = new CodeNamespace();
  365. CodeCompileUnit codeUnit = new CodeCompileUnit();
  366. codeUnit.Namespaces.Add (codeNamespace);
  367. ServiceDescriptionImporter importer = new ServiceDescriptionImporter();
  368. foreach (ServiceDescription sd in descriptions)
  369. importer.AddServiceDescription(sd, null, null);
  370. foreach (XmlSchema sc in schemas)
  371. importer.Schemas.Add (sc);
  372. importer.Import(codeNamespace, codeUnit);
  373. string langId = Request.QueryString ["lang"];
  374. if (langId == null || langId == "") langId = "cs";
  375. CodeDomProvider provider = GetProvider (langId);
  376. ICodeGenerator generator = provider.CreateGenerator();
  377. CodeGeneratorOptions options = new CodeGeneratorOptions();
  378. StringWriter sw = new StringWriter ();
  379. generator.GenerateCodeFromCompileUnit(codeUnit, sw, options);
  380. return Colorize (WrapText (sw.ToString (), CodeTextColumns), langId);
  381. }
  382. public string CurrentLanguage
  383. {
  384. get {
  385. string langId = Request.QueryString ["lang"];
  386. if (langId == null || langId == "") langId = "cs";
  387. return langId;
  388. }
  389. }
  390. public string CurrentProxytName
  391. {
  392. get {
  393. string lan = CurrentLanguage == "cs" ? "C#" : "Visual Basic";
  394. return lan + " Client Proxy";
  395. }
  396. }
  397. private CodeDomProvider GetProvider(string langId)
  398. {
  399. switch (langId.ToUpper())
  400. {
  401. case "CS": return new CSharpCodeProvider();
  402. case "VB": return new VBCodeProvider();
  403. default: return null;
  404. }
  405. }
  406. //
  407. // Document generation
  408. //
  409. string GenerateDocument ()
  410. {
  411. StringWriter sw = new StringWriter ();
  412. if (CurrentDocType == "wsdl")
  413. descriptions [CurrentDocInd].Write (sw);
  414. else if (CurrentDocType == "schema")
  415. schemas [CurrentDocInd].Write (sw);
  416. return Colorize (WrapText (sw.ToString (), CodeTextColumns), "xml");
  417. }
  418. public string CurrentDocType
  419. {
  420. get { return Request.QueryString ["doctype"] != null ? Request.QueryString ["doctype"] : "wsdl"; }
  421. }
  422. public int CurrentDocInd
  423. {
  424. get { return Request.QueryString ["docind"] != null ? int.Parse (Request.QueryString ["docind"]) : 0; }
  425. }
  426. public string CurrentDocumentName
  427. {
  428. get {
  429. if (CurrentDocType == "wsdl")
  430. return "WSDL document for namespace \"" + descriptions [CurrentDocInd].TargetNamespace + "\"";
  431. else
  432. return "Xml Schema for namespace \"" + schemas [CurrentDocInd].TargetNamespace + "\"";
  433. }
  434. }
  435. //
  436. // Pages and tabs
  437. //
  438. bool firstTab = true;
  439. ArrayList disabledTabs = new ArrayList ();
  440. string CurrentTab
  441. {
  442. get { return Request.QueryString["tab"] != null ? Request.QueryString["tab"] : "main" ; }
  443. }
  444. string CurrentPage
  445. {
  446. get { return Request.QueryString["page"] != null ? Request.QueryString["page"] : "main" ; }
  447. }
  448. void WriteTabs ()
  449. {
  450. if (CurrentOperationName != null)
  451. {
  452. WriteTab ("main","Overview");
  453. WriteTab ("test","Test Form");
  454. WriteTab ("msg","Message Layout");
  455. }
  456. }
  457. void WriteTab (string id, string label)
  458. {
  459. if (!firstTab) Response.Write("&nbsp;|&nbsp;");
  460. firstTab = false;
  461. string cname = CurrentTab == id ? "tabLabelOn" : "tabLabelOff";
  462. Response.Write ("<a href='" + PageName + "?" + GetPageContext(null) + GetDataContext() + "tab=" + id + "' style='text-decoration:none'>");
  463. Response.Write ("<span class='" + cname + "'>" + label + "</span>");
  464. Response.Write ("</a>");
  465. }
  466. string GetTabContext (string pag, string tab)
  467. {
  468. if (tab == null) tab = CurrentTab;
  469. if (pag == null) pag = CurrentPage;
  470. if (pag != CurrentPage) tab = "main";
  471. return "page=" + pag + "&tab=" + tab + "&";
  472. }
  473. string GetPageContext (string pag)
  474. {
  475. if (pag == null) pag = CurrentPage;
  476. return "page=" + pag + "&";
  477. }
  478. class Tab
  479. {
  480. public string Id;
  481. public string Label;
  482. }
  483. //
  484. // Syntax coloring
  485. //
  486. static string keywords_cs =
  487. "(\\babstract\\b|\\bevent\\b|\\bnew\\b|\\bstruct\\b|\\bas\\b|\\bexplicit\\b|\\bnull\\b|\\bswitch\\b|\\bbase\\b|\\bextern\\b|" +
  488. "\\bobject\\b|\\bthis\\b|\\bbool\\b|\\bfalse\\b|\\boperator\\b|\\bthrow\\b|\\bbreak\\b|\\bfinally\\b|\\bout\\b|\\btrue\\b|" +
  489. "\\bbyte\\b|\\bfixed\\b|\\boverride\\b|\\btry\\b|\\bcase\\b|\\bfloat\\b|\\bparams\\b|\\btypeof\\b|\\bcatch\\b|\\bfor\\b|" +
  490. "\\bprivate\\b|\\buint\\b|\\bchar\\b|\\bforeach\\b|\\bprotected\\b|\\bulong\\b|\\bchecked\\b|\\bgoto\\b|\\bpublic\\b|" +
  491. "\\bunchecked\\b|\\bclass\\b|\\bif\\b|\\breadonly\\b|\\bunsafe\\b|\\bconst\\b|\\bimplicit\\b|\\bref\\b|\\bushort\\b|" +
  492. "\\bcontinue\\b|\\bin\\b|\\breturn\\b|\\busing\\b|\\bdecimal\\b|\\bint\\b|\\bsbyte\\b|\\bvirtual\\b|\\bdefault\\b|" +
  493. "\\binterface\\b|\\bsealed\\b|\\bvolatile\\b|\\bdelegate\\b|\\binternal\\b|\\bshort\\b|\\bvoid\\b|\\bdo\\b|\\bis\\b|" +
  494. "\\bsizeof\\b|\\bwhile\\b|\\bdouble\\b|\\block\\b|\\bstackalloc\\b|\\belse\\b|\\blong\\b|\\bstatic\\b|\\benum\\b|" +
  495. "\\bnamespace\\b|\\bstring\\b)";
  496. static string keywords_vb =
  497. "(\\bAddHandler\\b|\\bAddressOf\\b|\\bAlias\\b|\\bAnd\\b|\\bAndAlso\\b|\\bAnsi\\b|\\bAs\\b|\\bAssembly\\b|" +
  498. "\\bAuto\\b|\\bBoolean\\b|\\bByRef\\b|\\bByte\\b|\\bByVal\\b|\\bCall\\b|\\bCase\\b|\\bCatch\\b|" +
  499. "\\bCBool\\b|\\bCByte\\b|\\bCChar\\b|\\bCDate\\b|\\bCDec\\b|\\bCDbl\\b|\\bChar\\b|\\bCInt\\b|" +
  500. "\\bClass\\b|\\bCLng\\b|\\bCObj\\b|\\bConst\\b|\\bCShort\\b|\\bCSng\\b|\\bCStr\\b|\\bCType\\b|" +
  501. "\\bDate\\b|\\bDecimal\\b|\\bDeclare\\b|\\bDefault\\b|\\bDelegate\\b|\\bDim\\b|\\bDirectCast\\b|\\bDo\\b|" +
  502. "\\bDouble\\b|\\bEach\\b|\\bElse\\b|\\bElseIf\\b|\\bEnd\\b|\\bEnum\\b|\\bErase\\b|\\bError\\b|" +
  503. "\\bEvent\\b|\\bExit\\b|\\bFalse\\b|\\bFinally\\b|\\bFor\\b|\\bFriend\\b|\\bFunction\\b|\\bGet\\b|" +
  504. "\\bGetType\\b|\\bGoSub\\b|\\bGoTo\\b|\\bHandles\\b|\\bIf\\b|\\bImplements\\b|\\bImports\\b|\\bIn\\b|" +
  505. "\\bInherits\\b|\\bInteger\\b|\\bInterface\\b|\\bIs\\b|\\bLet\\b|\\bLib\\b|\\bLike\\b|\\bLong\\b|" +
  506. "\\bLoop\\b|\\bMe\\b|\\bMod\\b|\\bModule\\b|\\bMustInherit\\b|\\bMustOverride\\b|\\bMyBase\\b|\\bMyClass\\b|" +
  507. "\\bNamespace\\b|\\bNew\\b|\\bNext\\b|\\bNot\\b|\\bNothing\\b|\\bNotInheritable\\b|\\bNotOverridable\\b|\\bObject\\b|" +
  508. "\\bOn\\b|\\bOption\\b|\\bOptional\\b|\\bOr\\b|\\bOrElse\\b|\\bOverloads\\b|\\bOverridable\\b|\\bOverrides\\b|" +
  509. "\\bParamArray\\b|\\bPreserve\\b|\\bPrivate\\b|\\bProperty\\b|\\bProtected\\b|\\bPublic\\b|\\bRaiseEvent\\b|\\bReadOnly\\b|" +
  510. "\\bReDim\\b|\\bREM\\b|\\bRemoveHandler\\b|\\bResume\\b|\\bReturn\\b|\\bSelect\\b|\\bSet\\b|\\bShadows\\b|" +
  511. "\\bShared\\b|\\bShort\\b|\\bSingle\\b|\\bStatic\\b|\\bStep\\b|\\bStop\\b|\\bString\\b|\\bStructure\\b|" +
  512. "\\bSub\\b|\\bSyncLock\\b|\\bThen\\b|\\bThrow\\b|\\bTo\\b|\\bTrue\\b|\\bTry\\b|\\bTypeOf\\b|" +
  513. "\\bUnicode\\b|\\bUntil\\b|\\bVariant\\b|\\bWhen\\b|\\bWhile\\b|\\bWith\\b|\\bWithEvents\\b|\\bWriteOnly\\b|\\bXor\\b)";
  514. string Colorize (string text, string lang)
  515. {
  516. if (lang == "xml") return ColorizeXml (text);
  517. else if (lang == "cs") return ColorizeCs (text);
  518. else if (lang == "vb") return ColorizeVb (text);
  519. else return text;
  520. }
  521. string ColorizeXml (string text)
  522. {
  523. text = text.Replace (" ", "&nbsp;");
  524. Regex re = new Regex ("\r\n|\r|\n");
  525. text = re.Replace (text, "_br_");
  526. re = new Regex ("<\\s*(\\/?)\\s*([\\s\\S]*?)\\s*(\\/?)\\s*>");
  527. text = re.Replace (text,"{blue:&lt;$1}{maroon:$2}{blue:$3&gt;}");
  528. re = new Regex ("\\{(\\w*):([\\s\\S]*?)\\}");
  529. text = re.Replace (text,"<span style='color:$1'>$2</span>");
  530. re = new Regex ("\"(.*?)\"");
  531. text = re.Replace (text,"\"<span style='color:purple'>$1</span>\"");
  532. text = text.Replace ("\t", "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
  533. text = text.Replace ("_br_", "<br>");
  534. return text;
  535. }
  536. string ColorizeCs (string text)
  537. {
  538. text = text.Replace (" ", "&nbsp;");
  539. text = text.Replace ("<", "&lt;");
  540. text = text.Replace (">", "&gt;");
  541. Regex re = new Regex ("\"((((?!\").)|\\\")*?)\"");
  542. text = re.Replace (text,"<span style='color:purple'>\"$1\"</span>");
  543. re = new Regex ("//(((.(?!\"</span>))|\"(((?!\").)*)\"</span>)*)(\r|\n|\r\n)");
  544. text = re.Replace (text,"<span style='color:green'>//$1</span><br/>");
  545. re = new Regex (keywords_cs);
  546. text = re.Replace (text,"<span style='color:blue'>$1</span>");
  547. text = text.Replace ("\t","&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
  548. text = text.Replace ("\n","<br/>");
  549. return text;
  550. }
  551. string ColorizeVb (string text)
  552. {
  553. text = text.Replace (" ", "&nbsp;");
  554. /* Regex re = new Regex ("\"((((?!\").)|\\\")*?)\"");
  555. text = re.Replace (text,"<span style='color:purple'>\"$1\"</span>");
  556. re = new Regex ("'(((.(?!\"\\<\\/span\\>))|\"(((?!\").)*)\"\\<\\/span\\>)*)(\r|\n|\r\n)");
  557. text = re.Replace (text,"<span style='color:green'>//$1</span><br/>");
  558. re = new Regex (keywords_vb);
  559. text = re.Replace (text,"<span style='color:blue'>$1</span>");
  560. */
  561. text = text.Replace ("\t","&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
  562. text = text.Replace ("\n","<br/>");
  563. return text;
  564. }
  565. //
  566. // Helper methods and classes
  567. //
  568. string GetDataContext ()
  569. {
  570. return "op=" + CurrentOperationName + "&bnd=" + CurrentOperationBinding + "&";
  571. }
  572. string GetOptionSel (string v1, string v2)
  573. {
  574. string op = "<option ";
  575. if (v1 == v2) op += "selected ";
  576. return op + "value='" + v1 + "'>";
  577. }
  578. string WrapText (string text, int maxChars)
  579. {
  580. text = text.Replace(" />","/>");
  581. string linspace = null;
  582. int lincount = 0;
  583. int breakpos = 0;
  584. int linstart = 0;
  585. bool inquotes = false;
  586. char lastc = ' ';
  587. string sublineIndent = "";
  588. System.Text.StringBuilder sb = new System.Text.StringBuilder ();
  589. for (int n=0; n<text.Length; n++)
  590. {
  591. char c = text [n];
  592. if (c=='\r' || c=='\n' || n==text.Length-1)
  593. {
  594. sb.Append (linspace + sublineIndent + text.Substring (linstart, n-linstart+1));
  595. linspace = null;
  596. lincount = 0;
  597. linstart = n+1;
  598. breakpos = linstart;
  599. sublineIndent = "";
  600. lastc = c;
  601. continue;
  602. }
  603. if (lastc==',' || lastc=='(')
  604. {
  605. if (!inquotes) breakpos = n;
  606. }
  607. if (lincount > maxChars && breakpos >= linstart)
  608. {
  609. if (linspace != null)
  610. sb.Append (linspace + sublineIndent);
  611. sb.Append (text.Substring (linstart, breakpos-linstart));
  612. sb.Append ("\n");
  613. sublineIndent = " ";
  614. lincount = linspace.Length + sublineIndent.Length + (n-breakpos);
  615. linstart = breakpos;
  616. }
  617. if (c==' ' || c=='\t')
  618. {
  619. if (!inquotes)
  620. breakpos = n;
  621. }
  622. else if (c=='"')
  623. {
  624. inquotes = !inquotes;
  625. }
  626. else
  627. if (linspace == null) {
  628. linspace = text.Substring (linstart, n-linstart);
  629. linstart = n;
  630. }
  631. lincount++;
  632. lastc = c;
  633. }
  634. return sb.ToString ();
  635. }
  636. class Parameter
  637. {
  638. string name;
  639. string type;
  640. string description;
  641. public string Name { get { return name; } set { name = value; } }
  642. public string Type { get { return type; } set { type = value; } }
  643. public string Description { get { return description; } set { description = value; } }
  644. }
  645. public class HtmlSampleGenerator: SampleGenerator
  646. {
  647. public HtmlSampleGenerator (ServiceDescriptionCollection services, XmlSchemas schemas)
  648. : base (services, schemas)
  649. {
  650. }
  651. protected override string GetLiteral (string s)
  652. {
  653. return "@placeholder!" + s + "!placeholder@";
  654. }
  655. }
  656. public class SampleGenerator
  657. {
  658. protected ServiceDescriptionCollection descriptions;
  659. protected XmlSchemas schemas;
  660. XmlSchemaElement anyElement;
  661. ArrayList queue;
  662. SoapBindingUse currentUse;
  663. XmlDocument document = new XmlDocument ();
  664. static readonly XmlQualifiedName anyType = new XmlQualifiedName ("anyType",XmlSchema.Namespace);
  665. static readonly XmlQualifiedName arrayType = new XmlQualifiedName ("Array","http://schemas.xmlsoap.org/soap/encoding/");
  666. static readonly XmlQualifiedName arrayTypeRefName = new XmlQualifiedName ("arrayType","http://schemas.xmlsoap.org/soap/encoding/");
  667. const string SoapEnvelopeNamespace = "http://schemas.xmlsoap.org/soap/envelope/";
  668. const string WsdlNamespace = "http://schemas.xmlsoap.org/wsdl/";
  669. const string SoapEncodingNamespace = "http://schemas.xmlsoap.org/soap/encoding/";
  670. class EncodedType
  671. {
  672. public EncodedType (string ns, XmlSchemaElement elem) { Namespace = ns; Element = elem; }
  673. public string Namespace;
  674. public XmlSchemaElement Element;
  675. }
  676. public SampleGenerator (ServiceDescriptionCollection services, XmlSchemas schemas)
  677. {
  678. descriptions = services;
  679. this.schemas = schemas;
  680. queue = new ArrayList ();
  681. }
  682. public string GenerateMessage (Port port, OperationBinding obin, Operation oper, string protocol, bool generateInput)
  683. {
  684. OperationMessage msg = null;
  685. foreach (OperationMessage opm in oper.Messages)
  686. {
  687. if (opm is OperationInput && generateInput) msg = opm;
  688. else if (opm is OperationOutput && !generateInput) msg = opm;
  689. }
  690. if (msg == null) return null;
  691. switch (protocol) {
  692. case "Soap": return GenerateHttpSoapMessage (port, obin, oper, msg);
  693. case "HttpGet": return GenerateHttpGetMessage (port, obin, oper, msg);
  694. case "HttpPost": return GenerateHttpPostMessage (port, obin, oper, msg);
  695. }
  696. return "Unknown protocol";
  697. }
  698. public string GenerateHttpSoapMessage (Port port, OperationBinding obin, Operation oper, OperationMessage msg)
  699. {
  700. string req = "";
  701. if (msg is OperationInput)
  702. {
  703. SoapAddressBinding sab = port.Extensions.Find (typeof(SoapAddressBinding)) as SoapAddressBinding;
  704. SoapOperationBinding sob = obin.Extensions.Find (typeof(SoapOperationBinding)) as SoapOperationBinding;
  705. req += "POST " + new Uri (sab.Location).AbsolutePath + "\n";
  706. req += "SOAPAction: " + sob.SoapAction + "\n";
  707. req += "Content-Type: text/xml; charset=utf-8\n";
  708. req += "Content-Length: " + GetLiteral ("string") + "\n";
  709. req += "Host: " + GetLiteral ("string") + "\n\n";
  710. }
  711. else
  712. {
  713. req += "HTTP/1.0 200 OK\n";
  714. req += "Content-Type: text/xml; charset=utf-8\n";
  715. req += "Content-Length: " + GetLiteral ("string") + "\n\n";
  716. }
  717. req += GenerateSoapMessage (obin, oper, msg);
  718. return req;
  719. }
  720. public string GenerateHttpGetMessage (Port port, OperationBinding obin, Operation oper, OperationMessage msg)
  721. {
  722. string req = "";
  723. if (msg is OperationInput)
  724. {
  725. HttpAddressBinding sab = port.Extensions.Find (typeof(HttpAddressBinding)) as HttpAddressBinding;
  726. HttpOperationBinding sob = obin.Extensions.Find (typeof(HttpOperationBinding)) as HttpOperationBinding;
  727. string location = new Uri (sab.Location).AbsolutePath + sob.Location + "?" + BuildQueryString (msg);
  728. req += "GET " + location + "\n";
  729. req += "Host: " + GetLiteral ("string");
  730. }
  731. else
  732. {
  733. req += "HTTP/1.0 200 OK\n";
  734. req += "Content-Type: text/xml; charset=utf-8\n";
  735. req += "Content-Length: " + GetLiteral ("string") + "\n\n";
  736. MimeXmlBinding mxb = (MimeXmlBinding) obin.Output.Extensions.Find (typeof(MimeXmlBinding)) as MimeXmlBinding;
  737. if (mxb == null) return req;
  738. Message message = descriptions.GetMessage (msg.Message);
  739. XmlQualifiedName ename = null;
  740. foreach (MessagePart part in message.Parts)
  741. if (part.Name == mxb.Part) ename = part.Element;
  742. if (ename == null) return req + GetLiteral("string");
  743. StringWriter sw = new StringWriter ();
  744. XmlTextWriter xtw = new XmlTextWriter (sw);
  745. xtw.Formatting = Formatting.Indented;
  746. currentUse = SoapBindingUse.Literal;
  747. WriteRootElementSample (xtw, ename);
  748. xtw.Close ();
  749. req += sw.ToString ();
  750. }
  751. return req;
  752. }
  753. public string GenerateHttpPostMessage (Port port, OperationBinding obin, Operation oper, OperationMessage msg)
  754. {
  755. string req = "";
  756. if (msg is OperationInput)
  757. {
  758. HttpAddressBinding sab = port.Extensions.Find (typeof(HttpAddressBinding)) as HttpAddressBinding;
  759. HttpOperationBinding sob = obin.Extensions.Find (typeof(HttpOperationBinding)) as HttpOperationBinding;
  760. string location = new Uri (sab.Location).AbsolutePath + sob.Location;
  761. req += "POST " + location + "\n";
  762. req += "Content-Type: application/x-www-form-urlencoded\n";
  763. req += "Content-Length: " + GetLiteral ("string") + "\n";
  764. req += "Host: " + GetLiteral ("string") + "\n\n";
  765. req += BuildQueryString (msg);
  766. }
  767. else return GenerateHttpGetMessage (port, obin, oper, msg);
  768. return req;
  769. }
  770. string BuildQueryString (OperationMessage opm)
  771. {
  772. string s = "";
  773. Message msg = descriptions.GetMessage (opm.Message);
  774. foreach (MessagePart part in msg.Parts)
  775. {
  776. if (s.Length != 0) s += "&";
  777. s += part.Name + "=" + GetLiteral (part.Type.Name);
  778. }
  779. return s;
  780. }
  781. public string GenerateSoapMessage (OperationBinding obin, Operation oper, OperationMessage msg)
  782. {
  783. SoapOperationBinding sob = obin.Extensions.Find (typeof(SoapOperationBinding)) as SoapOperationBinding;
  784. SoapBindingStyle style = (sob != null) ? sob.Style : SoapBindingStyle.Document;
  785. MessageBinding msgbin = (msg is OperationInput) ? (MessageBinding) obin.Input : (MessageBinding)obin.Output;
  786. SoapBodyBinding sbb = msgbin.Extensions.Find (typeof(SoapBodyBinding)) as SoapBodyBinding;
  787. SoapBindingUse bodyUse = (sbb != null) ? sbb.Use : SoapBindingUse.Literal;
  788. StringWriter sw = new StringWriter ();
  789. XmlTextWriter xtw = new XmlTextWriter (sw);
  790. xtw.Formatting = Formatting.Indented;
  791. xtw.WriteStartDocument ();
  792. xtw.WriteStartElement ("soap", "Envelope", SoapEnvelopeNamespace);
  793. xtw.WriteAttributeString ("xmlns", "xsi", null, XmlSchema.InstanceNamespace);
  794. xtw.WriteAttributeString ("xmlns", "xsd", null, XmlSchema.Namespace);
  795. if (bodyUse == SoapBindingUse.Encoded)
  796. {
  797. xtw.WriteAttributeString ("xmlns", "soapenc", null, SoapEncodingNamespace);
  798. xtw.WriteAttributeString ("xmlns", "tns", null, msg.Message.Namespace);
  799. }
  800. // Serialize headers
  801. bool writtenHeader = false;
  802. foreach (object ob in msgbin.Extensions)
  803. {
  804. SoapHeaderBinding hb = ob as SoapHeaderBinding;
  805. if (hb == null) continue;
  806. if (!writtenHeader) {
  807. xtw.WriteStartElement ("soap", "Header", SoapEnvelopeNamespace);
  808. writtenHeader = true;
  809. }
  810. WriteHeader (xtw, hb);
  811. }
  812. if (writtenHeader)
  813. xtw.WriteEndElement ();
  814. // Serialize body
  815. xtw.WriteStartElement ("soap", "Body", SoapEnvelopeNamespace);
  816. currentUse = bodyUse;
  817. WriteBody (xtw, oper, msg, sbb, style);
  818. xtw.WriteEndElement ();
  819. xtw.WriteEndElement ();
  820. xtw.Close ();
  821. return sw.ToString ();
  822. }
  823. void WriteHeader (XmlTextWriter xtw, SoapHeaderBinding header)
  824. {
  825. Message msg = descriptions.GetMessage (header.Message);
  826. if (msg == null) throw new InvalidOperationException ("Message " + header.Message + " not found");
  827. MessagePart part = msg.Parts [header.Part];
  828. if (part == null) throw new InvalidOperationException ("Message part " + header.Part + " not found in message " + header.Message);
  829. currentUse = header.Use;
  830. if (currentUse == SoapBindingUse.Literal)
  831. WriteRootElementSample (xtw, part.Element);
  832. else
  833. WriteTypeSample (xtw, part.Type);
  834. }
  835. void WriteBody (XmlTextWriter xtw, Operation oper, OperationMessage opm, SoapBodyBinding sbb, SoapBindingStyle style)
  836. {
  837. Message msg = descriptions.GetMessage (opm.Message);
  838. if (msg.Parts.Count > 0 && msg.Parts[0].Name == "parameters")
  839. {
  840. MessagePart part = msg.Parts[0];
  841. if (part.Element == XmlQualifiedName.Empty)
  842. WriteTypeSample (xtw, part.Type);
  843. else
  844. WriteRootElementSample (xtw, part.Element);
  845. }
  846. else
  847. {
  848. string elemName = oper.Name;
  849. string ns = "";
  850. if (opm is OperationOutput) elemName += "Response";
  851. if (style == SoapBindingStyle.Rpc) {
  852. xtw.WriteStartElement (elemName, sbb.Namespace);
  853. ns = sbb.Namespace;
  854. }
  855. foreach (MessagePart part in msg.Parts)
  856. {
  857. if (part.Element == XmlQualifiedName.Empty)
  858. {
  859. XmlSchemaElement elem = new XmlSchemaElement ();
  860. elem.SchemaTypeName = part.Type;
  861. elem.Name = part.Name;
  862. WriteElementSample (xtw, ns, elem);
  863. }
  864. else
  865. WriteRootElementSample (xtw, part.Element);
  866. }
  867. if (style == SoapBindingStyle.Rpc)
  868. xtw.WriteEndElement ();
  869. }
  870. WriteQueuedTypeSamples (xtw);
  871. }
  872. void WriteRootElementSample (XmlTextWriter xtw, XmlQualifiedName qname)
  873. {
  874. XmlSchemaElement elem = (XmlSchemaElement) schemas.Find (qname, typeof(XmlSchemaElement));
  875. if (elem == null) throw new InvalidOperationException ("Element not found: " + qname);
  876. WriteElementSample (xtw, qname.Namespace, elem);
  877. }
  878. void WriteElementSample (XmlTextWriter xtw, string ns, XmlSchemaElement elem)
  879. {
  880. bool sharedAnnType = false;
  881. XmlQualifiedName root;
  882. if (!elem.RefName.IsEmpty) {
  883. XmlSchemaElement refElem = FindRefElement (elem);
  884. if (refElem == null) throw new InvalidOperationException ("Global element not found: " + elem.RefName);
  885. root = elem.RefName;
  886. elem = refElem;
  887. sharedAnnType = true;
  888. }
  889. else
  890. root = new XmlQualifiedName (elem.Name, ns);
  891. if (!elem.SchemaTypeName.IsEmpty)
  892. {
  893. XmlSchemaComplexType st = FindComplexTyype (elem.SchemaTypeName);
  894. if (st != null)
  895. WriteComplexTypeSample (xtw, st, root);
  896. else
  897. {
  898. xtw.WriteStartElement (root.Name, root.Namespace);
  899. if (currentUse == SoapBindingUse.Encoded)
  900. xtw.WriteAttributeString ("type", XmlSchema.InstanceNamespace, GetQualifiedNameString (xtw, elem.SchemaTypeName));
  901. xtw.WriteString (GetLiteral (FindBuiltInType (elem.SchemaTypeName)));
  902. xtw.WriteEndElement ();
  903. }
  904. }
  905. else if (elem.SchemaType == null)
  906. {
  907. xtw.WriteStartElement ("any");
  908. xtw.WriteEndElement ();
  909. }
  910. else
  911. WriteComplexTypeSample (xtw, (XmlSchemaComplexType) elem.SchemaType, root);
  912. }
  913. void WriteTypeSample (XmlTextWriter xtw, XmlQualifiedName qname)
  914. {
  915. XmlSchemaComplexType ctype = FindComplexTyype (qname);
  916. if (ctype != null) {
  917. WriteComplexTypeSample (xtw, ctype, qname);
  918. return;
  919. }
  920. XmlSchemaSimpleType stype = (XmlSchemaSimpleType) schemas.Find (qname, typeof(XmlSchemaSimpleType));
  921. if (stype != null) {
  922. WriteSimpleTypeSample (xtw, stype);
  923. return;
  924. }
  925. xtw.WriteString (GetLiteral (FindBuiltInType (qname)));
  926. throw new InvalidOperationException ("Type not found: " + qname);
  927. }
  928. void WriteComplexTypeSample (XmlTextWriter xtw, XmlSchemaComplexType stype, XmlQualifiedName rootName)
  929. {
  930. WriteComplexTypeSample (xtw, stype, rootName, -1);
  931. }
  932. void WriteComplexTypeSample (XmlTextWriter xtw, XmlSchemaComplexType stype, XmlQualifiedName rootName, int id)
  933. {
  934. string ns = rootName.Namespace;
  935. if (rootName.Name.IndexOf ("[]") != -1) rootName = arrayType;
  936. if (currentUse == SoapBindingUse.Encoded) {
  937. string pref = xtw.LookupPrefix (rootName.Namespace);
  938. if (pref == null) pref = "q1";
  939. xtw.WriteStartElement (pref, rootName.Name, rootName.Namespace);
  940. ns = "";
  941. }
  942. else
  943. xtw.WriteStartElement (rootName.Name, rootName.Namespace);
  944. if (id != -1)
  945. {
  946. xtw.WriteAttributeString ("id", "id" + id);
  947. if (rootName != arrayType)
  948. xtw.WriteAttributeString ("type", XmlSchema.InstanceNamespace, GetQualifiedNameString (xtw, rootName));
  949. }
  950. WriteComplexTypeAttributes (xtw, stype);
  951. WriteComplexTypeElements (xtw, ns, stype);
  952. xtw.WriteEndElement ();
  953. }
  954. void WriteComplexTypeAttributes (XmlTextWriter xtw, XmlSchemaComplexType stype)
  955. {
  956. WriteAttributes (xtw, stype.Attributes, stype.AnyAttribute);
  957. }
  958. void WriteComplexTypeElements (XmlTextWriter xtw, string ns, XmlSchemaComplexType stype)
  959. {
  960. if (stype.Particle != null)
  961. WriteParticleComplexContent (xtw, ns, stype.Particle);
  962. else
  963. {
  964. if (stype.ContentModel is XmlSchemaSimpleContent)
  965. WriteSimpleContent (xtw, (XmlSchemaSimpleContent)stype.ContentModel);
  966. else if (stype.ContentModel is XmlSchemaComplexContent)
  967. WriteComplexContent (xtw, ns, (XmlSchemaComplexContent)stype.ContentModel);
  968. }
  969. }
  970. void WriteAttributes (XmlTextWriter xtw, XmlSchemaObjectCollection atts, XmlSchemaAnyAttribute anyat)
  971. {
  972. foreach (XmlSchemaObject at in atts)
  973. {
  974. if (at is XmlSchemaAttribute)
  975. {
  976. string ns;
  977. XmlSchemaAttribute attr = (XmlSchemaAttribute)at;
  978. XmlSchemaAttribute refAttr = attr;
  979. // refAttr.Form; TODO
  980. if (!attr.RefName.IsEmpty) {
  981. refAttr = FindRefAttribute (attr.RefName);
  982. if (refAttr == null) throw new InvalidOperationException ("Global attribute not found: " + attr.RefName);
  983. }
  984. string val;
  985. if (!refAttr.SchemaTypeName.IsEmpty) val = FindBuiltInType (refAttr.SchemaTypeName);
  986. else val = FindBuiltInType ((XmlSchemaSimpleType) refAttr.SchemaType);
  987. xtw.WriteAttributeString (refAttr.Name, val);
  988. }
  989. else if (at is XmlSchemaAttributeGroupRef)
  990. {
  991. XmlSchemaAttributeGroupRef gref = (XmlSchemaAttributeGroupRef)at;
  992. XmlSchemaAttributeGroup grp = (XmlSchemaAttributeGroup) schemas.Find (gref.RefName, typeof(XmlSchemaAttributeGroup));
  993. WriteAttributes (xtw, grp.Attributes, grp.AnyAttribute);
  994. }
  995. }
  996. if (anyat != null)
  997. xtw.WriteAttributeString ("custom-attribute","value");
  998. }
  999. void WriteParticleComplexContent (XmlTextWriter xtw, string ns, XmlSchemaParticle particle)
  1000. {
  1001. WriteParticleContent (xtw, ns, particle, false);
  1002. }
  1003. void WriteParticleContent (XmlTextWriter xtw, string ns, XmlSchemaParticle particle, bool multiValue)
  1004. {
  1005. if (particle is XmlSchemaGroupRef)
  1006. particle = GetRefGroupParticle ((XmlSchemaGroupRef)particle);
  1007. if (particle.MaxOccurs > 1) multiValue = true;
  1008. if (particle is XmlSchemaSequence) {
  1009. WriteSequenceContent (xtw, ns, ((XmlSchemaSequence)particle).Items, multiValue);
  1010. }
  1011. else if (particle is XmlSchemaChoice) {
  1012. if (((XmlSchemaChoice)particle).Items.Count == 1)
  1013. WriteSequenceContent (xtw, ns, ((XmlSchemaChoice)particle).Items, multiValue);
  1014. else
  1015. WriteChoiceContent (xtw, ns, (XmlSchemaChoice)particle, multiValue);
  1016. }
  1017. else if (particle is XmlSchemaAll) {
  1018. WriteSequenceContent (xtw, ns, ((XmlSchemaAll)particle).Items, multiValue);
  1019. }
  1020. }
  1021. void WriteSequenceContent (XmlTextWriter xtw, string ns, XmlSchemaObjectCollection items, bool multiValue)
  1022. {
  1023. foreach (XmlSchemaObject item in items)
  1024. WriteContentItem (xtw, ns, item, multiValue);
  1025. }
  1026. void WriteContentItem (XmlTextWriter xtw, string ns, XmlSchemaObject item, bool multiValue)
  1027. {
  1028. if (item is XmlSchemaGroupRef)
  1029. item = GetRefGroupParticle ((XmlSchemaGroupRef)item);
  1030. if (item is XmlSchemaElement)
  1031. {
  1032. XmlSchemaElement elem = (XmlSchemaElement) item;
  1033. XmlSchemaElement refElem;
  1034. if (!elem.RefName.IsEmpty) refElem = FindRefElement (elem);
  1035. else refElem = elem;
  1036. int num = (elem.MaxOccurs == 1 && !multiValue) ? 1 : 2;
  1037. for (int n=0; n<num; n++)
  1038. {
  1039. if (currentUse == SoapBindingUse.Literal)
  1040. WriteElementSample (xtw, ns, refElem);
  1041. else
  1042. WriteRefTypeSample (xtw, ns, refElem);
  1043. }
  1044. }
  1045. else if (item is XmlSchemaAny)
  1046. {
  1047. xtw.WriteString (GetLiteral ("xml"));
  1048. }
  1049. else if (item is XmlSchemaParticle) {
  1050. WriteParticleContent (xtw, ns, (XmlSchemaParticle)item, multiValue);
  1051. }
  1052. }
  1053. void WriteChoiceContent (XmlTextWriter xtw, string ns, XmlSchemaChoice choice, bool multiValue)
  1054. {
  1055. foreach (XmlSchemaObject item in choice.Items)
  1056. WriteContentItem (xtw, ns, item, multiValue);
  1057. }
  1058. void WriteSimpleContent (XmlTextWriter xtw, XmlSchemaSimpleContent content)
  1059. {
  1060. XmlSchemaSimpleContentExtension ext = content.Content as XmlSchemaSimpleContentExtension;
  1061. if (ext != null)
  1062. WriteAttributes (xtw, ext.Attributes, ext.AnyAttribute);
  1063. XmlQualifiedName qname = GetContentBaseType (content.Content);
  1064. xtw.WriteString (GetLiteral (FindBuiltInType (qname)));
  1065. }
  1066. string FindBuiltInType (XmlQualifiedName qname)
  1067. {
  1068. if (qname.Namespace == XmlSchema.Namespace)
  1069. return qname.Name;
  1070. XmlSchemaComplexType ct = FindComplexTyype (qname);
  1071. if (ct != null)
  1072. {
  1073. XmlSchemaSimpleContent sc = ct.ContentModel as XmlSchemaSimpleContent;
  1074. if (sc == null) throw new InvalidOperationException ("Invalid schema");
  1075. return FindBuiltInType (GetContentBaseType (sc.Content));
  1076. }
  1077. XmlSchemaSimpleType st = (XmlSchemaSimpleType) schemas.Find (qname, typeof(XmlSchemaSimpleType));
  1078. if (st != null)
  1079. return FindBuiltInType (st);
  1080. throw new InvalidOperationException ("Definition of type " + qname + " not found");
  1081. }
  1082. string FindBuiltInType (XmlSchemaSimpleType st)
  1083. {
  1084. if (st.Content is XmlSchemaSimpleTypeRestriction) {
  1085. return FindBuiltInType (GetContentBaseType (st.Content));
  1086. }
  1087. else if (st.Content is XmlSchemaSimpleTypeList) {
  1088. string s = FindBuiltInType (GetContentBaseType (st.Content));
  1089. return s + " " + s + " ...";
  1090. }
  1091. else if (st.Content is XmlSchemaSimpleTypeUnion)
  1092. {
  1093. //Check if all types of the union are equal. If not, then will use anyType.
  1094. XmlSchemaSimpleTypeUnion uni = (XmlSchemaSimpleTypeUnion) st.Content;
  1095. string utype = null;
  1096. // Anonymous types are unique
  1097. if (uni.BaseTypes.Count != 0 && uni.MemberTypes.Length != 0)
  1098. return "string";
  1099. foreach (XmlQualifiedName mt in uni.MemberTypes)
  1100. {
  1101. string qn = FindBuiltInType (mt);
  1102. if (utype != null && qn != utype) return "string";
  1103. else utype = qn;
  1104. }
  1105. return utype;
  1106. }
  1107. else
  1108. return "string";
  1109. }
  1110. XmlQualifiedName GetContentBaseType (XmlSchemaObject ob)
  1111. {
  1112. if (ob is XmlSchemaSimpleContentExtension)
  1113. return ((XmlSchemaSimpleContentExtension)ob).BaseTypeName;
  1114. else if (ob is XmlSchemaSimpleContentRestriction)
  1115. return ((XmlSchemaSimpleContentRestriction)ob).BaseTypeName;
  1116. else if (ob is XmlSchemaSimpleTypeRestriction)
  1117. return ((XmlSchemaSimpleTypeRestriction)ob).BaseTypeName;
  1118. else if (ob is XmlSchemaSimpleTypeList)
  1119. return ((XmlSchemaSimpleTypeList)ob).ItemTypeName;
  1120. else
  1121. return null;
  1122. }
  1123. void WriteComplexContent (XmlTextWriter xtw, string ns, XmlSchemaComplexContent content)
  1124. {
  1125. XmlQualifiedName qname;
  1126. XmlSchemaComplexContentExtension ext = content.Content as XmlSchemaComplexContentExtension;
  1127. if (ext != null) qname = ext.BaseTypeName;
  1128. else {
  1129. XmlSchemaComplexContentRestriction rest = (XmlSchemaComplexContentRestriction)content.Content;
  1130. qname = rest.BaseTypeName;
  1131. if (qname == arrayType) {
  1132. ParseArrayType (rest, out qname);
  1133. XmlSchemaElement elem = new XmlSchemaElement ();
  1134. elem.Name = "Item";
  1135. elem.SchemaTypeName = qname;
  1136. xtw.WriteAttributeString ("arrayType", SoapEncodingNamespace, qname.Name + "[2]");
  1137. WriteContentItem (xtw, ns, elem, true);
  1138. return;
  1139. }
  1140. }
  1141. // Add base map members to this map
  1142. XmlSchemaComplexType ctype = FindComplexTyype (qname);
  1143. WriteComplexTypeAttributes (xtw, ctype);
  1144. if (ext != null) {
  1145. // Add the members of this map
  1146. WriteAttributes (xtw, ext.Attributes, ext.AnyAttribute);
  1147. if (ext.Particle != null)
  1148. WriteParticleComplexContent (xtw, ns, ext.Particle);
  1149. }
  1150. WriteComplexTypeElements (xtw, ns, ctype);
  1151. }
  1152. void ParseArrayType (XmlSchemaComplexContentRestriction rest, out XmlQualifiedName qtype)
  1153. {
  1154. XmlSchemaAttribute arrayTypeAt = FindArrayAttribute (rest.Attributes);
  1155. XmlAttribute[] uatts = arrayTypeAt.UnhandledAttributes;
  1156. if (uatts == null || uatts.Length == 0) throw new InvalidOperationException ("arrayType attribute not specified in array declaration");
  1157. XmlAttribute xat = null;
  1158. foreach (XmlAttribute at in uatts)
  1159. if (at.LocalName == "arrayType" && at.NamespaceURI == WsdlNamespace)
  1160. { xat = at; break; }
  1161. if (xat == null)
  1162. throw new InvalidOperationException ("arrayType attribute not specified in array declaration");
  1163. string arrayType = xat.Value;
  1164. string type, ns;
  1165. int i = arrayType.LastIndexOf (":");
  1166. if (i == -1) ns = "";
  1167. else ns = arrayType.Substring (0,i);
  1168. int j = arrayType.IndexOf ("[", i+1);
  1169. if (j == -1) throw new InvalidOperationException ("Cannot parse WSDL array type: " + arrayType);
  1170. type = arrayType.Substring (i+1);
  1171. type = type.Substring (0, type.Length-2);
  1172. qtype = new XmlQualifiedName (type, ns);
  1173. }
  1174. XmlSchemaAttribute FindArrayAttribute (XmlSchemaObjectCollection atts)
  1175. {
  1176. foreach (object ob in atts)
  1177. {
  1178. XmlSchemaAttribute att = ob as XmlSchemaAttribute;
  1179. if (att != null && att.RefName == arrayTypeRefName) return att;
  1180. XmlSchemaAttributeGroupRef gref = ob as XmlSchemaAttributeGroupRef;
  1181. if (gref != null)
  1182. {
  1183. XmlSchemaAttributeGroup grp = (XmlSchemaAttributeGroup) schemas.Find (gref.RefName, typeof(XmlSchemaAttributeGroup));
  1184. att = FindArrayAttribute (grp.Attributes);
  1185. if (att != null) return att;
  1186. }
  1187. }
  1188. return null;
  1189. }
  1190. void WriteSimpleTypeSample (XmlTextWriter xtw, XmlSchemaSimpleType stype)
  1191. {
  1192. xtw.WriteString (GetLiteral (FindBuiltInType (stype)));
  1193. }
  1194. XmlSchemaParticle GetRefGroupParticle (XmlSchemaGroupRef refGroup)
  1195. {
  1196. XmlSchemaGroup grp = (XmlSchemaGroup) schemas.Find (refGroup.RefName, typeof (XmlSchemaGroup));
  1197. return grp.Particle;
  1198. }
  1199. XmlSchemaElement FindRefElement (XmlSchemaElement elem)
  1200. {
  1201. if (elem.RefName.Namespace == XmlSchema.Namespace)
  1202. {
  1203. if (anyElement != null) return anyElement;
  1204. anyElement = new XmlSchemaElement ();
  1205. anyElement.Name = "any";
  1206. anyElement.SchemaTypeName = anyType;
  1207. return anyElement;
  1208. }
  1209. return (XmlSchemaElement) schemas.Find (elem.RefName, typeof(XmlSchemaElement));
  1210. }
  1211. XmlSchemaAttribute FindRefAttribute (XmlQualifiedName refName)
  1212. {
  1213. if (refName.Namespace == XmlSchema.Namespace)
  1214. {
  1215. XmlSchemaAttribute at = new XmlSchemaAttribute ();
  1216. at.Name = refName.Name;
  1217. at.SchemaTypeName = new XmlQualifiedName ("string",XmlSchema.Namespace);
  1218. return at;
  1219. }
  1220. return (XmlSchemaAttribute) schemas.Find (refName, typeof(XmlSchemaAttribute));
  1221. }
  1222. void WriteRefTypeSample (XmlTextWriter xtw, string ns, XmlSchemaElement elem)
  1223. {
  1224. if (elem.SchemaTypeName.Namespace == XmlSchema.Namespace || schemas.Find (elem.SchemaTypeName, typeof(XmlSchemaSimpleType)) != null)
  1225. WriteElementSample (xtw, ns, elem);
  1226. else
  1227. {
  1228. xtw.WriteStartElement (elem.Name, ns);
  1229. xtw.WriteAttributeString ("href", "#id" + (queue.Count+1));
  1230. xtw.WriteEndElement ();
  1231. queue.Add (new EncodedType (ns, elem));
  1232. }
  1233. }
  1234. void WriteQueuedTypeSamples (XmlTextWriter xtw)
  1235. {
  1236. for (int n=0; n<queue.Count; n++)
  1237. {
  1238. EncodedType ec = (EncodedType) queue[n];
  1239. XmlSchemaComplexType st = FindComplexTyype (ec.Element.SchemaTypeName);
  1240. WriteComplexTypeSample (xtw, st, ec.Element.SchemaTypeName, n+1);
  1241. }
  1242. }
  1243. XmlSchemaComplexType FindComplexTyype (XmlQualifiedName qname)
  1244. {
  1245. if (qname.Name.IndexOf ("[]") != -1)
  1246. {
  1247. XmlSchemaComplexType stype = new XmlSchemaComplexType ();
  1248. stype.ContentModel = new XmlSchemaComplexContent ();
  1249. XmlSchemaComplexContentRestriction res = new XmlSchemaComplexContentRestriction ();
  1250. stype.ContentModel.Content = res;
  1251. res.BaseTypeName = arrayType;
  1252. XmlSchemaAttribute att = new XmlSchemaAttribute ();
  1253. att.RefName = arrayTypeRefName;
  1254. res.Attributes.Add (att);
  1255. XmlAttribute xat = document.CreateAttribute ("arrayType", WsdlNamespace);
  1256. xat.Value = qname.Namespace + ":" + qname.Name;
  1257. att.UnhandledAttributes = new XmlAttribute[] {xat};
  1258. return stype;
  1259. }
  1260. return (XmlSchemaComplexType) schemas.Find (qname, typeof(XmlSchemaComplexType));
  1261. }
  1262. string GetQualifiedNameString (XmlTextWriter xtw, XmlQualifiedName qname)
  1263. {
  1264. string pref = xtw.LookupPrefix (qname.Namespace);
  1265. if (pref != null) return pref + ":" + qname.Name;
  1266. xtw.WriteAttributeString ("xmlns", "q1", null, qname.Namespace);
  1267. return "q1:" + qname.Name;
  1268. }
  1269. protected virtual string GetLiteral (string s)
  1270. {
  1271. return s;
  1272. }
  1273. void GetOperationFormat (OperationBinding obin, out SoapBindingStyle style, out SoapBindingUse use)
  1274. {
  1275. style = SoapBindingStyle.Document;
  1276. use = SoapBindingUse.Literal;
  1277. SoapOperationBinding sob = obin.Extensions.Find (typeof(SoapOperationBinding)) as SoapOperationBinding;
  1278. if (sob != null) {
  1279. style = sob.Style;
  1280. SoapBodyBinding sbb = obin.Input.Extensions.Find (typeof(SoapBodyBinding)) as SoapBodyBinding;
  1281. if (sbb != null)
  1282. use = sbb.Use;
  1283. }
  1284. }
  1285. }
  1286. </script>
  1287. <head>
  1288. <link rel="alternate" type="text/xml" href="<%=Request.FilePath%>?disco"/>
  1289. <title><%=WebServiceName%> Web Service</title>
  1290. <style type="text/css">
  1291. BODY { font-family: Arial; margin-left: 20px; margin-top: 20px; font-size: x-small}
  1292. TABLE { font-size: x-small }
  1293. .title { color:dimgray; font-family: Arial; font-size:20pt; font-weight:900}
  1294. .operationTitle { color:dimgray; font-family: Arial; font-size:15pt; font-weight:900}
  1295. .method { font-size: x-small }
  1296. .bindingLabel { font-size: x-small; font-weight:bold; color:darkgray; line-height:8pt; display:block; margin-bottom:3px }
  1297. .label { font-size: small; font-weight:bold; color:darkgray }
  1298. .paramTable { font-size: x-small }
  1299. .paramTable TR { background-color: gainsboro }
  1300. .paramFormTable { font-size: x-small; padding: 10px; background-color: gainsboro }
  1301. .paramFormTable TR { background-color: gainsboro }
  1302. .paramInput { border: solid 1px gray }
  1303. .button {border: solid 1px gray }
  1304. .smallSeparator { height:3px; overflow:hidden }
  1305. .panel { background-color:whitesmoke; border: solid 1px silver; border-top: solid 1px silver }
  1306. .codePanel { background-color: white; font-size:x-small; padding:7px; border:solid 1px silver}
  1307. .code-xml { font-size:10pt; font-family:courier }
  1308. .code-cs { font-size:10pt; font-family:courier }
  1309. .code-vb { font-size:10pt; font-family:courier }
  1310. .tabLabelOn { font-weight:bold }
  1311. .tabLabelOff {color: darkgray }
  1312. .literal-placeholder {color: darkblue; font-weight:bold}
  1313. A:link { color: black; }
  1314. A:visited { color: black; }
  1315. A:active { color: black; }
  1316. A:hover { color: blue }
  1317. </style>
  1318. <script>
  1319. function clearForm ()
  1320. {
  1321. document.getElementById("testFormResult").style.display="none";
  1322. }
  1323. </script>
  1324. </head>
  1325. <body>
  1326. <div class="title" style="margin-left:20px">
  1327. <span class="label">Web Service</span><br>
  1328. <%=WebServiceName%>
  1329. </div>
  1330. <!--
  1331. **********************************************************
  1332. Left panel
  1333. -->
  1334. <table border="0" width="100%" cellpadding="15px" cellspacing="15px">
  1335. <tr valign="top"><td width="150px" class="panel">
  1336. <div style="width:150px"></div>
  1337. <a class="method" href='<%=PageName%>'>Overview</a><br>
  1338. <div class="smallSeparator"></div>
  1339. <a class="method" href='<%=PageName + "?" + GetPageContext("wsdl")%>'>Service Description</a>
  1340. <div class="smallSeparator"></div>
  1341. <a class="method" href='<%=PageName + "?" + GetPageContext("proxy")%>'>Client proxy</a>
  1342. <br><br>
  1343. <asp:repeater id="BindingsRepeater" runat=server>
  1344. <itemtemplate name="itemtemplate">
  1345. <span class="bindingLabel"><%#FormatBindingName(DataBinder.Eval(Container.DataItem, "Name").ToString())%></span>
  1346. <asp:repeater id="OperationsRepeater" runat=server datasource='<%# ((Binding)Container.DataItem).Operations %>'>
  1347. <itemtemplate>
  1348. <a class="method" href="<%=PageName%>?<%=GetTabContext("op",null)%>op=<%#GetOpName(Container.DataItem)%>&bnd=<%#DataBinder.Eval(Container.DataItem, "Binding.Name")%>"><%#GetOpName(Container.DataItem)%></a>
  1349. <div class="smallSeparator"></div>
  1350. </itemtemplate>
  1351. </asp:repeater>
  1352. <br>
  1353. </itemtemplate>
  1354. </asp:repeater>
  1355. </td><td class="panel">
  1356. <% if (CurrentPage == "main") {%>
  1357. <!--
  1358. **********************************************************
  1359. Web service overview
  1360. -->
  1361. <p class="label">Web Service Overview</p>
  1362. <%=WebServiceDescription%>
  1363. <%} if (DefaultBinding == null) {%>
  1364. This service does not contain any public web method.
  1365. <%} else if (CurrentPage == "op") {%>
  1366. <!--
  1367. **********************************************************
  1368. Operation description
  1369. -->
  1370. <span class="operationTitle"><%=CurrentOperationName%></span>
  1371. <br><br>
  1372. <% WriteTabs (); %>
  1373. <br><br><br>
  1374. <% if (CurrentTab == "main") { %>
  1375. <span class="label">Input Parameters</span>
  1376. <div class="smallSeparator"></div>
  1377. <% if (InParams.Count == 0) { %>
  1378. No input parameters<br>
  1379. <% } else { %>
  1380. <table class="paramTable" cellspacing="1" cellpadding="5">
  1381. <asp:repeater id="InputParamsRepeater" runat=server>
  1382. <itemtemplate>
  1383. <tr>
  1384. <td width="150"><%#DataBinder.Eval(Container.DataItem, "Name")%></td>
  1385. <td width="150"><%#DataBinder.Eval(Container.DataItem, "Type")%></td>
  1386. </tr>
  1387. </itemtemplate>
  1388. </asp:repeater>
  1389. </table>
  1390. <% } %>
  1391. <br>
  1392. <% if (OutParams.Count > 0) { %>
  1393. <span class="label">Output Parameters</span>
  1394. <div class="smallSeparator"></div>
  1395. <table class="paramTable" cellspacing="1" cellpadding="5">
  1396. <asp:repeater id="OutputParamsRepeater" runat=server>
  1397. <itemtemplate>
  1398. <tr>
  1399. <td width="150"><%#DataBinder.Eval(Container.DataItem, "Name")%></td>
  1400. <td width="150"><%#DataBinder.Eval(Container.DataItem, "Type")%></td>
  1401. </tr>
  1402. </itemtemplate>
  1403. </asp:repeater>
  1404. </table>
  1405. <br>
  1406. <% } %>
  1407. <span class="label">Remarks</span>
  1408. <div class="smallSeparator"></div>
  1409. <%=OperationDocumentation%>
  1410. <br><br>
  1411. <span class="label">Technical information</span>
  1412. <div class="smallSeparator"></div>
  1413. Format: <%=CurrentOperationFormat%>
  1414. <br>Supported protocols: <%=CurrentOperationProtocols%>
  1415. <% } %>
  1416. <!--
  1417. **********************************************************
  1418. Operation description - Test form
  1419. -->
  1420. <% if (CurrentTab == "test") {
  1421. if (CurrentOperationSupportsTest) {%>
  1422. Enter values for the parameters and click the 'Invoke' button to test this method:<br><br>
  1423. <form action="<%=PageName%>" method="GET">
  1424. <input type="hidden" name="page" value="<%=CurrentPage%>">
  1425. <input type="hidden" name="tab" value="<%=CurrentTab%>">
  1426. <input type="hidden" name="op" value="<%=CurrentOperationName%>">
  1427. <input type="hidden" name="bnd" value="<%=CurrentOperationBinding%>">
  1428. <input type="hidden" name="ext" value="testform">
  1429. <table class="paramFormTable" cellspacing="0" cellpadding="3">
  1430. <asp:repeater id="InputFormParamsRepeater" runat=server>
  1431. <itemtemplate>
  1432. <tr>
  1433. <td><%#DataBinder.Eval(Container.DataItem, "Name")%>:&nbsp;</td>
  1434. <td width="150"><input class="paramInput" type="text" size="20" name="<%#DataBinder.Eval(Container.DataItem, "Name")%>"></td>
  1435. </tr>
  1436. </itemtemplate>
  1437. </asp:repeater>
  1438. <tr><td></td><td><input class="button" type="submit" value="Invoke">&nbsp;<input class="button" type="button" onclick="clearForm()" value="Clear"></td></tr>
  1439. </table>
  1440. </form>
  1441. <div id="testFormResult" style="display:<%= (HasFormResult?"block":"none") %>">
  1442. The web service returned the following result:<br/><br/>
  1443. <div class="codePanel"><%=GetTestResult()%></div>
  1444. </div>
  1445. <% } else {%>
  1446. The test form is not available for this operation because it has parameters with a complex structure.
  1447. <% } %>
  1448. <% } %>
  1449. <!--
  1450. **********************************************************
  1451. Operation description - Message Layout
  1452. -->
  1453. <% if (CurrentTab == "msg") { %>
  1454. The following are sample SOAP requests and responses for each protocol supported by this method:
  1455. <br/><br/>
  1456. <% if (IsOperationSupported ("Soap")) { %>
  1457. <span class="label">Soap</span>
  1458. <br/><br/>
  1459. <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("Soap", true)%></div></div>
  1460. <br/>
  1461. <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("Soap", false)%></div></div>
  1462. <br/>
  1463. <% } %>
  1464. <% if (IsOperationSupported ("HttpGet")) { %>
  1465. <span class="label">HTTP Get</span>
  1466. <br/><br/>
  1467. <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("HttpGet", true)%></div></div>
  1468. <br/>
  1469. <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("HttpGet", false)%></div></div>
  1470. <br/>
  1471. <% } %>
  1472. <% if (IsOperationSupported ("HttpPost")) { %>
  1473. <span class="label">HTTP Post</span>
  1474. <br/><br/>
  1475. <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("HttpPost", true)%></div></div>
  1476. <br/>
  1477. <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("HttpPost", false)%></div></div>
  1478. <br/>
  1479. <% } %>
  1480. <% } %>
  1481. <%} else if (CurrentPage == "proxy") {%>
  1482. <!--
  1483. **********************************************************
  1484. Client Proxy
  1485. -->
  1486. <form action="<%=PageName%>" name="langForm" method="GET">
  1487. Select the language for which you want to generate a proxy
  1488. <input type="hidden" name="page" value="<%=CurrentPage%>">&nbsp;
  1489. <SELECT name="lang" onchange="langForm.submit()">
  1490. <%=GetOptionSel("cs",CurrentLanguage)%>C#</option>
  1491. <%=GetOptionSel("vb",CurrentLanguage)%>Visual Basic</option>
  1492. </SELECT>
  1493. &nbsp;&nbsp;
  1494. </form>
  1495. <br>
  1496. <span class="label"><%=CurrentProxytName%></span>&nbsp;&nbsp;&nbsp;
  1497. <a href="<%=PageName + "?code=" + CurrentLanguage%>">Download</a>
  1498. <br><br>
  1499. <div class="codePanel">
  1500. <div class="code-<%=CurrentLanguage%>"><%=GetProxyCode ()%></div>
  1501. </div>
  1502. <%} else if (CurrentPage == "wsdl") {%>
  1503. <!--
  1504. **********************************************************
  1505. Service description
  1506. -->
  1507. <% if (descriptions.Count > 1 || schemas.Count > 1) {%>
  1508. The description of this web service is composed by several documents. Click on the document you want to see:
  1509. <ul>
  1510. <%
  1511. for (int n=0; n<descriptions.Count; n++)
  1512. Response.Write ("<li><a href='" + PageName + "?" + GetPageContext(null) + "doctype=wsdl&docind=" + n + "'>WSDL document " + descriptions[n].TargetNamespace + "</a></li>");
  1513. for (int n=0; n<schemas.Count; n++)
  1514. Response.Write ("<li><a href='" + PageName + "?" + GetPageContext(null) + "doctype=schema&docind=" + n + "'>Xml Schema " + schemas[n].TargetNamespace + "</a></li>");
  1515. %>
  1516. </ul>
  1517. <%} else {%>
  1518. <%}%>
  1519. <br>
  1520. <span class="label"><%=CurrentDocumentName%></span>&nbsp;&nbsp;&nbsp;
  1521. <a href="<%=PageName + "?" + CurrentDocType + "=" + CurrentDocInd %>">Download</a>
  1522. <br><br>
  1523. <div class="codePanel">
  1524. <div class="code-xml"><%=GenerateDocument ()%></div>
  1525. </div>
  1526. <%}%>
  1527. <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
  1528. </td>
  1529. <td width="20px"></td>
  1530. </tr>
  1531. </table>
  1532. </body>
  1533. </html>