Пример #1
0
            public JsonErrorHandler(ServiceEndpoint endpoint, bool includeExceptionDetailInFaults)
            {
                WebMessageEncodingBindingElement webMEBE = endpoint.Binding.CreateBindingElements().Find <WebMessageEncodingBindingElement>();

                outgoingContentType = JsonMessageEncoderFactory.GetContentType(webMEBE);
                this.includeExceptionDetailInFaults = includeExceptionDetailInFaults;
            }
Пример #2
0
        public static Binding GetBinding(bool useHttps)
        {
            CustomBinding binding = new CustomBinding();

            binding.Elements.Add(new OAuthInterceptorBindingElement());
            binding.Elements.Add(new WebMessageEncodingBindingElement());

            if (useHttps)
            {
                binding.Elements.Add(new HttpsTransportBindingElement {
                    ManualAddressing = true, MaxReceivedMessageSize = (1024 * 1024) * 3
                });                                                                                                                                             // MaxReceivedMessageSize = 3 Mb
            }
            else
            {
                binding.Elements.Add(new HttpTransportBindingElement {
                    ManualAddressing = true, MaxReceivedMessageSize = (1024 * 1024) * 3
                });                                                                                                                                            // MaxReceivedMessageSize = 3 Mb
            }
            WebMessageEncodingBindingElement element = binding.Elements.Find <WebMessageEncodingBindingElement>();

            element.ContentTypeMapper = new OAuthRawMapper();

            return(binding);
        }
        public void BuildChannelFactory()
        {
            var m = new WebMessageEncodingBindingElement();
            var f = m.BuildChannelFactory <IRequestChannel> (CreateBindingContext());

            Assert.AreEqual(f.GetType(), new HttpTransportBindingElement().BuildChannelFactory <IRequestChannel> (CreateBindingContext()).GetType(), "#1");
        }
Пример #4
0
        protected internal override BindingElement CreateBindingElement()
        {
            var be = new WebMessageEncodingBindingElement();

            ApplyConfiguration(be);
            return(be);
        }
		public void CanBuildChannelFactory ()
		{
			// with HttpTransport
			var m = new WebMessageEncodingBindingElement ();
			Assert.IsTrue (m.CanBuildChannelFactory<IRequestChannel> (CreateBindingContext ()), "#1");
			Assert.IsFalse (m.CanBuildChannelFactory<IReplyChannel> (CreateBindingContext ()), "#2");
			Assert.IsFalse (m.CanBuildChannelFactory<IRequestSessionChannel> (CreateBindingContext ()), "#3");
			Assert.IsFalse (m.CanBuildChannelFactory<IDuplexChannel> (CreateBindingContext ()), "#4");

			// actually they are from transport
			var h = new HttpTransportBindingElement ();
			Assert.IsTrue (h.CanBuildChannelFactory<IRequestChannel> (CreateBindingContext ()), "#5");
			Assert.IsFalse (h.CanBuildChannelFactory<IReplyChannel> (CreateBindingContext ()), "#6");
			Assert.IsFalse (h.CanBuildChannelFactory<IRequestSessionChannel> (CreateBindingContext ()), "#7");
			Assert.IsFalse (h.CanBuildChannelFactory<IDuplexChannel> (CreateBindingContext ()), "#8");

			// with TcpTransport
			Assert.IsFalse (m.CanBuildChannelFactory<IRequestChannel> (CreateBindingContext2 ()), "#9");
			Assert.IsFalse (m.CanBuildChannelFactory<IReplyChannel> (CreateBindingContext2 ()), "#10");
			Assert.IsFalse (m.CanBuildChannelFactory<IRequestSessionChannel> (CreateBindingContext2 ()), "#11");
			Assert.IsFalse (m.CanBuildChannelFactory<IDuplexChannel> (CreateBindingContext2 ()), "#12");

			// ... yes, actually they are from transport
			var t = new TcpTransportBindingElement ();
			Assert.IsFalse (t.CanBuildChannelFactory<IRequestChannel> (CreateBindingContext2 ()), "#13");
			Assert.IsFalse (t.CanBuildChannelFactory<IReplyChannel> (CreateBindingContext2 ()), "#14");
			Assert.IsFalse (t.CanBuildChannelFactory<IRequestSessionChannel> (CreateBindingContext2 ()), "#15");
			Assert.IsFalse (t.CanBuildChannelFactory<IDuplexChannel> (CreateBindingContext2 ()), "#16");
		}
        public ReverseWebProxy(Uri upstreamUri, Uri downstreamUri, TransportClientEndpointBehavior credentials)
        {
            this.upstreamUri = upstreamUri;
            this.downstreamUri = downstreamUri;

            this.upstreamBasePath = this.upstreamUri.PathAndQuery;
            if (this.upstreamBasePath.EndsWith("/"))
            {
                this.upstreamBasePath = this.upstreamBasePath.Substring(0, this.upstreamBasePath.Length - 1);
            }

            ServicePointManager.DefaultConnectionLimit = 50;

            WebHttpRelayBinding relayBinding = new WebHttpRelayBinding(EndToEndWebHttpSecurityMode.None, RelayClientAuthenticationType.None);
            relayBinding.MaxReceivedMessageSize = int.MaxValue;
            relayBinding.TransferMode = TransferMode.Streamed;
            relayBinding.AllowCookies = false;
            relayBinding.ReceiveTimeout = TimeSpan.MaxValue;
            relayBinding.ReaderQuotas.MaxArrayLength = int.MaxValue;
            relayBinding.ReaderQuotas.MaxStringContentLength = int.MaxValue;
            this.upstreamBinding = relayBinding;

            WebMessageEncodingBindingElement encoderBindingElement = new WebMessageEncodingBindingElement();
            encoderBindingElement.ReaderQuotas.MaxArrayLength = int.MaxValue;
            encoderBindingElement.ReaderQuotas.MaxStringContentLength = int.MaxValue;
            encoderBindingElement.ContentTypeMapper = new RawContentTypeMapper();
            encoder = encoderBindingElement.CreateMessageEncoderFactory().Encoder;

            this.credentials = credentials;
        }
