コード例 #1
0
        public AzureProxyHandler(Uri requestUrl, Uri responseUrl)
        {
            _credentials = new TransportClientEndpointBehavior {
                CredentialType = TransportClientCredentialType.SharedSecret
            };
            _credentials.Credentials.SharedSecret.IssuerName   = Manager.Configuration.Azure.IssuerName;
            _credentials.Credentials.SharedSecret.IssuerSecret = Manager.Configuration.Azure.IssuerSecret;

            Init(requestUrl, responseUrl);

            ServicePointManager.DefaultConnectionLimit = 50;

            _requestBinding = new BasicHttpRelayBinding(EndToEndBasicHttpSecurityMode.None, RelayClientAuthenticationType.None);
            _requestBinding.MaxReceivedMessageSize              = int.MaxValue;
            _requestBinding.TransferMode                        = TransferMode.Streamed;
            _requestBinding.AllowCookies                        = false;
            _requestBinding.ReceiveTimeout                      = TimeSpan.MaxValue;
            _requestBinding.ReaderQuotas.MaxArrayLength         = int.MaxValue;
            _requestBinding.ReaderQuotas.MaxStringContentLength = int.MaxValue;
            _requestBinding.MaxReceivedMessageSize              = int.MaxValue;
            _requestBinding.MaxBufferSize                       = 4 * 1024 * 1024;
            _requestBinding.MaxBufferPoolSize                   = 32 * 4 * 1024 * 1024;

            WebMessageEncodingBindingElement encoderBindingElement = new WebMessageEncodingBindingElement();

            encoderBindingElement.ReaderQuotas.MaxArrayLength         = int.MaxValue;
            encoderBindingElement.ReaderQuotas.MaxStringContentLength = int.MaxValue;
            encoderBindingElement.ReaderQuotas.MaxDepth        = 128;
            encoderBindingElement.ReaderQuotas.MaxBytesPerRead = 65536;
            encoderBindingElement.ContentTypeMapper            = new RawContentTypeMapper();
            _webEncoder = encoderBindingElement.CreateMessageEncoderFactory().Encoder;
        }
コード例 #2
0
 public void ImportEndpoint(WsdlImporter importer, WsdlEndpointConversionContext endpointContext)
 {
     System.ServiceModel.Channels.Binding binding;
     if (endpointContext == null)
     {
         throw new ArgumentNullException("endpointContext");
     }
     if (endpointContext.Endpoint.Binding == null)
     {
         throw new ArgumentNullException("endpointContext.Binding");
     }
     if (endpointContext.Endpoint.Binding is CustomBinding)
     {
         BindingElementCollection elements = ((CustomBinding)endpointContext.Endpoint.Binding).Elements;
         if (elements.Find <HttpRelayTransportBindingElement>() != null)
         {
             elements.Remove <HttpsTransportBindingElement>();
             if (WSHttpRelayBindingBase.TryCreate(elements, out binding))
             {
                 StandardRelayBindingImporter.SetBinding(endpointContext.Endpoint, binding);
                 return;
             }
             if (BasicHttpRelayBinding.TryCreate(elements, out binding))
             {
                 StandardRelayBindingImporter.SetBinding(endpointContext.Endpoint, binding);
                 return;
             }
         }
         else if (elements.Find <TcpRelayTransportBindingElement>() != null && NetTcpRelayBinding.TryCreate(elements, out binding))
         {
             StandardRelayBindingImporter.SetBinding(endpointContext.Endpoint, binding);
         }
     }
 }
