Exemple #1
0
        void IPolicyExportExtension.ExportPolicy(MetadataExporter exporter, PolicyConversionContext context)
        {
            bool flag;

            if (exporter == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("exporter");
            }
            if (context == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context");
            }
            ICollection <XmlElement> bindingAssertions = context.GetBindingAssertions();

            if (TransferModeHelper.IsRequestStreamed(this.TransferMode) || TransferModeHelper.IsResponseStreamed(this.TransferMode))
            {
                bindingAssertions.Add(new XmlDocument().CreateElement("msf", "Streamed", "http://schemas.microsoft.com/ws/2006/05/framing/policy"));
            }
            MessageEncodingBindingElement element = this.FindMessageEncodingBindingElement(context.BindingElements, out flag);

            if (flag && (element is IPolicyExportExtension))
            {
                element = new BinaryMessageEncodingBindingElement();
                ((IPolicyExportExtension)element).ExportPolicy(exporter, context);
            }
            WsdlExporter.WSAddressingHelper.AddWSAddressingAssertion(exporter, context, element.MessageVersion.Addressing);
        }
Exemple #2
0
        void IPolicyExportExtension.ExportPolicy(MetadataExporter exporter, PolicyConversionContext context)
        {
            if (context == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context");
            }

            if (context.BindingElements != null)
            {
                PrivacyNoticeBindingElement settings =
                    context.BindingElements.Find <PrivacyNoticeBindingElement>();

                if (settings != null)
                {
                    XmlDocument doc = new XmlDocument();

                    // PrivacyNotice assertion
                    XmlElement assertion = doc.CreateElement(PrivacyNoticePolicyStrings.PrivacyNoticePrefix,
                                                             PrivacyNoticePolicyStrings.PrivacyNoticeName,
                                                             PrivacyNoticePolicyStrings.PrivacyNoticeNamespace);

                    assertion.InnerText = settings.Url.ToString();
                    assertion.SetAttribute(PrivacyNoticePolicyStrings.PrivacyNoticeVersionAttributeName, PrivacyNoticePolicyStrings.PrivacyNoticeNamespace, XmlConvert.ToString(settings.Version));

                    context.GetBindingAssertions().Add(assertion);
                }
            }
        }
 protected override void OnImportPolicy(XmlElement assertion,
                                        MessageVersion messageVersion,
                                        MetadataImporter exporter,
                                        PolicyConversionContext context)
 {
     throw new NotImplementedException();
 }
