コード例 #1
0
 private static System.ServiceModel.Channels.Binding CreateDefaultBinding()
 {
     System.ServiceModel.Channels.CustomBinding binding = new System.ServiceModel.Channels.CustomBinding();
     binding.Elements.Add(new System.ServiceModel.Channels.TextMessageEncodingBindingElement(System.ServiceModel.Channels.MessageVersion.Soap11, System.Text.Encoding.UTF8));
     System.ServiceModel.Channels.HttpTransportBindingElement http = new System.ServiceModel.Channels.HttpTransportBindingElement();
     http.MaxBufferPoolSize      = Int32.MaxValue;
     http.MaxBufferSize          = Int32.MaxValue;
     http.MaxReceivedMessageSize = Int32.MaxValue;
     http.TransferMode           = System.ServiceModel.TransferMode.Buffered;
     binding.Elements.Add(http);
     return(binding);
 }
コード例 #2
0
        private void GetEmotions()
        {
            var httpBindingElement = new System.ServiceModel.Channels.HttpTransportBindingElement();

            httpBindingElement.MaxBufferSize          = 2147483647;
            httpBindingElement.MaxReceivedMessageSize = 2147483647;


            CustomBinding binding = new CustomBinding(new BinaryMessageEncodingBindingElement(), httpBindingElement);

            EndpointAddress address = new EndpointAddress(new Uri(Application.Current.Host.Source, "/SinaDesktop.Web/SinaService.svc"));

            SinaDataService.DataServiceClient svc = new SinaDataService.DataServiceClient(binding, address);
            svc.GetEmotionsCompleted += client_GetEmotions;
            svc.GetEmotionsAsync("image", "xml", ConfigurationSettings.TokenKey, ConfigurationSettings.TokenKeySecret);
        }
コード例 #3
0
ファイル: Home.xaml.cs プロジェクト: jv9/lightbus
        private void GetEmotions()
        {
            var httpBindingElement = new System.ServiceModel.Channels.HttpTransportBindingElement();
            httpBindingElement.MaxBufferSize = 2147483647;
            httpBindingElement.MaxReceivedMessageSize = 2147483647;

            CustomBinding binding = new CustomBinding(new BinaryMessageEncodingBindingElement(), httpBindingElement);

            EndpointAddress address = new EndpointAddress(new Uri(Application.Current.Host.Source, "/SinaDesktop.Web/SinaService.svc"));

            SinaDataService.DataServiceClient svc = new SinaDataService.DataServiceClient(binding, address);
            svc.GetEmotionsCompleted += client_GetEmotions;
            svc.GetEmotionsAsync("image", "xml", ConfigurationSettings.TokenKey, ConfigurationSettings.TokenKeySecret);
        }
コード例 #4
0
 private HttpsTransportBindingElement(HttpTransportBindingElement elementToBeCloned)
     : base(elementToBeCloned)
 {
 }
コード例 #5
0
 internal static HttpsTransportBindingElement CreateFromHttpBindingElement(HttpTransportBindingElement elementToBeCloned)
 {
     return(new HttpsTransportBindingElement(elementToBeCloned));
 }
