DefaultWsdlHelpGenerator.aspx 59 KB

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