WebServicesInteroperability.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. //
  2. // System.Web.Services.Description.WebServicesInteroperability.cs
  3. //
  4. // Author:
  5. // Lluis Sanchez ([email protected])
  6. //
  7. // Copyright (C) Novell, Inc., 2004
  8. //
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. #if NET_2_0
  30. using System.Collections;
  31. using System.Xml.Schema;
  32. namespace System.Web.Services.Description
  33. {
  34. public sealed class WebServicesInteroperability
  35. {
  36. private WebServicesInteroperability ()
  37. {
  38. }
  39. [MonoTODO]
  40. public static bool CheckConformance (WsiClaims claims, ServiceDescription service, BasicProfileViolationCollection violations)
  41. {
  42. ServiceDescriptionCollection col = new ServiceDescriptionCollection ();
  43. col.Add (service);
  44. ConformanceCheckContext ctx = new ConformanceCheckContext (col, violations);
  45. return Check (claims, ctx, col);
  46. }
  47. [MonoTODO]
  48. public static bool CheckConformance (WsiClaims claims, ServiceDescriptionCollection services, BasicProfileViolationCollection violations)
  49. {
  50. ConformanceCheckContext ctx = new ConformanceCheckContext (services, violations);
  51. return Check (claims, ctx, services);
  52. }
  53. [MonoTODO]
  54. public static bool CheckConformance (WsiClaims claims, WebReference webReference, BasicProfileViolationCollection violations)
  55. {
  56. ConformanceCheckContext ctx = new ConformanceCheckContext (webReference, violations);
  57. return Check (claims, ctx, webReference.Documents.Values);
  58. }
  59. static bool Check (WsiClaims claims, ConformanceCheckContext ctx, IEnumerable documents)
  60. {
  61. ConformanceChecker[] checkers = GetCheckers (claims);
  62. if (checkers == null) return true;
  63. foreach (object doc in documents) {
  64. if (!(doc is ServiceDescription)) continue;
  65. foreach (ConformanceChecker c in checkers)
  66. Check (ctx, c, (ServiceDescription)doc);
  67. }
  68. return ctx.Violations.Count == 0;
  69. }
  70. static ConformanceChecker[] GetCheckers (WsiClaims claims)
  71. {
  72. if ((claims & WsiClaims.BP10) != 0)
  73. return new ConformanceChecker[] { BasicProfileChecker.Instance };
  74. return null;
  75. }
  76. static void Check (ConformanceCheckContext ctx, ConformanceChecker checker, ServiceDescription sd)
  77. {
  78. ctx.ServiceDescription = sd;
  79. ctx.Checker = checker;
  80. checker.Check (ctx, sd);
  81. CheckExtensions (ctx, checker, sd.Extensions);
  82. foreach (Import i in sd.Imports) {
  83. checker.Check (ctx, i);
  84. }
  85. foreach (Service s in sd.Services) {
  86. checker.Check (ctx, s);
  87. foreach (Port p in s.Ports) {
  88. checker.Check (ctx, p);
  89. CheckExtensions (ctx, checker, p.Extensions);
  90. }
  91. }
  92. foreach (Binding b in sd.Bindings)
  93. {
  94. checker.Check (ctx, b);
  95. CheckExtensions (ctx, checker, b.Extensions);
  96. foreach (OperationBinding oper in b.Operations) {
  97. CheckExtensions (ctx, checker, oper.Extensions);
  98. foreach (MessageBinding mb in oper.Faults) {
  99. checker.Check (ctx, mb);
  100. CheckExtensions (ctx, checker, mb.Extensions);
  101. }
  102. checker.Check (ctx, oper.Input);
  103. CheckExtensions (ctx, checker, oper.Input.Extensions);
  104. checker.Check (ctx, oper.Output);
  105. CheckExtensions (ctx, checker, oper.Output.Extensions);
  106. }
  107. }
  108. foreach (PortType pt in sd.PortTypes)
  109. {
  110. checker.Check (ctx, pt);
  111. foreach (Operation oper in pt.Operations) {
  112. checker.Check (ctx, oper);
  113. foreach (OperationMessage msg in oper.Messages)
  114. checker.Check (ctx, msg);
  115. foreach (OperationMessage msg in oper.Faults)
  116. checker.Check (ctx, msg);
  117. }
  118. }
  119. foreach (Message msg in sd.Messages)
  120. {
  121. checker.Check (ctx, msg);
  122. foreach (MessagePart part in msg.Parts)
  123. checker.Check (ctx, part);
  124. }
  125. if (sd.Types != null) {
  126. checker.Check (ctx, sd.Types);
  127. if (sd.Types.Schemas != null) {
  128. foreach (XmlSchema s in sd.Types.Schemas) {
  129. ctx.CurrentSchema = s;
  130. checker.Check (ctx, s);
  131. CheckObjects (ctx, checker, new Hashtable (), s.Items);
  132. }
  133. }
  134. }
  135. }
  136. static void CheckObjects (ConformanceCheckContext ctx, ConformanceChecker checker, Hashtable visitedObjects, XmlSchemaObjectCollection col)
  137. {
  138. foreach (XmlSchemaObject item in col)
  139. Check (ctx, checker, visitedObjects, item);
  140. }
  141. static void Check (ConformanceCheckContext ctx, ConformanceChecker checker, Hashtable visitedObjects, XmlSchemaObject value)
  142. {
  143. if (value == null) return;
  144. if (visitedObjects.Contains (value)) return;
  145. visitedObjects.Add (value, value);
  146. if (value is XmlSchemaImport) {
  147. XmlSchemaImport so = (XmlSchemaImport) value;
  148. checker.Check (ctx, so);
  149. }
  150. else if (value is XmlSchemaAll) {
  151. XmlSchemaAll so = (XmlSchemaAll) value;
  152. checker.Check (ctx, so);
  153. CheckObjects (ctx, checker, visitedObjects, so.Items);
  154. }
  155. else if (value is XmlSchemaAnnotation) {
  156. XmlSchemaAnnotation so = (XmlSchemaAnnotation) value;
  157. checker.Check (ctx, so);
  158. CheckObjects (ctx, checker, visitedObjects, so.Items);
  159. }
  160. else if (value is XmlSchemaAttribute) {
  161. XmlSchemaAttribute so = (XmlSchemaAttribute) value;
  162. checker.Check (ctx, so);
  163. }
  164. else if (value is XmlSchemaAttributeGroup) {
  165. XmlSchemaAttributeGroup so = (XmlSchemaAttributeGroup) value;
  166. checker.Check (ctx, so);
  167. CheckObjects (ctx, checker, visitedObjects, so.Attributes);
  168. Check (ctx, checker, visitedObjects, so.AnyAttribute);
  169. Check (ctx, checker, visitedObjects, so.RedefinedAttributeGroup);
  170. }
  171. else if (value is XmlSchemaAttributeGroupRef) {
  172. XmlSchemaAttributeGroupRef so = (XmlSchemaAttributeGroupRef) value;
  173. checker.Check (ctx, so);
  174. }
  175. else if (value is XmlSchemaChoice) {
  176. XmlSchemaChoice so = (XmlSchemaChoice) value;
  177. checker.Check (ctx, so);
  178. CheckObjects (ctx, checker, visitedObjects, so.Items);
  179. }
  180. else if (value is XmlSchemaComplexContent) {
  181. XmlSchemaComplexContent so = (XmlSchemaComplexContent) value;
  182. checker.Check (ctx, so);
  183. Check (ctx, checker, visitedObjects, so.Content);
  184. }
  185. else if (value is XmlSchemaComplexContentExtension) {
  186. XmlSchemaComplexContentExtension so = (XmlSchemaComplexContentExtension) value;
  187. checker.Check (ctx, so);
  188. Check (ctx, checker, visitedObjects, so.Particle);
  189. CheckObjects (ctx, checker, visitedObjects, so.Attributes);
  190. Check (ctx, checker, visitedObjects, so.AnyAttribute);
  191. }
  192. else if (value is XmlSchemaComplexContentRestriction) {
  193. XmlSchemaComplexContentRestriction so = (XmlSchemaComplexContentRestriction) value;
  194. checker.Check (ctx, so);
  195. Check (ctx, checker, visitedObjects, so.Particle);
  196. CheckObjects (ctx, checker, visitedObjects, so.Attributes);
  197. Check (ctx, checker, visitedObjects, so.AnyAttribute);
  198. }
  199. else if (value is XmlSchemaComplexType) {
  200. XmlSchemaComplexType so = (XmlSchemaComplexType) value;
  201. checker.Check (ctx, so);
  202. Check (ctx, checker, visitedObjects, so.ContentModel);
  203. Check (ctx, checker, visitedObjects, so.Particle);
  204. CheckObjects (ctx, checker, visitedObjects, so.Attributes);
  205. Check (ctx, checker, visitedObjects, so.AnyAttribute);
  206. Check (ctx, checker, visitedObjects, so.ContentTypeParticle);
  207. Check (ctx, checker, visitedObjects, so.AttributeWildcard);
  208. }
  209. else if (value is XmlSchemaElement) {
  210. XmlSchemaElement so = (XmlSchemaElement) value;
  211. checker.Check (ctx, so);
  212. Check (ctx, checker, visitedObjects, so.SchemaType);
  213. CheckObjects (ctx, checker, visitedObjects, so.Constraints);
  214. }
  215. else if (value is XmlSchemaGroup) {
  216. XmlSchemaGroup so = (XmlSchemaGroup) value;
  217. checker.Check (ctx, so);
  218. Check (ctx, checker, visitedObjects, so.Particle);
  219. }
  220. else if (value is XmlSchemaGroupRef) {
  221. XmlSchemaGroupRef so = (XmlSchemaGroupRef) value;
  222. checker.Check (ctx, so);
  223. }
  224. else if (value is XmlSchemaIdentityConstraint) {
  225. XmlSchemaIdentityConstraint so = (XmlSchemaIdentityConstraint) value;
  226. checker.Check (ctx, so);
  227. CheckObjects (ctx, checker, visitedObjects, so.Fields);
  228. Check (ctx, checker, visitedObjects, so.Selector);
  229. }
  230. else if (value is XmlSchemaKeyref) {
  231. XmlSchemaKeyref so = (XmlSchemaKeyref) value;
  232. checker.Check (ctx, so);
  233. }
  234. else if (value is XmlSchemaRedefine) {
  235. XmlSchemaRedefine so = (XmlSchemaRedefine) value;
  236. checker.Check (ctx, so);
  237. CheckObjects (ctx, checker, visitedObjects, so.Items);
  238. }
  239. else if (value is XmlSchemaSequence) {
  240. XmlSchemaSequence so = (XmlSchemaSequence) value;
  241. checker.Check (ctx, so);
  242. CheckObjects (ctx, checker, visitedObjects, so.Items);
  243. }
  244. else if (value is XmlSchemaSimpleContent) {
  245. XmlSchemaSimpleContent so = (XmlSchemaSimpleContent) value;
  246. checker.Check (ctx, so);
  247. Check (ctx, checker, visitedObjects, so.Content);
  248. }
  249. else if (value is XmlSchemaSimpleContentExtension) {
  250. XmlSchemaSimpleContentExtension so = (XmlSchemaSimpleContentExtension) value;
  251. checker.Check (ctx, so);
  252. CheckObjects (ctx, checker, visitedObjects, so.Attributes);
  253. Check (ctx, checker, visitedObjects, so.AnyAttribute);
  254. }
  255. else if (value is XmlSchemaSimpleContentRestriction) {
  256. XmlSchemaSimpleContentRestriction so = (XmlSchemaSimpleContentRestriction) value;
  257. checker.Check (ctx, so);
  258. CheckObjects (ctx, checker, visitedObjects, so.Attributes);
  259. Check (ctx, checker, visitedObjects, so.AnyAttribute);
  260. CheckObjects (ctx, checker, visitedObjects, so.Facets);
  261. }
  262. else if (value is XmlSchemaSimpleType) {
  263. XmlSchemaSimpleType so = (XmlSchemaSimpleType) value;
  264. checker.Check (ctx, so);
  265. Check (ctx, checker, visitedObjects, so.Content);
  266. }
  267. else if (value is XmlSchemaSimpleTypeList) {
  268. XmlSchemaSimpleTypeList so = (XmlSchemaSimpleTypeList) value;
  269. checker.Check (ctx, so);
  270. }
  271. else if (value is XmlSchemaSimpleTypeRestriction) {
  272. XmlSchemaSimpleTypeRestriction so = (XmlSchemaSimpleTypeRestriction) value;
  273. checker.Check (ctx, so);
  274. CheckObjects (ctx, checker, visitedObjects, so.Facets);
  275. }
  276. else if (value is XmlSchemaSimpleTypeUnion) {
  277. XmlSchemaSimpleTypeUnion so = (XmlSchemaSimpleTypeUnion) value;
  278. checker.Check (ctx, so);
  279. }
  280. }
  281. static void CheckExtensions (ConformanceCheckContext ctx, ConformanceChecker checker, ServiceDescriptionFormatExtensionCollection extensions)
  282. {
  283. foreach (ServiceDescriptionFormatExtension ext in extensions)
  284. checker.Check (ctx, ext);
  285. }
  286. }
  287. }
  288. #endif