BasicProfileChecker.cs 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959
  1. //
  2. // System.Web.Services.Description.BasicProfileChecker.cs
  3. //
  4. // Author:
  5. // Lluis Sanchez ([email protected])
  6. // Atsushi Enomoto ([email protected])
  7. //
  8. // Copyright (C) Novell, Inc., 2004
  9. //
  10. //
  11. // Permission is hereby granted, free of charge, to any person obtaining
  12. // a copy of this software and associated documentation files (the
  13. // "Software"), to deal in the Software without restriction, including
  14. // without limitation the rights to use, copy, modify, merge, publish,
  15. // distribute, sublicense, and/or sell copies of the Software, and to
  16. // permit persons to whom the Software is furnished to do so, subject to
  17. // the following conditions:
  18. //
  19. // The above copyright notice and this permission notice shall be
  20. // included in all copies or substantial portions of the Software.
  21. //
  22. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  23. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  24. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  25. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  26. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  27. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  28. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  29. //
  30. #if NET_2_0
  31. using System.IO;
  32. using System.Xml.Schema;
  33. using System.Xml.Serialization;
  34. using System.Xml;
  35. using System.Collections;
  36. namespace System.Web.Services.Description
  37. {
  38. internal class BasicProfileChecker: ConformanceChecker
  39. {
  40. public static BasicProfileChecker Instance = new BasicProfileChecker ();
  41. public override WsiProfiles Claims {
  42. get { return WsiProfiles.BasicProfile1_1; }
  43. }
  44. /*
  45. private string GetAbsoluteUri (string baseUri, string relativeUri)
  46. {
  47. string actualBaseUri = baseUri ?? Path.GetFullPath (".") + Path.DirectorySeparatorChar;
  48. Uri uri = new Uri (new Uri (actualBaseUri), relativeUri);
  49. return uri.ToString ();
  50. }
  51. */
  52. public override void Check (ConformanceCheckContext ctx, Import value)
  53. {
  54. if (value.Location == "" || value.Location == null) {
  55. ctx.ReportRuleViolation (value, BasicProfileRules.R2007);
  56. return;
  57. }
  58. if (!new Uri (value.Namespace, UriKind.RelativeOrAbsolute).IsAbsoluteUri)
  59. ctx.ReportRuleViolation (value, BasicProfileRules.R2803);
  60. // LAMESPEC: RetrievalUrl does not seem to help here (in .NET)
  61. //ServiceDescription importer = value.ServiceDescription;
  62. //string absUri = GetAbsoluteUri (importer != null ? importer.RetrievalUrl : null, value.Location);
  63. object doc = ctx.GetDocument (/*absUri*/value.Location, value.Namespace);
  64. if (doc == null) // and looks like .net ignores non-resolvable documentation... I dunno if it makes sense. I don't care :/
  65. return; //ctx.ReportError (value, "Document '" + value.Location + "' not found");
  66. if (doc is XmlSchema)
  67. ctx.ReportRuleViolation (value, BasicProfileRules.R2002);
  68. ServiceDescription imported = doc as ServiceDescription;
  69. if (imported == null) {
  70. ctx.ReportRuleViolation (value, BasicProfileRules.R2001);
  71. return;
  72. }
  73. if (imported.TargetNamespace != value.Namespace)
  74. ctx.ReportRuleViolation (value, BasicProfileRules.R2005);
  75. }
  76. public override void Check (ConformanceCheckContext ctx, ServiceDescription value)
  77. {
  78. // R4005 (and R1034, which turned out to be redundant)
  79. if (value.Namespaces != null)
  80. foreach (XmlQualifiedName qname in value.Namespaces.ToArray ())
  81. if (qname.Namespace == "http://www.w3.org/XML/1998/namespace")
  82. ctx.ReportRuleViolation (value, BasicProfileRules.R4005);
  83. CheckDuplicateSoapAddressBinding (ctx, value);
  84. }
  85. void CheckDuplicateSoapAddressBinding (ConformanceCheckContext ctx, ServiceDescription value)
  86. {
  87. ArrayList locations = new ArrayList ();
  88. foreach (PortType p in value.PortTypes) {
  89. SoapAddressBinding b = (SoapAddressBinding) p.Extensions.Find (typeof (SoapAddressBinding));
  90. if (b == null || b.Location == null || b.Location.Length == 0)
  91. continue;
  92. if (locations.Contains (b.Location)) {
  93. ctx.ReportRuleViolation (value, BasicProfileRules.R2711);
  94. // One report for one ServiceDescription should be enough.
  95. return;
  96. }
  97. locations.Add (b.Location);
  98. }
  99. }
  100. public override void Check (ConformanceCheckContext ctx, ServiceDescriptionFormatExtension value)
  101. {
  102. if (value.Required)
  103. ctx.ReportRuleViolation (value, BasicProfileRules.R2026);
  104. }
  105. public override void Check (ConformanceCheckContext ctx, MessagePart value)
  106. {
  107. CheckWsdlQName (ctx, value, value.Type);
  108. CheckWsdlQName (ctx, value, value.Element);
  109. if (value.DefinedByElement && value.Element.Namespace == XmlSchema.Namespace)
  110. ctx.ReportRuleViolation (value, BasicProfileRules.R2206);
  111. if (value.Type != null && value.Type != XmlQualifiedName.Empty &&
  112. value.Element != null && value.Element != XmlQualifiedName.Empty)
  113. ctx.ReportRuleViolation (value, BasicProfileRules.R2306);
  114. }
  115. public override void Check (ConformanceCheckContext ctx, Types value)
  116. {
  117. }
  118. public override void Check (ConformanceCheckContext ctx, Message value)
  119. {
  120. }
  121. public override void Check (ConformanceCheckContext ctx, BindingCollection value) {
  122. foreach (Binding b in value)
  123. foreach (ServiceDescriptionFormatExtension ext in b.Extensions)
  124. if (ext.GetType () == typeof (SoapBinding))
  125. return;
  126. ctx.ReportRuleViolation (value, BasicProfileRules.R2401);
  127. }
  128. public override void Check (ConformanceCheckContext ctx, Binding value)
  129. {
  130. SoapBinding sb = (SoapBinding) value.Extensions.Find (typeof(SoapBinding));
  131. if (sb == null)
  132. return;
  133. if (sb.Transport == null || sb.Transport == "") {
  134. ctx.ReportRuleViolation (value, BasicProfileRules.R2701);
  135. return;
  136. }
  137. if (sb.Transport != "http://schemas.xmlsoap.org/soap/http")
  138. ctx.ReportRuleViolation (value, BasicProfileRules.R2702);
  139. LiteralType type = GetLiteralBindingType (value);
  140. if (type == LiteralType.NotLiteral)
  141. ctx.ReportRuleViolation (value, BasicProfileRules.R2706);
  142. else if (type == LiteralType.Inconsistent)
  143. ctx.ReportRuleViolation (value, BasicProfileRules.R2705);
  144. // Collect all parts referenced from this type
  145. Hashtable parts = new Hashtable ();
  146. PortType port = ctx.Services.GetPortType (value.Type);
  147. foreach (Operation op in port.Operations) {
  148. foreach (OperationMessage om in op.Messages) {
  149. Message msg = ctx.Services.GetMessage (om.Message);
  150. foreach (MessagePart part in msg.Parts)
  151. parts [part] = part; // do not use Add() - there could be the same MessagePart instance.
  152. }
  153. }
  154. foreach (OperationBinding ob in value.Operations) {
  155. if (ob.Input != null) CheckMessageBinding (ctx, parts, ob.Input);
  156. if (ob.Output != null) CheckMessageBinding (ctx, parts, ob.Output);
  157. foreach (FaultBinding fb in ob.Faults)
  158. CheckMessageBinding (ctx, parts, fb);
  159. }
  160. if (parts.Count > 0)
  161. ctx.ReportRuleViolation (value, BasicProfileRules.R2209);
  162. // check existence of corresponding operation in portType for each binding operation
  163. if (CheckCorrespondingOperationsForBinding (ctx, value, port))
  164. ctx.ReportRuleViolation (value, BasicProfileRules.R2718);
  165. // check duplicate operation signature.
  166. ArrayList sigs = new ArrayList ();
  167. foreach (OperationBinding ob in value.Operations) {
  168. if (sigs.Contains (ob.Name))
  169. ctx.ReportRuleViolation (value, BasicProfileRules.R2710);
  170. sigs.Add (ob.Name);
  171. }
  172. // check namespace declarations.
  173. switch (type) {
  174. case LiteralType.Document:
  175. case LiteralType.Rpc:
  176. CheckSoapBindingExtensions (ctx, value, type);
  177. break;
  178. }
  179. }
  180. bool CheckCorrespondingOperationsForBinding (ConformanceCheckContext ctx, Binding value, PortType port)
  181. {
  182. if (value.Operations.Count != port.Operations.Count)
  183. return true;
  184. foreach (OperationBinding b in value.Operations) {
  185. Operation op = port.Operations.Find (b.Name);
  186. if (op == null)
  187. return true;
  188. bool msg, bind;
  189. // input
  190. msg = op.Messages.Input != null;
  191. bind = b.Input != null;
  192. if (msg != bind)
  193. return true;
  194. // output
  195. msg = op.Messages.Output != null;
  196. bind = b.Output != null;
  197. if (msg != bind)
  198. return true;
  199. // faults
  200. foreach (FaultBinding fb in b.Faults)
  201. if (op.Messages.Find (fb.Name) == null)
  202. return true;
  203. }
  204. return false;
  205. }
  206. void CheckSoapBindingExtensions (ConformanceCheckContext ctx, Binding value, LiteralType type)
  207. {
  208. bool violationNS = false;
  209. bool violation2717 = false;
  210. bool violation2720 = false;
  211. bool violation2721 = false;
  212. foreach (OperationBinding op in value.Operations) {
  213. SoapBodyBinding sbb = op.Extensions.Find (typeof (SoapBodyBinding)) as SoapBodyBinding;
  214. if (sbb != null) {
  215. if (type == LiteralType.Document && sbb.Namespace != null)
  216. violationNS = true;
  217. if (type == LiteralType.Rpc && sbb.Namespace == null)
  218. violation2717 = true;
  219. }
  220. SoapHeaderBinding shb = op.Extensions.Find (typeof (SoapHeaderBinding)) as SoapHeaderBinding;
  221. if (shb != null) {
  222. violationNS |= shb.Namespace != null;
  223. violation2720 |= !IsValidPart (shb.Part);
  224. }
  225. SoapHeaderFaultBinding sfhb = op.Extensions.Find (typeof (SoapHeaderFaultBinding)) as SoapHeaderFaultBinding;
  226. if (sfhb != null) {
  227. violationNS |= sfhb.Namespace != null;
  228. violation2720 |= !IsValidPart (sfhb.Part);
  229. }
  230. SoapFaultBinding sfb = op.Extensions.Find (typeof (SoapFaultBinding)) as SoapFaultBinding;
  231. if (sfb != null) {
  232. violation2721 |= sfb.Name == null;
  233. violationNS |= sfb.Namespace != null;
  234. }
  235. }
  236. if (violationNS)
  237. ctx.ReportRuleViolation (value,
  238. type == LiteralType.Document ?
  239. BasicProfileRules.R2716 :
  240. BasicProfileRules.R2726);
  241. if (violation2717)
  242. ctx.ReportRuleViolation (value, BasicProfileRules.R2717);
  243. if (violation2720)
  244. ctx.ReportRuleViolation (value, BasicProfileRules.R2720);
  245. if (violation2721)
  246. ctx.ReportRuleViolation (value, BasicProfileRules.R2721);
  247. }
  248. bool IsValidPart (string part)
  249. {
  250. if (part == null)
  251. return false;
  252. try {
  253. XmlConvert.VerifyNMTOKEN (part);
  254. return true;
  255. } catch (XmlException) {
  256. return false;
  257. }
  258. }
  259. public override void Check (ConformanceCheckContext ctx, OperationBinding value)
  260. {
  261. bool r2754 = false;
  262. bool r2723 = false;
  263. foreach (FaultBinding fb in value.Faults) {
  264. SoapFaultBinding sfb = (SoapFaultBinding) value.Extensions.Find (typeof (SoapFaultBinding));
  265. if (sfb == null)
  266. continue;
  267. r2754 |= sfb.Name != fb.Name;
  268. r2723 |= sfb.Use == SoapBindingUse.Encoded;
  269. }
  270. if (r2754)
  271. ctx.ReportRuleViolation (value, BasicProfileRules.R2754);
  272. if (r2723)
  273. ctx.ReportRuleViolation (value, BasicProfileRules.R2723);
  274. }
  275. void CheckMessageBinding (ConformanceCheckContext ctx, Hashtable portParts, MessageBinding value)
  276. {
  277. SoapBodyBinding sbb = (SoapBodyBinding) value.Extensions.Find (typeof(SoapBodyBinding));
  278. Message msg = FindMessage (ctx, value);
  279. LiteralType bt = GetLiteralBindingType (value.OperationBinding.Binding);
  280. if (sbb != null)
  281. {
  282. if (bt == LiteralType.Document)
  283. {
  284. if (sbb.Parts != null && sbb.Parts.Length > 1)
  285. ctx.ReportRuleViolation (value, BasicProfileRules.R2201);
  286. if (sbb.Parts == null) {
  287. if (msg.Parts != null && msg.Parts.Count > 1)
  288. ctx.ReportRuleViolation (value, BasicProfileRules.R2210);
  289. if (msg.Parts.Count == 1)
  290. portParts.Remove (msg.Parts[0]);
  291. }
  292. else {
  293. if (sbb.Parts.Length == 0 && msg.Parts.Count == 1) {
  294. portParts.Remove (msg.Parts[0]);
  295. } else {
  296. foreach (string part in sbb.Parts) {
  297. MessagePart mp = msg.FindPartByName (part);
  298. portParts.Remove (mp);
  299. if (!mp.DefinedByElement)
  300. ctx.ReportRuleViolation (value, BasicProfileRules.R2204);
  301. }
  302. }
  303. }
  304. }
  305. else if (bt == LiteralType.Rpc)
  306. {
  307. if (sbb.Parts != null) {
  308. foreach (string part in sbb.Parts) {
  309. MessagePart mp = msg.FindPartByName (part);
  310. portParts.Remove (mp);
  311. if (!mp.DefinedByType)
  312. ctx.ReportRuleViolation (value, BasicProfileRules.R2203);
  313. }
  314. }
  315. }
  316. }
  317. SoapHeaderBinding shb = (SoapHeaderBinding) value.Extensions.Find (typeof(SoapHeaderBinding));
  318. if (shb != null) {
  319. Message hm = ctx.Services.GetMessage (shb.Message);
  320. MessagePart mp = hm.FindPartByName (shb.Part);
  321. portParts.Remove (mp);
  322. if (mp != null && !mp.DefinedByElement)
  323. ctx.ReportRuleViolation (value, BasicProfileRules.R2205);
  324. }
  325. SoapHeaderFaultBinding shfb = (SoapHeaderFaultBinding) value.Extensions.Find (typeof(SoapHeaderFaultBinding));
  326. if (shfb != null) {
  327. Message hm = ctx.Services.GetMessage (shfb.Message);
  328. MessagePart mp = hm.FindPartByName (shfb.Part);
  329. portParts.Remove (mp);
  330. if (mp != null && !mp.DefinedByElement)
  331. ctx.ReportRuleViolation (value, BasicProfileRules.R2205);
  332. }
  333. // TODO: SoapFaultBinding ??
  334. }
  335. Message FindMessage (ConformanceCheckContext ctx, MessageBinding mb)
  336. {
  337. PortType pt = ctx.Services.GetPortType (mb.OperationBinding.Binding.Type);
  338. foreach (Operation op in pt.Operations)
  339. if (op.IsBoundBy (mb.OperationBinding)) {
  340. OperationMessage om;
  341. if (mb is InputBinding) om = op.Messages.Input;
  342. else if (mb is OutputBinding) om = op.Messages.Output;
  343. else if (mb is FaultBinding) om = op.Faults [mb.Name];
  344. else return null;
  345. if (om != null)
  346. return ctx.Services.GetMessage (om.Message);
  347. else
  348. return null;
  349. }
  350. return null;
  351. }
  352. public override void Check (ConformanceCheckContext ctx, Operation value)
  353. {
  354. switch (value.Messages.Flow) {
  355. case OperationFlow.SolicitResponse:
  356. case OperationFlow.Notification:
  357. ctx.ReportRuleViolation (value, BasicProfileRules.R2303);
  358. break;
  359. }
  360. CheckR2305 (ctx, value);
  361. }
  362. void CheckR2305 (ConformanceCheckContext ctx, Operation value)
  363. {
  364. string [] order = value.ParameterOrder;
  365. ServiceDescription sd = value.PortType.ServiceDescription;
  366. Message omitted = null;
  367. foreach (OperationMessage m in value.Messages) {
  368. if (m.Name == null)
  369. continue; // it is doubtful, but R2305 is not to check such cases anyways.
  370. Message msg = sd.Messages [m.Name];
  371. if (msg == null)
  372. continue; // it is doubtful, but R2305 is not to check such cases anyways.
  373. foreach (MessagePart p in msg.Parts) {
  374. if (Array.IndexOf (order, p.Name) >= 0)
  375. continue;
  376. if (omitted == null) {
  377. omitted = msg;
  378. continue;
  379. }
  380. ctx.ReportRuleViolation (value, BasicProfileRules.R2305);
  381. return;
  382. }
  383. }
  384. }
  385. public override void Check (ConformanceCheckContext ctx, OperationMessage value) { }
  386. public override void Check (ConformanceCheckContext ctx, Port value) { }
  387. public override void Check (ConformanceCheckContext ctx, PortType value)
  388. {
  389. ArrayList names = new ArrayList ();
  390. foreach (Operation o in value.Operations) {
  391. if (names.Contains (o.Name))
  392. ctx.ReportRuleViolation (value, BasicProfileRules.R2304);
  393. else
  394. names.Add (o.Name);
  395. }
  396. }
  397. public override void Check (ConformanceCheckContext ctx, Service value) { }
  398. public override void Check (ConformanceCheckContext ctx, XmlSchema s)
  399. {
  400. if (s.TargetNamespace == null || s.TargetNamespace == "") {
  401. foreach (XmlSchemaObject ob in s.Items)
  402. if (!(ob is XmlSchemaImport) && !(ob is XmlSchemaAnnotation)) {
  403. ctx.ReportRuleViolation (s, BasicProfileRules.R2105);
  404. break;
  405. }
  406. }
  407. }
  408. public override void Check (ConformanceCheckContext ctx, XmlSchemaImport value)
  409. {
  410. // LAMESPEC: same here to Check() for Import.
  411. XmlSchema doc = ctx.GetDocument (value.SchemaLocation, value.Namespace) as XmlSchema;
  412. if (doc == null) ctx.ReportError (value, "Schema '" + value.SchemaLocation + "' not found");
  413. }
  414. public override void Check (ConformanceCheckContext ctx, XmlSchemaAttribute value)
  415. {
  416. CheckSchemaQName (ctx, value, value.RefName);
  417. CheckSchemaQName (ctx, value, value.SchemaTypeName);
  418. XmlAttribute[] uatts = value.UnhandledAttributes;
  419. if (uatts != null) {
  420. foreach (XmlAttribute at in uatts)
  421. if (at.LocalName == "arrayType" && at.NamespaceURI == "http://schemas.xmlsoap.org/wsdl/")
  422. ctx.ReportRuleViolation (value, BasicProfileRules.R2111);
  423. }
  424. }
  425. public override void Check (ConformanceCheckContext ctx, XmlSchemaAttributeGroupRef value)
  426. {
  427. CheckSchemaQName (ctx, value, value.RefName);
  428. }
  429. public override void Check (ConformanceCheckContext ctx, XmlSchemaComplexContentExtension value)
  430. {
  431. CheckSchemaQName (ctx, value, value.BaseTypeName);
  432. if (value.BaseTypeName.Namespace == "http://schemas.xmlsoap.org/soap/encoding/" && value.BaseTypeName.Name == "Array")
  433. ctx.ReportRuleViolation (value, BasicProfileRules.R2110);
  434. }
  435. public override void Check (ConformanceCheckContext ctx, XmlSchemaComplexContentRestriction value)
  436. {
  437. CheckSchemaQName (ctx, value, value.BaseTypeName);
  438. if (value.BaseTypeName.Namespace == "http://schemas.xmlsoap.org/soap/encoding/" && value.BaseTypeName.Name == "Array")
  439. ctx.ReportRuleViolation (value, BasicProfileRules.R2110);
  440. }
  441. public override void Check (ConformanceCheckContext ctx, XmlSchemaElement value)
  442. {
  443. CheckSchemaQName (ctx, value, value.RefName);
  444. CheckSchemaQName (ctx, value, value.SubstitutionGroup);
  445. CheckSchemaQName (ctx, value, value.SchemaTypeName);
  446. if (value.Name != null && value.Name.StartsWith ("ArrayOf", StringComparison.Ordinal))
  447. ctx.ReportRuleViolation (value, BasicProfileRules.R2112);
  448. }
  449. public override void Check (ConformanceCheckContext ctx, XmlSchemaGroupRef value)
  450. {
  451. CheckSchemaQName (ctx, value, value.RefName);
  452. }
  453. public override void Check (ConformanceCheckContext ctx, XmlSchemaKeyref value)
  454. {
  455. CheckSchemaQName (ctx, value, value.Refer);
  456. }
  457. public override void Check (ConformanceCheckContext ctx, XmlSchemaSimpleContentExtension value)
  458. {
  459. CheckSchemaQName (ctx, value, value.BaseTypeName);
  460. }
  461. public override void Check (ConformanceCheckContext ctx, XmlSchemaSimpleContentRestriction value)
  462. {
  463. CheckSchemaQName (ctx, value, value.BaseTypeName);
  464. }
  465. public override void Check (ConformanceCheckContext ctx, XmlSchemaSimpleTypeList value)
  466. {
  467. CheckSchemaQName (ctx, value, value.ItemTypeName);
  468. }
  469. public override void Check (ConformanceCheckContext ctx, XmlSchemaSimpleTypeRestriction value)
  470. {
  471. CheckSchemaQName (ctx, value, value.BaseTypeName);
  472. }
  473. public override void Check (ConformanceCheckContext ctx, XmlSchemaSimpleTypeUnion value)
  474. {
  475. if (value.MemberTypes != null) {
  476. foreach (XmlQualifiedName name in value.MemberTypes)
  477. CheckSchemaQName (ctx, value, name);
  478. }
  479. }
  480. // Helper methods
  481. void CheckWsdlQName (ConformanceCheckContext ctx, object element, XmlQualifiedName name)
  482. {
  483. if (name == null || name == XmlQualifiedName.Empty) return;
  484. if (name.Namespace == "" || name.Namespace == XmlSchema.Namespace) return;
  485. if (ctx.ServiceDescription.Types != null && ctx.ServiceDescription.Types.Schemas != null)
  486. {
  487. foreach (XmlSchema s in ctx.ServiceDescription.Types.Schemas)
  488. {
  489. if (s.TargetNamespace == name.Namespace) return;
  490. foreach (XmlSchemaObject i in s.Includes)
  491. if ((i is XmlSchemaImport) && ((XmlSchemaImport)i).Namespace == name.Namespace) return;
  492. }
  493. }
  494. ctx.ReportRuleViolation (element, BasicProfileRules.R2101);
  495. }
  496. void CheckSchemaQName (ConformanceCheckContext ctx, object element, XmlQualifiedName name)
  497. {
  498. if (name == null || name == XmlQualifiedName.Empty) return;
  499. if (name.Namespace == "" || name.Namespace == XmlSchema.Namespace) return;
  500. if (ctx.CurrentSchema.TargetNamespace == name.Namespace) return;
  501. foreach (XmlSchemaObject i in ctx.CurrentSchema.Includes)
  502. if ((i is XmlSchemaImport) && ((XmlSchemaImport)i).Namespace == name.Namespace) return;
  503. ctx.ReportRuleViolation (element, BasicProfileRules.R2102);
  504. }
  505. LiteralType GetLiteralBindingType (Binding b)
  506. {
  507. SoapBinding sb = (SoapBinding) b.Extensions.Find (typeof(SoapBinding));
  508. SoapBindingStyle style = (sb != null) ? sb.Style : SoapBindingStyle.Document;
  509. if (style == SoapBindingStyle.Default) style = SoapBindingStyle.Document;
  510. foreach (OperationBinding ob in b.Operations) {
  511. SoapOperationBinding sob = (SoapOperationBinding) ob.Extensions.Find (typeof(SoapOperationBinding));
  512. if (sob.Style != SoapBindingStyle.Default && sob.Style != style)
  513. return LiteralType.Inconsistent;
  514. if (ob.Input != null) {
  515. SoapBodyBinding sbb = (SoapBodyBinding) ob.Input.Extensions.Find (typeof(SoapBodyBinding));
  516. if (sbb != null && sbb.Use != SoapBindingUse.Literal) return LiteralType.NotLiteral;
  517. SoapFaultBinding sfb = (SoapFaultBinding) ob.Input.Extensions.Find (typeof(SoapFaultBinding));
  518. if (sfb != null && sfb.Use != SoapBindingUse.Literal) return LiteralType.NotLiteral;
  519. SoapHeaderBinding shb = (SoapHeaderBinding) ob.Input.Extensions.Find (typeof(SoapHeaderBinding));
  520. if (shb != null && shb.Use != SoapBindingUse.Literal) return LiteralType.NotLiteral;
  521. SoapHeaderFaultBinding shfb = (SoapHeaderFaultBinding) ob.Input.Extensions.Find (typeof(SoapHeaderFaultBinding));
  522. if (shfb != null && shfb.Use != SoapBindingUse.Literal) return LiteralType.NotLiteral;
  523. }
  524. if (ob.Output != null) {
  525. SoapBodyBinding sbb = (SoapBodyBinding) ob.Output.Extensions.Find (typeof(SoapBodyBinding));
  526. if (sbb != null && sbb.Use != SoapBindingUse.Literal) return LiteralType.NotLiteral;
  527. SoapFaultBinding sfb = (SoapFaultBinding) ob.Input.Extensions.Find (typeof(SoapFaultBinding));
  528. if (sfb != null && sfb.Use != SoapBindingUse.Literal) return LiteralType.NotLiteral;
  529. SoapHeaderBinding shb = (SoapHeaderBinding) ob.Input.Extensions.Find (typeof(SoapHeaderBinding));
  530. if (shb != null && shb.Use != SoapBindingUse.Literal) return LiteralType.NotLiteral;
  531. SoapHeaderFaultBinding shfb = (SoapHeaderFaultBinding) ob.Input.Extensions.Find (typeof(SoapHeaderFaultBinding));
  532. if (shfb != null && shfb.Use != SoapBindingUse.Literal) return LiteralType.NotLiteral;
  533. }
  534. }
  535. if (style == SoapBindingStyle.Document) return LiteralType.Document;
  536. else return LiteralType.Rpc;
  537. }
  538. enum LiteralType {
  539. NotLiteral,
  540. Inconsistent,
  541. Rpc,
  542. Document
  543. }
  544. }
  545. internal class BasicProfileRules
  546. {
  547. #region "Basic Profile 1.1 Section 4 (Service Description)"
  548. // (BTW R1034 turned out to be a spec bug.)
  549. // 4.1 Required Description
  550. // Can't check: R0001
  551. // 4.2 Document Structure
  552. // R2028, R2029: schema conformance, depends on underlying XML
  553. public static readonly ConformanceRule R2001 = new ConformanceRule (
  554. "R2001",
  555. "A DESCRIPTION MUST only use the WSDL \"import\" statement to import another WSDL description",
  556. "");
  557. public static readonly ConformanceRule R2803 = new ConformanceRule (
  558. "R2803",
  559. "In a DESCRIPTION, the namespace attribute of the wsdl:import MUST NOT be a relative URI.",
  560. "");
  561. public static readonly ConformanceRule R2002 = new ConformanceRule (
  562. "R2002",
  563. "To import XML Schema Definitions, a DESCRIPTION MUST use the XML Schema \"import\" statement",
  564. "");
  565. // R2003: depends on ServiceDescription raw XML.
  566. // R2004, R2009, R2010, R2011: requires schema resolution
  567. // which depends on XmlResolver, while 1) XmlUrlResolver
  568. // might not always be proper (e.g. network resolution) and
  569. // 2) custom XmlResolver might resolve non-XML.
  570. public static readonly ConformanceRule R2007 = new ConformanceRule (
  571. "R2007",
  572. "A DESCRIPTION MUST specify a non-empty location attribute on the wsdl:import element",
  573. "");
  574. // R2008: denotes a possibility that cannot be verified.
  575. // R2022, R2023, R4004: depends on underlying XML, which
  576. // is impossible when ServiceDescription is already read
  577. // (WebServiceInteroperability.CheckConformance() is the case).
  578. public static readonly ConformanceRule R4005 = new ConformanceRule (
  579. "R4005",
  580. "A DESCRIPTION SHOULD NOT contain the namespace declaration xmlns:xml=\"http://www.w3.org/XML/1998/namespace\"",
  581. "");
  582. // R4002, R4003: depends on underlying XML
  583. public static readonly ConformanceRule R2005 = new ConformanceRule (
  584. "R2005",
  585. "The targetNamespace attribute on the wsdl:definitions element of a description that is being imported MUST have same the value as the namespace attribute on the wsdl:import element in the importing DESCRIPTION",
  586. "");
  587. // R2030: is satisfied by API nature (DocumentableItem).
  588. // R2025: cannot be checked.
  589. public static readonly ConformanceRule R2026 = new ConformanceRule (
  590. "R2026",
  591. "A DESCRIPTION SHOULD NOT include extension elements with a wsdl:required attribute value of \"true\" on any WSDL construct (wsdl:binding, wsdl:portType, wsdl:message, wsdl:types or wsdl:import) that claims conformance to the Profile",
  592. "");
  593. // R2027: is about the CONSUMER, cannot be checked.
  594. // 4.3 Types
  595. public static readonly ConformanceRule R2101 = new ConformanceRule (
  596. "R2101",
  597. "A DESCRIPTION MUST NOT use QName references to elements in namespaces that have been neither imported, nor defined in the referring WSDL document",
  598. "");
  599. public static readonly ConformanceRule R2102 = new ConformanceRule (
  600. "R2102",
  601. "A QName reference to a Schema component in a DESCRIPTION MUST use the namespace defined in the targetNamespace attribute on the xsd:schema element, or to a namespace defined in the namespace attribute on an xsd:import element within the xsd:schema element",
  602. "");
  603. public static readonly ConformanceRule R2105 = new ConformanceRule (
  604. "R2105",
  605. "All xsd:schema elements contained in a wsdl:types element of a DESCRIPTION MUST have a targetNamespace attribute with a valid and non-null value, UNLESS the xsd:schema element has xsd:import and/or xsd:annotation as its only child element(s)",
  606. "");
  607. public static readonly ConformanceRule R2110 = new ConformanceRule (
  608. "R2110",
  609. "In a DESCRIPTION, array declarations MUST NOT extend or restrict the soapenc:Array type",
  610. "");
  611. public static readonly ConformanceRule R2111 = new ConformanceRule (
  612. "R2111",
  613. "In a DESCRIPTION, array declarations MUST NOT use wsdl:arrayType attribute in the type declaration",
  614. "");
  615. public static readonly ConformanceRule R2112 = new ConformanceRule (
  616. "R2112",
  617. "In a DESCRIPTION, elements SHOULD NOT be named using the convention ArrayOfXXX.",
  618. "");
  619. // R2113: is about ENVELOPE.
  620. // R2114: is satisfied by our processor.
  621. // 4.4 Messages
  622. public static readonly ConformanceRule R2201 = new ConformanceRule (
  623. "R2201",
  624. "A document-literal binding in a DESCRIPTION MUST, in each of its soapbind:body element(s), have at most one part listed in the parts attribute, if the parts attribute is specified",
  625. "");
  626. public static readonly ConformanceRule R2209 = new ConformanceRule (
  627. "R2209",
  628. "A wsdl:binding in a DESCRIPTION SHOULD bind every wsdl:part of a wsdl:message in the wsdl:portType to which it refers to one of soapbind:body, soapbind:header, soapbind:fault or soapbind:headerfault",
  629. "");
  630. public static readonly ConformanceRule R2210 = new ConformanceRule (
  631. "R2210",
  632. "If a document-literal binding in a DESCRIPTION does not specify the parts attribute on a soapbind:body element, the corresponding abstract wsdl:message MUST define zero or one wsdl:parts",
  633. "");
  634. // R2202: Suggestion.
  635. public static readonly ConformanceRule R2203 = new ConformanceRule (
  636. "R2203",
  637. "An rpc-literal binding in a DESCRIPTION MUST refer, in its soapbind:body element(s), only to wsdl:part element(s) that have been defined using the type attribute",
  638. "");
  639. // R2211: Related to ENVELOPE
  640. // R2207: is about allowed condition (MAY).
  641. public static readonly ConformanceRule R2204 = new ConformanceRule (
  642. "R2204",
  643. "A document-literal binding in a DESCRIPTION MUST refer, in each of its soapbind:body element(s), only to wsdl:part element(s) that have been defined using the element attribute",
  644. "");
  645. // R2208: is about allowed condition (MAY).
  646. // R2212, R2213, R2214: related to ENVELOPE
  647. public static readonly ConformanceRule R2205 = new ConformanceRule (
  648. "R2205",
  649. "A wsdl:binding in a DESCRIPTION MUST refer, in each of its soapbind:header, soapbind:headerfault and soapbind:fault elements, only to wsdl:part element(s) that have been defined using the element attribute",
  650. "");
  651. public static readonly ConformanceRule R2206 = new ConformanceRule (
  652. "R2206",
  653. "A wsdl:message in a DESCRIPTION containing a wsdl:part that uses the element attribute MUST refer, in that attribute, to a global element declaration",
  654. "");
  655. // 4.5 Port Types
  656. // R2301: Related to ENVELOPE.
  657. // R2302: Optional
  658. // btw it's not on Basic Profile TAD
  659. public static readonly ConformanceRule R2303 = new ConformanceRule (
  660. "R2303",
  661. "A DESCRIPTION MUST NOT use Solicit-Response and Notification type operations in a wsdl:portType definition.",
  662. "");
  663. public static readonly ConformanceRule R2304 = new ConformanceRule (
  664. "R2304",
  665. "A wsdl:portType in a DESCRIPTION MUST have operations with distinct values for their name attributes.",
  666. "");
  667. public static readonly ConformanceRule R2305 = new ConformanceRule (
  668. "R2305",
  669. "A wsdl:operation element child of a wsdl:portType element in a DESCRIPTION MUST be constructed so that the parameterOrder attribute, if present, omits at most 1 wsdl:part from the output message.",
  670. "");
  671. public static readonly ConformanceRule R2306 = new ConformanceRule (
  672. "R2306",
  673. "A wsdl:message in a DESCRIPTION MUST NOT specify both type and element attributes on the same wsdl:part.",
  674. "");
  675. // 4.6 Bindings
  676. public static readonly ConformanceRule R2401 = new ConformanceRule (
  677. "R2401",
  678. "A wsdl:binding element in a DESCRIPTION MUST use WSDL SOAP Binding as defined in WSDL 1.1 Section 3.",
  679. "");
  680. // 4.7 SOAP Binding
  681. public static readonly ConformanceRule R2701 = new ConformanceRule (
  682. "R2701",
  683. "The wsdl:binding element in a DESCRIPTION MUST be constructed so that its soapbind:binding child element specifies the transport attribute",
  684. "");
  685. public static readonly ConformanceRule R2702 = new ConformanceRule (
  686. "R2702",
  687. "A wsdl:binding element in a DESCRIPTION MUST specify the HTTP transport protocol with SOAP binding. Specifically, the transport attribute of its soapbind:binding child MUST have the value \"http://schemas.xmlsoap.org/soap/http\"",
  688. "");
  689. public static readonly ConformanceRule R2705 = new ConformanceRule (
  690. "R2705",
  691. "A wsdl:binding in a DESCRIPTION MUST use either be a rpc-literal binding or a document-literal binding",
  692. "");
  693. public static readonly ConformanceRule R2706 = new ConformanceRule (
  694. "R2706",
  695. "A wsdl:binding in a DESCRIPTION MUST use the value of \"literal\" for the use attribute in all soapbind:body, soapbind:fault, soapbind:header and soapbind:headerfault elements",
  696. "");
  697. // R2709: Suggestion.
  698. public static readonly ConformanceRule R2710 = new ConformanceRule (
  699. "R2710",
  700. "The operations in a wsdl:binding in a DESCRIPTION MUST result in operation signatures that are different from one another.",
  701. "");
  702. public static readonly ConformanceRule R2711 = new ConformanceRule (
  703. "R2711",
  704. "A DESCRIPTION SHOULD NOT have more than one wsdl:port with the same value for the location attribute of the soapbind:address element.",
  705. "");
  706. // R2712: related to ENVELOPE.
  707. // R2714: related to INSTANCE.
  708. // R2750, R2727: related to CONSUMER.
  709. public static readonly ConformanceRule R2716 = new ConformanceRule (
  710. "R2716",
  711. "A document-literal binding in a DESCRIPTION MUST NOT have the namespace attribute specified on contained soapbind:body, soapbind:header, soapbind:headerfault and soapbind:fault elements.",
  712. "");
  713. public static readonly ConformanceRule R2717 = new ConformanceRule (
  714. "R2717",
  715. "An rpc-literal binding in a DESCRIPTION MUST have the namespace attribute specified, the value of which MUST be an absolute URI, on contained soapbind:body elements.",
  716. "");
  717. public static readonly ConformanceRule R2726 = new ConformanceRule (
  718. "R2726",
  719. "An rpc-literal binding in a DESCRIPTION MUST NOT have the namespace attribute specified on contained soapbind:header, soapbind:headerfault and soapbind:fault elements.",
  720. "");
  721. public static readonly ConformanceRule R2718 = new ConformanceRule (
  722. "R2718",
  723. "A wsdl:binding in a DESCRIPTION MUST have the same set of wsdl:operations as the wsdl:portType to which it refers.",
  724. "");
  725. // R2719: is about allowed condition (MAY).
  726. // R2740, R2741: no way to detect known faults here.
  727. // R2742, R2743: related to ENVELOPE.
  728. public static readonly ConformanceRule R2720 = new ConformanceRule (
  729. "R2720",
  730. "A wsdl:binding in a DESCRIPTION MUST use the part attribute with a schema type of \"NMTOKEN\" on all contained soapbind:header and soapbind:headerfault elements.",
  731. "");
  732. // R2749: is satisfied by API nature.
  733. public static readonly ConformanceRule R2721 = new ConformanceRule (
  734. "R2721",
  735. "A wsdl:binding in a DESCRIPTION MUST have the name attribute specified on all contained soapbind:fault elements.",
  736. "");
  737. public static readonly ConformanceRule R2754 = new ConformanceRule (
  738. "R2754",
  739. "In a DESCRIPTION, the value of the name attribute on a soapbind:fault element MUST match the value of the name attribute on its parent wsdl:fault element.",
  740. "");
  741. // R2722: is about allowed condition (MAY).
  742. public static readonly ConformanceRule R2723 = new ConformanceRule (
  743. "R2723",
  744. "f in a wsdl:binding in a DESCRIPTION the use attribute on a contained soapbind:fault element is present, its value MUST be \"literal\".",
  745. "");
  746. // R2707: is satisfied by our implementation.
  747. // R2724, R2725: related to INSTANCE.
  748. // R2729, R2735: related to ENVELOPE.
  749. // R2755: related to MESSAGE.
  750. // R2737, R2738, R2739, R2753: related to ENVELOPE.
  751. // R2751, R2752: related to ENVELOPE.
  752. // R2744, R2745: related to MESSAGE.
  753. // R2747, R2748: related to CONSUMER.
  754. // 4.8 Use of XML Schema
  755. // R2800: satisfied by API nature.
  756. // R2801: ditto.
  757. #endregion
  758. /*
  759. Below are the combination of these documents:
  760. http://www.ws-i.org/Profiles/BasicProfile-1.1-2004-08-24.html
  761. http://www.ws-i.org/Testing/Tools/2005/01/BP11_TAD_1-1.htm
  762. TAD No. component recomm. WS-I Req.
  763. BP2010 portType R2304
  764. BP2011 types R2011
  765. BP2012 binding R2204
  766. BP2013 binding R2203
  767. BP2014 operation R2305
  768. BP2017 binding R2705,R2706
  769. BP2018 definitions R2023,R2030
  770. BP2019 binding R2716
  771. BP2020 binding R2717
  772. BP2021 binding R2720,R2749
  773. BP2022 binding R2721
  774. BP2032 binding R2754
  775. BP2034 definitions rec. R1034,R4005
  776. BP2098 import R2007
  777. BP2101 definitions R2001
  778. BP2103 definitions R2003
  779. BP2104 definitions R2005
  780. BP2105 definitions R2022,R2030
  781. BP2107 types R2105
  782. BP2108 types R2110,R2111
  783. BP2110 types rec. R2112
  784. BP2111 binding R2201
  785. BP2112 binding R2207
  786. BP2113 binding R2205
  787. BP2114 binding rec. R2209
  788. BP2115 message R2206
  789. BP2116 message R2306
  790. BP2117 binding R2726
  791. BP2118 binding R2718
  792. BP2119 binding R2210
  793. BP2120 binding R2710
  794. BP2122 types R2801
  795. BP2123 definitions rec. R2026
  796. BP2803 import R2803
  797. */
  798. }
  799. }
  800. #endif