コード例 #6
0
 public HttpBindingProperties(HttpTransportBindingElement source)
 {
     this.source = source;
 }
        internal override bool IsMatch(BindingElement b)
        {
            if (!base.IsMatch(b))
            {
                return(false);
            }
            HttpTransportBindingElement element = b as HttpTransportBindingElement;

            if (element == null)
            {
                return(false);
            }
            if (this.allowCookies != element.allowCookies)
            {
                return(false);
            }
            if (this.authenticationScheme != element.authenticationScheme)
            {
                return(false);
            }
            if (this.decompressionEnabled != element.decompressionEnabled)
            {
                return(false);
            }
            if (this.hostNameComparisonMode != element.hostNameComparisonMode)
            {
                return(false);
            }
            if (this.inheritBaseAddressSettings != element.inheritBaseAddressSettings)
            {
                return(false);
            }
            if (this.keepAliveEnabled != element.keepAliveEnabled)
            {
                return(false);
            }
            if (this.maxBufferSize != element.maxBufferSize)
            {
                return(false);
            }
            if (this.method != element.method)
            {
                return(false);
            }
            if (this.proxyAddress != element.proxyAddress)
            {
                return(false);
            }
            if (this.proxyAuthenticationScheme != element.proxyAuthenticationScheme)
            {
                return(false);
            }
            if (this.realm != element.realm)
            {
                return(false);
            }
            if (this.transferMode != element.transferMode)
            {
                return(false);
            }
            if (this.unsafeConnectionNtlmAuthentication != element.unsafeConnectionNtlmAuthentication)
            {
                return(false);
            }
            if (this.useDefaultWebProxy != element.useDefaultWebProxy)
            {
                return(false);
            }
            if (this.webProxy != element.webProxy)
            {
                return(false);
            }
            if (!ChannelBindingUtility.AreEqual(this.ExtendedProtectionPolicy, element.ExtendedProtectionPolicy))
            {
                return(false);
            }
            return(true);
        }
        public void ImportEndpoint(WsdlImporter importer, WsdlEndpointConversionContext context)
        {
            if (context == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context");
            }
            if (context.Endpoint == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context.Endpoint");
            }
            if (context.Endpoint.Binding == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context.Endpoint.Binding");
            }
            CustomBinding binding = context.Endpoint.Binding as CustomBinding;

            if (binding != null)
            {
                System.ServiceModel.Channels.Binding binding2;
                UnrecognizedAssertionsBindingElement item = null;
                item = binding.Elements.Find <UnrecognizedAssertionsBindingElement>();
                HttpTransportBindingElement element2 = null;
                if (item != null)
                {
                    XmlElement httpUseCookieAssertion = null;
                    if (ContextBindingElementPolicy.TryGetHttpUseCookieAssertion(item.BindingAsserions, out httpUseCookieAssertion))
                    {
                        foreach (BindingElement element4 in binding.Elements)
                        {
                            element2 = element4 as HttpTransportBindingElement;
                            if (element2 != null)
                            {
                                element2.AllowCookies = true;
                                item.BindingAsserions.Remove(httpUseCookieAssertion);
                                if (item.BindingAsserions.Count == 0)
                                {
                                    binding.Elements.Remove(item);
                                }
                                break;
                            }
                        }
                    }
                }
                BindingElementCollection bindingElements = binding.CreateBindingElements();
                if (!WSHttpContextBinding.TryCreate(bindingElements, out binding2) && !NetTcpContextBinding.TryCreate(bindingElements, out binding2))
                {
                    if (element2 == null)
                    {
                        foreach (BindingElement element5 in bindingElements)
                        {
                            element2 = element5 as HttpTransportBindingElement;
                            if (element2 != null)
                            {
                                break;
                            }
                        }
                    }
                    if ((element2 != null) && element2.AllowCookies)
                    {
                        element2.AllowCookies = false;
                        if (BasicHttpBinding.TryCreate(bindingElements, out binding2))
                        {
                            ((BasicHttpBinding)binding2).AllowCookies = true;
                        }
                    }
                }
                if (binding2 != null)
                {
                    binding2.Name            = context.Endpoint.Binding.Name;
                    binding2.Namespace       = context.Endpoint.Binding.Namespace;
                    context.Endpoint.Binding = binding2;
                }
            }
        }
コード例 #9
0
        internal override bool IsMatch(BindingElement b)
        {
            if (!base.IsMatch(b))
            {
                return(false);
            }
            HttpTransportBindingElement http = b as HttpTransportBindingElement;

            if (http == null)
            {
                return(false);
            }
            if (_allowCookies != http._allowCookies)
            {
                return(false);
            }
            if (_authenticationScheme != http._authenticationScheme)
            {
                return(false);
            }
            if (_decompressionEnabled != http._decompressionEnabled)
            {
                return(false);
            }
            if (_hostNameComparisonMode != http._hostNameComparisonMode)
            {
                return(false);
            }
            if (_inheritBaseAddressSettings != http._inheritBaseAddressSettings)
            {
                return(false);
            }
            if (_keepAliveEnabled != http._keepAliveEnabled)
            {
                return(false);
            }
            if (_maxBufferSize != http._maxBufferSize)
            {
                return(false);
            }
            if (_method != http._method)
            {
                return(false);
            }
            if (_realm != http._realm)
            {
                return(false);
            }
            if (_transferMode != http._transferMode)
            {
                return(false);
            }
            if (_unsafeConnectionNtlmAuthentication != http._unsafeConnectionNtlmAuthentication)
            {
                return(false);
            }
            if (_useDefaultWebProxy != http._useDefaultWebProxy)
            {
                return(false);
            }
            if (!this.WebSocketSettings.Equals(http.WebSocketSettings))
            {
                return(false);
            }

            return(true);
        }
