void IPolicyImportExtension.ImportPolicy(MetadataImporter importer, PolicyConversionContext context) { if (importer == null) { throw new ArgumentNullException("importer"); } if (context == null) { throw new ArgumentNullException("context"); } ICollection <XmlElement> assertions = context.GetBindingAssertions(); foreach (XmlElement assertion in assertions) { if ((assertion.NamespaceURI == GZipMessageEncodingPolicyConstants.GZipEncodingNamespace) && (assertion.LocalName == GZipMessageEncodingPolicyConstants.GZipEncodingName) ) { assertions.Remove(assertion); context.BindingElements.Add(new GZipMessageEncodingBindingElement()); break; } } }
static void AddWSAddressingAssertion(PolicyConversionContext context, AddressingVersion addressing) { XmlElement addressingAssertion = null; if (addressing == AddressingVersion.WSAddressing10) { addressingAssertion = XmlDoc.CreateElement("wsaw", "UsingAddressing", "http://www.w3.org/2006/05/addressing/wsdl"); } else if (addressing == AddressingVersion.WSAddressingAugust2004) { addressingAssertion = XmlDoc.CreateElement("wsap", "UsingAddressing", AddressingVersionConstants.WSAddressingAugust2004NameSpace + "/policy"); } else if (addressing == AddressingVersion.None) { // do nothing addressingAssertion = null; } else { throw new InvalidOperationException("This addressing version is not supported:\n" + addressing.ToString()); } if (addressingAssertion != null) { context.GetBindingAssertions().Add(addressingAssertion); } }
// We expose in policy the fact that we're UDP, and whether we're multicast or not. // Import is done through UdpBindingElementImporter. void IPolicyExportExtension.ExportPolicy(MetadataExporter exporter, PolicyConversionContext context) { if (exporter == null) { throw new ArgumentNullException("exporter"); } if (context == null) { throw new ArgumentNullException("context"); } ICollection <XmlElement> bindingAssertions = context.GetBindingAssertions(); XmlDocument xmlDocument = new XmlDocument(); bindingAssertions.Add(xmlDocument.CreateElement( UdpPolicyStrings.Prefix, UdpPolicyStrings.TransportAssertion, UdpPolicyStrings.UdpNamespace)); bool createdNew = false; MessageEncodingBindingElement encodingBindingElement = context.BindingElements.Find <MessageEncodingBindingElement>(); if (encodingBindingElement == null) { createdNew = true; encodingBindingElement = new TextMessageEncodingBindingElement(); } if (createdNew && encodingBindingElement is IPolicyExportExtension) { ((IPolicyExportExtension)encodingBindingElement).ExportPolicy(exporter, context); } AddWSAddressingAssertion(context, encodingBindingElement.MessageVersion.Addressing); }
void IPolicyExportExtension.ExportPolicy(MetadataExporter exporter, PolicyConversionContext context) { if (exporter == null) { throw new NullReferenceException("exporter"); } if (context == null) { throw new NullReferenceException("context"); } XmlElement mhscElement = xmlDocument.CreateElement(HttpCookiePolicyStrings.Prefix, HttpCookiePolicyStrings.HttpCookiePolicyElement, HttpCookiePolicyStrings.Namespace); if (exchangeTerminateMessage) { XmlAttribute attribute = xmlDocument.CreateAttribute( HttpCookiePolicyStrings.ExchangeTerminateAttribute); attribute.Value = "true"; mhscElement.Attributes.Append(attribute); } context.GetBindingAssertions().Add(mhscElement); }
void IPolicyImportExtension.ImportPolicy(MetadataImporter importer, PolicyConversionContext context) { if (importer == null) { throw new ArgumentNullException("importer"); } if (context == null) { throw new ArgumentNullException("context"); } UdpTransportBindingElement udpBindingElement = null; bool multicast = false; PolicyAssertionCollection policyAssertions = context.GetBindingAssertions(); if (policyAssertions.Remove(UdpPolicyStrings.TransportAssertion, UdpPolicyStrings.UdpNamespace) != null) { udpBindingElement = new UdpTransportBindingElement(); } if (policyAssertions.Remove(UdpPolicyStrings.MulticastAssertion, UdpPolicyStrings.UdpNamespace) != null) { multicast = true; } if (udpBindingElement != null) { udpBindingElement.Multicast = multicast; context.BindingElements.Add(udpBindingElement); } }
void IPolicyExportExtension.ExportPolicy(MetadataExporter exporter, PolicyConversionContext context) { if (context == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context"); } if (context.BindingElements != null) { OneWayBindingElement oneWay = context.BindingElements.Find <OneWayBindingElement>(); if (oneWay != null) { // base assertion XmlDocument doc = new XmlDocument(); XmlElement assertion = doc.CreateElement(OneWayPolicyConstants.Prefix, OneWayPolicyConstants.OneWay, OneWayPolicyConstants.Namespace); if (oneWay.PacketRoutable) { // add nested packet routable assertion XmlElement child = doc.CreateElement(OneWayPolicyConstants.Prefix, OneWayPolicyConstants.PacketRoutable, OneWayPolicyConstants.Namespace); assertion.AppendChild(child); } context.GetBindingAssertions().Add(assertion); } } }
void System.ServiceModel.Description.IPolicyExportExtension.ExportPolicy(MetadataExporter exporter, PolicyConversionContext context) { if (exporter == null) { throw new ArgumentNullException("exporter"); } if (context == null) { throw new ArgumentNullException("context"); } XmlDocument xmlDocument = new XmlDocument(); XmlElement xmlElement = null; if (this.TransportProtectionEnabled) { SslStreamSecurityBindingElement sslStreamSecurityBindingElement = new SslStreamSecurityBindingElement(); if (!context.BindingElements.Contains(typeof(SecurityBindingElement))) { context.BindingElements.Add(sslStreamSecurityBindingElement); } ((IPolicyExportExtension)sslStreamSecurityBindingElement).ExportPolicy(exporter, context); } switch (this.relayedConnectionMode) { case TcpRelayConnectionMode.Hybrid: { xmlElement = xmlDocument.CreateElement("rel", "HybridSocketConnection", "http://schemas.microsoft.com/netservices/2009/05/servicebus/connect"); break; } default: { xmlElement = xmlDocument.CreateElement("rel", "RelaySocketConnection", "http://schemas.microsoft.com/netservices/2009/05/servicebus/connect"); break; } } context.GetBindingAssertions().Add(xmlElement); XmlElement xmlElement1 = xmlDocument.CreateElement("rel", "ListenerRelayCredential", "http://schemas.microsoft.com/netservices/2009/05/servicebus/connect"); xmlElement1.SetAttribute("Optional", exporter.PolicyVersion.Namespace, "true"); context.GetBindingAssertions().Add(xmlElement1); if (this.RelayClientAuthenticationType == Microsoft.ServiceBus.RelayClientAuthenticationType.RelayAccessToken) { XmlElement xmlElement2 = xmlDocument.CreateElement("rel", "SenderRelayCredential", "http://schemas.microsoft.com/netservices/2009/05/servicebus/connect"); context.GetBindingAssertions().Add(xmlElement2); } }
void ImportPolicyInternal(PolicyConversionContext context) { ICollection <XmlElement> assertions = context.GetBindingAssertions(); XmlElement encodingAssertion; MessageEncodingBindingElement encodingBindingElement; encodingBindingElement = CreateEncodingBindingElement(context.GetBindingAssertions(), out encodingAssertion); AddressingVersion addressingVersion = WsdlImporter.WSAddressingHelper.FindAddressingVersion(context); ApplyAddressingVersion(encodingBindingElement, addressingVersion); #pragma warning suppress 56506 context.BindingElements.Add(encodingBindingElement); }
void IPolicyExportExtension.ExportPolicy(MetadataExporter exporter, PolicyConversionContext context) { PolicyAssertionCollection assertions = context.GetBindingAssertions(); XmlDocument doc = new XmlDocument(); assertions.Add(doc.CreateElement("msb", "BinaryEncoding", "http://schemas.microsoft.com/ws/06/2004/mspolicy/netbinary1")); }
public virtual void ExportPolicy(MetadataExporter exporter, PolicyConversionContext context) { if (context == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context"); } ContextBindingElementPolicy.ExportRequireContextAssertion(this, context.GetBindingAssertions()); }
public void ExportPolicy(MetadataExporter exporter, PolicyConversionContext context) { PolicyAssertionCollection assertions = context.GetBindingAssertions(); XmlDocument doc = new XmlDocument(); assertions.Add(doc.CreateElement("wsoma", "OptimizedMimeSerialization", "http://schemas.xmlsoap.org/ws/2004/09/policy/optimizedmimeserialization")); }
// BindingElement implementation . . . public void ExportPolicy( MetadataExporter exporter, PolicyConversionContext context) { XmlDocument xmlDoc = new XmlDocument(); XmlElement xmlElement = xmlDoc.CreateElement("MyPolicyAssertion"); context.GetBindingAssertions().Add(xmlElement); }
void IPolicyExportExtension.ExportPolicy( MetadataExporter exporter, PolicyConversionContext context) { var token = GetTransportTokenAssertion(); var transportBinding = TransportBindingElement.CreateTransportBinding(token); context.GetBindingAssertions().Add(transportBinding); }
void ITransportPolicyImport.ImportPolicy(MetadataImporter importer, PolicyConversionContext policyContext) { if (PolicyConversionContext.FindAssertion(policyContext.GetBindingAssertions(), "Streamed", "http://schemas.microsoft.com/ws/2006/05/framing/policy", true) != null) { this.TransferMode = System.ServiceModel.TransferMode.Streamed; } WindowsStreamSecurityBindingElement.ImportPolicy(importer, policyContext); SslStreamSecurityBindingElement.ImportPolicy(importer, policyContext); }
void IPolicyExportExtension.ExportPolicy(MetadataExporter exporter, PolicyConversionContext context) { if (context == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context"); } exporter.State[typeof(SupportedAddressingMode).Name] = SupportedAddressingMode.NonAnonymous; context.GetBindingAssertions().Add(CreateCompositeDuplexAssertion()); }
/// <summary> /// Configura a política de export. /// </summary> /// <param name="exporter"></param> /// <param name="policyContext"></param> void IPolicyExportExtension.ExportPolicy(MetadataExporter exporter, PolicyConversionContext policyContext) { if (policyContext == null) { throw new ArgumentNullException("policyContext"); } XmlDocument document = new XmlDocument(); policyContext.GetBindingAssertions().Add(document.CreateElement(GZipMessageEncodingPolicyConstants.GZipEncodingPrefix, GZipMessageEncodingPolicyConstants.GZipEncodingName, GZipMessageEncodingPolicyConstants.GZipEncodingNamespace)); }
void ITransportPolicyImport.ImportPolicy(MetadataImporter importer, PolicyConversionContext policyContext) { if (PolicyConversionContext.FindAssertion(policyContext.GetBindingAssertions(), TransportPolicyConstants.StreamedName, TransportPolicyConstants.DotNetFramingNamespace, true) != null) { this.TransferMode = TransferMode.Streamed; } WindowsStreamSecurityBindingElement.ImportPolicy(importer, policyContext); SslStreamSecurityBindingElement.ImportPolicy(importer, policyContext); }
/// <summary> /// ExportPolicy method implementation /// </summary> public void ExportPolicy(MetadataExporter exporter, PolicyConversionContext policyContext) { if (policyContext == null) { throw new ArgumentNullException("policyContext"); } XmlDocument document = new XmlDocument(); policyContext.GetBindingAssertions().Add(document.CreateElement(ReplayMessageEncodingPolicyConstants.MFAEncodingPrefix, ReplayMessageEncodingPolicyConstants.MFAEncodingName, ReplayMessageEncodingPolicyConstants.MFAEncodingNamespace)); }
void IPolicyExportExtension.ExportPolicy(MetadataExporter exporter, PolicyConversionContext policyContext) { if (policyContext == null) { throw new ArgumentNullException("policyContext"); } XmlDocument document = new XmlDocument(); policyContext.GetBindingAssertions().Add(document.CreateElement("gzip", "GZipEncoding", "http://Sample.Service.netgzip1")); }
void IPolicyExportExtension.ExportPolicy(MetadataExporter exporter, PolicyConversionContext policyContext) { if (policyContext == null) { throw new ArgumentNullException("policyContext"); } XmlDocument xmlDocument = new XmlDocument(); policyContext.GetBindingAssertions().Add(xmlDocument.CreateElement("gzip", "GZipEncoding", "http://schemas.microsoft.com/ws/06/2004/mspolicy/netgzip1")); }
void IPolicyExportExtension.ExportPolicy(MetadataExporter exporter, PolicyConversionContext policyContext) { if (policyContext == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("policyContext"); } XmlDocument document = new XmlDocument(); policyContext.GetBindingAssertions().Add(document.CreateElement("wsoma", "OptimizedMimeSerialization", "http://schemas.xmlsoap.org/ws/2004/09/policy/optimizedmimeserialization")); }
void IPolicyExportExtension.ExportPolicy(MetadataExporter exporter, PolicyConversionContext policyContext) { if (policyContext == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("policyContext"); } XmlDocument document = new XmlDocument(); policyContext.GetBindingAssertions().Add(document.CreateElement("msb", "BinaryEncoding", "http://schemas.microsoft.com/ws/06/2004/mspolicy/netbinary1")); }
private void ImportPolicyInternal(PolicyConversionContext context) { XmlElement element; context.GetBindingAssertions(); MessageEncodingBindingElement encodingBindingElement = this.CreateEncodingBindingElement(context.GetBindingAssertions(), out element); AddressingVersion addressingVersion = WsdlImporter.WSAddressingHelper.FindAddressingVersion(context); ApplyAddressingVersion(encodingBindingElement, addressingVersion); context.BindingElements.Add(encodingBindingElement); }
bool ImportHttpAuthScheme(MetadataImporter importer, HttpTransportBindingElement bindingElement, PolicyConversionContext context) { var assertions = context.GetBindingAssertions(); var authSchemes = AuthenticationSchemes.None; var httpsTransport = bindingElement as HttpsTransportBindingElement; bool certificate = httpsTransport != null ? httpsTransport.RequireClientCertificate : false; var authElements = PolicyImportHelper.FindAssertionByNS( assertions, PolicyImportHelper.HttpAuthNS); foreach (XmlElement authElement in authElements) { assertions.Remove(authElement); if (certificate) { importer.AddWarning( "Invalid authentication assertion while " + "using client certificate: {0}", authElement.OuterXml); return(false); } switch (authElement.LocalName) { case "BasicAuthentication": authSchemes |= AuthenticationSchemes.Basic; break; case "NtlmAuthentication": authSchemes |= AuthenticationSchemes.Ntlm; break; case "DigestAuthentication": authSchemes |= AuthenticationSchemes.Digest; break; case "NegotiateAuthentication": authSchemes |= AuthenticationSchemes.Negotiate; break; default: importer.AddWarning( "Invalid policy assertion: {0}", authElement.OuterXml); return(false); } } bindingElement.AuthenticationScheme = authSchemes; return(true); }
void IPolicyExportExtension.ExportPolicy(MetadataExporter exporter, PolicyConversionContext context) { if (context == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context"); } if ((context.BindingElements != null) && (context.BindingElements.Find <UseManagedPresentationBindingElement>() != null)) { XmlElement item = new XmlDocument().CreateElement("ic", "RequireFederatedIdentityProvisioning", "http://schemas.xmlsoap.org/ws/2005/05/identity"); context.GetBindingAssertions().Add(item); } }
void IPolicyImportExtension.ImportPolicy(MetadataImporter importer, PolicyConversionContext policyContext) { if (policyContext == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("policyContext"); } if ((PolicyConversionContext.FindAssertion(policyContext.GetBindingAssertions(), "RequireFederatedIdentityProvisioning", "http://schemas.xmlsoap.org/ws/2005/05/identity", true) != null) && (policyContext.BindingElements.Find <UseManagedPresentationBindingElement>() == null)) { UseManagedPresentationBindingElement item = new UseManagedPresentationBindingElement(); policyContext.BindingElements.Add(item); } }
void System.ServiceModel.Description.IPolicyImportExtension.ImportPolicy(MetadataImporter importer, PolicyConversionContext context) { if (importer == null || context == null) { throw Microsoft.ServiceBus.Messaging.FxTrace.Exception.ArgumentNull((importer == null ? "importer" : "context")); } if (context.GetBindingAssertions().Remove("netMessaging", "http://sample.schemas.microsoft.com/policy/netMessaging") != null) { NetMessagingTransportBindingElement netMessagingTransportBindingElement = new NetMessagingTransportBindingElement(); context.BindingElements.Add(netMessagingTransportBindingElement); } }
void IPolicyImportExtension.ImportPolicy(MetadataImporter importer, PolicyConversionContext context) { if (importer == null) { throw new ArgumentNullException("importer"); } if (context == null) { throw new ArgumentNullException("context"); } ICollection <XmlElement> bindingAssertions = context.GetBindingAssertions(); List <XmlElement> processedAssertions = new List <XmlElement>(); UdpTransportBindingElement udpBindingElement = null; bool multicast = false; foreach (XmlElement assertion in bindingAssertions) { if (assertion.NamespaceURI != UdpPolicyStrings.UdpNamespace) { continue; } switch (assertion.LocalName) { case UdpPolicyStrings.TransportAssertion: udpBindingElement = new UdpTransportBindingElement(); break; case UdpPolicyStrings.MulticastAssertion: multicast = true; break; default: continue; } processedAssertions.Add(assertion); } if (udpBindingElement != null) { udpBindingElement.Multicast = multicast; context.BindingElements.Add(udpBindingElement); } for (int i = 0; i < processedAssertions.Count; i++) { bindingAssertions.Remove(processedAssertions[i]); } }
// isDualSecurityModeOnly is true if the binding has both message security and https security enabled. private bool TryImportTransportSecurityBindingElement(MetadataImporter importer, PolicyConversionContext policyContext, out SecurityBindingElement sbe, bool isDualSecurityModeOnly) { TransportSecurityBindingElement binding = null; XmlElement assertion; sbe = null; WSSecurityPolicy securityPolicy; if (WSSecurityPolicy.TryGetSecurityPolicyDriver(policyContext.GetBindingAssertions(), out securityPolicy)) { if (securityPolicy.TryImportWsspTransportBindingAssertion(importer, policyContext.GetBindingAssertions(), out binding, out assertion)) { this.ImportEndpointScopeMessageBindingAssertions(importer, policyContext, binding); // If it is not DualSecurityMode then it is Mixed mode. So we need to look for supporting tokens in the binding. if (!isDualSecurityModeOnly) { this.ImportOperationScopeSupportingTokensPolicy(importer, policyContext, binding); if (importer.State.ContainsKey(InSecureConversationBootstrapBindingImportMode)) { this.ImportMessageScopeProtectionPolicy(importer, policyContext); } if (HasSupportingTokens(binding) || binding.IncludeTimestamp) { sbe = binding; policyContext.BindingElements.Add(binding); } } } else if (assertion != null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(string.Format(SRServiceModel.UnsupportedSecurityPolicyAssertion, assertion.OuterXml))); } } return(binding != null); }
// <snippet0> public void ImportPolicy(MetadataImporter importer, PolicyConversionContext context) { Console.WriteLine("The custom policy importer has been called."); foreach (XmlElement assertion in context.GetBindingAssertions()) { Console.WriteLine(assertion.NamespaceURI + " : " + assertion.Name); // locate a particular assertion by Name and NamespaceURI XmlElement customAssertion = context.GetBindingAssertions().Find(name1, ns1); if (customAssertion != null) { // Found assertion; remove from collection. context.GetBindingAssertions().Remove(customAssertion); Console.WriteLine( "Removed our custom assertion from the imported " + "assertions collection and inserting our custom binding element." ); // Here if you find the custom policy assertion that you are looking for, // add the custom binding element that handles the functionality that the policy indicates. // Attach it to the PolicyConversionContext.BindingElements collection. // For example, if the custom policy had a "speed" attribute value: /* * string speed * = customAssertion.GetAttribute(SpeedBindingElement.name2, SpeedBindingElement.ns2); * SpeedBindingElement e = new SpeedBindingElement(speed); * context.BindingElements.Add(e); */ } // write assertion name in red. Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(assertion.NamespaceURI + " : " + assertion.Name); //write contents in gray. Console.WriteLine(assertion.OuterXml); Console.ForegroundColor = ConsoleColor.Gray; } }