예제 #1
0
        public void Properties()
        {
            MessageEncoder t = new TextElement().CreateMessageEncoderFactory().Encoder;
            MessageEncoder b = new BinaryElement().CreateMessageEncoderFactory().Encoder;
            MessageEncoder m = new MtomElement().CreateMessageEncoderFactory().Encoder;

            // TextMessageEncodingBindingElement.WriteEncoding
            // default value is UTF8.
            ServiceAssert.AssertMessageEncoder(
                // Those curly double quotations are smelly, very implementation specific.
                "application/soap+xml; charset=utf-8", "application/soap+xml",
                MessageVersion.Default, t, "Text");
            ServiceAssert.AssertMessageEncoder(
                "application/soap+msbin1", "application/soap+msbin1",
                MessageVersion.Default, b, "Binary");
            ServiceAssert.AssertMessageEncoder(
                "multipart/related; type=\"application/xop+xml\"", "multipart/related",
                MessageVersion.Default, m, "Mtom");

            MessageEncoder t2 = new TextElement(
                MessageVersion.Soap11WSAddressing10,
                Encoding.UTF8)
                                .CreateMessageEncoderFactory().Encoder;

            ServiceAssert.AssertMessageEncoder(
                // Those curly double quotations are smelly, very implementation specific.
                "text/xml; charset=utf-8", "text/xml",
                MessageVersion.Soap11WSAddressing10, t2, "Text2");
        }
예제 #2
0
        internal override bool IsMatch(BindingElement b)
        {
            if (!base.IsMatch(b))
            {
                return(false);
            }
            MtomMessageEncodingBindingElement mtom = b as MtomMessageEncodingBindingElement;

            if (mtom == null)
            {
                return(false);
            }
            if (_maxReadPoolSize != mtom.MaxReadPoolSize)
            {
                return(false);
            }
            if (_maxWritePoolSize != mtom.MaxWritePoolSize)
            {
                return(false);
            }

            // compare XmlDictionaryReaderQuotas
            if (_readerQuotas.MaxStringContentLength != mtom.ReaderQuotas.MaxStringContentLength)
            {
                return(false);
            }
            if (_readerQuotas.MaxArrayLength != mtom.ReaderQuotas.MaxArrayLength)
            {
                return(false);
            }
            if (_readerQuotas.MaxBytesPerRead != mtom.ReaderQuotas.MaxBytesPerRead)
            {
                return(false);
            }
            if (_readerQuotas.MaxDepth != mtom.ReaderQuotas.MaxDepth)
            {
                return(false);
            }
            if (_readerQuotas.MaxNameTableCharCount != mtom.ReaderQuotas.MaxNameTableCharCount)
            {
                return(false);
            }

            if (_maxBufferSize != mtom.MaxBufferSize)
            {
                return(false);
            }

            if (this.WriteEncoding.EncodingName != mtom.WriteEncoding.EncodingName)
            {
                return(false);
            }
            if (!this.MessageVersion.IsMatch(mtom.MessageVersion))
            {
                return(false);
            }

            return(true);
        }
예제 #3
0
 private MtomMessageEncodingBindingElement(MtomMessageEncodingBindingElement elementToBeCloned) : base(elementToBeCloned)
 {
     this.maxReadPoolSize  = elementToBeCloned.maxReadPoolSize;
     this.maxWritePoolSize = elementToBeCloned.maxWritePoolSize;
     this.readerQuotas     = new XmlDictionaryReaderQuotas();
     elementToBeCloned.readerQuotas.CopyTo(this.readerQuotas);
     this.maxBufferSize  = elementToBeCloned.maxBufferSize;
     this.writeEncoding  = elementToBeCloned.writeEncoding;
     this.messageVersion = elementToBeCloned.messageVersion;
 }
예제 #4
0
 private MtomMessageEncodingBindingElement(MtomMessageEncodingBindingElement elementToBeCloned)
     : base(elementToBeCloned)
 {
     _maxReadPoolSize  = elementToBeCloned._maxReadPoolSize;
     _maxWritePoolSize = elementToBeCloned._maxWritePoolSize;
     _readerQuotas     = new XmlDictionaryReaderQuotas();
     elementToBeCloned._readerQuotas.CopyTo(_readerQuotas);
     _maxBufferSize  = elementToBeCloned._maxBufferSize;
     _writeEncoding  = elementToBeCloned._writeEncoding;
     _messageVersion = elementToBeCloned._messageVersion;
 }