Пример #7
0
        /// <summary>
        /// Constructor that inits the connection to the uTorrent Web API.
        /// </summary>
        public UtorrentClient(string uTorrentUserName, string uTorrentPassword, string uTorrentAddress)
        {
            var encodingBindingElement = new WebMessageEncodingBindingElement()
            {
                ContentTypeMapper = new JsonContentTypeMapper()
            };

            var transportBindingElement = new HttpTransportBindingElement()
            {
                ManualAddressing     = true,
                AuthenticationScheme = AuthenticationSchemes.Basic,
                Realm                  = "uTorrent",
                AllowCookies           = true,
                MaxReceivedMessageSize = 524288 // 512k ought to be enough for everybody.. ;)
            };

            var binding = new CustomBinding(encodingBindingElement, transportBindingElement);

            var factory = new WebChannelFactory <IUtorrentChannel>(binding);

            factory.Endpoint.Address = new EndpointAddress(uTorrentAddress);;
            factory.Credentials.UserName.UserName = uTorrentUserName;
            factory.Credentials.UserName.Password = uTorrentPassword;

            Channel = factory.CreateChannel();
        }
Пример #8
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;
        }
        internal static void SetRawContentTypeMapperIfNecessary(ServiceEndpoint endpoint, bool isDispatch)
        {
            Binding             binding  = endpoint.Binding;
            ContractDescription contract = endpoint.Contract;

            if (binding == null)
            {
                return;
            }
            CustomBinding                    customBinding   = new CustomBinding(binding);
            BindingElementCollection         bec             = customBinding.Elements;
            WebMessageEncodingBindingElement encodingElement = bec.Find <WebMessageEncodingBindingElement>();

            if (encodingElement == null || encodingElement.ContentTypeMapper != null)
            {
                return;
            }
            bool areAllOperationsRawMapperCompatible = true;
            int  numStreamOperations = 0;

            foreach (OperationDescription operation in contract.Operations)
            {
                bool isCompatible = (isDispatch) ? IsRawContentMapperCompatibleDispatchOperation(operation, ref numStreamOperations) : IsRawContentMapperCompatibleClientOperation(operation, ref numStreamOperations);
                if (!isCompatible)
                {
                    areAllOperationsRawMapperCompatible = false;
                    break;
                }
            }
            if (areAllOperationsRawMapperCompatible && numStreamOperations > 0)
            {
                encodingElement.ContentTypeMapper = RawContentTypeMapper.Instance;
                endpoint.Binding = customBinding;
            }
        }
        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;
        }
 public JsonRpcHttpBinding()
     : base()
 {
     transport = new HttpTransportBindingElement();
     encoding = new WebMessageEncodingBindingElement();
     encoding.ContentTypeMapper = new JsonRpcRawMapper();
 }
Пример #12
0
        internal protected override BindingElement CreateBindingElement()
        {
            WebMessageEncodingBindingElement binding = new WebMessageEncodingBindingElement();

            this.ApplyConfiguration(binding);
            return(binding);
        }