コード例 #10
0
        internal HttpChannelFactory(HttpTransportBindingElement bindingElement, BindingContext context)
            : base(bindingElement, context, HttpTransportDefaults.GetDefaultMessageEncoderFactory())
        {
            // validate setting interactions
            if (bindingElement.TransferMode == TransferMode.Buffered)
            {
                if (bindingElement.MaxReceivedMessageSize > int.MaxValue)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                              new ArgumentOutOfRangeException("bindingElement.MaxReceivedMessageSize",
                                                              SR.MaxReceivedMessageSizeMustBeInIntegerRange));
                }

                if (bindingElement.MaxBufferSize != bindingElement.MaxReceivedMessageSize)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("bindingElement",
                                                                                 SR.MaxBufferSizeMustMatchMaxReceivedMessageSize);
                }
            }
            else
            {
                if (bindingElement.MaxBufferSize > bindingElement.MaxReceivedMessageSize)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("bindingElement",
                                                                                 SR.MaxBufferSizeMustNotExceedMaxReceivedMessageSize);
                }
            }

            if (TransferModeHelper.IsRequestStreamed(bindingElement.TransferMode) &&
                bindingElement.AuthenticationScheme != AuthenticationSchemes.Anonymous)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("bindingElement",
                                                                             SR.HttpAuthDoesNotSupportRequestStreaming);
            }

            _allowCookies = bindingElement.AllowCookies;

            if (_allowCookies)
            {
                _httpCookieContainerManager = new HttpCookieContainerManager();
            }

            if (!bindingElement.AuthenticationScheme.IsSingleton())
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("value", SR.Format(SR.HttpRequiresSingleAuthScheme,
                                                                                                bindingElement.AuthenticationScheme));
            }
            _authenticationScheme = bindingElement.AuthenticationScheme;
            _maxBufferSize        = bindingElement.MaxBufferSize;
            _transferMode         = bindingElement.TransferMode;
            _useDefaultWebProxy   = bindingElement.UseDefaultWebProxy;

            _channelCredentials   = context.BindingParameters.Find <SecurityCredentialsManager>();
            _securityCapabilities = bindingElement.GetProperty <ISecurityCapabilities>(context);

            _webSocketSettings = WebSocketHelper.GetRuntimeWebSocketSettings(bindingElement.WebSocketSettings);
            int webSocketBufferSize = WebSocketHelper.ComputeClientBufferSize(MaxReceivedMessageSize);

            _bufferPool               = new ConnectionBufferPool(webSocketBufferSize);
            _clientWebSocketFactory   = ClientWebSocketFactory.GetFactory();
            _webSocketSoapContentType = new Lazy <string>(() => MessageEncoderFactory.CreateSessionEncoder().ContentType, LazyThreadSafetyMode.ExecutionAndPublication);
        }
コード例 #11
0
 public AspNetListenerManager(IChannelListener channelListener, HttpTransportBindingElement source)
     : base(channelListener, source)
 {
     http_handler = SvcHttpHandlerFactory.GetHandlerForListener(channelListener);
 }
コード例 #12
0
 public HttpSimpleListenerManager(IChannelListener channelListener, HttpTransportBindingElement source)
     : base(channelListener, source)
 {
 }
コード例 #13
0
 public AspNetChannelListener(HttpTransportBindingElement source,
                              BindingContext context)
     : base(source, context)
 {
 }
