2 // System.Web.Services.Description.WebServicesInteroperability.cs
5 // Lluis Sanchez (lluis@novell.com)
7 // Copyright (C) Novell, Inc., 2004
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:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
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.
33 using System.Collections;
35 namespace System.Web.Services.Description
37 public sealed class WebServicesInteroperability
39 private WebServicesInteroperability ()
44 public static bool CheckConformance (WsiClaims claims, ServiceDescription service, BasicProfileViolationCollection violations)
46 ServiceDescriptionCollection col = new ServiceDescriptionCollection ();
48 ConformanceCheckContext ctx = new ConformanceCheckContext (col, violations);
49 return Check (claims, ctx, col);
53 public static bool CheckConformance (WsiClaims claims, ServiceDescriptionCollection services, BasicProfileViolationCollection violations)
55 ConformanceCheckContext ctx = new ConformanceCheckContext (services, violations);
56 return Check (claims, ctx, services);
60 public static bool CheckConformance (WsiClaims claims, WebReference webReference, BasicProfileViolationCollection violations)
62 ConformanceCheckContext ctx = new ConformanceCheckContext (webReference, violations);
63 return Check (claims, ctx, webReference.Documents);
66 static bool Check (WsiClaims claims, ConformanceCheckContext ctx, IEnumerable documents)
68 ConformanceChecker[] checkers = GetCheckers (claims);
69 if (checkers == null) return true;
71 foreach (object doc in documents) {
72 if (!(doc is ServiceDescription)) continue;
74 foreach (ConformanceChecker c in checkers)
75 Check (ctx, c, (ServiceDescription)doc);
78 return ctx.Violations.Count == 0;
81 static ConformanceChecker[] GetCheckers (WsiClaims claims)
83 if ((claims & WsiClaims.BP10) != 0)
84 return new ConformanceChecker[] { BasicProfileChecker.Instance };
88 static void Check (ConformanceCheckContext ctx, ConformanceChecker checker, ServiceDescription sd)
90 ctx.ServiceDescription = sd;
91 ctx.Checker = checker;
93 checker.Check (ctx, sd);
94 CheckExtensions (ctx, checker, sd.Extensions);
96 foreach (Service s in sd.Services) {
97 checker.Check (ctx, s);
98 foreach (Port p in s.Ports) {
99 checker.Check (ctx, p);
100 CheckExtensions (ctx, checker, p.Extensions);
104 foreach (Binding b in sd.Bindings)
106 checker.Check (ctx, b);
107 CheckExtensions (ctx, checker, b.Extensions);
109 foreach (OperationBinding oper in b.Operations) {
110 CheckExtensions (ctx, checker, oper.Extensions);
112 foreach (MessageBinding mb in oper.Faults) {
113 checker.Check (ctx, mb);
114 CheckExtensions (ctx, checker, mb.Extensions);
117 checker.Check (ctx, oper.Input);
118 CheckExtensions (ctx, checker, oper.Input.Extensions);
120 checker.Check (ctx, oper.Output);
121 CheckExtensions (ctx, checker, oper.Output.Extensions);
125 foreach (PortType pt in sd.PortTypes)
127 checker.Check (ctx, pt);
129 foreach (Operation oper in pt.Operations) {
130 checker.Check (ctx, oper);
131 foreach (OperationMessage msg in oper.Messages)
132 checker.Check (ctx, msg);
134 foreach (OperationMessage msg in oper.Faults)
135 checker.Check (ctx, msg);
139 foreach (Message msg in sd.Messages)
141 checker.Check (ctx, msg);
142 foreach (MessagePart part in msg.Parts)
143 checker.Check (ctx, part);
147 static void CheckExtensions (ConformanceCheckContext ctx, ConformanceChecker checker, ServiceDescriptionFormatExtensionCollection extensions)
149 foreach (ServiceDescriptionFormatExtension ext in extensions)
150 checker.Check (ctx, ext);