Пример #13
0
        /// <summary>
        /// Generates a binding to use for requests to the Nintex Forms service endpoint.
        /// </summary>
        /// <returns>A <see cref="System.ServiceModel.Channels.Binding" /> used for requests to the service endpoint.</returns>
        /// <remarks>The <see cref="System.ServiceModel.Channels.Binding" /> contains encoding and transport binding elements, and sets the timeouts for opening, closing, and sending requests to two hours.</remarks>
        public static Binding GetDefaultBinding()
        {
            // Create and configure a new WebMessageEncodingBindingElement binding element.
            var webMessageEncodingBindingElement = new WebMessageEncodingBindingElement {
                MessageVersion = MessageVersion.None
            };

            webMessageEncodingBindingElement.ReaderQuotas.MaxStringContentLength = 2147483647;

            // Create and configure a new HttpTransportBindingElement binding element.
            var transport = new HttpTransportBindingElement
            {
                MaxBufferPoolSize      = 524288,
                MaxBufferSize          = 65536000,
                MaxReceivedMessageSize = 65536000,
                ManualAddressing       = true,
                AuthenticationScheme   = AuthenticationSchemes.Ntlm
            };

            // Create a new custom binding based on the new binding elements.
            var binding = new CustomBinding(webMessageEncodingBindingElement, transport)
            {
                CloseTimeout = new TimeSpan(2, 0, 0),
                OpenTimeout  = new TimeSpan(2, 0, 0),
                SendTimeout  = new TimeSpan(2, 0, 0)
            };

            return(binding);
        }
        public void CanBuildChannelFactory()
        {
            // with HttpTransport
            var m = new WebMessageEncodingBindingElement();

            Assert.IsTrue(m.CanBuildChannelFactory <IRequestChannel> (CreateBindingContext()), "#1");
            Assert.IsFalse(m.CanBuildChannelFactory <IReplyChannel> (CreateBindingContext()), "#2");
            Assert.IsFalse(m.CanBuildChannelFactory <IRequestSessionChannel> (CreateBindingContext()), "#3");
            Assert.IsFalse(m.CanBuildChannelFactory <IDuplexChannel> (CreateBindingContext()), "#4");

            // actually they are from transport
            var h = new HttpTransportBindingElement();

            Assert.IsTrue(h.CanBuildChannelFactory <IRequestChannel> (CreateBindingContext()), "#5");
            Assert.IsFalse(h.CanBuildChannelFactory <IReplyChannel> (CreateBindingContext()), "#6");
            Assert.IsFalse(h.CanBuildChannelFactory <IRequestSessionChannel> (CreateBindingContext()), "#7");
            Assert.IsFalse(h.CanBuildChannelFactory <IDuplexChannel> (CreateBindingContext()), "#8");

            // with TcpTransport
            Assert.IsFalse(m.CanBuildChannelFactory <IRequestChannel> (CreateBindingContext2()), "#9");
            Assert.IsFalse(m.CanBuildChannelFactory <IReplyChannel> (CreateBindingContext2()), "#10");
            Assert.IsFalse(m.CanBuildChannelFactory <IRequestSessionChannel> (CreateBindingContext2()), "#11");
            Assert.IsFalse(m.CanBuildChannelFactory <IDuplexChannel> (CreateBindingContext2()), "#12");

            // ... yes, actually they are from transport
            var t = new TcpTransportBindingElement();

            Assert.IsFalse(t.CanBuildChannelFactory <IRequestChannel> (CreateBindingContext2()), "#13");
            Assert.IsFalse(t.CanBuildChannelFactory <IReplyChannel> (CreateBindingContext2()), "#14");
            Assert.IsFalse(t.CanBuildChannelFactory <IRequestSessionChannel> (CreateBindingContext2()), "#15");
            Assert.IsFalse(t.CanBuildChannelFactory <IDuplexChannel> (CreateBindingContext2()), "#16");
        }
Пример #15
0
 public JsonRpcHttpBinding()
     : base()
 {
     transport = new HttpTransportBindingElement();
     encoding  = new WebMessageEncodingBindingElement();
     encoding.ContentTypeMapper = new JsonRpcRawMapper();
 }
        public void GetPropertyMessageVersion()
        {
            var m  = new WebMessageEncodingBindingElement();
            var bc = new BindingContext(new CustomBinding(), new BindingParameterCollection());

            Assert.AreEqual(MessageVersion.None, m.GetProperty <MessageVersion> (bc), "#1");
        }
