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.

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