コード例 #3
0
ファイル: Program.cs プロジェクト: tablesmit/OneCode
        static void Main(string[] args)
        {
            // 将{service namespace}替换为你的服务命名空间.
            EndpointAddress       address = new EndpointAddress(ServiceBusEnvironment.CreateServiceUri("https", "{service namespace}", "ProcessDataWorkflowService"));
            BasicHttpRelayBinding binding = new BasicHttpRelayBinding();

            // 提供Service Bus证书.
            TransportClientEndpointBehavior sharedSecretServiceBusCredential = new TransportClientEndpointBehavior();

            sharedSecretServiceBusCredential.CredentialType = TransportClientCredentialType.SharedSecret;
            // 将{issuer name}和{issuer secret}替换为你的证书.
            sharedSecretServiceBusCredential.Credentials.SharedSecret.IssuerName   = "{issuer name}";
            sharedSecretServiceBusCredential.Credentials.SharedSecret.IssuerSecret = "{issuer secret}";

            ChannelFactory <IProcessDataWorkflowServiceChannel> factory = new ChannelFactory <IProcessDataWorkflowServiceChannel>(binding, address);

            factory.Endpoint.Behaviors.Add(sharedSecretServiceBusCredential);
            factory.Open();
            IProcessDataWorkflowServiceChannel channel = factory.CreateChannel();

            channel.Open();
            Console.WriteLine("正在处理 10...");
            Console.WriteLine("服务返回: " + channel.ProcessData(new ProcessDataRequest(0)).@string);
            Console.WriteLine("正在处理 30...");
            Console.WriteLine("服务返回: " + channel.ProcessData(new ProcessDataRequest(30)).@string);
            channel.Close();
            factory.Close();
            Console.Read();
        }
コード例 #4
0
        public AzureProxyHandler(Uri requestUrl, Uri responseUrl)
        {
            _credentials = new TransportClientEndpointBehavior {
                CredentialType = TransportClientCredentialType.SharedSecret
            };
            _credentials.Credentials.SharedSecret.IssuerName = Manager.Configuration.Azure.IssuerName;
            _credentials.Credentials.SharedSecret.IssuerSecret = Manager.Configuration.Azure.IssuerSecret;

            Init(requestUrl, responseUrl);

            ServicePointManager.DefaultConnectionLimit = 50;

            _requestBinding = new BasicHttpRelayBinding(EndToEndBasicHttpSecurityMode.None, RelayClientAuthenticationType.None);
            _requestBinding.MaxReceivedMessageSize = int.MaxValue;
            _requestBinding.TransferMode = TransferMode.Streamed;
            _requestBinding.AllowCookies = false;
            _requestBinding.ReceiveTimeout = TimeSpan.MaxValue;
            _requestBinding.ReaderQuotas.MaxArrayLength = int.MaxValue;
            _requestBinding.ReaderQuotas.MaxStringContentLength = int.MaxValue;
            _requestBinding.MaxReceivedMessageSize = int.MaxValue;
            _requestBinding.MaxBufferSize = 4 * 1024 * 1024;
            _requestBinding.MaxBufferPoolSize = 32 * 4 * 1024 * 1024;

            WebMessageEncodingBindingElement encoderBindingElement = new WebMessageEncodingBindingElement();
            encoderBindingElement.ReaderQuotas.MaxArrayLength = int.MaxValue;
            encoderBindingElement.ReaderQuotas.MaxStringContentLength = int.MaxValue;
            encoderBindingElement.ReaderQuotas.MaxDepth = 128;
            encoderBindingElement.ReaderQuotas.MaxBytesPerRead = 65536;
            encoderBindingElement.ContentTypeMapper = new RawContentTypeMapper();
            _webEncoder = encoderBindingElement.CreateMessageEncoderFactory().Encoder;
        }
コード例 #5
0
        void ConfigureStreaming(Binding binding)
        {
            m_StreamingEnabledLabel.Text = "N/A";

            if (binding is BasicHttpBinding)
            {
                BasicHttpBinding basicBinding = binding as BasicHttpBinding;
                if (basicBinding.TransferMode == TransferMode.Streamed)
                {
                    m_StreamingEnabledLabel.Text = "Enabled";
                }
                else
                {
                    m_StreamingEnabledLabel.Text = "Disabled";
                }
            }
            if (binding is BasicHttpRelayBinding)
            {
                BasicHttpRelayBinding basicRelayBinding = binding as BasicHttpRelayBinding;
                if (basicRelayBinding.TransferMode == TransferMode.Streamed)
                {
                    m_StreamingEnabledLabel.Text = "Enabled";
                }
                else
                {
                    m_StreamingEnabledLabel.Text = "Disabled";
                }
            }
        }