Пример #17
0
        public void MessageFormatterSupportsRaw()
        {
            // serializing reply
            var ms    = new MemoryStream();
            var bytes = new byte [] { 0, 1, 2, 0xFF };

            ms.Write(bytes, 0, bytes.Length);
            ms.Position = 0;
            var cd        = ContractDescription.GetContract(typeof(ITestService));
            var od        = cd.Operations [0];
            var se        = new ServiceEndpoint(cd, new WebHttpBinding(), new EndpointAddress("http://localhost:37564/"));
            var formatter = new WebHttpBehaviorExt().DoGetReplyDispatchFormatter(od, se);

            var msg = formatter.SerializeReply(MessageVersion.None, null, ms);
            var wp  = msg.Properties ["WebBodyFormatMessageProperty"] as WebBodyFormatMessageProperty;

            Assert.IsNotNull(wp, "#1");
            Assert.AreEqual(WebContentFormat.Raw, wp.Format, "#2");

            var wmebe = new WebMessageEncodingBindingElement();
            var wme   = wmebe.CreateMessageEncoderFactory().Encoder;
            var ms2   = new MemoryStream();

            wme.WriteMessage(msg, ms2);
            Assert.AreEqual(bytes, ms2.ToArray(), "#3");
        }
Пример #18
0
        internal static Binding GetBinding()
        {
            CustomBinding result = new CustomBinding(new WebHttpBinding());
            WebMessageEncodingBindingElement element = result.Elements.Find <WebMessageEncodingBindingElement>();

            element.ContentTypeMapper = new RawMapper();
            return(result);
        }
Пример #19
0
        //Used by live contacts channel and Solr search and RelatedItems
        public static CustomBinding GetCustomBinding(Binding source)
        {
            CustomBinding result = new CustomBinding(source);
            WebMessageEncodingBindingElement element = result.Elements.Find <WebMessageEncodingBindingElement>();

            element.ContentTypeMapper = new RawMapper();
            return(result);
        }
Пример #20
0
        private bool InitServiceToAdmin()
        {
            try
            {
                List <BindingElement> bindingElements = new List <BindingElement>();

                WebMessageEncodingBindingElement webCncoding = new WebMessageEncodingBindingElement();
                webCncoding.ReaderQuotas.MaxArrayLength         = 1024 * 1024 * 5;
                webCncoding.ReaderQuotas.MaxBytesPerRead        = 1024 * 1024 * 3;
                webCncoding.ReaderQuotas.MaxStringContentLength = 1024 * 1024 * 5;
                CryptMessageEncoderElement encoding = new CryptMessageEncoderElement(webCncoding);

                HttpTransportBindingElement transport = new HttpTransportBindingElement();
                transport.ManualAddressing       = true;
                transport.MaxReceivedMessageSize = Int32.MaxValue;
                transport.MaxBufferSize          = Int32.MaxValue;
                transport.MaxBufferPoolSize      = 1024 * 1024 * 5;

                bindingElements.Add(encoding);
                bindingElements.Add(transport);

                CustomBinding bind = new CustomBinding(bindingElements);

                var baseAddress = new Uri("http://localhost:" + GlobalData.ServiceToAdministrator);
                this._serviceToAdminHost = new ServiceHost(typeof(ServiceToAdmin), baseAddress);
                this._serviceToAdminHost.Description.Behaviors.Add(new ServiceThrottlingBehavior()
                {
                    MaxConcurrentCalls     = 1024,
                    MaxConcurrentInstances = 512,
                    MaxConcurrentSessions  = 512,
                });

                var servieEP = this._serviceToAdminHost.AddServiceEndpoint(typeof(IServiceToAdmin), bind, baseAddress);

                servieEP.Behaviors.Add(new WebHttpBehavior());

                foreach (var item in servieEP.Contract.Operations)
                {
                    DataContractSerializerOperationBehavior dc = item.Behaviors.Find <DataContractSerializerOperationBehavior>();
                    if (dc == null)
                    {
                        dc = new DataContractSerializerOperationBehavior(item);
                        item.Behaviors.Add(dc);
                    }

                    // Change the settings of the behavior.
                    dc.MaxItemsInObjectGraph = Int32.MaxValue;
                }

                this._serviceToAdminHost.Open();
                return(true);
            }
            catch (Exception exc)
            {
                LogHelper.Instance.AddErrorLog("Init Service To Admin failed.", exc);
                return(false);
            }
        }