Exemple #4
0
        internal void OnImportPolicy(MetadataImporter importer, PolicyConversionContext context)
        {
            string     str;
            XmlElement element = PolicyConversionContext.FindAssertion(context.GetBindingAssertions(), "PeerTransportSecurityMode", "http://schemas.microsoft.com/soap/peer", true);

            this.Mode = SecurityMode.Transport;
            if ((element != null) && ((str = element.InnerText) != null))
            {
                if (!(str == "PeerTransportSecurityModeNone"))
                {
                    if (str == "PeerTransportSecurityModeTransport")
                    {
                        this.Mode = SecurityMode.Transport;
                    }
                    else if (str == "PeerTransportSecurityModeMessage")
                    {
                        this.Mode = SecurityMode.Message;
                    }
                    else if (str == "PeerTransportSecurityModeTransportWithMessageCredential")
                    {
                        this.Mode = SecurityMode.TransportWithMessageCredential;
                    }
                }
                else
                {
                    this.Mode = SecurityMode.None;
                }
            }
            this.transportSecurity.OnImportPolicy(importer, context);
        }
        void IPolicyImportExtension.ImportPolicy(MetadataImporter importer, PolicyConversionContext context)
        {
            if (importer == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("importer");
            }
            if (context == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context");
            }
            bool       flag    = false;
            XmlElement element = PolicyConversionContext.FindAssertion(context.GetBindingAssertions(), "RMAssertion", "http://schemas.xmlsoap.org/ws/2005/02/rm/policy", true);

            if (element != null)
            {
                ProcessReliableSessionFeb2005Assertion(element, GetReliableSessionBindingElement(context));
                flag = true;
            }
            element = PolicyConversionContext.FindAssertion(context.GetBindingAssertions(), "RMAssertion", "http://docs.oasis-open.org/ws-rx/wsrmp/200702", true);
            if (element != null)
            {
                if (flag)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidChannelBindingException(System.ServiceModel.SR.GetString("MultipleVersionsFoundInPolicy", new object[] { "RMAssertion" })));
                }
                ProcessReliableSession11Assertion(importer, element, GetReliableSessionBindingElement(context));
            }
        }
        internal void OnExportPolicy(MetadataExporter exporter, PolicyConversionContext context)
        {
            string assertion = "";

            switch (this.Mode)
            {
            case SecurityMode.None:
                assertion = PeerTransportPolicyConstants.PeerTransportSecurityModeNone;
                break;

            case SecurityMode.Transport:
                assertion = PeerTransportPolicyConstants.PeerTransportSecurityModeTransport;
                break;

            case SecurityMode.Message:
                assertion = PeerTransportPolicyConstants.PeerTransportSecurityModeMessage;
                break;

            case SecurityMode.TransportWithMessageCredential:
                assertion = PeerTransportPolicyConstants.PeerTransportSecurityModeTransportWithMessageCredential;
                break;

            default:
                Fx.Assert("Unsupported value for PeerSecuritySettings.Mode");
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException());
            }
            XmlDocument doc     = new XmlDocument();
            XmlElement  element = doc.CreateElement(PeerTransportPolicyConstants.PeerTransportPrefix,
                                                    PeerTransportPolicyConstants.PeerTransportSecurityMode,
                                                    TransportPolicyConstants.PeerTransportUri);

            element.InnerText = assertion;
            context.GetBindingAssertions().Add(element);
            transportSecurity.OnExportPolicy(exporter, context);
        }
        void IPolicyImportExtension.ImportPolicy(MetadataImporter importer, PolicyConversionContext context)
        {
            Console.WriteLine("ImportPolicy");
            if (importer == null)
            {
                throw new ArgumentNullException("importer");
            }
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            SsbBindingElement         ssbBindingElement = null;
            PolicyAssertionCollection policyAssertions  = context.GetBindingAssertions();

            if (policyAssertions.Remove(SsbConstants.SsbTransportAssertion, SsbConstants.SsbNs) != null)
            {
                ssbBindingElement = new SsbBindingElement();
                ssbBindingElement.SqlConnectionString = "";
            }
            if (ssbBindingElement != null)
            {
                context.BindingElements.Add(ssbBindingElement);
            }
        }
        void ITransportPolicyImport.ImportPolicy(MetadataImporter importer, PolicyConversionContext policyContext)
        {
            ICollection <XmlElement> bindingAssertions = policyContext.GetBindingAssertions();

            if (FindAssertion(bindingAssertions, "MsmqVolatile"))
            {
                this.Durable = false;
            }
            if (FindAssertion(bindingAssertions, "MsmqBestEffort"))
            {
                this.ExactlyOnce = false;
            }
            if (FindAssertion(bindingAssertions, "MsmqSession"))
            {
                policyContext.Contract.SessionMode = SessionMode.Required;
            }
            if (FindAssertion(bindingAssertions, "Authenticated"))
            {
                this.MsmqTransportSecurity.MsmqProtectionLevel = ProtectionLevel.Sign;
                if (FindAssertion(bindingAssertions, "WindowsDomain"))
                {
                    this.MsmqTransportSecurity.MsmqAuthenticationMode = MsmqAuthenticationMode.WindowsDomain;
                }
                else
                {
                    this.MsmqTransportSecurity.MsmqAuthenticationMode = MsmqAuthenticationMode.Certificate;
                }
            }
            else
            {
                this.MsmqTransportSecurity.MsmqProtectionLevel    = ProtectionLevel.None;
                this.MsmqTransportSecurity.MsmqAuthenticationMode = MsmqAuthenticationMode.None;
            }
        }