コード例 #6
0
        static void Main(string[] args)
        {
            // Replace {service namespace} with your service name space.
            EndpointAddress       address = new EndpointAddress(ServiceBusEnvironment.CreateServiceUri("https", "{service namespace}", "ProcessDataWorkflowService"));
            BasicHttpRelayBinding binding = new BasicHttpRelayBinding();

            // Provide the Service Bus credential.
            TransportClientEndpointBehavior sharedSecretServiceBusCredential = new TransportClientEndpointBehavior();

            sharedSecretServiceBusCredential.CredentialType = TransportClientCredentialType.SharedSecret;
            // Replace {issuer name} and {issuer secret} with your credential.
            sharedSecretServiceBusCredential.Credentials.SharedSecret.IssuerName   = "{issuer name}";
            sharedSecretServiceBusCredential.Credentials.SharedSecret.IssuerSecret = "{issuer secret}";

            ChannelFactory <IProcessDataWorkflowServiceChannel> factory = new ChannelFactory <IProcessDataWorkflowServiceChannel>(binding, address);

            factory.Endpoint.Behaviors.Add(sharedSecretServiceBusCredential);
            factory.Open();
            IProcessDataWorkflowServiceChannel channel = factory.CreateChannel();

            channel.Open();
            Console.WriteLine("Processing 10...");
            Console.WriteLine("Service returned: " + channel.ProcessData(new ProcessDataRequest(0)).@string);
            Console.WriteLine("Processing 30...");
            Console.WriteLine("Service returned: " + channel.ProcessData(new ProcessDataRequest(30)).@string);
            channel.Close();
            factory.Close();
            Console.Read();
        }
コード例 #7
0
        protected override void InitializeFrom(Binding binding)
        {
            base.InitializeFrom(binding);
            BasicHttpRelayBinding basicHttpRelayBinding = (BasicHttpRelayBinding)binding;

            this.MaxBufferSize          = basicHttpRelayBinding.MaxBufferSize;
            this.MaxBufferPoolSize      = basicHttpRelayBinding.MaxBufferPoolSize;
            this.MaxReceivedMessageSize = basicHttpRelayBinding.MaxReceivedMessageSize;
            this.MessageEncoding        = basicHttpRelayBinding.MessageEncoding;
            if (basicHttpRelayBinding.ProxyAddress != null)
            {
                this.ProxyAddress = basicHttpRelayBinding.ProxyAddress;
            }
            this.TextEncoding       = basicHttpRelayBinding.TextEncoding;
            this.TransferMode       = basicHttpRelayBinding.TransferMode;
            this.UseDefaultWebProxy = basicHttpRelayBinding.UseDefaultWebProxy;
            this.IsDynamic          = basicHttpRelayBinding.IsDynamic;
            this.AllowCookies       = basicHttpRelayBinding.AllowCookies;
            this.Security.InitializeFrom(basicHttpRelayBinding.Security);
            this.ReaderQuotas.InitializeFrom(basicHttpRelayBinding.ReaderQuotas);
        }
コード例 #8
0
        protected override void OnApplyConfiguration(Binding binding)
        {
            BasicHttpRelayBinding maxBufferPoolSize = (BasicHttpRelayBinding)binding;

            maxBufferPoolSize.MaxBufferPoolSize      = this.MaxBufferPoolSize;
            maxBufferPoolSize.MaxReceivedMessageSize = this.MaxReceivedMessageSize;
            maxBufferPoolSize.MessageEncoding        = this.MessageEncoding;
            maxBufferPoolSize.TextEncoding           = this.TextEncoding;
            maxBufferPoolSize.TransferMode           = this.TransferMode;
            maxBufferPoolSize.UseDefaultWebProxy     = this.UseDefaultWebProxy;
            maxBufferPoolSize.IsDynamic    = this.IsDynamic;
            maxBufferPoolSize.AllowCookies = this.AllowCookies;
            if (this.ProxyAddress != null)
            {
                maxBufferPoolSize.ProxyAddress = this.ProxyAddress;
            }
            if (base.ElementInformation.Properties["maxBufferSize"].ValueOrigin != PropertyValueOrigin.Default)
            {
                maxBufferPoolSize.MaxBufferSize = this.MaxBufferSize;
            }
            this.Security.ApplyConfiguration(maxBufferPoolSize.Security);
            this.ReaderQuotas.ApplyConfiguration(maxBufferPoolSize.ReaderQuotas);
        }