Пример #21
0
 void Initialize()
 {
     httpTransportBindingElement  = new HttpTransportBindingElement();
     httpsTransportBindingElement = new HttpsTransportBindingElement();
     httpTransportBindingElement.ManualAddressing  = true;
     httpsTransportBindingElement.ManualAddressing = true;
     webMessageEncodingBindingElement = new WebMessageEncodingBindingElement();
     webMessageEncodingBindingElement.MessageVersion = MessageVersion.None;
 }
        protected CustomBinding GetBinding(
            WcfRestWebServiceAppSettings settings,
            WebHttpBinding webHttpBinding)
        {
            CustomBinding result = new CustomBinding(webHttpBinding);
            WebMessageEncodingBindingElement webMEBE = result.Elements.Find <WebMessageEncodingBindingElement>();

            webMEBE.ContentTypeMapper = new WcfRawContentTypeMapperWindows();
            return(result);
        }
Пример #23
0
        // Internal Methods (1) 

        internal static WebMessageEncodingBindingElement CreateWebMessageBindingEncoder()
        {
            var encoding = new WebMessageEncodingBindingElement();

            encoding.MaxReadPoolSize             = int.MaxValue;
            encoding.ContentTypeMapper           = new RawContentTypeMapper();
            encoding.ReaderQuotas.MaxArrayLength = int.MaxValue;

            return(encoding);
        }
 private void Initialize()
 {
     this.httpRelayTransportBindingElement  = new HttpRelayTransportBindingElement();
     this.httpsRelayTransportBindingElement = new HttpsRelayTransportBindingElement();
     this.httpRelayTransportBindingElement.ManualAddressing  = true;
     this.httpsRelayTransportBindingElement.ManualAddressing = true;
     this.webMessageEncodingBindingElement = new WebMessageEncodingBindingElement()
     {
         MessageVersion = System.ServiceModel.Channels.MessageVersion.None
     };
 }
 internal static string GetContentType(WebMessageEncodingBindingElement encodingElement)
 {
     if (encodingElement == null)
     {
         return WebMessageEncoderFactory.GetContentType(JsonGlobals.applicationJsonMediaType, TextEncoderDefaults.Encoding);
     }
     else
     {
         return WebMessageEncoderFactory.GetContentType(JsonGlobals.applicationJsonMediaType, encodingElement.WriteEncoding);
     }
 }
        public void MessageEncoderIsContentTypeSupported()
        {
            var enc = new WebMessageEncodingBindingElement().CreateMessageEncoderFactory().Encoder;

            Assert.IsTrue(enc.IsContentTypeSupported("application/xml"), "#1");
            Assert.IsTrue(enc.IsContentTypeSupported("text/xml"), "#2");
            Assert.IsTrue(enc.IsContentTypeSupported("application/soap+xml"), "#3");
            Assert.IsTrue(enc.IsContentTypeSupported("application/foobar+xml"), "#4");   // wow.
            Assert.IsTrue(enc.IsContentTypeSupported("application"), "#5");              // wow.
            Assert.IsTrue(enc.IsContentTypeSupported(String.Empty), "#6");               // wow.
        }
Пример #27
0
        public void Validate(ServiceEndpoint endpoint)
        {
            //base.Validate(endpoint);
            BindingElementCollection         bindingElements = endpoint.Binding.CreateBindingElements();
            WebMessageEncodingBindingElement webEncoder      = bindingElements.Find <WebMessageEncodingBindingElement>();

            if (webEncoder == null)
            {
                throw new InvalidOperationException("IMSI Must be bound to type webHttpBinding");
            }
        }
Пример #28
0
        /// <summary>
        /// 初始化基本HTTP服务绑定
        /// </summary>
        private CustomBinding InitBinding()
        {
            var encoder = new WebMessageEncodingBindingElement {
                ReaderQuotas = { MaxArrayLength = 67108864, MaxStringContentLength = 67108864 }
            };
            var transport = new HttpTransportBindingElement {
                ManualAddressing = true, MaxReceivedMessageSize = 1073741824, TransferMode = TransferMode.Streamed
            };
            var binding = new CustomBinding {
                SendTimeout = TimeSpan.FromSeconds(600), ReceiveTimeout = TimeSpan.FromSeconds(600)
            };

            binding.Elements.AddRange(encoder, transport);
            return(binding);
        }
Пример #29
0
        /// <summary>
        /// Valida o endpoint.
        /// </summary>
        /// <param name="endpoint"></param>
        public override void Validate(ServiceEndpoint endpoint)
        {
            base.Validate(endpoint);
            BindingElementCollection         elements   = endpoint.Binding.CreateBindingElements();
            WebMessageEncodingBindingElement webEncoder = elements.Find <WebMessageEncodingBindingElement>();

            if (webEncoder == null)
            {
                throw new InvalidOperationException("This behavior must be used in an endpoint with the WebHttpBinding (or a custom binding with the WebMessageEncodingBindingElement).");
            }
            foreach (OperationDescription operation in endpoint.Contract.Operations)
            {
                this.ValidateOperation(operation);
            }
        }
