DefaultWsdlHelpGenerator.aspx 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927
  1. <%
  2. //
  3. // DefaultWsdlHelpGenerator.aspx:
  4. //
  5. // Author:
  6. // Lluis Sanchez Gual ([email protected])
  7. //
  8. // (C) 2003 Ximian, Inc. http://www.ximian.com
  9. //
  10. %>
  11. <%@ Import Namespace="System.Collections" %>
  12. <%@ Import Namespace="System.IO" %>
  13. <%@ Import Namespace="System.Xml.Serialization" %>
  14. <%@ Import Namespace="System.Xml" %>
  15. <%@ Import Namespace="System.Xml.Schema" %>
  16. <%@ Import Namespace="System.Web.Services.Description" %>
  17. <%@ Import Namespace="System" %>
  18. <%@ Import Namespace="System.Net" %>
  19. <%@ Import Namespace="System.Globalization" %>
  20. <%@ Import Namespace="System.Resources" %>
  21. <%@ Import Namespace="System.Diagnostics" %>
  22. <%@ Import Namespace="System.CodeDom" %>
  23. <%@ Import Namespace="System.CodeDom.Compiler" %>
  24. <%@ Import Namespace="Microsoft.CSharp" %>
  25. <%@ Import Namespace="Microsoft.VisualBasic" %>
  26. <%@ Import Namespace="System.Text.RegularExpressions" %>
  27. <%@ Assembly name="System.Web.Services" %>
  28. <%@ Page debug="true" %>
  29. <html>
  30. <script language="C#" runat="server">
  31. ServiceDescriptionCollection descriptions;
  32. XmlSchemas schemas;
  33. string WebServiceName;
  34. string WebServiceDescription;
  35. string PageName;
  36. string DefaultBinding;
  37. ArrayList ServiceProtocols;
  38. string CurrentOperationName;
  39. string CurrentOperationBinding;
  40. string OperationDocumentation;
  41. string CurrentOperationFormat;
  42. bool CurrentOperationSupportsTest;
  43. ArrayList InParams;
  44. ArrayList OutParams;
  45. string CurrentOperationProtocols;
  46. int CodeTextColumns = 95;
  47. void Page_Load(object sender, EventArgs e)
  48. {
  49. descriptions = (ServiceDescriptionCollection) Context.Items["wsdls"];
  50. schemas = (XmlSchemas) Context.Items["schemas"];
  51. ServiceDescription desc = descriptions [0];
  52. if (schemas.Count == 0) schemas = desc.Types.Schemas;
  53. Service service = desc.Services[0];
  54. WebServiceName = service.Name;
  55. DefaultBinding = desc.Bindings[0].Name;
  56. WebServiceDescription = service.Documentation;
  57. ServiceProtocols = FindServiceProtocols (null);
  58. CurrentOperationName = Request.QueryString["op"];
  59. CurrentOperationBinding = Request.QueryString["bnd"];
  60. if (CurrentOperationName != null) BuildOperationInfo ();
  61. PageName = HttpUtility.UrlEncode (Path.GetFileName(Request.Path), Encoding.UTF8);
  62. ArrayList list = new ArrayList ();
  63. foreach (ServiceDescription sd in descriptions) {
  64. foreach (Binding bin in sd.Bindings)
  65. if (bin.Extensions.Find (typeof(SoapBinding)) != null) list.Add (bin);
  66. }
  67. BindingsRepeater.DataSource = list;
  68. Page.DataBind();
  69. }
  70. void BuildOperationInfo ()
  71. {
  72. InParams = new ArrayList ();
  73. OutParams = new ArrayList ();
  74. Binding binding = FindBinding (CurrentOperationBinding);
  75. PortType portType = descriptions.GetPortType (binding.Type);
  76. Operation oper = FindOperation (portType, CurrentOperationName);
  77. OperationDocumentation = oper.Documentation;
  78. if (OperationDocumentation == null || OperationDocumentation == "")
  79. OperationDocumentation = "No additional remarks";
  80. foreach (OperationMessage opm in oper.Messages)
  81. {
  82. if (opm is OperationInput)
  83. BuildParameters (InParams, opm);
  84. else if (opm is OperationOutput)
  85. BuildParameters (OutParams, opm);
  86. }
  87. // Protocols supported by the operation
  88. CurrentOperationProtocols = "";
  89. ArrayList prots = FindServiceProtocols (CurrentOperationName);
  90. for (int n=0; n<prots.Count; n++) {
  91. if (n != 0) CurrentOperationProtocols += ", ";
  92. CurrentOperationProtocols += (string) prots[n];
  93. }
  94. CurrentOperationSupportsTest = prots.Contains ("HttpGet") || prots.Contains ("HttpPost");
  95. // Operation format
  96. OperationBinding obin = FindOperation (binding, CurrentOperationName);
  97. if (obin != null)
  98. CurrentOperationFormat = GetOperationFormat (obin);
  99. InputParamsRepeater.DataSource = InParams;
  100. InputFormParamsRepeater.DataSource = InParams;
  101. OutputParamsRepeater.DataSource = OutParams;
  102. }
  103. void BuildParameters (ArrayList list, OperationMessage opm)
  104. {
  105. Message msg = descriptions.GetMessage (opm.Message);
  106. if (msg.Parts.Count > 0 && msg.Parts[0].Name == "parameters")
  107. {
  108. MessagePart part = msg.Parts[0];
  109. XmlSchemaComplexType ctype;
  110. if (part.Element == XmlQualifiedName.Empty)
  111. {
  112. ctype = (XmlSchemaComplexType) schemas.Find (part.Type, typeof(XmlSchemaComplexType));
  113. }
  114. else
  115. {
  116. XmlSchemaElement elem = (XmlSchemaElement) schemas.Find (part.Element, typeof(XmlSchemaElement));
  117. ctype = (XmlSchemaComplexType) elem.SchemaType;
  118. }
  119. XmlSchemaSequence seq = ctype.Particle as XmlSchemaSequence;
  120. if (seq == null) return;
  121. foreach (XmlSchemaObject ob in seq.Items)
  122. {
  123. Parameter p = new Parameter();
  124. p.Description = "No additional remarks";
  125. if (ob is XmlSchemaElement)
  126. {
  127. XmlSchemaElement selem = GetRefElement ((XmlSchemaElement)ob);
  128. p.Name = selem.Name;
  129. p.Type = selem.SchemaTypeName.Name;
  130. }
  131. else
  132. {
  133. p.Name = "Unknown";
  134. p.Type = "Unknown";
  135. }
  136. list.Add (p);
  137. }
  138. }
  139. else
  140. {
  141. foreach (MessagePart part in msg.Parts)
  142. {
  143. Parameter p = new Parameter ();
  144. p.Description = "No additional remarks";
  145. p.Name = part.Name;
  146. if (part.Element == XmlQualifiedName.Empty)
  147. p.Type = part.Type.Name;
  148. else
  149. {
  150. XmlSchemaElement elem = (XmlSchemaElement) schemas.Find (part.Element, typeof(XmlSchemaElement));
  151. p.Type = elem.SchemaTypeName.Name;
  152. }
  153. list.Add (p);
  154. }
  155. }
  156. }
  157. string GetOperationFormat (OperationBinding obin)
  158. {
  159. string format = "";
  160. SoapOperationBinding sob = obin.Extensions.Find (typeof(SoapOperationBinding)) as SoapOperationBinding;
  161. if (sob != null) {
  162. format = sob.Style.ToString ();
  163. SoapBodyBinding sbb = obin.Input.Extensions.Find (typeof(SoapBodyBinding)) as SoapBodyBinding;
  164. if (sbb != null)
  165. format += " / " + sbb.Use;
  166. }
  167. return format;
  168. }
  169. XmlSchemaElement GetRefElement (XmlSchemaElement elem)
  170. {
  171. if (!elem.RefName.IsEmpty)
  172. return (XmlSchemaElement) schemas.Find (elem.RefName, typeof(XmlSchemaElement));
  173. else
  174. return elem;
  175. }
  176. ArrayList FindServiceProtocols(string operName)
  177. {
  178. ArrayList table = new ArrayList ();
  179. Service service = descriptions[0].Services[0];
  180. foreach (Port port in service.Ports)
  181. {
  182. string prot = null;
  183. Binding bin = descriptions.GetBinding (port.Binding);
  184. if (bin.Extensions.Find (typeof(SoapBinding)) != null)
  185. prot = "Soap";
  186. else
  187. {
  188. HttpBinding hb = (HttpBinding) bin.Extensions.Find (typeof(HttpBinding));
  189. if (hb != null && hb.Verb == "POST") prot = "HttpPost";
  190. else if (hb != null && hb.Verb == "GET") prot = "HttpGet";
  191. }
  192. if (prot != null && operName != null)
  193. {
  194. if (FindOperation (bin, operName) == null)
  195. prot = null;
  196. }
  197. if (prot != null && !table.Contains (prot))
  198. table.Add (prot);
  199. }
  200. return table;
  201. }
  202. Binding FindBinding (string portName)
  203. {
  204. Service service = descriptions[0].Services[0];
  205. foreach (Port port in service.Ports)
  206. if (port.Name == portName)
  207. return descriptions.GetBinding (port.Binding);
  208. return null;
  209. }
  210. Operation FindOperation (PortType portType, string name)
  211. {
  212. foreach (Operation oper in portType.Operations) {
  213. if (oper.Messages.Input.Name != null) {
  214. if (oper.Messages.Input.Name == name) return oper;
  215. }
  216. else
  217. if (oper.Name == name) return oper;
  218. }
  219. return null;
  220. }
  221. OperationBinding FindOperation (Binding binding, string name)
  222. {
  223. foreach (OperationBinding oper in binding.Operations) {
  224. if (oper.Input.Name != null) {
  225. if (oper.Input.Name == name) return oper;
  226. }
  227. else
  228. if (oper.Name == name) return oper;
  229. }
  230. return null;
  231. }
  232. string FormatBindingName (string name)
  233. {
  234. if (name == DefaultBinding) return "Methods";
  235. else return "Methods for binding<br>" + name;
  236. }
  237. string GetOpName (object op)
  238. {
  239. OperationBinding ob = op as OperationBinding;
  240. if (ob == null) return "";
  241. if (ob.Input.Name != null) return ob.Input.Name;
  242. else return ob.Name;
  243. }
  244. bool HasFormResult
  245. {
  246. get { return Request.QueryString ["ext"] == "testform"; }
  247. }
  248. string GetTestResult ()
  249. {
  250. if (!HasFormResult) return null;
  251. bool fill = false;
  252. string qs = "";
  253. for (int n=0; n<Request.QueryString.Count; n++)
  254. {
  255. if (fill) {
  256. if (qs != "") qs += "&";
  257. qs += Request.QueryString.GetKey(n) + "=" + Request.QueryString [n];
  258. }
  259. if (Request.QueryString.GetKey(n) == "ext") fill = true;
  260. }
  261. string location = null;
  262. ServiceDescription desc = descriptions [0];
  263. Service service = desc.Services[0];
  264. foreach (Port port in service.Ports)
  265. if (port.Name == CurrentOperationBinding)
  266. {
  267. SoapAddressBinding sbi = (SoapAddressBinding) port.Extensions.Find (typeof(SoapAddressBinding));
  268. if (sbi != null)
  269. location = sbi.Location;
  270. }
  271. if (location == null)
  272. return "Could not locate web service";
  273. try
  274. {
  275. WebRequest req = WebRequest.Create (location + "/" + CurrentOperationName + "?" + qs);
  276. WebResponse resp = req.GetResponse();
  277. StreamReader sr = new StreamReader (resp.GetResponseStream());
  278. string s = sr.ReadToEnd ();
  279. sr.Close ();
  280. return "<div class='code-xml'>" + ColorizeXml(WrapText(s,CodeTextColumns)) + "</div>";
  281. }
  282. catch (Exception ex)
  283. {
  284. string res = "<b style='color:red'>" + ex.Message + "</b>";
  285. WebException wex = ex as WebException;
  286. if (wex != null)
  287. {
  288. WebResponse resp = wex.Response;
  289. if (resp != null) {
  290. StreamReader sr = new StreamReader (resp.GetResponseStream());
  291. string s = sr.ReadToEnd ();
  292. sr.Close ();
  293. res += "<div class='code-xml'>" + ColorizeXml(WrapText(s,CodeTextColumns)) + "</div>";
  294. }
  295. }
  296. return res;
  297. }
  298. }
  299. //
  300. // Proxy code generation
  301. //
  302. string GetProxyCode ()
  303. {
  304. CodeNamespace codeNamespace = new CodeNamespace();
  305. CodeCompileUnit codeUnit = new CodeCompileUnit();
  306. codeUnit.Namespaces.Add (codeNamespace);
  307. ServiceDescriptionImporter importer = new ServiceDescriptionImporter();
  308. foreach (ServiceDescription sd in descriptions)
  309. importer.AddServiceDescription(sd, null, null);
  310. foreach (XmlSchema sc in schemas)
  311. importer.Schemas.Add (sc);
  312. importer.Import(codeNamespace, codeUnit);
  313. string langId = Request.QueryString ["lang"];
  314. if (langId == null || langId == "") langId = "cs";
  315. CodeDomProvider provider = GetProvider (langId);
  316. ICodeGenerator generator = provider.CreateGenerator();
  317. CodeGeneratorOptions options = new CodeGeneratorOptions();
  318. StringWriter sw = new StringWriter ();
  319. generator.GenerateCodeFromCompileUnit(codeUnit, sw, options);
  320. return Colorize (WrapText (sw.ToString (), CodeTextColumns), langId);
  321. }
  322. public string CurrentLanguage
  323. {
  324. get {
  325. string langId = Request.QueryString ["lang"];
  326. if (langId == null || langId == "") langId = "cs";
  327. return langId;
  328. }
  329. }
  330. public string CurrentProxytName
  331. {
  332. get {
  333. string lan = CurrentLanguage == "cs" ? "C#" : "Visual Basic";
  334. return lan + " Client Proxy";
  335. }
  336. }
  337. private CodeDomProvider GetProvider(string langId)
  338. {
  339. switch (langId.ToUpper())
  340. {
  341. case "CS": return new CSharpCodeProvider();
  342. case "VB": return new VBCodeProvider();
  343. default: return null;
  344. }
  345. }
  346. //
  347. // Document generation
  348. //
  349. string GenerateDocument ()
  350. {
  351. StringWriter sw = new StringWriter ();
  352. if (CurrentDocType == "wsdl")
  353. descriptions [CurrentDocInd].Write (sw);
  354. else if (CurrentDocType == "schema")
  355. schemas [CurrentDocInd].Write (sw);
  356. return Colorize (WrapText (sw.ToString (), CodeTextColumns), "xml");
  357. }
  358. public string CurrentDocType
  359. {
  360. get { return Request.QueryString ["doctype"] != null ? Request.QueryString ["doctype"] : "wsdl"; }
  361. }
  362. public int CurrentDocInd
  363. {
  364. get { return Request.QueryString ["docind"] != null ? int.Parse (Request.QueryString ["docind"]) : 0; }
  365. }
  366. public string CurrentDocumentName
  367. {
  368. get {
  369. if (CurrentDocType == "wsdl")
  370. return "WSDL document for namespace \"" + descriptions [CurrentDocInd].TargetNamespace + "\"";
  371. else
  372. return "Xml Schema for namespace \"" + schemas [CurrentDocInd].TargetNamespace + "\"";
  373. }
  374. }
  375. //
  376. // Pages and tabs
  377. //
  378. bool firstTab = true;
  379. ArrayList disabledTabs = new ArrayList ();
  380. string CurrentTab
  381. {
  382. get { return Request.QueryString["tab"] != null ? Request.QueryString["tab"] : "main" ; }
  383. }
  384. string CurrentPage
  385. {
  386. get { return Request.QueryString["page"] != null ? Request.QueryString["page"] : "main" ; }
  387. }
  388. void WriteTabs ()
  389. {
  390. if (CurrentOperationName != null)
  391. {
  392. WriteTab ("main","Overview");
  393. WriteTab ("test","Test Form");
  394. WriteTab ("msg","Message Layout");
  395. }
  396. }
  397. void WriteTab (string id, string label)
  398. {
  399. if (!firstTab) Response.Write("&nbsp;|&nbsp;");
  400. firstTab = false;
  401. string cname = CurrentTab == id ? "tabLabelOn" : "tabLabelOff";
  402. Response.Write ("<a href='" + PageName + "?" + GetPageContext(null) + GetDataContext() + "tab=" + id + "' style='text-decoration:none'>");
  403. Response.Write ("<span class='" + cname + "'>" + label + "</span>");
  404. Response.Write ("</a>");
  405. }
  406. string GetTabContext (string pag, string tab)
  407. {
  408. if (tab == null) tab = CurrentTab;
  409. if (pag == null) pag = CurrentPage;
  410. if (pag != CurrentPage) tab = "main";
  411. return "page=" + pag + "&tab=" + tab + "&";
  412. }
  413. string GetPageContext (string pag)
  414. {
  415. if (pag == null) pag = CurrentPage;
  416. return "page=" + pag + "&";
  417. }
  418. class Tab
  419. {
  420. public string Id;
  421. public string Label;
  422. }
  423. //
  424. // Syntax coloring
  425. //
  426. static string keywords_cs =
  427. "(\\babstract\\b|\\bevent\\b|\\bnew\\b|\\bstruct\\b|\\bas\\b|\\bexplicit\\b|\\bnull\\b|\\bswitch\\b|\\bbase\\b|\\bextern\\b|" +
  428. "\\bobject\\b|\\bthis\\b|\\bbool\\b|\\bfalse\\b|\\boperator\\b|\\bthrow\\b|\\bbreak\\b|\\bfinally\\b|\\bout\\b|\\btrue\\b|" +
  429. "\\bbyte\\b|\\bfixed\\b|\\boverride\\b|\\btry\\b|\\bcase\\b|\\bfloat\\b|\\bparams\\b|\\btypeof\\b|\\bcatch\\b|\\bfor\\b|" +
  430. "\\bprivate\\b|\\buint\\b|\\bchar\\b|\\bforeach\\b|\\bprotected\\b|\\bulong\\b|\\bchecked\\b|\\bgoto\\b|\\bpublic\\b|" +
  431. "\\bunchecked\\b|\\bclass\\b|\\bif\\b|\\breadonly\\b|\\bunsafe\\b|\\bconst\\b|\\bimplicit\\b|\\bref\\b|\\bushort\\b|" +
  432. "\\bcontinue\\b|\\bin\\b|\\breturn\\b|\\busing\\b|\\bdecimal\\b|\\bint\\b|\\bsbyte\\b|\\bvirtual\\b|\\bdefault\\b|" +
  433. "\\binterface\\b|\\bsealed\\b|\\bvolatile\\b|\\bdelegate\\b|\\binternal\\b|\\bshort\\b|\\bvoid\\b|\\bdo\\b|\\bis\\b|" +
  434. "\\bsizeof\\b|\\bwhile\\b|\\bdouble\\b|\\block\\b|\\bstackalloc\\b|\\belse\\b|\\blong\\b|\\bstatic\\b|\\benum\\b|" +
  435. "\\bnamespace\\b|\\bstring\\b)";
  436. static string keywords_vb =
  437. "(\\bAddHandler\\b|\\bAddressOf\\b|\\bAlias\\b|\\bAnd\\b|\\bAndAlso\\b|\\bAnsi\\b|\\bAs\\b|\\bAssembly\\b|" +
  438. "\\bAuto\\b|\\bBoolean\\b|\\bByRef\\b|\\bByte\\b|\\bByVal\\b|\\bCall\\b|\\bCase\\b|\\bCatch\\b|" +
  439. "\\bCBool\\b|\\bCByte\\b|\\bCChar\\b|\\bCDate\\b|\\bCDec\\b|\\bCDbl\\b|\\bChar\\b|\\bCInt\\b|" +
  440. "\\bClass\\b|\\bCLng\\b|\\bCObj\\b|\\bConst\\b|\\bCShort\\b|\\bCSng\\b|\\bCStr\\b|\\bCType\\b|" +
  441. "\\bDate\\b|\\bDecimal\\b|\\bDeclare\\b|\\bDefault\\b|\\bDelegate\\b|\\bDim\\b|\\bDirectCast\\b|\\bDo\\b|" +
  442. "\\bDouble\\b|\\bEach\\b|\\bElse\\b|\\bElseIf\\b|\\bEnd\\b|\\bEnum\\b|\\bErase\\b|\\bError\\b|" +
  443. "\\bEvent\\b|\\bExit\\b|\\bFalse\\b|\\bFinally\\b|\\bFor\\b|\\bFriend\\b|\\bFunction\\b|\\bGet\\b|" +
  444. "\\bGetType\\b|\\bGoSub\\b|\\bGoTo\\b|\\bHandles\\b|\\bIf\\b|\\bImplements\\b|\\bImports\\b|\\bIn\\b|" +
  445. "\\bInherits\\b|\\bInteger\\b|\\bInterface\\b|\\bIs\\b|\\bLet\\b|\\bLib\\b|\\bLike\\b|\\bLong\\b|" +
  446. "\\bLoop\\b|\\bMe\\b|\\bMod\\b|\\bModule\\b|\\bMustInherit\\b|\\bMustOverride\\b|\\bMyBase\\b|\\bMyClass\\b|" +
  447. "\\bNamespace\\b|\\bNew\\b|\\bNext\\b|\\bNot\\b|\\bNothing\\b|\\bNotInheritable\\b|\\bNotOverridable\\b|\\bObject\\b|" +
  448. "\\bOn\\b|\\bOption\\b|\\bOptional\\b|\\bOr\\b|\\bOrElse\\b|\\bOverloads\\b|\\bOverridable\\b|\\bOverrides\\b|" +
  449. "\\bParamArray\\b|\\bPreserve\\b|\\bPrivate\\b|\\bProperty\\b|\\bProtected\\b|\\bPublic\\b|\\bRaiseEvent\\b|\\bReadOnly\\b|" +
  450. "\\bReDim\\b|\\bREM\\b|\\bRemoveHandler\\b|\\bResume\\b|\\bReturn\\b|\\bSelect\\b|\\bSet\\b|\\bShadows\\b|" +
  451. "\\bShared\\b|\\bShort\\b|\\bSingle\\b|\\bStatic\\b|\\bStep\\b|\\bStop\\b|\\bString\\b|\\bStructure\\b|" +
  452. "\\bSub\\b|\\bSyncLock\\b|\\bThen\\b|\\bThrow\\b|\\bTo\\b|\\bTrue\\b|\\bTry\\b|\\bTypeOf\\b|" +
  453. "\\bUnicode\\b|\\bUntil\\b|\\bVariant\\b|\\bWhen\\b|\\bWhile\\b|\\bWith\\b|\\bWithEvents\\b|\\bWriteOnly\\b|\\bXor\\b)";
  454. string Colorize (string text, string lang)
  455. {
  456. if (lang == "xml") return ColorizeXml (text);
  457. else if (lang == "cs") return ColorizeCs (text);
  458. else if (lang == "vb") return ColorizeVb (text);
  459. else return text;
  460. }
  461. string ColorizeXml (string text)
  462. {
  463. text = text.Replace (" ", "&nbsp;");
  464. Regex re = new Regex ("\r\n|\r|\n");
  465. text = re.Replace (text, "_br_");
  466. re = new Regex ("<\\s*(\\/?)\\s*([\\s\\S]*?)\\s*(\\/?)\\s*>");
  467. text = re.Replace (text,"{blue:&lt;$1}{maroon:$2}{blue:$3&gt;}");
  468. re = new Regex ("\\{(\\w*):([\\s\\S]*?)\\}");
  469. text = re.Replace (text,"<span style='color:$1'>$2</span>");
  470. re = new Regex ("\"(.*?)\"");
  471. text = re.Replace (text,"\"<span style='color:purple'>$1</span>\"");
  472. text = text.Replace ("\t", "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
  473. text = text.Replace ("_br_", "<br>");
  474. return text;
  475. }
  476. string ColorizeCs (string text)
  477. {
  478. text = text.Replace (" ", "&nbsp;");
  479. text = text.Replace ("<", "&lt;");
  480. text = text.Replace (">", "&gt;");
  481. Regex re = new Regex ("\"((((?!\").)|\\\")*?)\"");
  482. text = re.Replace (text,"<span style='color:purple'>\"$1\"</span>");
  483. re = new Regex ("//(((.(?!\"</span>))|\"(((?!\").)*)\"</span>)*)(\r|\n|\r\n)");
  484. text = re.Replace (text,"<span style='color:green'>//$1</span><br/>");
  485. re = new Regex (keywords_cs);
  486. text = re.Replace (text,"<span style='color:blue'>$1</span>");
  487. text = text.Replace ("\t","&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
  488. text = text.Replace ("\n","<br/>");
  489. return text;
  490. }
  491. string ColorizeVb (string text)
  492. {
  493. text = text.Replace (" ", "&nbsp;");
  494. /* Regex re = new Regex ("\"((((?!\").)|\\\")*?)\"");
  495. text = re.Replace (text,"<span style='color:purple'>\"$1\"</span>");
  496. re = new Regex ("'(((.(?!\"\\<\\/span\\>))|\"(((?!\").)*)\"\\<\\/span\\>)*)(\r|\n|\r\n)");
  497. text = re.Replace (text,"<span style='color:green'>//$1</span><br/>");
  498. re = new Regex (keywords_vb);
  499. text = re.Replace (text,"<span style='color:blue'>$1</span>");
  500. */
  501. text = text.Replace ("\t","&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
  502. text = text.Replace ("\n","<br/>");
  503. return text;
  504. }
  505. //
  506. // Helper methods and classes
  507. //
  508. string GetDataContext ()
  509. {
  510. return "op=" + CurrentOperationName + "&bnd=" + CurrentOperationBinding + "&";
  511. }
  512. string GetOptionSel (string v1, string v2)
  513. {
  514. string op = "<option ";
  515. if (v1 == v2) op += "selected ";
  516. return op + "value='" + v1 + "'>";
  517. }
  518. string WrapText (string text, int maxChars)
  519. {
  520. text = text.Replace(" />","/>");
  521. string linspace = null;
  522. int lincount = 0;
  523. int breakpos = 0;
  524. int linstart = 0;
  525. bool inquotes = false;
  526. char lastc = ' ';
  527. string sublineIndent = "";
  528. System.Text.StringBuilder sb = new System.Text.StringBuilder ();
  529. for (int n=0; n<text.Length; n++)
  530. {
  531. char c = text [n];
  532. if (c=='\r' || c=='\n' || n==text.Length-1)
  533. {
  534. sb.Append (linspace + sublineIndent + text.Substring (linstart, n-linstart+1));
  535. linspace = null;
  536. lincount = 0;
  537. linstart = n+1;
  538. breakpos = linstart;
  539. sublineIndent = "";
  540. lastc = c;
  541. continue;
  542. }
  543. if (lastc==',' || lastc=='(')
  544. {
  545. if (!inquotes) breakpos = n;
  546. }
  547. if (lincount > maxChars && breakpos >= linstart)
  548. {
  549. if (linspace != null)
  550. sb.Append (linspace + sublineIndent);
  551. sb.Append (text.Substring (linstart, breakpos-linstart));
  552. sb.Append ("\n");
  553. sublineIndent = " ";
  554. lincount = linspace.Length + sublineIndent.Length + (n-breakpos);
  555. linstart = breakpos;
  556. }
  557. if (c==' ' || c=='\t')
  558. {
  559. if (!inquotes)
  560. breakpos = n;
  561. }
  562. else if (c=='"')
  563. {
  564. inquotes = !inquotes;
  565. }
  566. else
  567. if (linspace == null) {
  568. linspace = text.Substring (linstart, n-linstart);
  569. linstart = n;
  570. }
  571. lincount++;
  572. lastc = c;
  573. }
  574. return sb.ToString ();
  575. }
  576. class Parameter
  577. {
  578. string name;
  579. string type;
  580. string description;
  581. public string Name { get { return name; } set { name = value; } }
  582. public string Type { get { return type; } set { type = value; } }
  583. public string Description { get { return description; } set { description = value; } }
  584. }
  585. </script>
  586. <head>
  587. <title><%=WebServiceName%> Web Service</title>
  588. <style type="text/css">
  589. BODY { font-family: Arial; margin-left: 20px; margin-top: 20px; font-size: x-small}
  590. TABLE { font-size: x-small }
  591. .title { color:dimgray; font-family: Arial; font-size:20pt; font-weight:900}
  592. .operationTitle { color:dimgray; font-family: Arial; font-size:15pt; font-weight:900}
  593. .method { font-size: x-small }
  594. .bindingLabel { font-size: x-small; font-weight:bold; color:darkgray; line-height:8pt; display:block; margin-bottom:3px }
  595. .label { font-size: small; font-weight:bold; color:darkgray }
  596. .paramTable { font-size: x-small }
  597. .paramTable TR { background-color: gainsboro }
  598. .paramFormTable { font-size: x-small; padding: 10px; background-color: gainsboro }
  599. .paramFormTable TR { background-color: gainsboro }
  600. .paramInput { border: solid 1px gray }
  601. .button {border: solid 1px gray }
  602. .smallSeparator { height:3px; overflow:hidden }
  603. .panel { background-color:whitesmoke; border: solid 1px silver; border-top: solid 1px silver }
  604. .codePanel { background-color: white; font-size:x-small; padding:7px; border:solid 1px silver}
  605. .code-xml { font-size:10pt; font-family:courier }
  606. .code-cs { font-size:10pt; font-family:courier }
  607. .code-vb { font-size:10pt; font-family:courier }
  608. .tabLabelOn { font-weight:bold }
  609. .tabLabelOff {color: darkgray }
  610. A:link { color: black; }
  611. A:visited { color: black; }
  612. A:active { color: black; }
  613. A:hover { color: blue }
  614. </style>
  615. <script>
  616. function clearForm ()
  617. {
  618. document.getElementById("testFormResult").style.display="none";
  619. }
  620. </script>
  621. </head>
  622. <body>
  623. <div class="title" style="margin-left:20px">
  624. <span class="label">Web Service</span><br>
  625. <%=WebServiceName%>
  626. </div>
  627. <!--
  628. **********************************************************
  629. Left panel
  630. -->
  631. <table border="0" width="100%" cellpadding="15px" cellspacing="15px">
  632. <tr valign="top"><td width="150px" class="panel">
  633. <div style="width:150px"></div>
  634. <a class="method" href='<%=PageName%>'>Overview</a><br>
  635. <div class="smallSeparator"></div>
  636. <a class="method" href='<%=PageName + "?" + GetPageContext("wsdl")%>'>Service Description</a>
  637. <div class="smallSeparator"></div>
  638. <a class="method" href='<%=PageName + "?" + GetPageContext("proxy")%>'>Client proxy</a>
  639. <br><br>
  640. <asp:repeater id="BindingsRepeater" runat=server>
  641. <itemtemplate name="itemtemplate">
  642. <span class="bindingLabel"><%#FormatBindingName(DataBinder.Eval(Container.DataItem, "Name").ToString())%></span>
  643. <asp:repeater id="OperationsRepeater" runat=server datasource='<%# ((Binding)Container.DataItem).Operations %>'>
  644. <itemtemplate>
  645. <a class="method" href="<%#PageName%>?<%#GetTabContext("op",null)%>op=<%#GetOpName(Container.DataItem)%>&bnd=<%#DataBinder.Eval(Container.DataItem, "Binding.Name")%>"><%#GetOpName(Container.DataItem)%></a>
  646. <div class="smallSeparator"></div>
  647. </itemtemplate>
  648. </asp:repeater>
  649. <br>
  650. </itemtemplate>
  651. </asp:repeater>
  652. </td><td class="panel">
  653. <% if (CurrentPage == "main") {%>
  654. <!--
  655. **********************************************************
  656. Web service overview
  657. -->
  658. <p class="label">Web Service Overview</p>
  659. <%#WebServiceDescription%>
  660. <%} if (CurrentPage == "op") {%>
  661. <!--
  662. **********************************************************
  663. Operation description
  664. -->
  665. <span class="operationTitle"><%#CurrentOperationName%></span>
  666. <br><br>
  667. <% WriteTabs (); %>
  668. <br><br><br>
  669. <% if (CurrentTab == "main") { %>
  670. <span class="label">Input Parameters</span>
  671. <div class="smallSeparator"></div>
  672. <% if (InParams.Count == 0) { %>
  673. No input parameters<br>
  674. <% } else { %>
  675. <table class="paramTable" cellspacing="1" cellpadding="5">
  676. <asp:repeater id="InputParamsRepeater" runat=server>
  677. <itemtemplate>
  678. <tr>
  679. <td width="150"><%#DataBinder.Eval(Container.DataItem, "Name")%></td>
  680. <td width="150"><%#DataBinder.Eval(Container.DataItem, "Type")%></td>
  681. </tr>
  682. </itemtemplate>
  683. </asp:repeater>
  684. </table>
  685. <% } %>
  686. <br>
  687. <% if (OutParams.Count > 0) { %>
  688. <span class="label">Output Parameters</span>
  689. <div class="smallSeparator"></div>
  690. <table class="paramTable" cellspacing="1" cellpadding="5">
  691. <asp:repeater id="OutputParamsRepeater" runat=server>
  692. <itemtemplate>
  693. <tr>
  694. <td width="150"><%#DataBinder.Eval(Container.DataItem, "Name")%></td>
  695. <td width="150"><%#DataBinder.Eval(Container.DataItem, "Type")%></td>
  696. </tr>
  697. </itemtemplate>
  698. </asp:repeater>
  699. </table>
  700. <br>
  701. <% } %>
  702. <span class="label">Remarks</span>
  703. <div class="smallSeparator"></div>
  704. <%#OperationDocumentation%>
  705. <br><br>
  706. <span class="label">Technical information</span>
  707. <div class="smallSeparator"></div>
  708. Format: <%#CurrentOperationFormat%>
  709. <br>Supported protocols: <%#CurrentOperationProtocols%>
  710. <% } %>
  711. <% if (CurrentTab == "test") {
  712. if (CurrentOperationSupportsTest) {%>
  713. Enter values for the parameters and click the 'Invoke' button to test this method:<br><br>
  714. <form action="<%#PageName%>" method="GET">
  715. <input type="hidden" name="page" value="<%#CurrentPage%>">
  716. <input type="hidden" name="tab" value="<%#CurrentTab%>">
  717. <input type="hidden" name="op" value="<%#CurrentOperationName%>">
  718. <input type="hidden" name="bnd" value="<%#CurrentOperationBinding%>">
  719. <input type="hidden" name="ext" value="testform">
  720. <table class="paramFormTable" cellspacing="0" cellpadding="3">
  721. <asp:repeater id="InputFormParamsRepeater" runat=server>
  722. <itemtemplate>
  723. <tr>
  724. <td><%#DataBinder.Eval(Container.DataItem, "Name")%>:&nbsp;</td>
  725. <td width="150"><input class="paramInput" type="text" size="20" name="<%#DataBinder.Eval(Container.DataItem, "Name")%>"></td>
  726. </tr>
  727. </itemtemplate>
  728. </asp:repeater>
  729. <tr><td></td><td><input class="button" type="submit" value="Invoke">&nbsp;<input class="button" type="button" onclick="clearForm()" value="Clear"></td></tr>
  730. </table>
  731. </form>
  732. <div id="testFormResult" style="display:<%# (HasFormResult?"block":"none") %>">
  733. The web service returned the following result:<br/><br/>
  734. <div class="codePanel"><%#GetTestResult()%></div>
  735. </div>
  736. <% } else {%>
  737. The test form is not available for this operation because it has parameters with a complex structure.
  738. <% } %>
  739. <% } %>
  740. <% if (CurrentTab == "msg") { %>
  741. TODO
  742. <% } %>
  743. <%}%>
  744. <% if (CurrentPage == "proxy") {%>
  745. <!--
  746. **********************************************************
  747. Client Proxy
  748. -->
  749. <form action="<%#PageName%>" name="langForm" method="GET">
  750. Select the language for which you want to generate a proxy
  751. <input type="hidden" name="page" value="<%#CurrentPage%>">&nbsp;
  752. <SELECT name="lang" onchange="langForm.submit()">
  753. <%#GetOptionSel("cs",CurrentLanguage)%>C#</option>
  754. <%#GetOptionSel("vb",CurrentLanguage)%>Visual Basic</option>
  755. </SELECT>
  756. &nbsp;&nbsp;
  757. </form>
  758. <br>
  759. <span class="label"><%#CurrentProxytName%></span>&nbsp;&nbsp;&nbsp;
  760. <a href="<%#PageName + "?code=" + CurrentLanguage%>">Download</a>
  761. <br><br>
  762. <div class="codePanel">
  763. <div class="code-<%#CurrentLanguage%>"><%#GetProxyCode ()%></div>
  764. </div>
  765. <%}%>
  766. <% if (CurrentPage == "wsdl") {%>
  767. <!--
  768. **********************************************************
  769. Service description
  770. -->
  771. <% if (descriptions.Count > 1 || schemas.Count > 1) {%>
  772. The description of this web service is composed by several documents. Click on the document you want to see:
  773. <ul>
  774. <%
  775. for (int n=0; n<descriptions.Count; n++)
  776. Response.Write ("<li><a href='" + PageName + "?" + GetPageContext(null) + "doctype=wsdl&docind=" + n + "'>WSDL document " + descriptions[n].TargetNamespace + "</a></li>");
  777. for (int n=0; n<schemas.Count; n++)
  778. Response.Write ("<li><a href='" + PageName + "?" + GetPageContext(null) + "doctype=schema&docind=" + n + "'>Xml Schema " + schemas[n].TargetNamespace + "</a></li>");
  779. %>
  780. </ul>
  781. <%} else {%>
  782. <%}%>
  783. <br>
  784. <span class="label"><%#CurrentDocumentName%></span>&nbsp;&nbsp;&nbsp;
  785. <a href="<%=PageName + "?" + CurrentDocType + "=" + CurrentDocInd %>">Download</a>
  786. <br><br>
  787. <div class="codePanel">
  788. <div class="code-xml"><%#GenerateDocument ()%></div>
  789. </div>
  790. <%}%>
  791. <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
  792. </td>
  793. <td withd="20px"></td>
  794. </tr>
  795. </table>
  796. </body>
  797. </html>