コード例 #14
0
        internal virtual void OnExportPolicy(MetadataExporter exporter, PolicyConversionContext policyContext)
        {
            List <string>         assertionNames = new List <string>();
            AuthenticationSchemes effectiveAuthenticationSchemes = HttpTransportBindingElement.GetEffectiveAuthenticationSchemes(this.AuthenticationScheme,
                                                                                                                                 policyContext.BindingParameters);

            if (effectiveAuthenticationSchemes != AuthenticationSchemes.None && !(effectiveAuthenticationSchemes.IsSet(AuthenticationSchemes.Anonymous)))
            {
                // ATTENTION: The order of the if-statements below is essential! When importing WSDL svcutil is actually
                // using the first assertion - and the HTTP spec requires clients to use the most secure authentication
                // scheme supported by the client. (especially important for downlevel (3.5/4.0) clients
                if (effectiveAuthenticationSchemes.IsSet(AuthenticationSchemes.Negotiate))
                {
                    assertionNames.Add(TransportPolicyConstants.NegotiateHttpAuthenticationName);
                }

                if (effectiveAuthenticationSchemes.IsSet(AuthenticationSchemes.Ntlm))
                {
                    assertionNames.Add(TransportPolicyConstants.NtlmHttpAuthenticationName);
                }

                if (effectiveAuthenticationSchemes.IsSet(AuthenticationSchemes.Digest))
                {
                    assertionNames.Add(TransportPolicyConstants.DigestHttpAuthenticationName);
                }

                if (effectiveAuthenticationSchemes.IsSet(AuthenticationSchemes.Basic))
                {
                    assertionNames.Add(TransportPolicyConstants.BasicHttpAuthenticationName);
                }

                if (assertionNames != null && assertionNames.Count > 0)
                {
                    if (assertionNames.Count == 1)
                    {
                        policyContext.GetBindingAssertions().Add(new XmlDocument().CreateElement(TransportPolicyConstants.HttpTransportPrefix,
                                                                                                 assertionNames[0], TransportPolicyConstants.HttpTransportNamespace));
                    }
                    else
                    {
                        XmlDocument dummy = new XmlDocument();
                        XmlElement  root  = dummy.CreateElement(MetadataStrings.WSPolicy.Prefix,
                                                                MetadataStrings.WSPolicy.Elements.ExactlyOne,
                                                                exporter.PolicyVersion.Namespace);

                        foreach (string assertionName in assertionNames)
                        {
                            root.AppendChild(dummy.CreateElement(TransportPolicyConstants.HttpTransportPrefix,
                                                                 assertionName,
                                                                 TransportPolicyConstants.HttpTransportNamespace));
                        }

                        policyContext.GetBindingAssertions().Add(root);
                    }
                }
            }

            bool useWebSocketTransport = WebSocketHelper.UseWebSocketTransport(this.WebSocketSettings.TransportUsage, policyContext.Contract.IsDuplex());

            if (useWebSocketTransport && this.TransferMode != TransferMode.Buffered)
            {
                policyContext.GetBindingAssertions().Add(new XmlDocument().CreateElement(TransportPolicyConstants.WebSocketPolicyPrefix,
                                                                                         this.TransferMode.ToString(), TransportPolicyConstants.WebSocketPolicyNamespace));
            }
        }
        public void ImportEndpoint(WsdlImporter importer, WsdlEndpointConversionContext context)
        {
            if (context == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context");
            }
            if (context.Endpoint == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context.Endpoint");
            }
            if (context.Endpoint.Binding == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context.Endpoint.Binding");
            }

            // Try to post-process the unrecognized RequireHttpCookie assertion to augment the AllowCookies value
            // of HttpTransportBindingElement

            CustomBinding customBinding = context.Endpoint.Binding as CustomBinding;

            if (customBinding != null)
            {
                UnrecognizedAssertionsBindingElement unrecognized = null;
                unrecognized = customBinding.Elements.Find <UnrecognizedAssertionsBindingElement>();
                HttpTransportBindingElement http = null;
                if (unrecognized != null)
                {
                    XmlElement httpUseCookieAssertion = null;
                    if (ContextBindingElementPolicy.TryGetHttpUseCookieAssertion(unrecognized.BindingAsserions, out httpUseCookieAssertion))
                    {
                        foreach (BindingElement element in customBinding.Elements)
                        {
                            http = element as HttpTransportBindingElement;
                            if (http != null)
                            {
                                http.AllowCookies = true;
                                unrecognized.BindingAsserions.Remove(httpUseCookieAssertion);
                                if (unrecognized.BindingAsserions.Count == 0)
                                {
                                    customBinding.Elements.Remove(unrecognized);
                                }
                                break;
                            }
                        }
                    }
                }

                // Try to upgrade to standard binding

                BindingElementCollection bindingElements = customBinding.CreateBindingElements();
                Binding binding;
                if (!WSHttpContextBinding.TryCreate(bindingElements, out binding) &&
                    !NetTcpContextBinding.TryCreate(bindingElements, out binding))
                {
                    // Work around BasicHttpBinding.TryCreate insensitivity to HttpTransportBindingElement.AllowCookies value

                    if (http == null)
                    {
                        foreach (BindingElement bindingElement in bindingElements)
                        {
                            http = bindingElement as HttpTransportBindingElement;
                            if (http != null)
                            {
                                break;
                            }
                        }
                    }
                    if (http != null && http.AllowCookies)
                    {
                        http.AllowCookies = false;
                        if (BasicHttpBinding.TryCreate(bindingElements, out binding))
                        {
                            ((BasicHttpBinding)binding).AllowCookies = true;
                        }
                    }
                }

                if (binding != null)
                {
                    binding.Name             = context.Endpoint.Binding.Name;
                    binding.Namespace        = context.Endpoint.Binding.Namespace;
                    context.Endpoint.Binding = binding;
                }
            }
        }