Пример #30
0
    static Binding GetBinding()
    {
        var b = new WebHttpBinding();

        b.MaxReceivedMessageSize              = 28 * 1024 * 1024 * 2;
        b.ReaderQuotas.MaxBytesPerRead        = 4096 * 1024;
        b.ReaderQuotas.MaxDepth               = 32;
        b.ReaderQuotas.MaxStringContentLength = 4096 * 1024;
        b.ReaderQuotas.MaxArrayLength         = 4096 * 1024;
        b.Security.Mode = WebHttpSecurityMode.Transport;
        CustomBinding result = new CustomBinding(b);
        WebMessageEncodingBindingElement webMEBE = result.Elements.Find <WebMessageEncodingBindingElement>();

        webMEBE.ContentTypeMapper = new MyMapper();
        return(result);
    }
Пример #31
0
        //produces a custom web service binding mapped to the obtained gzip classes
        private static Binding GetWebHttpBinding(WebHttpBinding whb)
        {
            CustomBinding customBinding = new CustomBinding(whb);

            for (int i = 0; i < customBinding.Elements.Count; i++)
            {
                if (customBinding.Elements[i] is WebMessageEncodingBindingElement)
                {
                    WebMessageEncodingBindingElement webBE = (WebMessageEncodingBindingElement)customBinding.Elements[i];
                    customBinding.Elements[i] = new GZipEncoder.GZipMessageEncodingBindingElement(webBE);
                    break;
                }
            } //for

            return(customBinding);
        }
Пример #32
0
        public JsonValueFormatter(OperationDescription operationDescription, ServiceEndpoint endpoint, QueryStringConverter queryStringConverter, int jsonValuePosition)
        {
            this.operationDescription = operationDescription;
            this.queryStringConverter = queryStringConverter;
            this.jsonValuePosition    = jsonValuePosition;

            BindingElementCollection         bindingElements = endpoint.Binding.CreateBindingElements();
            WebMessageEncodingBindingElement webEncoding     = bindingElements.Find <WebMessageEncodingBindingElement>();

            this.charset      = CharsetFromEncoding(webEncoding);
            this.readerQuotas = new XmlDictionaryReaderQuotas();
            XmlDictionaryReaderQuotas.Max.CopyTo(this.readerQuotas);
            if (webEncoding != null)
            {
                webEncoding.ReaderQuotas.CopyTo(this.readerQuotas);
            }
        }
Пример #33
0
		internal static BinaryMessageEncodingBindingElement CreateInnerEncodingBindingElement(BindingContext context)
		{
			BinaryMessageEncodingBindingElement binaryMessageEncodingBindingElement;
			if (context == null)
			{
				return ClientMessageUtility.defaultEncoderBindingElement;
			}
			BinaryMessageEncodingBindingElement binaryMessageEncodingBindingElement1 = context.BindingParameters.Find<BinaryMessageEncodingBindingElement>();
			if (binaryMessageEncodingBindingElement1 == null)
			{
				binaryMessageEncodingBindingElement = new BinaryMessageEncodingBindingElement();
				TextMessageEncodingBindingElement textMessageEncodingBindingElement = context.BindingParameters.Find<TextMessageEncodingBindingElement>();
				if (textMessageEncodingBindingElement == null)
				{
					MtomMessageEncodingBindingElement mtomMessageEncodingBindingElement = context.BindingParameters.Find<MtomMessageEncodingBindingElement>();
					if (mtomMessageEncodingBindingElement == null)
					{
						WebMessageEncodingBindingElement webMessageEncodingBindingElement = context.BindingParameters.Find<WebMessageEncodingBindingElement>();
						if (webMessageEncodingBindingElement != null)
						{
							webMessageEncodingBindingElement.ReaderQuotas.CopyTo(binaryMessageEncodingBindingElement.ReaderQuotas);
							binaryMessageEncodingBindingElement.MaxReadPoolSize = webMessageEncodingBindingElement.MaxReadPoolSize;
							binaryMessageEncodingBindingElement.MaxWritePoolSize = webMessageEncodingBindingElement.MaxWritePoolSize;
						}
					}
					else
					{
						mtomMessageEncodingBindingElement.ReaderQuotas.CopyTo(binaryMessageEncodingBindingElement.ReaderQuotas);
						binaryMessageEncodingBindingElement.MaxReadPoolSize = mtomMessageEncodingBindingElement.MaxReadPoolSize;
						binaryMessageEncodingBindingElement.MaxWritePoolSize = mtomMessageEncodingBindingElement.MaxWritePoolSize;
					}
				}
				else
				{
					textMessageEncodingBindingElement.ReaderQuotas.CopyTo(binaryMessageEncodingBindingElement.ReaderQuotas);
					binaryMessageEncodingBindingElement.MaxReadPoolSize = textMessageEncodingBindingElement.MaxReadPoolSize;
					binaryMessageEncodingBindingElement.MaxWritePoolSize = textMessageEncodingBindingElement.MaxWritePoolSize;
				}
			}
			else
			{
				binaryMessageEncodingBindingElement = binaryMessageEncodingBindingElement1.Clone() as BinaryMessageEncodingBindingElement;
			}
			return binaryMessageEncodingBindingElement;
		}