Exemple #9
0
        internal void OnImportPolicy(MetadataImporter importer, PolicyConversionContext context)
        {
            XmlElement element = PolicyConversionContext.FindAssertion(context.GetBindingAssertions(),
                                                                       PeerTransportPolicyConstants.PeerTransportCredentialType,
                                                                       TransportPolicyConstants.PeerTransportUri, true);
            PeerTransportCredentialType credentialType = PeerTransportCredentialType.Password;

            if (element != null)
            {
                switch (element.InnerText)
                {
                case PeerTransportPolicyConstants.PeerTransportCredentialTypePassword:
                    credentialType = PeerTransportCredentialType.Password;
                    break;

                case PeerTransportPolicyConstants.PeerTransportCredentialTypeCertificate:
                    credentialType = PeerTransportCredentialType.Certificate;
                    break;

                default:
                    break;
                }
            }
            this.CredentialType = credentialType;
        }
Exemple #10
0
        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);
            }
        }
Exemple #11
0
        //<snippet14>
        #region IPolicyExporter Members
        public void ExportPolicy(MetadataExporter exporter, PolicyConversionContext policyContext)
        {
            if (exporter == null)
            {
                throw new NullReferenceException("The MetadataExporter object passed to the ExporterBindingElement is null.");
            }
            if (policyContext == null)
            {
                throw new NullReferenceException("The PolicyConversionContext object passed to the ExporterBindingElement is null.");
            }

            XmlElement elem = doc.CreateElement(name1, ns1);

            elem.InnerText = "My custom text.";
            XmlAttribute att = doc.CreateAttribute("MyCustomAttribute", ns1);

            att.Value = "ExampleValue";
            elem.Attributes.Append(att);
            XmlElement subElement = doc.CreateElement("MyCustomSubElement", ns1);

            subElement.InnerText = "Custom Subelement Text.";
            elem.AppendChild(subElement);
            policyContext.GetBindingAssertions().Add(elem);
            Console.WriteLine("The custom policy exporter was called.");
        }
Exemple #12
0
        /// <summary>
        /// Implement to include for exporting a custom policy assertion about bindings.
        /// </summary>
        /// <param name="exporter">The <see cref="T:System.ServiceModel.Description.MetadataExporter" /> that you can use to modify the exporting process.</param>
        /// <param name="context">The <see cref="T:System.ServiceModel.Description.PolicyConversionContext" /> that you can use to insert your custom policy assertion.</param>
        public void ExportPolicy(MetadataExporter exporter, PolicyConversionContext context)
        {
            if (exporter == null)
            {
                throw new ArgumentNullException("exporter");
            }

            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            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 (context == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context");
            }

            if (context.BindingElements != null)
            {
                UseManagedPresentationBindingElement settings =
                    context.BindingElements.Find <UseManagedPresentationBindingElement>();

                if (settings != null)
                {
                    XmlDocument doc = new XmlDocument();

                    // UseUseManagedPresentation assertion
                    XmlElement assertion = doc.CreateElement(UseManagedPresentationPolicyStrings.UseManagedPresentationPrefix,
                                                             UseManagedPresentationPolicyStrings.RequireFederatedIdentityProvisioningName,
                                                             UseManagedPresentationPolicyStrings.UseManagedPresentationNamespace);

                    context.GetBindingAssertions().Add(assertion);
                }
            }
        }
Exemple #14
0
        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(
                                      SsbConstants.SsbNsPrefix, SsbConstants.SsbTransportAssertion, SsbConstants.SsbNs));

            bool createdNew = false;
            MessageEncodingBindingElement encodingBindingElement = context.BindingElements.Find <MessageEncodingBindingElement>();

            if (encodingBindingElement == null)
            {
                createdNew             = true;
                encodingBindingElement = SsbConstants.DefaultMessageEncodingBindingElement;
            }

            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);
        }
