コード例 #1
0
ファイル: BindingFactory.cs プロジェクト: rlefever68/Wulka
        /// <summary>
        /// Creates the binding from key.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <returns></returns>
        public static Binding CreateBindingFromKey(string key)
        {
            switch (key)
            {
            case Key.BasicWinHttpBinding:
            {
                var bnd = new BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly);
                bnd.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
                bnd.Upscale();
                return(bnd);
            };


            case Key.WsWinHttpBinding:
            {
                var bnd = new WSHttpBinding(SecurityMode.Transport);
                bnd.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
                bnd.Upscale();
                return(bnd);
            }


            case Key.BasicHttpBindingNoSecurity:
            {
                var bnd = new BasicHttpBinding(BasicHttpSecurityMode.None);
                bnd.Upscale();
                return(bnd);
            }

            case Key.BasicHttpBindingMessageSecurity:
            {
                var bnd = new BasicHttpBinding(BasicHttpSecurityMode.Message);
                bnd.Upscale();
                return(bnd);
            }

            case Key.BasicHttpBindingTransportSecurity:
            {
                var bnd = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
                bnd.Upscale();
                return(bnd);
            }

            case Key.BasicHttpBindingTransportOnlySecurity:
            {
                var bnd = new BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly);
                bnd.Upscale();
                return(bnd);
            }

            case Key.BasicHttpBindingTransportWithMessageSecurity:
            {
                var bnd = new BasicHttpBinding(BasicHttpSecurityMode.TransportWithMessageCredential);
                bnd.Upscale();
                return(bnd);
            }


            case Key.MsmqIntegrationBinding:
            {
                var bnd = new MsmqIntegrationBinding();
                bnd.Upscale();
                return(bnd);
            }

            case Key.NetMsmqBinding:
            {
                var bnd = new NetMsmqBinding();
                bnd.Upscale();
                return(bnd);
            }

            case Key.NetNamedPipeBinding:
            {
                //     var bnd = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None);
                var bnd = new NetNamedPipeBinding();

                bnd.Upscale();
                return(bnd);
            }

            case Key.UnsecureNetMsmqBinding:
            {
                var bnd = new NetMsmqBinding(NetMsmqSecurityMode.None);
                bnd.Security.Transport.MsmqAuthenticationMode = MsmqAuthenticationMode.None;
                bnd.Security.Transport.MsmqProtectionLevel    = ProtectionLevel.None;
                bnd.Security.Message.ClientCredentialType     = MessageCredentialType.None;
                bnd.Upscale();
                return(bnd);
            }

            case Key.NetTcpBinding:
            {
                var bnd = new NetTcpBinding();
                bnd.Upscale();
                return(bnd);
            }

            case Key.WebHttpBinding:
            {
                var bnd = new WebHttpBinding();
                bnd.Upscale();
                return(bnd);
            }

            case Key.Ws2007FederationHttpBinding:
            {
                var bnd = new WS2007FederationHttpBinding();
                bnd.Upscale();
                return(bnd);
            }

            case Key.Ws2007HttpBinding:
            {
                var bnd = new WS2007HttpBinding();
                bnd.Upscale();
                return(bnd);
            };

            case Key.WsDualHttpBinding:
            {
                var bnd = new WSDualHttpBinding();
                bnd.Upscale();
                return(bnd);
            }

            case Key.WsFederationHttpBinding:
            {
                var bnd = new WSFederationHttpBinding();
                bnd.Upscale();
                return(bnd);
            }

            case Key.CustomValidationWsHttpBindingTransportAndMessage:
            {
                //http://www.codeproject.com/Articles/59927/WCF-Service-over-HTTPS-with-custom-username-and-pa
                var bnd = new WSHttpBinding(SecurityMode.TransportWithMessageCredential);
                bnd.Security.Message.ClientCredentialType = MessageCredentialType.UserName;
                bnd.Upscale();
                return(bnd);
            }

            case Key.CustomValidationWsHttpBindingMessage:
            {
                //http://www.codeproject.com/Articles/59927/WCF-Service-over-HTTPS-with-custom-username-and-pa
                var bnd = new WSHttpBinding(SecurityMode.Message);
                bnd.Security.Message.ClientCredentialType = MessageCredentialType.UserName;
                bnd.Upscale();
                return(bnd);
            }

            case Key.CustomValidationBasicHttpBindingTransportAndMessage:
            {
                var bnd = new BasicHttpBinding((BasicHttpSecurityMode.TransportWithMessageCredential));
                bnd.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;
                bnd.Upscale();
                return(bnd);
            }

            case Key.CustomValidationBasicHttpBindingMessage:
            {
                var bnd = new BasicHttpBinding((BasicHttpSecurityMode.Message));
                bnd.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;
                bnd.Upscale();
                return(bnd);
            }

            case Key.WsHttpBindingMessageSecurity:
            {
                var bnd = new WSHttpBinding(SecurityMode.Message);
                bnd.Upscale();
                return(bnd);
            }

            case Key.WsHttpBindingTransportSecurity:
            {
                var bnd = new WSHttpBinding(SecurityMode.Transport);
                bnd.Upscale();
                return(bnd);
            }

            case Key.WsHttpBindingTransportWithMessageSecurity:
            {
                var bnd = new WSHttpBinding(SecurityMode.TransportWithMessageCredential);
                bnd.Upscale();
                return(bnd);
            }

            case Key.WsHttpBindingNoSecurity:
            {
                var bnd = new WSHttpBinding(SecurityMode.None);
                bnd.Upscale();
                return(bnd);
            }

            default:
            {
                var bnd = new BasicHttpBinding(BasicHttpSecurityMode.None);
                bnd.Upscale();
                return(bnd);
            }
            }
        }