Пример #34
0
        private void ShowMessageEncodingDetails(MessageEncodingBindingElement element)
        {
            string encodingInfoStr = "messageVersion=" + element.MessageVersion;

            if (element is WebMessageEncodingBindingElement)
            {
                WebMessageEncodingBindingElement webElement = (WebMessageEncodingBindingElement)element;
                encodingInfoStr += ", writeEncoding=" + webElement.WriteEncoding;
                if (webElement.ContentTypeMapper != null)
                {
                    encodingInfoStr += ",contentTypeMapper=" + webElement.ContentTypeMapper.GetType().FullName;
                }
                if (webElement.ReaderQuotas != null)
                {
                    encodingInfoStr += ",readerQuotas=" + webElement.ReaderQuotas.GetType().FullName;
                }
            }
        }
Пример #35
0
        public void MessageFormatterSupportsRaw2()
        {
            // deserializing request
            var ms = new MemoryStream();

            ms.Write(new byte [] { 0, 1, 2, 0xFF }, 0, 4);
            ms.Position = 0;
            var cd        = ContractDescription.GetContract(typeof(ITestService));
            var od        = cd.Operations [0];
            var se        = new ServiceEndpoint(cd, new WebHttpBinding(), new EndpointAddress("http://localhost:8080/"));
            var wmebe     = new WebMessageEncodingBindingElement();
            var wme       = wmebe.CreateMessageEncoderFactory().Encoder;
            var msg       = wme.ReadMessage(ms, 100, null); // "application/xml" causes error.
            var formatter = new WebHttpBehaviorExt().DoGetRequestDispatchFormatter(od, se);

            object [] pars = new object [1];
            formatter.DeserializeRequest(msg, pars);
            Assert.IsTrue(pars [0] is Stream, "ret");
        }
Пример #36
0
		public WebMessageEncoder (WebMessageEncodingBindingElement source)
		{
			this.source = source;
		}
Пример #37
0
        private static string CharsetFromEncoding(WebMessageEncodingBindingElement webEncoding)
        {
            const string UTF8Charset = "utf-8";
            const string UnicodeLECharset = "utf-16LE";
            const string UnicodeBECharset = "utf-16BE";
            string result = UTF8Charset;
            if (webEncoding != null)
            {
                if (webEncoding.WriteEncoding.WebName == Encoding.Unicode.WebName)
                {
                    result = UnicodeLECharset;
                }
                else if (webEncoding.WriteEncoding.WebName == Encoding.BigEndianUnicode.WebName)
                {
                    result = UnicodeBECharset;
                }
            }

            return result;
        }
 internal protected override BindingElement CreateBindingElement()
 {
     WebMessageEncodingBindingElement binding = new WebMessageEncodingBindingElement();
     this.ApplyConfiguration(binding);
     return binding;
 }
 public WebMessageEncoderFactory(WebMessageEncodingBindingElement source)
 {
     encoder = new WebMessageEncoder (source);
 }
Пример #40
0
 string GetDefaultContentType(bool isStream, bool useJson, WebMessageEncodingBindingElement webEncoding)
 {
     if (isStream)
     {
         return defaultStreamContentType;
     }
     else if (useJson)
     {
         return JsonMessageEncoderFactory.GetContentType(webEncoding);
     }
     else
     {
         return null;
     }
 }
		public override BindingElementCollection CreateBindingElements ()
		{
			WebMessageEncodingBindingElement m = new WebMessageEncodingBindingElement (WriteEncoding);
#if !NET_2_1
			if (ReaderQuotas != null)
				ReaderQuotas.CopyTo (m.ReaderQuotas);
#endif

			return new BindingElementCollection (new BindingElement [] { m, t.Clone () });
		}