Exemple #16
0
        internal void OnExportPolicy(MetadataExporter exporter, PolicyConversionContext context)
        {
            string assertion = "";

            switch (this.CredentialType)
            {
            case PeerTransportCredentialType.Password:
                assertion = PeerTransportPolicyConstants.PeerTransportCredentialTypePassword;
                break;

            case PeerTransportCredentialType.Certificate:
                assertion = PeerTransportPolicyConstants.PeerTransportCredentialTypeCertificate;
                break;

            default:
                Fx.Assert("Unsupported value for PeerTransportSecuritySettings.CredentialType");
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException());
            }
            XmlDocument doc     = new XmlDocument();
            XmlElement  element = doc.CreateElement(PeerTransportPolicyConstants.PeerTransportPrefix,
                                                    PeerTransportPolicyConstants.PeerTransportCredentialType,
                                                    TransportPolicyConstants.PeerTransportUri);

            element.InnerText = assertion;
            context.GetBindingAssertions().Add(element);
        }
        public virtual void ImportPolicy(MetadataImporter importer, PolicyConversionContext context)
        {
            if (context == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context");
            }
            if (context.BindingElements == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SRServiceModel.PolicyImportContextBindingElementCollectionIsNull));
            }

            ContextBindingElement contextBindingElement;
            XmlElement            httpUseCookieAssertion = null;

            if (ContextBindingElementPolicy.TryImportRequireContextAssertion(context.GetBindingAssertions(), out contextBindingElement))
            {
                context.BindingElements.Insert(0, contextBindingElement);
            }
            else if (ContextBindingElementPolicy.TryGetHttpUseCookieAssertion(context.GetBindingAssertions(), out httpUseCookieAssertion))
            {
                foreach (BindingElement bindingElement in context.BindingElements)
                {
                    HttpTransportBindingElement http = bindingElement as HttpTransportBindingElement;
                    if (http != null)
                    {
                        http.AllowCookies = true;
                        context.GetBindingAssertions().Remove(httpUseCookieAssertion);
                        break;
                    }
                }
            }
        }
Exemple #18
0
        void IPolicyExportExtension.ExportPolicy(
            MetadataExporter exporter,
            PolicyConversionContext context)
        {
            if (exporter == null)
            {
                throw new ArgumentNullException("exporter");
            }
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            PolicyAssertionCollection assertions = context.GetBindingAssertions();
            XmlDocument doc = new XmlDocument();

            assertions.Add(doc.CreateElement("wsaw", "UsingAddressing", "http://www.w3.org/2006/05/addressing/wsdl"));

            switch (auth_scheme)
            {
            case AuthenticationSchemes.Basic:
            case AuthenticationSchemes.Digest:
            case AuthenticationSchemes.Negotiate:
            case AuthenticationSchemes.Ntlm:
                assertions.Add(doc.CreateElement("http",
                                                 auth_scheme.ToString() + "Authentication",
                                                 "http://schemas.microsoft.com/ws/06/2004/policy/http"));
                break;
            }
        }
        internal void OnImportPolicy(MetadataImporter importer, PolicyConversionContext context)
        {
            XmlElement element = PolicyConversionContext.FindAssertion(context.GetBindingAssertions(),
                                                                       PeerTransportPolicyConstants.PeerTransportSecurityMode,
                                                                       TransportPolicyConstants.PeerTransportUri, true);

            this.Mode = SecurityMode.Transport;
            if (element != null)
            {
                switch (element.InnerText)
                {
                case PeerTransportPolicyConstants.PeerTransportSecurityModeNone:
                    this.Mode = SecurityMode.None;
                    break;

                case PeerTransportPolicyConstants.PeerTransportSecurityModeTransport:
                    this.Mode = SecurityMode.Transport;
                    break;

                case PeerTransportPolicyConstants.PeerTransportSecurityModeMessage:
                    this.Mode = SecurityMode.Message;
                    break;

                case PeerTransportPolicyConstants.PeerTransportSecurityModeTransportWithMessageCredential:
                    this.Mode = SecurityMode.TransportWithMessageCredential;
                    break;

                default:
                    break;
                }
            }
            transportSecurity.OnImportPolicy(importer, context);
        }
        void ImportEndpointScopeMessageBindingAssertions(MetadataImporter importer, PolicyConversionContext policyContext, SecurityBindingElement binding)
        {
            XmlElement assertion = null;

            this.ImportSupportingTokenAssertions(importer, policyContext, policyContext.GetBindingAssertions(), binding.EndpointSupportingTokenParameters, binding.OptionalEndpointSupportingTokenParameters);

            WSSecurityPolicy securityPolicy;

            if (WSSecurityPolicy.TryGetSecurityPolicyDriver(policyContext.GetBindingAssertions(), out securityPolicy))
            {
                if (!securityPolicy.TryImportWsspWssAssertion(importer, policyContext.GetBindingAssertions(), binding, out assertion) &&
                    assertion != null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.UnsupportedSecurityPolicyAssertion, assertion.OuterXml)));
                }

                if (!securityPolicy.TryImportWsspTrustAssertion(importer, policyContext.GetBindingAssertions(), binding, out assertion) &&
                    assertion != null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.UnsupportedSecurityPolicyAssertion, assertion.OuterXml)));
                }
            }

            //
            // We don't have WSTrust assertion => it is possible we are a BasicHttpBinding
            // Set the flag here so that later when we tried to compare binding element with basic http binding
            // we can have an exact match.
            //
            if (assertion == null)
            {
                binding.DoNotEmitTrust = true;
            }
        }
