Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1543 lines
60 KiB

  1. <%@ Import Namespace="System.Collections" %>
  2. <%@ Import Namespace="System.IO" %>
  3. <%@ Import Namespace="System.Xml.Serialization" %>
  4. <%@ Import Namespace="System.Xml" %>
  5. <%@ Import Namespace="System.Xml.Schema" %>
  6. <%@ Import Namespace="System.Web.Services.Description" %>
  7. <%@ Import Namespace="System" %>
  8. <%@ Import Namespace="System.Globalization" %>
  9. <%@ Import Namespace="System.Resources" %>
  10. <%@ Import Namespace="System.Diagnostics" %>
  11. <%@ Import Namespace="System.Net" %>
  12. <html>
  13. <script language="C#" runat="server">
  14. // set this to true if you want to see a POST test form instead of a GET test form
  15. bool showPost = true;
  16. // set this to true if you want to see the raw XML as outputted from the XmlWriter (useful for debugging)
  17. bool dontFilterXml = false;
  18. // set this higher or lower to adjust the depth into your object graph of the sample messages
  19. int maxObjectGraphDepth = 4;
  20. // set this higher or lower to adjust the number of array items in sample messages
  21. int maxArraySize = 2;
  22. // set this to true to see debug output in sample messages
  23. bool debug = false;
  24. string soapNs = "http://schemas.xmlsoap.org/soap/envelope/";
  25. string soapEncNs = "http://schemas.xmlsoap.org/soap/encoding/";
  26. string msTypesNs = "http://microsoft.com/wsdl/types/";
  27. string wsdlNs = "http://schemas.xmlsoap.org/wsdl/";
  28. string urType = "anyType";
  29. ServiceDescriptionCollection serviceDescriptions;
  30. XmlSchemas schemas;
  31. string operationName;
  32. OperationBinding soapOperationBinding;
  33. Operation soapOperation;
  34. OperationBinding httpGetOperationBinding;
  35. Operation httpGetOperation;
  36. OperationBinding httpPostOperationBinding;
  37. Operation httpPostOperation;
  38. StringWriter writer;
  39. MemoryStream xmlSrc;
  40. XmlTextWriter xmlWriter;
  41. Uri getUrl, postUrl;
  42. Queue referencedTypes;
  43. int hrefID;
  44. bool operationExists = false;
  45. int nextPrefix = 1;
  46. static readonly char[] hexTable = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
  47. bool requestIsLocal = false;
  48. string OperationName {
  49. get { return operationName; }
  50. }
  51. string ServiceName {
  52. get { return serviceDescriptions[0].Services[0].Name; }
  53. }
  54. string ServiceNamespace {
  55. get { return serviceDescriptions[0].TargetNamespace; }
  56. }
  57. string ServiceDocumentation {
  58. get { return serviceDescriptions[0].Services[0].Documentation; }
  59. }
  60. string FileName {
  61. get {
  62. return Path.GetFileName(Request.Path);
  63. }
  64. }
  65. string EscapedFileName {
  66. get {
  67. return HttpUtility.UrlEncode(FileName, Encoding.UTF8);
  68. }
  69. }
  70. bool ShowingMethodList {
  71. get { return operationName == null; }
  72. }
  73. bool OperationExists {
  74. get { return operationExists; }
  75. }
  76. // encodes a Unicode string into utf-8 bytes then copies each byte into a new Unicode string,
  77. // escaping bytes > 0x7f, per the URI escaping rules
  78. static string UTF8EscapeString(string source) {
  79. byte[] bytes = Encoding.UTF8.GetBytes(source);
  80. StringBuilder sb = new StringBuilder(bytes.Length); // start out with enough room to hold each byte as a char
  81. for (int i = 0; i < bytes.Length; i++) {
  82. byte b = bytes[i];
  83. if (b > 0x7f) {
  84. sb.Append('%');
  85. sb.Append(hexTable[(b >> 4) & 0x0f]);
  86. sb.Append(hexTable[(b ) & 0x0f]);
  87. }
  88. else
  89. sb.Append((char)b);
  90. }
  91. return sb.ToString();
  92. }
  93. string EscapeParam(string param) {
  94. return HttpUtility.UrlEncode(param, Request.ContentEncoding);
  95. }
  96. XmlQualifiedName XmlEscapeQName(XmlQualifiedName qname) {
  97. return new XmlQualifiedName(XmlConvert.EncodeLocalName(qname.Name), qname.Namespace);
  98. }
  99. string SoapOperationInput {
  100. get {
  101. if (SoapOperationBinding == null) return "";
  102. WriteBegin();
  103. Port port = FindPort(SoapOperationBinding.Binding);
  104. SoapAddressBinding soapAddress = (SoapAddressBinding)port.Extensions.Find(typeof(SoapAddressBinding));
  105. string action = UTF8EscapeString(((SoapOperationBinding)SoapOperationBinding.Extensions.Find(typeof(SoapOperationBinding))).SoapAction);
  106. Uri uri = new Uri(soapAddress.Location, false);
  107. Write("POST ");
  108. Write(uri.AbsolutePath);
  109. Write(" HTTP/1.1");
  110. WriteLine();
  111. Write("Host: ");
  112. Write(uri.Host);
  113. WriteLine();
  114. Write("Content-Type: text/xml; charset=utf-8");
  115. WriteLine();
  116. Write("Content-Length: ");
  117. WriteValue("length");
  118. WriteLine();
  119. Write("SOAPAction: \"");
  120. Write(action);
  121. Write("\"");
  122. WriteLine();
  123. WriteLine();
  124. WriteSoapMessage(SoapOperationBinding.Input, serviceDescriptions.GetMessage(SoapOperation.Messages.Input.Message));
  125. return WriteEnd();
  126. }
  127. }
  128. string SoapOperationOutput {
  129. get {
  130. if (SoapOperationBinding == null) return "";
  131. WriteBegin();
  132. if (SoapOperationBinding.Output == null) {
  133. Write("HTTP/1.1 202 Accepted");
  134. WriteLine();
  135. }
  136. else {
  137. Write("HTTP/1.1 200 OK");
  138. WriteLine();
  139. Write("Content-Type: text/xml; charset=utf-8");
  140. WriteLine();
  141. Write("Content-Length: ");
  142. WriteValue("length");
  143. WriteLine();
  144. WriteLine();
  145. WriteSoapMessage(SoapOperationBinding.Output, serviceDescriptions.GetMessage(SoapOperation.Messages.Output.Message));
  146. }
  147. return WriteEnd();
  148. }
  149. }
  150. OperationBinding SoapOperationBinding {
  151. get {
  152. if (soapOperationBinding == null)
  153. soapOperationBinding = FindBinding(typeof(SoapBinding));
  154. return soapOperationBinding;
  155. }
  156. }
  157. Operation SoapOperation {
  158. get {
  159. if (soapOperation == null)
  160. soapOperation = FindOperation(SoapOperationBinding);
  161. return soapOperation;
  162. }
  163. }
  164. bool ShowingSoap {
  165. get {
  166. return SoapOperationBinding != null;
  167. }
  168. }
  169. private static string GetEncodedNamespace(string ns) {
  170. if (ns.EndsWith("/"))
  171. return ns + "encodedTypes";
  172. else return ns + "/encodedTypes";
  173. }
  174. void WriteSoapMessage(MessageBinding messageBinding, Message message) {
  175. SoapOperationBinding soapBinding = (SoapOperationBinding)SoapOperationBinding.Extensions.Find(typeof(SoapOperationBinding));
  176. SoapBodyBinding soapBodyBinding = (SoapBodyBinding)messageBinding.Extensions.Find(typeof(SoapBodyBinding));
  177. bool rpc = soapBinding != null && soapBinding.Style == SoapBindingStyle.Rpc;
  178. bool encoded = soapBodyBinding.Use == SoapBindingUse.Encoded;
  179. xmlWriter.WriteStartDocument();
  180. xmlWriter.WriteStartElement("soap", "Envelope", soapNs);
  181. DefineNamespace("xsi", XmlSchema.InstanceNamespace);
  182. DefineNamespace("xsd", XmlSchema.Namespace);
  183. if (encoded) {
  184. DefineNamespace("soapenc", soapEncNs);
  185. string targetNamespace = message.ServiceDescription.TargetNamespace;
  186. DefineNamespace("tns", targetNamespace);
  187. DefineNamespace("types", GetEncodedNamespace(targetNamespace));
  188. }
  189. SoapHeaderBinding[] headers = (SoapHeaderBinding[])messageBinding.Extensions.FindAll(typeof(SoapHeaderBinding));
  190. if (headers.Length > 0) {
  191. xmlWriter.WriteStartElement("Header", soapNs);
  192. foreach (SoapHeaderBinding header in headers) {
  193. Message headerMessage = serviceDescriptions.GetMessage(header.Message);
  194. if (headerMessage != null) {
  195. MessagePart part = headerMessage.Parts[header.Part];
  196. if (part != null) {
  197. if (encoded)
  198. WriteType(part.Type, part.Type, XmlSchemaForm.Qualified, -1, 0, false);
  199. else
  200. WriteTopLevelElement(XmlEscapeQName(part.Element), 0);
  201. }
  202. }
  203. }
  204. if (encoded)
  205. WriteQueuedTypes();
  206. xmlWriter.WriteEndElement();
  207. }
  208. xmlWriter.WriteStartElement("Body", soapNs);
  209. if (soapBodyBinding.Encoding != null && soapBodyBinding.Encoding != String.Empty)
  210. xmlWriter.WriteAttributeString("encodingStyle", soapNs, soapEncNs);
  211. if (rpc) {
  212. string messageName = SoapOperationBinding.Output == messageBinding ? SoapOperation.Name + "Response" : SoapOperation.Name;
  213. if (encoded) {
  214. string prefix = null;
  215. if (soapBodyBinding.Namespace.Length > 0) {
  216. prefix = xmlWriter.LookupPrefix(soapBodyBinding.Namespace);
  217. if (prefix == null)
  218. prefix = "q" + nextPrefix++;
  219. }
  220. xmlWriter.WriteStartElement(prefix, messageName, soapBodyBinding.Namespace);
  221. }
  222. else
  223. xmlWriter.WriteStartElement(messageName, soapBodyBinding.Namespace);
  224. }
  225. foreach (MessagePart part in message.Parts) {
  226. if (encoded) {
  227. if (rpc)
  228. WriteType(new XmlQualifiedName(part.Name, soapBodyBinding.Namespace), part.Type, XmlSchemaForm.Unqualified, 0, 0, true);
  229. else
  230. WriteType(part.Type, part.Type, XmlSchemaForm.Qualified, -1, 0, true); // id == -1 writes the definition without writing the id attr
  231. }
  232. else {
  233. if (!part.Element.IsEmpty)
  234. WriteTopLevelElement(XmlEscapeQName(part.Element), 0);
  235. else
  236. WriteXmlValue("xml");
  237. }
  238. }
  239. if (rpc) {
  240. xmlWriter.WriteEndElement();
  241. }
  242. if (encoded) {
  243. WriteQueuedTypes();
  244. }
  245. xmlWriter.WriteEndElement();
  246. xmlWriter.WriteEndElement();
  247. }
  248. string HttpGetOperationInput {
  249. get {
  250. if (TryGetUrl == null) return "";
  251. WriteBegin();
  252. Write("GET ");
  253. Write(TryGetUrl.AbsolutePath);
  254. Write("?");
  255. WriteQueryStringMessage(serviceDescriptions.GetMessage(HttpGetOperation.Messages.Input.Message));
  256. Write(" HTTP/1.1");
  257. WriteLine();
  258. Write("Host: ");
  259. Write(TryGetUrl.Host);
  260. WriteLine();
  261. return WriteEnd();
  262. }
  263. }
  264. string HttpGetOperationOutput {
  265. get {
  266. if (HttpGetOperationBinding == null) return "";
  267. if (HttpGetOperationBinding.Output == null) return "";
  268. Message message = serviceDescriptions.GetMessage(HttpGetOperation.Messages.Output.Message);
  269. WriteBegin();
  270. Write("HTTP/1.1 200 OK");
  271. WriteLine();
  272. if (message.Parts.Count > 0) {
  273. Write("Content-Type: text/xml; charset=utf-8");
  274. WriteLine();
  275. Write("Content-Length: ");
  276. WriteValue("length");
  277. WriteLine();
  278. WriteLine();
  279. WriteHttpReturnPart(message.Parts[0].Element);
  280. }
  281. return WriteEnd();
  282. }
  283. }
  284. void WriteQueryStringMessage(Message message) {
  285. bool first = true;
  286. foreach (MessagePart part in message.Parts) {
  287. int count = 1;
  288. string typeName = part.Type.Name;
  289. if (part.Type.Namespace != XmlSchema.Namespace && part.Type.Namespace != msTypesNs) {
  290. int arrIndex = typeName.IndexOf("Array");
  291. if (arrIndex >= 0) {
  292. typeName = CodeIdentifier.MakeCamel(typeName.Substring(0, arrIndex));
  293. count = 2;
  294. }
  295. }
  296. for (int i=0; i<count; i++) {
  297. if (first) {
  298. first = false;
  299. }
  300. else {
  301. Write("&amp;");
  302. }
  303. Write("<font class=key>");
  304. Write(part.Name);
  305. Write("</font>=");
  306. WriteValue(typeName);
  307. }
  308. }
  309. }
  310. OperationBinding HttpGetOperationBinding {
  311. get {
  312. if (httpGetOperationBinding == null)
  313. httpGetOperationBinding = FindHttpBinding("GET");
  314. return httpGetOperationBinding;
  315. }
  316. }
  317. Operation HttpGetOperation {
  318. get {
  319. if (httpGetOperation == null)
  320. httpGetOperation = FindOperation(HttpGetOperationBinding);
  321. return httpGetOperation;
  322. }
  323. }
  324. bool ShowingHttpGet {
  325. get {
  326. return HttpGetOperationBinding != null;
  327. }
  328. }
  329. string HttpPostOperationInput {
  330. get {
  331. if (TryPostUrl == null) return "";
  332. WriteBegin();
  333. Write("POST ");
  334. Write(TryPostUrl.AbsolutePath);
  335. Write(" HTTP/1.1");
  336. WriteLine();
  337. Write("Host: ");
  338. Write(TryPostUrl.Host);
  339. WriteLine();
  340. Write("Content-Type: application/x-www-form-urlencoded");
  341. WriteLine();
  342. Write("Content-Length: ");
  343. WriteValue("length");
  344. WriteLine();
  345. WriteLine();
  346. WriteQueryStringMessage(serviceDescriptions.GetMessage(HttpPostOperation.Messages.Input.Message));
  347. return WriteEnd();
  348. }
  349. }
  350. string HttpPostOperationOutput {
  351. get {
  352. if (HttpPostOperationBinding == null) return "";
  353. if (HttpPostOperationBinding.Output == null) return "";
  354. Message message = serviceDescriptions.GetMessage(HttpPostOperation.Messages.Output.Message);
  355. WriteBegin();
  356. Write("HTTP/1.1 200 OK");
  357. WriteLine();
  358. if (message.Parts.Count > 0) {
  359. Write("Content-Type: text/xml; charset=utf-8");
  360. WriteLine();
  361. Write("Content-Length: ");
  362. WriteValue("length");
  363. WriteLine();
  364. WriteLine();
  365. WriteHttpReturnPart(message.Parts[0].Element);
  366. }
  367. return WriteEnd();
  368. }
  369. }
  370. OperationBinding HttpPostOperationBinding {
  371. get {
  372. if (httpPostOperationBinding == null)
  373. httpPostOperationBinding = FindHttpBinding("POST");
  374. return httpPostOperationBinding;
  375. }
  376. }
  377. Operation HttpPostOperation {
  378. get {
  379. if (httpPostOperation == null)
  380. httpPostOperation = FindOperation(HttpPostOperationBinding);
  381. return httpPostOperation;
  382. }
  383. }
  384. bool ShowingHttpPost {
  385. get {
  386. return HttpPostOperationBinding != null;
  387. }
  388. }
  389. MessagePart[] TryGetMessageParts {
  390. get {
  391. if (HttpGetOperationBinding == null) return new MessagePart[0];
  392. Message message = serviceDescriptions.GetMessage(HttpGetOperation.Messages.Input.Message);
  393. MessagePart[] parts = new MessagePart[message.Parts.Count];
  394. message.Parts.CopyTo(parts, 0);
  395. return parts;
  396. }
  397. }
  398. bool ShowGetTestForm {
  399. get {
  400. if (!ShowingHttpGet) return false;
  401. Message message = serviceDescriptions.GetMessage(HttpGetOperation.Messages.Input.Message);
  402. foreach (MessagePart part in message.Parts) {
  403. if (part.Type.Namespace != XmlSchema.Namespace && part.Type.Namespace != msTypesNs)
  404. return false;
  405. }
  406. return true;
  407. }
  408. }
  409. Uri TryGetUrl {
  410. get {
  411. if (getUrl == null) {
  412. if (HttpGetOperationBinding == null) return null;
  413. Port port = FindPort(HttpGetOperationBinding.Binding);
  414. if (port == null) return null;
  415. HttpAddressBinding httpAddress = (HttpAddressBinding)port.Extensions.Find(typeof(HttpAddressBinding));
  416. HttpOperationBinding httpOperation = (HttpOperationBinding)HttpGetOperationBinding.Extensions.Find(typeof(HttpOperationBinding));
  417. if (httpAddress == null || httpOperation == null) return null;
  418. getUrl = new Uri(httpAddress.Location + httpOperation.Location);
  419. }
  420. return getUrl;
  421. }
  422. }
  423. MessagePart[] TryPostMessageParts {
  424. get {
  425. if (HttpPostOperationBinding == null) return new MessagePart[0];
  426. Message message = serviceDescriptions.GetMessage(HttpPostOperation.Messages.Input.Message);
  427. MessagePart[] parts = new MessagePart[message.Parts.Count];
  428. message.Parts.CopyTo(parts, 0);
  429. return parts;
  430. }
  431. }
  432. bool ShowPostTestForm {
  433. get {
  434. if (!ShowingHttpPost) return false;
  435. Message message = serviceDescriptions.GetMessage(HttpPostOperation.Messages.Input.Message);
  436. foreach (MessagePart part in message.Parts) {
  437. if (part.Type.Namespace != XmlSchema.Namespace && part.Type.Namespace != msTypesNs)
  438. return false;
  439. }
  440. return true;
  441. }
  442. }
  443. Uri TryPostUrl {
  444. get {
  445. if (postUrl == null) {
  446. if (HttpPostOperationBinding == null) return null;
  447. Port port = FindPort(HttpPostOperationBinding.Binding);
  448. if (port == null) return null;
  449. HttpAddressBinding httpAddress = (HttpAddressBinding)port.Extensions.Find(typeof(HttpAddressBinding));
  450. HttpOperationBinding httpOperation = (HttpOperationBinding)HttpPostOperationBinding.Extensions.Find(typeof(HttpOperationBinding));
  451. if (httpAddress == null || httpOperation == null) return null;
  452. postUrl = new Uri(httpAddress.Location + httpOperation.Location);
  453. }
  454. return postUrl;
  455. }
  456. }
  457. void WriteHttpReturnPart(XmlQualifiedName elementName) {
  458. if (elementName == null || elementName.IsEmpty) {
  459. Write("&lt;?xml version=\"1.0\"?&gt;");
  460. WriteLine();
  461. WriteValue("xml");
  462. }
  463. else {
  464. xmlWriter.WriteStartDocument();
  465. WriteTopLevelElement(XmlEscapeQName(elementName), 0);
  466. }
  467. }
  468. XmlSchemaType GetPartType(MessagePart part) {
  469. if (part.Element != null && !part.Element.IsEmpty) {
  470. XmlSchemaElement element = (XmlSchemaElement)schemas.Find(part.Element, typeof(XmlSchemaElement));
  471. if (element != null) return element.SchemaType;
  472. return null;
  473. }
  474. else if (part.Type != null && !part.Type.IsEmpty) {
  475. XmlSchemaType xmlSchemaType = (XmlSchemaType)schemas.Find(part.Type, typeof(XmlSchemaSimpleType));
  476. if (xmlSchemaType != null) return xmlSchemaType;
  477. xmlSchemaType = (XmlSchemaType)schemas.Find(part.Type, typeof(XmlSchemaComplexType));
  478. return xmlSchemaType;
  479. }
  480. return null;
  481. }
  482. void WriteTopLevelElement(XmlQualifiedName name, int depth) {
  483. WriteTopLevelElement((XmlSchemaElement)schemas.Find(name, typeof(XmlSchemaElement)), name.Namespace, depth);
  484. }
  485. void WriteTopLevelElement(XmlSchemaElement element, string ns, int depth) {
  486. WriteElement(element, ns, XmlSchemaForm.Qualified, false, 0, depth, false);
  487. }
  488. class QueuedType {
  489. internal XmlQualifiedName name;
  490. internal XmlQualifiedName typeName;
  491. internal XmlSchemaForm form;
  492. internal int id;
  493. internal int depth;
  494. internal bool writeXsiType;
  495. }
  496. void WriteQueuedTypes() {
  497. while (referencedTypes.Count > 0) {
  498. QueuedType q = (QueuedType)referencedTypes.Dequeue();
  499. WriteType(q.name, q.typeName, q.form, q.id, q.depth, q.writeXsiType);
  500. }
  501. }
  502. void AddQueuedType(XmlQualifiedName name, XmlQualifiedName type, int id, int depth, bool writeXsiType) {
  503. AddQueuedType(name, type, XmlSchemaForm.Unqualified, id, depth, writeXsiType);
  504. }
  505. void AddQueuedType(XmlQualifiedName name, XmlQualifiedName typeName, XmlSchemaForm form, int id, int depth, bool writeXsiType) {
  506. QueuedType q = new QueuedType();
  507. q.name = name;
  508. q.typeName = typeName;
  509. q.form = form;
  510. q.id = id;
  511. q.depth = depth;
  512. q.writeXsiType = writeXsiType;
  513. referencedTypes.Enqueue(q);
  514. }
  515. void WriteType(XmlQualifiedName name, XmlQualifiedName typeName, int id, int depth, bool writeXsiType) {
  516. WriteType(name, typeName, XmlSchemaForm.None, id, depth, writeXsiType);
  517. }
  518. void WriteType(XmlQualifiedName name, XmlQualifiedName typeName, XmlSchemaForm form, int id, int depth, bool writeXsiType) {
  519. XmlSchemaElement element = new XmlSchemaElement();
  520. element.Name = name.Name;
  521. element.MaxOccurs = 1;
  522. element.Form = form;
  523. element.SchemaTypeName = typeName;
  524. WriteElement(element, name.Namespace, true, id, depth, writeXsiType);
  525. }
  526. void WriteElement(XmlSchemaElement element, string ns, bool encoded, int id, int depth, bool writeXsiType) {
  527. XmlSchemaForm form = element.Form;
  528. if (form == XmlSchemaForm.None) {
  529. XmlSchema schema = schemas[ns];
  530. if (schema != null) form = schema.ElementFormDefault;
  531. }
  532. WriteElement(element, ns, form, encoded, id, depth, writeXsiType);
  533. }
  534. void WriteElement(XmlSchemaElement element, string ns, XmlSchemaForm form, bool encoded, int id, int depth, bool writeXsiType) {
  535. if (element == null) return;
  536. int count = element.MaxOccurs > 1 ? maxArraySize : 1;
  537. for (int i = 0; i < count; i++) {
  538. XmlQualifiedName elementName = (element.QualifiedName == null || element.QualifiedName.IsEmpty ? new XmlQualifiedName(element.Name, ns) : element.QualifiedName);
  539. if (encoded && count > 1) {
  540. elementName = new XmlQualifiedName("Item", null);
  541. }
  542. if (IsRef(element.RefName)) {
  543. WriteTopLevelElement(XmlEscapeQName(element.RefName), depth);
  544. continue;
  545. }
  546. if (encoded) {
  547. string prefix = null;
  548. if (form != XmlSchemaForm.Unqualified && elementName.Namespace.Length > 0) {
  549. prefix = xmlWriter.LookupPrefix(elementName.Namespace);
  550. if (prefix == null)
  551. prefix = "q" + nextPrefix++;
  552. }
  553. if (id != 0) { // intercept array definitions
  554. XmlSchemaComplexType ct = null;
  555. if (IsStruct(element, out ct)) {
  556. XmlQualifiedName typeName = element.SchemaTypeName;
  557. XmlQualifiedName baseTypeName = GetBaseTypeName(ct);
  558. if (baseTypeName != null && IsArray(baseTypeName))
  559. typeName = baseTypeName;
  560. if (typeName != elementName) {
  561. WriteType(typeName, element.SchemaTypeName, form, id, depth, writeXsiType);
  562. return;
  563. }
  564. }
  565. }
  566. xmlWriter.WriteStartElement(prefix, elementName.Name, form != XmlSchemaForm.Unqualified ? elementName.Namespace : "");
  567. }
  568. else
  569. xmlWriter.WriteStartElement(elementName.Name, form != XmlSchemaForm.Unqualified ? elementName.Namespace : "");
  570. XmlSchemaSimpleType simpleType = null;
  571. XmlSchemaComplexType complexType = null;
  572. if (IsPrimitive(element.SchemaTypeName)) {
  573. if (writeXsiType) WriteTypeAttribute(element.SchemaTypeName);
  574. WritePrimitive(element.SchemaTypeName);
  575. }
  576. else if (IsEnum(element.SchemaTypeName, out simpleType)) {
  577. if (writeXsiType) WriteTypeAttribute(element.SchemaTypeName);
  578. WriteEnum(simpleType);
  579. }
  580. else if (IsStruct(element, out complexType)) {
  581. if (depth >= maxObjectGraphDepth)
  582. WriteNullAttribute(encoded);
  583. else if (encoded) {
  584. if (id != 0) {
  585. // id == -1 means write the definition without writing the id
  586. if (id > 0) {
  587. WriteIDAttribute(id);
  588. }
  589. WriteComplexType(complexType, ns, encoded, depth, writeXsiType);
  590. }
  591. else {
  592. int href = hrefID++;
  593. WriteHref(href);
  594. AddQueuedType(elementName, element.SchemaTypeName, XmlSchemaForm.Qualified, href, depth, true);
  595. }
  596. }
  597. else {
  598. WriteComplexType(complexType, ns, encoded, depth, false);
  599. }
  600. }
  601. else if (IsByteArray(element, out simpleType)) {
  602. WriteByteArray(simpleType);
  603. }
  604. else if (IsSchemaRef(element.RefName)) {
  605. WriteXmlValue("schema");
  606. }
  607. else if (IsUrType(element.SchemaTypeName)) {
  608. WriteTypeAttribute(new XmlQualifiedName(GetXmlValue("type"), null));
  609. }
  610. else {
  611. if (debug) {
  612. WriteDebugAttribute("error", "Unknown type");
  613. WriteDebugAttribute("elementName", element.QualifiedName.ToString());
  614. WriteDebugAttribute("typeName", element.SchemaTypeName.ToString());
  615. WriteDebugAttribute("type", element.SchemaType != null ? element.SchemaType.ToString() : "null");
  616. }
  617. }
  618. xmlWriter.WriteEndElement();
  619. xmlWriter.Formatting = Formatting.Indented;
  620. }
  621. }
  622. bool IsArray(XmlQualifiedName typeName) {
  623. return (typeName.Namespace == soapEncNs && typeName.Name == "Array");
  624. }
  625. bool IsPrimitive(XmlQualifiedName typeName) {
  626. return (!typeName.IsEmpty &&
  627. (typeName.Namespace == XmlSchema.Namespace || typeName.Namespace == msTypesNs) &&
  628. typeName.Name != urType);
  629. }
  630. bool IsRef(XmlQualifiedName refName) {
  631. return refName != null && !refName.IsEmpty && !IsSchemaRef(refName);
  632. }
  633. bool IsSchemaRef(XmlQualifiedName refName) {
  634. return refName != null && refName.Name == "schema" && refName.Namespace == XmlSchema.Namespace;
  635. }
  636. bool IsUrType(XmlQualifiedName typeName) {
  637. return (!typeName.IsEmpty && typeName.Namespace == XmlSchema.Namespace && typeName.Name == urType);
  638. }
  639. bool IsEnum(XmlQualifiedName typeName, out XmlSchemaSimpleType type) {
  640. XmlSchemaSimpleType simpleType = null;
  641. if (typeName != null && !typeName.IsEmpty) {
  642. simpleType = (XmlSchemaSimpleType)schemas.Find(typeName, typeof(XmlSchemaSimpleType));
  643. if (simpleType != null) {
  644. type = simpleType;
  645. return true;
  646. }
  647. }
  648. type = null;
  649. return false;
  650. }
  651. bool IsStruct(XmlSchemaElement element, out XmlSchemaComplexType type) {
  652. XmlSchemaComplexType complexType = null;
  653. if (!element.SchemaTypeName.IsEmpty) {
  654. complexType = (XmlSchemaComplexType)schemas.Find(element.SchemaTypeName, typeof(XmlSchemaComplexType));
  655. if (complexType != null) {
  656. type = complexType;
  657. return true;
  658. }
  659. }
  660. if (element.SchemaType != null && element.SchemaType is XmlSchemaComplexType) {
  661. complexType = element.SchemaType as XmlSchemaComplexType;
  662. if (complexType != null) {
  663. type = complexType;
  664. return true;
  665. }
  666. }
  667. type = null;
  668. return false;
  669. }
  670. bool IsByteArray(XmlSchemaElement element, out XmlSchemaSimpleType type) {
  671. if (element.SchemaTypeName.IsEmpty && element.SchemaType is XmlSchemaSimpleType) {
  672. type = element.SchemaType as XmlSchemaSimpleType;
  673. return true;
  674. }
  675. type = null;
  676. return false;
  677. }
  678. XmlQualifiedName ArrayItemType(string typeDef) {
  679. string ns;
  680. string name;
  681. int nsLen = typeDef.LastIndexOf(':');
  682. if (nsLen <= 0) {
  683. ns = "";
  684. }
  685. else {
  686. ns = typeDef.Substring(0, nsLen);
  687. }
  688. int nameLen = typeDef.IndexOf('[', nsLen + 1);
  689. if (nameLen <= nsLen) {
  690. return new XmlQualifiedName(urType, XmlSchema.Namespace);
  691. }
  692. name = typeDef.Substring(nsLen + 1, nameLen - nsLen - 1);
  693. return new XmlQualifiedName(name, ns);
  694. }
  695. void WriteByteArray(XmlSchemaSimpleType dataType) {
  696. WriteXmlValue("bytes");
  697. }
  698. void WriteEnum(XmlSchemaSimpleType dataType) {
  699. if (dataType.Content is XmlSchemaSimpleTypeList) { // "flags" enum -- appears inside a list
  700. XmlSchemaSimpleTypeList list = (XmlSchemaSimpleTypeList)dataType.Content;
  701. dataType = list.ItemType;
  702. }
  703. bool first = true;
  704. if (dataType.Content is XmlSchemaSimpleTypeRestriction) {
  705. XmlSchemaSimpleTypeRestriction restriction = (XmlSchemaSimpleTypeRestriction)dataType.Content;
  706. foreach (XmlSchemaFacet facet in restriction.Facets) {
  707. if (facet is XmlSchemaEnumerationFacet) {
  708. if (!first) xmlWriter.WriteString(" or "); else first = false;
  709. WriteXmlValue(facet.Value);
  710. }
  711. }
  712. }
  713. }
  714. void WriteArrayTypeAttribute(XmlQualifiedName type, int maxOccurs) {
  715. StringBuilder sb = new StringBuilder(type.Name);
  716. sb.Append("[");
  717. sb.Append(maxOccurs.ToString());
  718. sb.Append("]");
  719. string prefix = DefineNamespace("q1", type.Namespace);
  720. XmlQualifiedName typeName = new XmlQualifiedName(sb.ToString(), prefix);
  721. xmlWriter.WriteAttributeString("arrayType", soapEncNs, typeName.ToString());
  722. }
  723. void WriteTypeAttribute(XmlQualifiedName type) {
  724. string prefix = DefineNamespace("s0", type.Namespace);
  725. xmlWriter.WriteStartAttribute("type", XmlSchema.InstanceNamespace);
  726. xmlWriter.WriteString(new XmlQualifiedName(type.Name, prefix).ToString());
  727. xmlWriter.WriteEndAttribute();
  728. }
  729. void WriteNullAttribute(bool encoded) {
  730. if (encoded)
  731. xmlWriter.WriteAttributeString("null", XmlSchema.InstanceNamespace, "1");
  732. else
  733. xmlWriter.WriteAttributeString("nil", XmlSchema.InstanceNamespace, "true");
  734. }
  735. void WriteIDAttribute(int href) {
  736. xmlWriter.WriteAttributeString("id", "id" + href.ToString());
  737. }
  738. void WriteHref(int href) {
  739. xmlWriter.WriteAttributeString("href", "#id" + href.ToString());
  740. }
  741. void WritePrimitive(XmlQualifiedName name) {
  742. if (name.Namespace == XmlSchema.Namespace && name.Name == "QName") {
  743. DefineNamespace("q1", "http://tempuri.org/SampleNamespace");
  744. WriteXmlValue("q1:QName");
  745. }
  746. else
  747. WriteXmlValue(name.Name);
  748. }
  749. XmlQualifiedName GetBaseTypeName(XmlSchemaComplexType complexType) {
  750. if (complexType.ContentModel is XmlSchemaComplexContent) {
  751. XmlSchemaComplexContent content = (XmlSchemaComplexContent)complexType.ContentModel;
  752. if (content.Content is XmlSchemaComplexContentRestriction) {
  753. XmlSchemaComplexContentRestriction restriction = (XmlSchemaComplexContentRestriction)content.Content;
  754. return restriction.BaseTypeName;
  755. }
  756. }
  757. return null;
  758. }
  759. internal class TypeItems {
  760. internal XmlSchemaObjectCollection Attributes = new XmlSchemaObjectCollection();
  761. internal XmlSchemaAnyAttribute AnyAttribute;
  762. internal XmlSchemaObjectCollection Items = new XmlSchemaObjectCollection();
  763. internal XmlQualifiedName baseSimpleType;
  764. }
  765. TypeItems GetTypeItems(XmlSchemaComplexType type) {
  766. TypeItems items = new TypeItems();
  767. if (type == null)
  768. return items;
  769. XmlSchemaParticle particle = null;
  770. if (type.ContentModel != null) {
  771. XmlSchemaContent content = type.ContentModel.Content;
  772. if (content is XmlSchemaComplexContentExtension) {
  773. XmlSchemaComplexContentExtension extension = (XmlSchemaComplexContentExtension)content;
  774. items.Attributes = extension.Attributes;
  775. items.AnyAttribute = extension.AnyAttribute;
  776. particle = extension.Particle;
  777. }
  778. else if (content is XmlSchemaComplexContentRestriction) {
  779. XmlSchemaComplexContentRestriction restriction = (XmlSchemaComplexContentRestriction)content;
  780. items.Attributes = restriction.Attributes;
  781. items.AnyAttribute = restriction.AnyAttribute;
  782. particle = restriction.Particle;
  783. }
  784. else if (content is XmlSchemaSimpleContentExtension) {
  785. XmlSchemaSimpleContentExtension extension = (XmlSchemaSimpleContentExtension)content;
  786. items.Attributes = extension.Attributes;
  787. items.AnyAttribute = extension.AnyAttribute;
  788. items.baseSimpleType = extension.BaseTypeName;
  789. }
  790. else if (content is XmlSchemaSimpleContentRestriction) {
  791. XmlSchemaSimpleContentRestriction restriction = (XmlSchemaSimpleContentRestriction)content;
  792. items.Attributes = restriction.Attributes;
  793. items.AnyAttribute = restriction.AnyAttribute;
  794. items.baseSimpleType = restriction.BaseTypeName;
  795. }
  796. }
  797. else {
  798. items.Attributes = type.Attributes;
  799. items.AnyAttribute = type.AnyAttribute;
  800. particle = type.Particle;
  801. }
  802. if (particle != null) {
  803. if (particle is XmlSchemaGroupRef) {
  804. XmlSchemaGroupRef refGroup = (XmlSchemaGroupRef)particle;
  805. XmlSchemaGroup group = (XmlSchemaGroup)schemas.Find(refGroup.RefName, typeof(XmlSchemaGroup));
  806. if (group != null) {
  807. items.Items = group.Particle.Items;
  808. }
  809. }
  810. else if (particle is XmlSchemaGroupBase) {
  811. items.Items = ((XmlSchemaGroupBase)particle).Items;
  812. }
  813. }
  814. return items;
  815. }
  816. void WriteComplexType(XmlSchemaComplexType type, string ns, bool encoded, int depth, bool writeXsiType) {
  817. bool wroteArrayType = false;
  818. bool isSoapArray = false;
  819. TypeItems typeItems = GetTypeItems(type);
  820. if (encoded) {
  821. /*
  822. Check to see if the type looks like the new WSDL 1.1 array delaration:
  823. <xsd:complexType name="ArrayOfInt">
  824. <xsd:complexContent mixed="false">
  825. <xsd:restriction base="soapenc:Array">
  826. <xsd:attribute ref="soapenc:arrayType" wsdl:arrayType="xsd:int[]" />
  827. </xsd:restriction>
  828. </xsd:complexContent>
  829. </xsd:complexType>
  830. */
  831. XmlQualifiedName itemType = null;
  832. XmlQualifiedName topItemType = null;
  833. string brackets = "";
  834. XmlSchemaComplexType t = type;
  835. XmlQualifiedName baseTypeName = GetBaseTypeName(t);
  836. TypeItems arrayItems = typeItems;
  837. while (t != null) {
  838. XmlSchemaObjectCollection attributes = arrayItems.Attributes;
  839. t = null; // if we don't set t after this stop looping
  840. if (baseTypeName != null && IsArray(baseTypeName) && attributes.Count > 0) {
  841. XmlSchemaAttribute refAttr = attributes[0] as XmlSchemaAttribute;
  842. if (refAttr != null) {
  843. XmlQualifiedName qnameArray = refAttr.RefName;
  844. if (qnameArray.Namespace == soapEncNs && qnameArray.Name == "arrayType") {
  845. isSoapArray = true;
  846. XmlAttribute typeAttribute = refAttr.UnhandledAttributes[0];
  847. if (typeAttribute.NamespaceURI == wsdlNs && typeAttribute.LocalName == "arrayType") {
  848. itemType = ArrayItemType(typeAttribute.Value);
  849. if (topItemType == null)
  850. topItemType = itemType;
  851. else
  852. brackets += "[]";
  853. if (!IsPrimitive(itemType)) {
  854. t = (XmlSchemaComplexType)schemas.Find(itemType, typeof(XmlSchemaComplexType));
  855. arrayItems = GetTypeItems(t);
  856. }
  857. }
  858. }
  859. }
  860. }
  861. }
  862. if (itemType != null) {
  863. wroteArrayType = true;
  864. if (IsUrType(itemType))
  865. WriteArrayTypeAttribute(new XmlQualifiedName(GetXmlValue("type") + brackets, null), maxArraySize);
  866. else
  867. WriteArrayTypeAttribute(new XmlQualifiedName(itemType.Name + brackets, itemType.Namespace), maxArraySize);
  868. for (int i = 0; i < maxArraySize; i++) {
  869. WriteType(new XmlQualifiedName("Item", null), topItemType, 0, depth+1, false);
  870. }
  871. }
  872. }
  873. if (writeXsiType && !wroteArrayType) {
  874. WriteTypeAttribute(type.QualifiedName);
  875. }
  876. if (!isSoapArray) {
  877. foreach (XmlSchemaAttribute attr in typeItems.Attributes) {
  878. if (attr != null && attr.Use != XmlSchemaUse.Prohibited) {
  879. if (attr.Form == XmlSchemaForm.Qualified && attr.QualifiedName != null)
  880. xmlWriter.WriteStartAttribute(attr.Name, attr.QualifiedName.Namespace);
  881. else
  882. xmlWriter.WriteStartAttribute(attr.Name, null);
  883. XmlSchemaSimpleType dataType = null;
  884. // special code for the QNames
  885. if (attr.SchemaTypeName.Namespace == XmlSchema.Namespace && attr.SchemaTypeName.Name == "QName") {
  886. WriteXmlValue("q1:QName");
  887. xmlWriter.WriteEndAttribute();
  888. DefineNamespace("q1", "http://tempuri.org/SampleNamespace");
  889. }
  890. else {
  891. if (IsPrimitive(attr.SchemaTypeName))
  892. WriteXmlValue(attr.SchemaTypeName.Name);
  893. else if (IsEnum(attr.SchemaTypeName, out dataType))
  894. WriteEnum(dataType);
  895. xmlWriter.WriteEndAttribute();
  896. }
  897. }
  898. }
  899. }
  900. XmlSchemaObjectCollection items = typeItems.Items;
  901. foreach (object item in items) {
  902. if (item is XmlSchemaElement) {
  903. WriteElement((XmlSchemaElement)item, ns, encoded, 0, depth + 1, encoded);
  904. }
  905. else if (item is XmlSchemaAny) {
  906. XmlSchemaAny any = (XmlSchemaAny)item;
  907. XmlSchema schema = schemas[any.Namespace];
  908. if (schema == null) {
  909. WriteXmlValue("xml");
  910. }
  911. else {
  912. foreach (object schemaItem in schema.Items) {
  913. if (schemaItem is XmlSchemaElement) {
  914. if (IsDataSetRoot((XmlSchemaElement)schemaItem))
  915. WriteXmlValue("dataset");
  916. else
  917. WriteTopLevelElement((XmlSchemaElement)schemaItem, any.Namespace, depth + 1);
  918. }
  919. }
  920. }
  921. }
  922. }
  923. }
  924. bool IsDataSetRoot(XmlSchemaElement element) {
  925. if (element.UnhandledAttributes == null) return false;
  926. foreach (XmlAttribute a in element.UnhandledAttributes) {
  927. if (a.NamespaceURI == "urn:schemas-microsoft-com:xml-msdata" && a.LocalName == "IsDataSet")
  928. return true;
  929. }
  930. return false;
  931. }
  932. void WriteBegin() {
  933. writer = new StringWriter();
  934. xmlSrc = new MemoryStream();
  935. xmlWriter = new XmlTextWriter(xmlSrc, new UTF8Encoding(false));
  936. xmlWriter.Formatting = Formatting.Indented;
  937. xmlWriter.Indentation = 2;
  938. referencedTypes = new Queue();
  939. hrefID = 1;
  940. }
  941. string WriteEnd() {
  942. xmlWriter.Flush();
  943. xmlSrc.Position = 0;
  944. StreamReader reader = new StreamReader(xmlSrc, Encoding.UTF8);
  945. writer.Write(HtmlEncode(reader.ReadToEnd()));
  946. return writer.ToString();
  947. }
  948. string HtmlEncode(string text) {
  949. StringBuilder sb = new StringBuilder();
  950. for (int i=0; i<text.Length; i++) {
  951. char c = text[i];
  952. if (c == '&') {
  953. string special = ReadComment(text, i);
  954. if (special.Length > 0) {
  955. sb.Append(Server.HtmlDecode(special));
  956. i += (special.Length + "&lt;!--".Length + "--&gt;".Length - 1);
  957. }
  958. else
  959. sb.Append("&amp;");
  960. }
  961. else if (c == '<')
  962. sb.Append("&lt;");
  963. else if (c == '>')
  964. sb.Append("&gt;");
  965. else
  966. sb.Append(c);
  967. }
  968. return sb.ToString();
  969. }
  970. string ReadComment(string text, int index) {
  971. if (dontFilterXml) return String.Empty;
  972. if (String.Compare(text, index, "&lt;!--", 0, "&lt;!--".Length, false, CultureInfo.InvariantCulture) == 0) {
  973. int start = index + "&lt;!--".Length;
  974. int end = text.IndexOf("--&gt;", start);
  975. if (end < 0) return String.Empty;
  976. return text.Substring(start, end-start);
  977. }
  978. return String.Empty;
  979. }
  980. void Write(string text) {
  981. writer.Write(text);
  982. }
  983. void WriteLine() {
  984. writer.WriteLine();
  985. }
  986. void WriteValue(string text) {
  987. Write("<font class=value>" + text + "</font>");
  988. }
  989. void WriteStartXmlValue() {
  990. xmlWriter.WriteString("<!--<font class=value>");
  991. }
  992. void WriteEndXmlValue() {
  993. xmlWriter.WriteString("</font>-->");
  994. }
  995. void WriteDebugAttribute(string text) {
  996. WriteDebugAttribute("debug", text);
  997. }
  998. void WriteDebugAttribute(string id, string text) {
  999. xmlWriter.WriteAttributeString(id, text);
  1000. }
  1001. string GetXmlValue(string text) {
  1002. return "<!--<font class=value>" + text + "</font>-->";
  1003. }
  1004. void WriteXmlValue(string text) {
  1005. xmlWriter.WriteString(GetXmlValue(text));
  1006. }
  1007. string DefineNamespace(string prefix, string ns) {
  1008. if (ns == null || ns == String.Empty) return null;
  1009. string existingPrefix = xmlWriter.LookupPrefix(ns);
  1010. if (existingPrefix != null && existingPrefix.Length > 0)
  1011. return existingPrefix;
  1012. xmlWriter.WriteAttributeString("xmlns", prefix, null, ns);
  1013. return prefix;
  1014. }
  1015. Port FindPort(Binding binding) {
  1016. foreach (ServiceDescription description in serviceDescriptions) {
  1017. foreach (Service service in description.Services) {
  1018. foreach (Port port in service.Ports) {
  1019. if (port.Binding.Name == binding.Name &&
  1020. port.Binding.Namespace == binding.ServiceDescription.TargetNamespace) {
  1021. return port;
  1022. }
  1023. }
  1024. }
  1025. }
  1026. return null;
  1027. }
  1028. OperationBinding FindBinding(Type bindingType) {
  1029. OperationBinding nextBestMatch = null;
  1030. foreach (ServiceDescription description in serviceDescriptions) {
  1031. foreach (Binding binding in description.Bindings) {
  1032. object ext = binding.Extensions.Find(bindingType);
  1033. if (ext == null) continue;
  1034. foreach (OperationBinding operationBinding in binding.Operations) {
  1035. string messageName = operationBinding.Input.Name;
  1036. if (messageName == null || messageName.Length == 0)
  1037. messageName = operationBinding.Name;
  1038. if (messageName == operationName) {
  1039. if (ext.GetType() != bindingType) {
  1040. nextBestMatch = operationBinding; // see if we can do better
  1041. break;
  1042. }
  1043. else
  1044. return operationBinding;
  1045. }
  1046. }
  1047. }
  1048. }
  1049. return nextBestMatch;
  1050. }
  1051. OperationBinding FindHttpBinding(string verb) {
  1052. foreach (ServiceDescription description in serviceDescriptions) {
  1053. foreach (Binding binding in description.Bindings) {
  1054. HttpBinding httpBinding = (HttpBinding)binding.Extensions.Find(typeof(HttpBinding));
  1055. if (httpBinding == null)
  1056. continue;
  1057. if (httpBinding.Verb != verb)
  1058. continue;
  1059. foreach (OperationBinding operationBinding in binding.Operations) {
  1060. string messageName = operationBinding.Input.Name;
  1061. if (messageName == null || messageName.Length == 0)
  1062. messageName = operationBinding.Name;
  1063. if (messageName == operationName)
  1064. return operationBinding;
  1065. }
  1066. }
  1067. }
  1068. return null;
  1069. }
  1070. Operation FindOperation(OperationBinding operationBinding) {
  1071. PortType portType = serviceDescriptions.GetPortType(operationBinding.Binding.Type);
  1072. foreach (Operation operation in portType.Operations) {
  1073. if (operation.IsBoundBy(operationBinding)) {
  1074. return operation;
  1075. }
  1076. }
  1077. return null;
  1078. }
  1079. string GetLocalizedText(string name) {
  1080. return GetLocalizedText(name, new object[0]);
  1081. }
  1082. string GetLocalizedText(string name, object[] args) {
  1083. ResourceManager rm = (ResourceManager)Application["RM"];
  1084. string val = rm.GetString("HelpGenerator" + name);
  1085. if (val == null) return String.Empty;
  1086. return String.Format(val, args);
  1087. }
  1088. void Page_Load(object sender, EventArgs e) {
  1089. if (Application["RM"] == null) {
  1090. lock (this.GetType()) {
  1091. if (Application["RM"] == null) {
  1092. Application["RM"] = new ResourceManager("System.Web.Services", typeof(System.Web.Services.WebService).Assembly);
  1093. }
  1094. }
  1095. }
  1096. operationName = Request.QueryString["op"];
  1097. // Slots filled on HttpContext:
  1098. // "wsdls" A ServiceDescriptionCollection representing what is displayed for .asmx?wsdl
  1099. // "schemas" An XmlSchemas object containing schemas associated with .asmx?wsdl
  1100. // "wsdlsWithPost" Wsdls the same as "wsdls", plus bindings for the HttpPost protocol.
  1101. // "schemasWithPost" Schemas corresponding to "wsdlsWithPost".
  1102. // The objects stored at "wsdlsWithPost" and "schemasWithPost" are available if
  1103. // the HttpPost protocol is turned on in config.
  1104. // Obtain WSDL contract from Http Context
  1105. XmlSchemas schemasToUse;
  1106. serviceDescriptions = (ServiceDescriptionCollection) Context.Items["wsdlsWithPost"];
  1107. if (serviceDescriptions != null) {
  1108. requestIsLocal = true;
  1109. schemasToUse = (XmlSchemas) Context.Items["schemasWithPost"];
  1110. }
  1111. else {
  1112. serviceDescriptions = (ServiceDescriptionCollection) Context.Items["wsdls"];
  1113. schemasToUse = (XmlSchemas) Context.Items["schemas"];
  1114. }
  1115. schemas = new XmlSchemas();
  1116. foreach (XmlSchema schema in schemasToUse) {
  1117. schemas.Add(schema);
  1118. }
  1119. foreach (ServiceDescription description in serviceDescriptions) {
  1120. foreach (XmlSchema schema in description.Types.Schemas) {
  1121. schemas.Add(schema);
  1122. }
  1123. }
  1124. Hashtable methodsTable = new Hashtable();
  1125. operationExists = false;
  1126. foreach (ServiceDescription description in serviceDescriptions) {
  1127. foreach (PortType portType in description.PortTypes) {
  1128. foreach (Operation operation in portType.Operations) {
  1129. string messageName = operation.Messages.Input.Name;
  1130. if (messageName == null || messageName.Length == 0)
  1131. messageName = operation.Name;
  1132. if (messageName == operationName)
  1133. operationExists = true;
  1134. if (messageName == null)
  1135. messageName = String.Empty;
  1136. methodsTable[messageName] = operation;
  1137. }
  1138. }
  1139. }
  1140. MethodList.DataSource = methodsTable;
  1141. // Databind all values within the page
  1142. Page.DataBind();
  1143. }
  1144. </script>
  1145. <head>
  1146. <link rel="alternate" type="text/xml" href="<%#FileName%>?disco"/>
  1147. <style type="text/css">
  1148. BODY { <%#GetLocalizedText("StyleBODY")%> }
  1149. #content { <%#GetLocalizedText("Stylecontent")%> }
  1150. A:link { <%#GetLocalizedText("StyleAlink")%> }
  1151. A:visited { <%#GetLocalizedText("StyleAvisited")%> }
  1152. A:active { <%#GetLocalizedText("StyleAactive")%> }
  1153. A:hover { <%#GetLocalizedText("StyleAhover")%> }
  1154. P { <%#GetLocalizedText("StyleP")%> }
  1155. pre { <%#GetLocalizedText("Stylepre")%> }
  1156. td { <%#GetLocalizedText("Styletd")%> }
  1157. h2 { <%#GetLocalizedText("Styleh2")%> }
  1158. h3 { <%#GetLocalizedText("Styleh3")%> }
  1159. ul { <%#GetLocalizedText("Styleul")%> }
  1160. ol { <%#GetLocalizedText("Styleol")%> }
  1161. li { <%#GetLocalizedText("Styleli")%> }
  1162. font.value { <%#GetLocalizedText("Stylefontvalue")%> }
  1163. font.key { <%#GetLocalizedText("Stylefontkey")%> }
  1164. .heading1 { <%#GetLocalizedText("Styleheading1")%> }
  1165. .button { <%#GetLocalizedText("Stylebutton")%> }
  1166. .frmheader { <%#GetLocalizedText("Stylefrmheader")%> }
  1167. .frmtext { <%#GetLocalizedText("Stylefrmtext")%> }
  1168. .frmInput { <%#GetLocalizedText("StylefrmInput")%> }
  1169. .intro { <%#GetLocalizedText("Styleintro")%> }
  1170. </style>
  1171. <title><%#ServiceName + " " + GetLocalizedText("WebService")%></title>
  1172. </head>
  1173. <body>
  1174. <div id="content">
  1175. <p class="heading1"><%#ServiceName%></p><br>
  1176. <span visible='<%#ShowingMethodList && ServiceDocumentation.Length > 0%>' runat=server>
  1177. <p class="intro"><%#ServiceDocumentation%></p>
  1178. </span>
  1179. <span visible='<%#ShowingMethodList%>' runat=server>
  1180. <p class="intro"><%#GetLocalizedText("OperationsIntro", new object[] { EscapedFileName + "?WSDL" })%></p>
  1181. <asp:repeater id="MethodList" runat=server>
  1182. <headertemplate name="headertemplate">
  1183. <ul>
  1184. </headertemplate>
  1185. <itemtemplate name="itemtemplate">
  1186. <li>
  1187. <a href="<%#EscapedFileName%>?op=<%#EscapeParam(DataBinder.Eval(Container.DataItem, "Key").ToString())%>"><%#DataBinder.Eval(Container.DataItem, "Key")%></a>
  1188. <span visible='<%#((string)DataBinder.Eval(Container.DataItem, "Value.Documentation")).Length>0%>' runat=server>
  1189. <br><%#DataBinder.Eval(Container.DataItem, "Value.Documentation")%>
  1190. </span>
  1191. </li>
  1192. <p>
  1193. </itemtemplate>
  1194. <footertemplate name="footertemplate">
  1195. </ul>
  1196. </footertemplate>
  1197. </asp:repeater>
  1198. </span>
  1199. <span visible='<%#!ShowingMethodList && OperationExists%>' runat=server>
  1200. <p class="intro"><%#GetLocalizedText("LinkBack", new object[] { EscapedFileName })%></p>
  1201. <h2><%#OperationName%></h2>
  1202. <p class="intro"><%#SoapOperationBinding == null ? "" : SoapOperation.Documentation%></p>
  1203. <h3><%#GetLocalizedText("TestHeader")%></h3>
  1204. <% if (!showPost) {
  1205. if (!ShowingHttpGet) { %>
  1206. <%#GetLocalizedText("NoHttpGetTest")%>
  1207. <% }
  1208. else {
  1209. if (!ShowGetTestForm) { %>
  1210. <%#GetLocalizedText("NoTestNonPrimitive")%>
  1211. <% }
  1212. else { %>
  1213. <%#GetLocalizedText("TestText")%>
  1214. <form target="_blank" action='<%#TryGetUrl == null ? "" : TryGetUrl.AbsoluteUri%>' method="GET">
  1215. <asp:repeater datasource='<%#TryGetMessageParts%>' runat=server>
  1216. <headertemplate name="HeaderTemplate">
  1217. <table cellspacing="0" cellpadding="4" frame="box" bordercolor="#dcdcdc" rules="none" style="border-collapse: collapse;">
  1218. <tr visible='<%# TryGetMessageParts.Length > 0%>' runat=server>
  1219. <td class="frmHeader" background="#dcdcdc" style="border-right: 2px solid white;"><%#GetLocalizedText("Parameter")%></td>
  1220. <td class="frmHeader" background="#dcdcdc"><%#GetLocalizedText("Value")%></td>
  1221. </tr>
  1222. </headertemplate>
  1223. <itemtemplate name="ItemTemplate">
  1224. <tr>
  1225. <td class="frmText" style="color: #000000; font-weight:normal;"><%# ((MessagePart)Container.DataItem).Name %>:</td>
  1226. <td><input class="frmInput" type="text" size="50" name="<%# ((MessagePart)Container.DataItem).Name %>"></td>
  1227. </tr>
  1228. </itemtemplate>
  1229. <footertemplate name="FooterTemplate">
  1230. <tr>
  1231. <td></td>
  1232. <td align="right"> <input type="submit" value="<%#GetLocalizedText("InvokeButton")%>" class="button"></td>
  1233. </tr>
  1234. </table>
  1235. </footertemplate>
  1236. </asp:repeater>
  1237. </form>
  1238. <% }
  1239. }
  1240. }
  1241. else { // showPost
  1242. if (!ShowingHttpPost) {
  1243. if (requestIsLocal) { %>
  1244. <%#GetLocalizedText("NoTestNonPrimitive")%>
  1245. <% }
  1246. else { %>
  1247. <%#GetLocalizedText("NoTestFormRemote")%>
  1248. <% }
  1249. }
  1250. else {
  1251. if (!ShowPostTestForm) { %>
  1252. <%#GetLocalizedText("NoTestNonPrimitive")%>
  1253. <% }
  1254. else { %>
  1255. <%#GetLocalizedText("TestText")%>
  1256. <form target="_blank" action='<%#TryPostUrl == null ? "" : TryPostUrl.AbsoluteUri%>' method="POST">
  1257. <asp:repeater datasource='<%#TryPostMessageParts%>' runat=server>
  1258. <headertemplate name="HeaderTemplate">
  1259. <table cellspacing="0" cellpadding="4" frame="box" bordercolor="#dcdcdc" rules="none" style="border-collapse: collapse;">
  1260. <tr visible='<%# TryPostMessageParts.Length > 0%>' runat=server>
  1261. <td class="frmHeader" background="#dcdcdc" style="border-right: 2px solid white;"><%#GetLocalizedText("Parameter")%></td>
  1262. <td class="frmHeader" background="#dcdcdc"><%#GetLocalizedText("Value")%></td>
  1263. </tr>
  1264. </headertemplate>
  1265. <itemtemplate name="ItemTemplate">
  1266. <tr>
  1267. <td class="frmText" style="color: #000000; font-weight: normal;"><%# ((MessagePart)Container.DataItem).Name %>:</td>
  1268. <td><input class="frmInput" type="text" size="50" name="<%# ((MessagePart)Container.DataItem).Name %>"></td>
  1269. </tr>
  1270. </itemtemplate>
  1271. <footertemplate name="FooterTemplate">
  1272. <tr>
  1273. <td></td>
  1274. <td align="right"> <input type="submit" value="<%#GetLocalizedText("InvokeButton")%>" class="button"></td>
  1275. </tr>
  1276. </table>
  1277. </footertemplate>
  1278. </asp:repeater>
  1279. </form>
  1280. <% }
  1281. }
  1282. } %>
  1283. <span visible='<%#ShowingSoap%>' runat=server>
  1284. <h3><%#GetLocalizedText("SoapTitle")%></h3>
  1285. <p><%#GetLocalizedText("SoapText")%></p>
  1286. <pre><%#SoapOperationInput%></pre>
  1287. <pre><%#SoapOperationOutput%></pre>
  1288. </span>
  1289. <span visible='<%#ShowingHttpGet%>' runat=server>
  1290. <h3><%#GetLocalizedText("HttpGetTitle")%></h3>
  1291. <p><%#GetLocalizedText("HttpGetText")%></p>
  1292. <pre><%#HttpGetOperationInput%></pre>
  1293. <pre><%#HttpGetOperationOutput%></pre>
  1294. </span>
  1295. <span visible='<%#ShowingHttpPost%>' runat=server>
  1296. <h3><%#GetLocalizedText("HttpPostTitle")%></h3>
  1297. <p><%#GetLocalizedText("HttpPostText")%></p>
  1298. <pre><%#HttpPostOperationInput%></pre>
  1299. <pre><%#HttpPostOperationOutput%></pre>
  1300. </span>
  1301. </span>
  1302. <span visible='<%#ShowingMethodList && ServiceNamespace == "http://tempuri.org/"%>' runat=server>
  1303. <hr>
  1304. <h3><%#GetLocalizedText("DefaultNamespaceWarning1")%></h3>
  1305. <h3><%#GetLocalizedText("DefaultNamespaceWarning2")%></h3>
  1306. <p class="intro"><%#GetLocalizedText("DefaultNamespaceHelp1")%></p>
  1307. <p class="intro"><%#GetLocalizedText("DefaultNamespaceHelp2")%></p>
  1308. <p class="intro"><%#GetLocalizedText("DefaultNamespaceHelp3")%></p>
  1309. <p class="intro">C#</p>
  1310. <pre>[WebService(Namespace="http://microsoft.com/webservices/")]
  1311. public class MyWebService {
  1312. // <%#GetLocalizedText("Implementation")%>
  1313. }</pre>
  1314. <p class="intro">Visual Basic.NET</p>
  1315. <pre>&lt;WebService(Namespace:="http://microsoft.com/webservices/")&gt; Public Class MyWebService
  1316. ' <%#GetLocalizedText("Implementation")%>
  1317. End Class</pre>
  1318. <p class="intro"><%#GetLocalizedText("DefaultNamespaceHelp4")%></p>
  1319. <p class="intro"><%#GetLocalizedText("DefaultNamespaceHelp5")%></p>
  1320. <p class="intro"><%#GetLocalizedText("DefaultNamespaceHelp6")%></p>
  1321. </span>
  1322. <span visible='<%#!ShowingMethodList && !OperationExists%>' runat=server>
  1323. <%#GetLocalizedText("LinkBack", new object[] { EscapedFileName })%>
  1324. <h2><%#GetLocalizedText("MethodNotFound")%></h2>
  1325. <%#GetLocalizedText("MethodNotFoundText", new object[] { Server.HtmlEncode(OperationName), ServiceName })%>
  1326. </span>
  1327. </body>
  1328. </html>