Пример #42
0
		protected internal override BindingElement CreateBindingElement ()
		{
			var be = new WebMessageEncodingBindingElement ();
			ApplyConfiguration (be);
			return be;
		}
Пример #43
0
		public void MessageFormatterSupportsRaw ()
		{
			// serializing reply
			var ms = new MemoryStream ();
			var bytes = new byte [] {0, 1, 2, 0xFF};
			ms.Write (bytes, 0, bytes.Length);
			ms.Position = 0;
			var cd = ContractDescription.GetContract (typeof (ITestService));
			var od = cd.Operations [0];
			var se = new ServiceEndpoint (cd, new WebHttpBinding (), new EndpointAddress ("http://localhost:37564/"));
			var formatter = new WebHttpBehaviorExt ().DoGetReplyDispatchFormatter (od, se);

			var msg = formatter.SerializeReply (MessageVersion.None, null, ms);
			var wp = msg.Properties ["WebBodyFormatMessageProperty"] as WebBodyFormatMessageProperty;
			Assert.IsNotNull (wp, "#1");
			Assert.AreEqual (WebContentFormat.Raw, wp.Format, "#2");

			var wmebe = new WebMessageEncodingBindingElement ();
			var wme = wmebe.CreateMessageEncoderFactory ().Encoder;
			var ms2 = new MemoryStream ();
			wme.WriteMessage (msg, ms2);
			Assert.AreEqual (bytes, ms2.ToArray (), "#3");
		}
 public JSONPEncoder()
 {
     WebMessageEncodingBindingElement element = new WebMessageEncodingBindingElement();
     encoder = element.CreateMessageEncoderFactory().Encoder;
 }
Пример #45
0
		public void MessageFormatterSupportsRaw2 ()
		{
			// deserializing request
			var ms = new MemoryStream ();
			ms.Write (new byte [] {0, 1, 2, 0xFF}, 0, 4);
			ms.Position = 0;
			var cd = ContractDescription.GetContract (typeof (ITestService));
			var od = cd.Operations [0];
			var se = new ServiceEndpoint (cd, new WebHttpBinding (), new EndpointAddress ("http://localhost:8080/"));
			var wmebe = new WebMessageEncodingBindingElement ();
			var wme = wmebe.CreateMessageEncoderFactory ().Encoder;
			var msg = wme.ReadMessage (ms, 100, null); // "application/xml" causes error.
			var formatter = new WebHttpBehaviorExt ().DoGetRequestDispatchFormatter (od, se);
			object [] pars = new object [1];
			formatter.DeserializeRequest (msg, pars);
			Assert.IsTrue (pars [0] is Stream, "ret");
		}
		public void BuildChannelFactory ()
		{
			var m = new WebMessageEncodingBindingElement ();
			var f = m.BuildChannelFactory<IRequestChannel> (CreateBindingContext ());
			Assert.AreEqual (f.GetType (), new HttpTransportBindingElement ().BuildChannelFactory<IRequestChannel> (CreateBindingContext ()).GetType (), "#1");
		}
		MessageEncoder CreateEncoder ()
		{
			WebMessageEncodingBindingElement m = new WebMessageEncodingBindingElement ();
			return m.CreateMessageEncoderFactory ().Encoder;
		}
		public void DefaultPropertyValues ()
		{
			WebMessageEncodingBindingElement be = new WebMessageEncodingBindingElement ();
			Assert.AreEqual (Encoding.UTF8, be.WriteEncoding, "#1");
		}
		public void MessageEncoderIsContentTypeSupported ()
		{
			var enc = new WebMessageEncodingBindingElement ().CreateMessageEncoderFactory ().Encoder;
			Assert.IsTrue (enc.IsContentTypeSupported ("application/xml"), "#1");
			Assert.IsTrue (enc.IsContentTypeSupported ("text/xml"), "#2");
			Assert.IsTrue (enc.IsContentTypeSupported ("application/soap+xml"), "#3");
			Assert.IsTrue (enc.IsContentTypeSupported ("application/foobar+xml"), "#4"); // wow.
			Assert.IsTrue (enc.IsContentTypeSupported ("application"), "#5"); // wow.
			Assert.IsTrue (enc.IsContentTypeSupported (String.Empty), "#6"); // wow.
		}
		public void GetPropertyMessageVersion ()
		{
			var m = new WebMessageEncodingBindingElement ();
			var bc = new BindingContext (new CustomBinding (), new BindingParameterCollection ());
			Assert.AreEqual (MessageVersion.None, m.GetProperty<MessageVersion> (bc), "#1");
		}