Beispiel #1
0
        protected ILiveContacts BuildContactsChannel(string epAddress)
        {
            EndpointAddress address = new EndpointAddress(epAddress);

            var binding = RawMapper.GetCustomBinding(new WebHttpBinding(WebHttpSecurityMode.Transport));
            ChannelFactory <ILiveContacts> cf = new ChannelFactory <ILiveContacts>(binding, address);

            cf.Endpoint.Behaviors.Add(new WebHttpBehavior());

            var channel = cf.CreateChannel();

            return(channel);
        }
        private void CreateEndpoints()
        {
            AuthenticationSchemes oneAuthScheme;

            ClientRequestServiceBehaviorAttribute.GetAllAuthenticationSchemes(out oneAuthScheme);

            foreach (var baseAddress in this.m_baseAddresses)
            {
                var binding = new WebHttpBinding
                {
                    AllowCookies           = true,
                    ReceiveTimeout         = TimeSpan.FromHours(1),
                    SendTimeout            = TimeSpan.FromHours(1),
                    OpenTimeout            = TimeSpan.FromHours(1),
                    CloseTimeout           = TimeSpan.FromHours(1),
                    MaxReceivedMessageSize = int.MaxValue,
                    TransferMode           = TransferMode.Streamed,
                    ReaderQuotas           = new System.Xml.XmlDictionaryReaderQuotas
                    {
                        MaxArrayLength         = int.MaxValue,
                        MaxBytesPerRead        = 2048,
                        MaxDepth               = int.MaxValue,
                        MaxNameTableCharCount  = int.MaxValue,
                        MaxStringContentLength = int.MaxValue,
                    }
                };

                if (object.ReferenceEquals(baseAddress.Scheme, Uri.UriSchemeHttps))
                {
                    binding.Security.Mode = WebHttpSecurityMode.Transport;
                }
                else if (object.ReferenceEquals(baseAddress.Scheme, Uri.UriSchemeHttp))
                {
                    binding.Security.Mode = WebHttpSecurityMode.TransportCredentialOnly;
                }
                else if ((oneAuthScheme != AuthenticationSchemes.None) && (oneAuthScheme != AuthenticationSchemes.Anonymous))
                {
                    binding.Security.Mode = WebHttpSecurityMode.TransportCredentialOnly;
                }
                else
                {
                    binding.Security.Mode = WebHttpSecurityMode.None;
                }

                binding.Security.Transport.ClientCredentialType = ServiceUtility.ClientCredentialTypeFromAuthenticationScheme(oneAuthScheme);

                //Set the content type mapper on the binding to return raw elements (for json.)
                var cb      = new CustomBinding(binding);
                var webMebe = cb.Elements.Find <WebMessageEncodingBindingElement>();

                var rawMapper = new RawMapper();
                if (this.Description.Behaviors.Find <RawJsonRequestBehaviorAttribute>() != null)
                {
                    rawMapper.UseRawForJson = true;
                }

                webMebe.ContentTypeMapper = rawMapper;

                Type contractType = ServiceUtility.GetContractType(ImplementedContracts);
                AddServiceEndpoint(contractType, cb, baseAddress);
            }
        }