Exemple #21
0
        internal void OnExportPolicy(MetadataExporter exporter, PolicyConversionContext context)
        {
            string str = "";

            switch (this.Mode)
            {
            case SecurityMode.None:
                str = "PeerTransportSecurityModeNone";
                break;

            case SecurityMode.Transport:
                str = "PeerTransportSecurityModeTransport";
                break;

            case SecurityMode.Message:
                str = "PeerTransportSecurityModeMessage";
                break;

            case SecurityMode.TransportWithMessageCredential:
                str = "PeerTransportSecurityModeTransportWithMessageCredential";
                break;

            default:
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException());
            }
            XmlElement item = new XmlDocument().CreateElement("pc", "PeerTransportSecurityMode", "http://schemas.microsoft.com/soap/peer");

            item.InnerText = str;
            context.GetBindingAssertions().Add(item);
            this.transportSecurity.OnExportPolicy(exporter, context);
        }
        internal virtual void OnExportPolicy(MetadataExporter exporter, PolicyConversionContext policyContext)
        {
            string localName = null;

            switch (this.AuthenticationScheme)
            {
            case AuthenticationSchemes.Digest:
                localName = "DigestAuthentication";
                break;

            case AuthenticationSchemes.Negotiate:
                localName = "NegotiateAuthentication";
                break;

            case AuthenticationSchemes.Ntlm:
                localName = "NtlmAuthentication";
                break;

            case AuthenticationSchemes.Basic:
                localName = "BasicAuthentication";
                break;
            }
            if (localName != null)
            {
                policyContext.GetBindingAssertions().Add(new XmlDocument().CreateElement("http", localName, "http://schemas.microsoft.com/ws/06/2004/policy/http"));
            }
        }
        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);
            }
        }