예제 #5
0
 public MtomMessageEncoderFactory(
     MtomMessageEncodingBindingElement owner)
 {
     this.owner = owner;
     encoder    = new MtomMessageEncoder(this);
 }
예제 #6
0
        bool ImportBasicHttpBinding(
            WsdlImporter importer, WsdlEndpointConversionContext context,
            CustomBinding custom, WS.SoapBinding soap)
        {
            TransportBindingElement           transportElement = null;
            MtomMessageEncodingBindingElement mtomElement      = null;
            TextMessageEncodingBindingElement textElement      = null;
            bool foundUnknownElement = false;

            foreach (var element in custom.Elements)
            {
                if (element is TransportBindingElement)
                {
                    transportElement = (TransportBindingElement)element;
                }
                else if (element is MtomMessageEncodingBindingElement)
                {
                    mtomElement = (MtomMessageEncodingBindingElement)element;
                }
                else if (element is TextMessageEncodingBindingElement)
                {
                    textElement = (TextMessageEncodingBindingElement)element;
                }
                else
                {
                    importer.AddWarning(
                        "Found unknown binding element `{0}' while attempting " +
                        "to import binding `{0}'.", element.GetType(),
                        custom.Name);
                    foundUnknownElement = true;
                }
            }

            if (foundUnknownElement)
            {
                return(false);
            }

            if ((mtomElement != null) && (textElement != null))
            {
                // FIXME: Should never happen
                importer.AddWarning(
                    "Found both MtomMessageEncodingBindingElement and " +
                    "TextMessageEncodingBindingElement while attempting to " +
                    "import binding `{0}'.", custom.Name);
                return(false);
            }

            BasicHttpBinding      httpBinding;
            AuthenticationSchemes authScheme;

            /*
             * FIXME: Maybe make the BasicHttpBinding use the transport element
             * that we created with the TransportBindingElementImporter ?
             *
             * There seems to be no public API to do that, so maybe add a private .ctor ?
             *
             */

            var httpsTransport = transportElement as HttpsTransportBindingElement;
            var httpTransport  = transportElement as HttpTransportBindingElement;

            if (httpsTransport != null)
            {
                httpBinding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
                authScheme  = httpsTransport.AuthenticationScheme;
            }
            else if (httpTransport != null)
            {
                authScheme = httpTransport.AuthenticationScheme;
                if ((authScheme != AuthenticationSchemes.None) &&
                    (authScheme != AuthenticationSchemes.Anonymous))
                {
                    httpBinding = new BasicHttpBinding(
                        BasicHttpSecurityMode.TransportCredentialOnly);
                }
                else
                {
                    httpBinding = new BasicHttpBinding();
                }
            }
            else
            {
                httpBinding = new BasicHttpBinding();
                authScheme  = AuthenticationSchemes.Anonymous;
            }

            if (mtomElement != null)
            {
                httpBinding.MessageEncoding = WSMessageEncoding.Mtom;
            }
            else if (textElement != null)
            {
                httpBinding.MessageEncoding = WSMessageEncoding.Text;
            }
            else
            {
                importer.AddWarning(
                    "Found neither MtomMessageEncodingBindingElement nor " +
                    "TextMessageEncodingBindingElement while attempting to " +
                    "import binding `{0}'.", custom.Name);
                return(false);
            }

            httpBinding.Name      = context.Endpoint.Binding.Name;
            httpBinding.Namespace = context.Endpoint.Binding.Namespace;

            switch (authScheme)
            {
            case AuthenticationSchemes.None:
            case AuthenticationSchemes.Anonymous:
                httpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
                break;

            case AuthenticationSchemes.Basic:
                httpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
                break;

            case AuthenticationSchemes.Digest:
                httpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Digest;
                break;

            case AuthenticationSchemes.Ntlm:
                httpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Ntlm;
                break;

            case AuthenticationSchemes.Negotiate:
                httpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
                break;

            default:
                importer.AddWarning("Invalid auth scheme: {0}", authScheme);
                return(false);
            }

            if ((httpsTransport != null) && httpsTransport.RequireClientCertificate)
            {
                if (httpBinding.Security.Transport.ClientCredentialType != HttpClientCredentialType.None)
                {
                    importer.AddWarning("Cannot use both client certificate and explicit auth type.");
                    return(false);
                }
                httpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;
            }

            context.Endpoint.Binding = httpBinding;
            return(true);
        }