コード例 #9
0
        void ConfigureSecurityMode(Binding binding)
        {
            SecurityModeEx securityMode = SecurityModeEx.None;

            bool enabled = false;

            if (binding is NetTcpBinding)
            {
                NetTcpBinding tcpBinding = binding as NetTcpBinding;
                switch (tcpBinding.Security.Mode)
                {
                case SecurityMode.Message:
                {
                    securityMode = SecurityModeEx.Message;
                    break;
                }

                case SecurityMode.None:
                {
                    securityMode = SecurityModeEx.None;
                    break;
                }

                case SecurityMode.Transport:
                {
                    securityMode = SecurityModeEx.Transport;
                    break;
                }

                case SecurityMode.TransportWithMessageCredential:
                {
                    securityMode = SecurityModeEx.Mixed;
                    break;
                }
                }
                enabled = true;
            }
            if (binding is NetNamedPipeBinding)
            {
                NetNamedPipeBinding pipeBinding = binding as NetNamedPipeBinding;
                switch (pipeBinding.Security.Mode)
                {
                case NetNamedPipeSecurityMode.None:
                {
                    securityMode = SecurityModeEx.None;
                    break;
                }

                case NetNamedPipeSecurityMode.Transport:
                {
                    securityMode = SecurityModeEx.Transport;
                    break;
                }
                }
                enabled = true;
            }
            if (binding is NetMsmqBinding)
            {
                NetMsmqBinding msmqBinding = binding as NetMsmqBinding;
                switch (msmqBinding.Security.Mode)
                {
                case NetMsmqSecurityMode.Both:
                {
                    securityMode = SecurityModeEx.Both;
                    break;
                }

                case NetMsmqSecurityMode.Message:
                {
                    securityMode = SecurityModeEx.Message;
                    break;
                }

                case NetMsmqSecurityMode.None:
                {
                    securityMode = SecurityModeEx.None;
                    break;
                }

                case NetMsmqSecurityMode.Transport:
                {
                    securityMode = SecurityModeEx.Transport;
                    break;
                }
                }
                enabled = true;
            }
            if (binding is BasicHttpBinding)
            {
                BasicHttpBinding basicBinding = binding as BasicHttpBinding;
                switch (basicBinding.Security.Mode)
                {
                case BasicHttpSecurityMode.Message:
                {
                    securityMode = SecurityModeEx.Message;
                    break;
                }

                case BasicHttpSecurityMode.None:
                {
                    securityMode = SecurityModeEx.None;
                    break;
                }

                case BasicHttpSecurityMode.Transport:
                {
                    securityMode = SecurityModeEx.Transport;
                    break;
                }

                case BasicHttpSecurityMode.TransportCredentialOnly:
                {
                    securityMode = SecurityModeEx.Transport;
                    break;
                }

                case BasicHttpSecurityMode.TransportWithMessageCredential:
                {
                    securityMode = SecurityModeEx.Mixed;
                    break;
                }
                }
                enabled = true;
            }
            if (binding is WSHttpBinding)
            {
                WSHttpBinding wsBinding = binding as WSHttpBinding;
                switch (wsBinding.Security.Mode)
                {
                case SecurityMode.Message:
                {
                    securityMode = SecurityModeEx.Message;
                    break;
                }

                case SecurityMode.None:
                {
                    securityMode = SecurityModeEx.None;
                    break;
                }

                case SecurityMode.Transport:
                {
                    securityMode = SecurityModeEx.Transport;
                    break;
                }

                case SecurityMode.TransportWithMessageCredential:
                {
                    securityMode = SecurityModeEx.Mixed;
                    break;
                }
                }
                enabled = true;
            }

            if (binding is WSDualHttpBinding)
            {
                WSDualHttpBinding wsDualBinding = binding as WSDualHttpBinding;
                switch (wsDualBinding.Security.Mode)
                {
                case WSDualHttpSecurityMode.Message:
                {
                    securityMode = SecurityModeEx.Message;
                    break;
                }

                case WSDualHttpSecurityMode.None:
                {
                    securityMode = SecurityModeEx.None;
                    break;
                }
                }
                enabled = true;
            }
            if (binding is NetPeerTcpBinding)
            {
                NetPeerTcpBinding peerBinding = binding as NetPeerTcpBinding;
                switch (peerBinding.Security.Mode)
                {
                case SecurityMode.Message:
                {
                    securityMode = SecurityModeEx.Message;
                    break;
                }

                case SecurityMode.None:
                {
                    securityMode = SecurityModeEx.None;
                    break;
                }

                case SecurityMode.Transport:
                {
                    securityMode = SecurityModeEx.Transport;
                    break;
                }

                case SecurityMode.TransportWithMessageCredential:
                {
                    securityMode = SecurityModeEx.Transport;
                    break;
                }
                }
                enabled = true;
            }
            if (binding is WSFederationHttpBinding)
            {
                WSFederationHttpBinding federatedBinding = binding as WSFederationHttpBinding;
                switch (federatedBinding.Security.Mode)
                {
                case WSFederationHttpSecurityMode.Message:
                {
                    securityMode = SecurityModeEx.Message;
                    break;
                }

                case WSFederationHttpSecurityMode.None:
                {
                    securityMode = SecurityModeEx.None;
                    break;
                }

                case WSFederationHttpSecurityMode.TransportWithMessageCredential:
                {
                    securityMode = SecurityModeEx.Mixed;
                    break;
                }
                }
                enabled = true;
            }

            if (binding is NetTcpRelayBinding)
            {
                NetTcpRelayBinding tcpRelayBinding = binding as NetTcpRelayBinding;
                switch (tcpRelayBinding.Security.Mode)
                {
                case EndToEndSecurityMode.Message:
                {
                    securityMode = SecurityModeEx.Message;
                    break;
                }

                case EndToEndSecurityMode.None:
                {
                    securityMode = SecurityModeEx.None;
                    break;
                }

                case EndToEndSecurityMode.Transport:
                {
                    securityMode = SecurityModeEx.Transport;
                    break;
                }

                case EndToEndSecurityMode.TransportWithMessageCredential:
                {
                    securityMode = SecurityModeEx.Mixed;
                    break;
                }
                }
                enabled = true;
            }

            if (binding is BasicHttpRelayBinding)
            {
                BasicHttpRelayBinding basicRelayBinding = binding as BasicHttpRelayBinding;
                switch (basicRelayBinding.Security.Mode)
                {
                case EndToEndBasicHttpSecurityMode.Message:
                {
                    securityMode = SecurityModeEx.Message;
                    break;
                }

                case EndToEndBasicHttpSecurityMode.None:
                {
                    securityMode = SecurityModeEx.None;
                    break;
                }

                case EndToEndBasicHttpSecurityMode.Transport:
                {
                    securityMode = SecurityModeEx.Transport;
                    break;
                }

                case EndToEndBasicHttpSecurityMode.TransportWithMessageCredential:
                {
                    securityMode = SecurityModeEx.Mixed;
                    break;
                }
                }
                enabled = true;
            }

            if (binding is NetOnewayRelayBinding)
            {
                NetOnewayRelayBinding onewayRelayBinding = binding as NetOnewayRelayBinding;
                switch (onewayRelayBinding.Security.Mode)
                {
                case EndToEndSecurityMode.Message:
                {
                    securityMode = SecurityModeEx.Message;
                    break;
                }

                case EndToEndSecurityMode.None:
                {
                    securityMode = SecurityModeEx.None;
                    break;
                }

                case EndToEndSecurityMode.Transport:
                {
                    securityMode = SecurityModeEx.Transport;
                    break;
                }

                case EndToEndSecurityMode.TransportWithMessageCredential:
                {
                    securityMode = SecurityModeEx.Mixed;
                    break;
                }
                }
                enabled = true;
            }

            if (binding is CustomBinding)
            {
                enabled = false;
            }

            m_NoneRadioButton.Checked      = securityMode == SecurityModeEx.None;
            m_TransportRadioButton.Checked = securityMode == SecurityModeEx.Transport;
            m_MessageRadioButton.Checked   = securityMode == SecurityModeEx.Message;
            m_MixedRadioButton.Checked     = securityMode == SecurityModeEx.Mixed;
            m_BothRadioButton.Checked      = securityMode == SecurityModeEx.Both;

            m_NoneRadioButton.Enabled      = enabled;
            m_TransportRadioButton.Enabled = enabled;
            m_MessageRadioButton.Enabled   = enabled;
            m_MixedRadioButton.Enabled     = enabled;
            m_BothRadioButton.Enabled      = enabled;
        }