DefaultWsdlHelpGenerator.aspx 58 KB

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