Exemple #24
0
        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 == MakeConnectionConstants.Namespace)
                {
                    if (assertion.LocalName == MakeConnectionConstants.Policy.Assertion)
                    {
                        assertions.Remove(assertion);
                        context.BindingElements.Insert(0, new MakeConnectionBindingElement());
                        return;
                    }
                }
            }
        }
        internal static void ImportPolicy(MetadataImporter importer, PolicyConversionContext policyContext)
        {
            XmlElement assertion = PolicyConversionContext.FindAssertion(policyContext.GetBindingAssertions(),
                                                                         TransportPolicyConstants.WindowsTransportSecurityName, TransportPolicyConstants.DotNetFramingNamespace, true);

            if (assertion != null)
            {
                WindowsStreamSecurityBindingElement windowsBindingElement
                    = new WindowsStreamSecurityBindingElement();

                XmlReader reader = new XmlNodeReader(assertion);
                reader.ReadStartElement();
                string protectionLevelString = null;
                if (reader.IsStartElement(
                        TransportPolicyConstants.ProtectionLevelName,
                        TransportPolicyConstants.DotNetFramingNamespace) && !reader.IsEmptyElement)
                {
                    protectionLevelString = reader.ReadElementContentAsString();
                }
                if (string.IsNullOrEmpty(protectionLevelString))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(
                                                                                  SR.GetString(SR.ExpectedElementMissing, TransportPolicyConstants.ProtectionLevelName, TransportPolicyConstants.DotNetFramingNamespace)));
                }
                windowsBindingElement.ProtectionLevel = (ProtectionLevel)Enum.Parse(typeof(ProtectionLevel), protectionLevelString);
                policyContext.BindingElements.Add(windowsBindingElement);
            }
        }
        void IPolicyExportExtension.ExportPolicy(MetadataExporter exporter, PolicyConversionContext context)
        {
            if (exporter == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("exporter");
            }

            if (context == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context");
            }

            ICollection <XmlElement> policyAssertions = context.GetBindingAssertions();

            if (TransferModeHelper.IsRequestStreamed(this.TransferMode) ||
                TransferModeHelper.IsResponseStreamed(this.TransferMode))
            {
                policyAssertions.Add(new XmlDocument().CreateElement(TransportPolicyConstants.DotNetFramingPrefix,
                                                                     TransportPolicyConstants.StreamedName, TransportPolicyConstants.DotNetFramingNamespace));
            }

            bool createdNew;
            MessageEncodingBindingElement encodingBindingElement = FindMessageEncodingBindingElement(context.BindingElements, out createdNew);

            if (createdNew && encodingBindingElement is IPolicyExportExtension)
            {
                encodingBindingElement = new BinaryMessageEncodingBindingElement();
                ((IPolicyExportExtension)encodingBindingElement).ExportPolicy(exporter, context);
            }

            WsdlExporter.WSAddressingHelper.AddWSAddressingAssertion(exporter, context, encodingBindingElement.MessageVersion.Addressing);
        }
        void IPolicyImportExtension.ImportPolicy(MetadataImporter importer, PolicyConversionContext context)
        {
            if (importer == null)
            {
                throw new ArgumentNullException(nameof(importer));
            }

            if (context == null)
            {
                throw new ArgumentNullException(nameof(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;
                }
            }
        }
Exemple #28
0
 void IPolicyExportExtension.ExportPolicy(MetadataExporter exporter, PolicyConversionContext context)
 {
     if (context == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context");
     }
 }
Exemple #29
0
// <Snippet0>
        public void ImportPolicy(MetadataImporter importer,
                                 PolicyConversionContext context)
        {
            Console.WriteLine("The custom policy importer has been called.");
            foreach (XmlElement assertion in context.GetBindingAssertions())
            {
                // locate a particular assertion by Name and NamespaceURI
                if ((assertion.Name == "name") &&
                    assertion.NamespaceURI == "http://localhost/name/uri")
                {
                    // 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;

                    // 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 = assertion.GetAttribute(SpeedBindingElement.name2, SpeedBindingElement.ns2);
                     * SpeedBindingElement e = new SpeedBindingElement(speed);
                     * context.BindingElements.Add(e);
                     * // remove your custom assertion from the assertions collection.
                     * context.GetBindingAssertions()Remove(assertion);
                     */
                    continue;
                }
                Console.WriteLine(assertion.NamespaceURI + " : " + assertion.Name);
            }
        }
        void IPolicyExportExtension.ExportPolicy(MetadataExporter exporter, PolicyConversionContext context)
        {
            if (exporter == null)
            {
                throw new ArgumentNullException("exporter");
            }
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            PolicyAssertionCollection assertions = context.GetBindingAssertions();
            XmlDocument doc = new XmlDocument();

            var messageEncodingElement = ExportAddressingPolicy(context);

            if (messageEncodingElement == null)
            {
                assertions.Add(doc.CreateElement(
                                   "msb", "BinaryEncoding",
                                   "http://schemas.microsoft.com/ws/06/2004/mspolicy/netbinary1"));
            }

            if (transfer_mode == TransferMode.Streamed || transfer_mode == TransferMode.StreamedRequest ||
                transfer_mode == TransferMode.StreamedResponse)
            {
                assertions.Add(doc.CreateElement("msf", "Streamed", "http://schemas.microsoft.com/ws/2006/05/framing/policy"));
            }
        }