示例#1
0
        PolicyConversionContext ExportPolicy(ServiceEndpoint endpoint, WSBinding binding)
        {
            var context = new CustomPolicyConversionContext(endpoint);

            var elements = endpoint.Binding.CreateBindingElements();

            foreach (var element in elements)
            {
                var exporter = element as IPolicyExportExtension;
                if (exporter == null)
                {
                    continue;
                }

                try {
                    exporter.ExportPolicy(this, context);
                } catch (Exception ex) {
                    var error = AddError(
                        "Failed to export endpoint '{0}': policy exporter " +
                        "'{1}' threw an exception: {2}", endpoint.Name,
                        element.GetType(), ex);
                    throw new MetadataExportException(error, ex);
                }
            }

            var assertions = context.GetBindingAssertions();

            if (assertions.Count == 0)
            {
                return(context);
            }

            var doc    = new XmlDocument();
            var policy = doc.CreateElement("wsp", "Policy", PolicyImportHelper.PolicyNS);

            doc.AppendChild(policy);

            var exactlyOne = doc.CreateElement("wsp", "ExactlyOne", PolicyImportHelper.PolicyNS);
            var all        = doc.CreateElement("wsp", "All", PolicyImportHelper.PolicyNS);

            policy.AppendChild(exactlyOne);
            exactlyOne.AppendChild(all);

            foreach (var assertion in assertions)
            {
                var imported = doc.ImportNode(assertion, true);
                all.AppendChild(imported);
            }

            binding.Extensions.Add(policy);
            return(context);
        }
示例#2
0
		PolicyConversionContext ExportPolicy (ServiceEndpoint endpoint, WSBinding binding)
		{
			var context = new CustomPolicyConversionContext (endpoint);

			var elements = endpoint.Binding.CreateBindingElements ();
			foreach (var element in elements) {
				var exporter = element as IPolicyExportExtension;
				if (exporter == null)
					continue;

				try {
					exporter.ExportPolicy (this, context);
				} catch (Exception ex) {
					var error = AddError (
						"Failed to export endpoint '{0}': policy exporter " +
						"'{1}' threw an exception: {2}", endpoint.Name,
						element.GetType (), ex);
					throw new MetadataExportException (error, ex);
				}
			}

			var assertions = context.GetBindingAssertions ();
			if (assertions.Count == 0)
				return context;

			var doc = new XmlDocument ();
			var policy = doc.CreateElement ("wsp", "Policy", PolicyImportHelper.PolicyNS);
			doc.AppendChild (policy);

			var exactlyOne = doc.CreateElement ("wsp", "ExactlyOne", PolicyImportHelper.PolicyNS);
			var all = doc.CreateElement ("wsp", "All", PolicyImportHelper.PolicyNS);

			policy.AppendChild (exactlyOne);
			exactlyOne.AppendChild (all);

			foreach (var assertion in assertions) {
				var imported = doc.ImportNode (assertion, true);
				all.AppendChild (imported);
			}

			binding.Extensions.Add (policy);
			return context;
		}
示例#3
0
		void ImportPolicy (WSBinding binding, ServiceEndpoint endpoint)
		{
			var context = new Description.CustomPolicyConversionContext (binding, endpoint);
			var assertions = context.GetBindingAssertions ();

			foreach (var ext in binding.Extensions) {
				var xml = ext as XmlElement;
				if (xml == null)
					continue;
				if (!xml.NamespaceURI.Equals (Constants.WspNamespace))
					continue;
				if (xml.LocalName.Equals ("Policy")) {
					context.AddPolicyAssertion (xml);
					continue;
				}
				if (!xml.LocalName.Equals ("PolicyReference"))
					continue;
				var uri = xml.GetAttribute ("URI");

				if (!uri.StartsWith ("#")) {
					// FIXME
					AddWarning (
						"Failed to resolve unknown policy reference `{0}' for " +
						"binding `{1}'.", uri, binding.Name);
					continue;
				}

				foreach (var sext in binding.ServiceDescription.Extensions) {
					var sxml = sext as XmlElement;
					if (sxml == null)
						continue;
					if (!sxml.NamespaceURI.Equals (Constants.WspNamespace))
						continue;
					if (!sxml.LocalName.Equals ("Policy"))
						continue;
					var id = sxml.GetAttribute ("Id", Constants.WsuNamespace);
					if (!uri.Substring (1).Equals (id))
						continue;
					context.AddPolicyAssertion (sxml);
				}
			}

			foreach (IPolicyImportExtension extension in PolicyImportExtensions) {
				try {
					extension.ImportPolicy (this, context);
				} catch (Exception ex) {
					AddWarning (
						"PolicyImportException `{0}' threw an exception while " +
						"trying to import policy references for endpoint `{1}': {2}",
						extension.GetType ().Name, endpoint.Name, ex.Message);
				}
			}
		}