Example #1
0
 private static System.ServiceModel.Channels.Binding GetBindingForEndpoint(EndpointConfiguration endpointConfiguration)
 {
     if ((endpointConfiguration == EndpointConfiguration.SchoolServiceSoap))
     {
         System.ServiceModel.BasicHttpBinding result = new System.ServiceModel.BasicHttpBinding();
         result.MaxBufferSize          = int.MaxValue;
         result.ReaderQuotas           = System.Xml.XmlDictionaryReaderQuotas.Max;
         result.MaxReceivedMessageSize = int.MaxValue;
         result.AllowCookies           = true;
         return(result);
     }
     if ((endpointConfiguration == EndpointConfiguration.SchoolServiceSoap12))
     {
         System.ServiceModel.Channels.CustomBinding result = new System.ServiceModel.Channels.CustomBinding();
         System.ServiceModel.Channels.TextMessageEncodingBindingElement textBindingElement = new System.ServiceModel.Channels.TextMessageEncodingBindingElement();
         textBindingElement.MessageVersion = System.ServiceModel.Channels.MessageVersion.CreateVersion(System.ServiceModel.EnvelopeVersion.Soap12, System.ServiceModel.Channels.AddressingVersion.None);
         result.Elements.Add(textBindingElement);
         System.ServiceModel.Channels.HttpTransportBindingElement httpBindingElement = new System.ServiceModel.Channels.HttpTransportBindingElement();
         httpBindingElement.AllowCookies           = true;
         httpBindingElement.MaxBufferSize          = int.MaxValue;
         httpBindingElement.MaxReceivedMessageSize = int.MaxValue;
         result.Elements.Add(httpBindingElement);
         return(result);
     }
     throw new System.InvalidOperationException(string.Format("Não foi possível encontrar o ponto de extremidade com o nome \'{0}\'.", endpointConfiguration));
 }
Example #2
0
 private static System.ServiceModel.Channels.Binding GetBindingForEndpoint(EndpointConfiguration endpointConfiguration)
 {
     if ((endpointConfiguration == EndpointConfiguration.NameService))
     {
         System.ServiceModel.Channels.CustomBinding result = new System.ServiceModel.Channels.CustomBinding();
         result.Elements.Add(new System.ServiceModel.Channels.BinaryMessageEncodingBindingElement());
         System.ServiceModel.Channels.HttpTransportBindingElement httpBindingElement = new System.ServiceModel.Channels.HttpTransportBindingElement();
         httpBindingElement.AllowCookies           = true;
         httpBindingElement.MaxBufferSize          = int.MaxValue;
         httpBindingElement.MaxReceivedMessageSize = int.MaxValue;
         result.Elements.Add(httpBindingElement);
         return(result);
     }
     if ((endpointConfiguration == EndpointConfiguration.NameService1))
     {
         System.ServiceModel.Channels.CustomBinding result = new System.ServiceModel.Channels.CustomBinding();
         result.Elements.Add(new System.ServiceModel.Channels.BinaryMessageEncodingBindingElement());
         System.ServiceModel.Channels.HttpTransportBindingElement httpBindingElement = new System.ServiceModel.Channels.HttpTransportBindingElement();
         httpBindingElement.AllowCookies           = true;
         httpBindingElement.MaxBufferSize          = int.MaxValue;
         httpBindingElement.MaxReceivedMessageSize = int.MaxValue;
         result.Elements.Add(httpBindingElement);
         return(result);
     }
     throw new System.InvalidOperationException(string.Format("找不到名称为“{0}”的终结点。", endpointConfiguration));
 }
Example #3
0
 private static System.ServiceModel.Channels.Binding GetBindingForEndpoint(EndpointConfiguration endpointConfiguration)
 {
     if ((endpointConfiguration == EndpointConfiguration.KPSPublicSoap))
     {
         System.ServiceModel.BasicHttpBinding result = new System.ServiceModel.BasicHttpBinding();
         result.MaxBufferSize          = int.MaxValue;
         result.ReaderQuotas           = System.Xml.XmlDictionaryReaderQuotas.Max;
         result.MaxReceivedMessageSize = int.MaxValue;
         result.AllowCookies           = true;
         result.Security.Mode          = System.ServiceModel.BasicHttpSecurityMode.Transport;
         return(result);
     }
     if ((endpointConfiguration == EndpointConfiguration.KPSPublicSoap12))
     {
         System.ServiceModel.Channels.CustomBinding result = new System.ServiceModel.Channels.CustomBinding();
         System.ServiceModel.Channels.TextMessageEncodingBindingElement textBindingElement = new System.ServiceModel.Channels.TextMessageEncodingBindingElement();
         textBindingElement.MessageVersion = System.ServiceModel.Channels.MessageVersion.CreateVersion(System.ServiceModel.EnvelopeVersion.Soap12, System.ServiceModel.Channels.AddressingVersion.None);
         result.Elements.Add(textBindingElement);
         System.ServiceModel.Channels.HttpsTransportBindingElement httpsBindingElement = new System.ServiceModel.Channels.HttpsTransportBindingElement();
         httpsBindingElement.AllowCookies           = true;
         httpsBindingElement.MaxBufferSize          = int.MaxValue;
         httpsBindingElement.MaxReceivedMessageSize = int.MaxValue;
         result.Elements.Add(httpsBindingElement);
         return(result);
     }
     throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration));
 }
Example #4
0
 private static System.ServiceModel.Channels.Binding GetBindingForEndpoint(EndpointConfiguration endpointConfiguration)
 {
     if ((endpointConfiguration == EndpointConfiguration.CalculatorSoap))
     {
         System.ServiceModel.BasicHttpBinding result = new System.ServiceModel.BasicHttpBinding();
         result.MaxBufferSize          = int.MaxValue;
         result.ReaderQuotas           = System.Xml.XmlDictionaryReaderQuotas.Max;
         result.MaxReceivedMessageSize = int.MaxValue;
         result.AllowCookies           = true;
         return(result);
     }
     if ((endpointConfiguration == EndpointConfiguration.CalculatorSoap12))
     {
         System.ServiceModel.Channels.CustomBinding result = new System.ServiceModel.Channels.CustomBinding();
         System.ServiceModel.Channels.TextMessageEncodingBindingElement textBindingElement = new System.ServiceModel.Channels.TextMessageEncodingBindingElement();
         textBindingElement.MessageVersion = System.ServiceModel.Channels.MessageVersion.CreateVersion(System.ServiceModel.EnvelopeVersion.Soap12, System.ServiceModel.Channels.AddressingVersion.None);
         result.Elements.Add(textBindingElement);
         System.ServiceModel.Channels.HttpTransportBindingElement httpBindingElement = new System.ServiceModel.Channels.HttpTransportBindingElement();
         httpBindingElement.AllowCookies           = true;
         httpBindingElement.MaxBufferSize          = int.MaxValue;
         httpBindingElement.MaxReceivedMessageSize = int.MaxValue;
         result.Elements.Add(httpBindingElement);
         return(result);
     }
     throw new System.InvalidOperationException(string.Format("Le point de terminaison nommé \'{0}\' est introuvable.", endpointConfiguration));
 }
Example #5
0
 public 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));
     binding.Elements.Add(new System.ServiceModel.Channels.HttpTransportBindingElement());
     return(binding);
 }
Example #6
0
 private static System.ServiceModel.Channels.Binding GetBindingForEndpoint(EndpointConfiguration endpointConfiguration)
 {
     if ((endpointConfiguration == EndpointConfiguration.WSHttpBinding_IMFUploadService))
     {
         System.ServiceModel.Channels.CustomBinding result = new System.ServiceModel.Channels.CustomBinding();
         System.ServiceModel.Channels.TextMessageEncodingBindingElement textBindingElement = new System.ServiceModel.Channels.TextMessageEncodingBindingElement();
         result.Elements.Add(textBindingElement);
         System.ServiceModel.Channels.HttpTransportBindingElement httpBindingElement = new System.ServiceModel.Channels.HttpTransportBindingElement();
         httpBindingElement.AllowCookies           = true;
         httpBindingElement.MaxBufferSize          = int.MaxValue;
         httpBindingElement.MaxReceivedMessageSize = int.MaxValue;
         result.Elements.Add(httpBindingElement);
         return(result);
     }
     if ((endpointConfiguration == EndpointConfiguration.WSHttpBinding_IMFUploadService1))
     {
         System.ServiceModel.Channels.CustomBinding result = new System.ServiceModel.Channels.CustomBinding();
         System.ServiceModel.Channels.TextMessageEncodingBindingElement textBindingElement = new System.ServiceModel.Channels.TextMessageEncodingBindingElement();
         result.Elements.Add(textBindingElement);
         System.ServiceModel.Channels.HttpsTransportBindingElement httpsBindingElement = new System.ServiceModel.Channels.HttpsTransportBindingElement();
         httpsBindingElement.AllowCookies           = true;
         httpsBindingElement.MaxBufferSize          = int.MaxValue;
         httpsBindingElement.MaxReceivedMessageSize = int.MaxValue;
         result.Elements.Add(httpsBindingElement);
         return(result);
     }
     throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration));
 }
Example #7
0
 private static System.ServiceModel.Channels.Binding GetBindingForEndpoint(EndpointConfiguration endpointConfiguration)
 {
     if ((endpointConfiguration == EndpointConfiguration.PxUniversalSoap))
     {
         //System.ServiceModel.BasicHttpBinding result = new System.ServiceModel.BasicHttpBinding();
         System.ServiceModel.BasicHttpBinding result = new System.ServiceModel.BasicHttpBinding(System.ServiceModel.BasicHttpSecurityMode.TransportCredentialOnly);
         result.Security.Transport.ClientCredentialType = System.ServiceModel.HttpClientCredentialType.Basic;
         result.MaxBufferSize          = int.MaxValue;
         result.ReaderQuotas           = System.Xml.XmlDictionaryReaderQuotas.Max;
         result.MaxReceivedMessageSize = int.MaxValue;
         result.AllowCookies           = true;
         result.Security.Mode          = System.ServiceModel.BasicHttpSecurityMode.Transport;
         return(result);
     }
     if ((endpointConfiguration == EndpointConfiguration.PxUniversalSoap12))
     {
         System.ServiceModel.Channels.CustomBinding result = new System.ServiceModel.Channels.CustomBinding();
         System.ServiceModel.Channels.TextMessageEncodingBindingElement textBindingElement = new System.ServiceModel.Channels.TextMessageEncodingBindingElement();
         textBindingElement.MessageVersion = System.ServiceModel.Channels.MessageVersion.CreateVersion(System.ServiceModel.EnvelopeVersion.Soap12, System.ServiceModel.Channels.AddressingVersion.None);
         result.Elements.Add(textBindingElement);
         System.ServiceModel.Channels.HttpsTransportBindingElement httpsBindingElement = new System.ServiceModel.Channels.HttpsTransportBindingElement();
         httpsBindingElement.AllowCookies           = true;
         httpsBindingElement.MaxBufferSize          = int.MaxValue;
         httpsBindingElement.MaxReceivedMessageSize = int.MaxValue;
         result.Elements.Add(httpsBindingElement);
         return(result);
     }
     throw new System.InvalidOperationException(string.Format("No se pudo encontrar un punto de conexión con el nombre \"{0}\".", endpointConfiguration));
 }
Example #8
0
        static System.ServiceModel.Channels.Binding GetRestBinding()
        {
            var result  = new System.ServiceModel.Channels.CustomBinding(new WebHttpBinding());
            var webMEBE = result.Elements.Find <System.ServiceModel.Channels.WebMessageEncodingBindingElement>();

            webMEBE.ContentTypeMapper = new RawWebContentTypeMapper();
            return(result);
        }
 public 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);
 }
Example #10
0
            protected static System.ServiceModel.Channels.Binding GetClientBinding(System.ServiceModel.Channels.CompressionFormat compressionFormat)
            {
                var binding = new System.ServiceModel.Channels.CustomBinding();

                binding.Elements.Add(new System.ServiceModel.Channels.BinaryMessageEncodingBindingElement {
                    CompressionFormat = compressionFormat
                });
                binding.Elements.Add(new System.ServiceModel.Channels.HttpTransportBindingElement {
                    MaxReceivedMessageSize = 200065536
                });
                return(binding);
            }
Example #11
0
            public static System.ServiceModel.Channels.Binding GetClientBinding(System.ServiceModel.TransferMode transferMode)
            {
                var binding = new System.ServiceModel.Channels.CustomBinding();

                binding.Elements.Add(new System.ServiceModel.Channels.TextMessageEncodingBindingElement {
                    ReaderQuotas = XmlDictionaryReaderQuotas.Max
                });
                binding.Elements.Add(new System.ServiceModel.Channels.HttpTransportBindingElement {
                    MaxReceivedMessageSize = int.MaxValue, TransferMode = transferMode
                });
                return(binding);
            }
Example #12
0
    partial void OnCreated()
    {
        if (Application.Current.IsRunningOutOfBrowser)
        {
            ClientHttpAuthenticationUtility.ShareCookieContainer(this);
        }
        System.ServiceModel.DomainServices.Client.WebDomainClient <Main.Services.IDSContract> dctx = this.DomainClient as System.ServiceModel.DomainServices.Client.WebDomainClient <Main.Services.IDSContract>;
        ChannelFactory factory = dctx.ChannelFactory;

        System.ServiceModel.Channels.CustomBinding binding = factory.Endpoint.Binding as System.ServiceModel.Channels.CustomBinding;
        binding.SendTimeout    = new TimeSpan(0, 30, 0);
        binding.ReceiveTimeout = new TimeSpan(0, 30, 0);
        binding.OpenTimeout    = new TimeSpan(0, 30, 0);
        binding.CloseTimeout   = new TimeSpan(0, 30, 0);
    }
Example #13
0
 private static System.ServiceModel.Channels.Binding GetBindingForEndpoint(EndpointConfiguration endpointConfiguration)
 {
     if ((endpointConfiguration == EndpointConfiguration.CustomBinding_IMotorRegrasService))
     {
         System.ServiceModel.Channels.CustomBinding result = new System.ServiceModel.Channels.CustomBinding();
         result.Elements.Add(new System.ServiceModel.Channels.BinaryMessageEncodingBindingElement());
         System.ServiceModel.Channels.HttpTransportBindingElement httpBindingElement = new System.ServiceModel.Channels.HttpTransportBindingElement();
         httpBindingElement.AllowCookies           = true;
         httpBindingElement.MaxBufferSize          = int.MaxValue;
         httpBindingElement.MaxReceivedMessageSize = int.MaxValue;
         result.Elements.Add(httpBindingElement);
         return(result);
     }
     throw new System.InvalidOperationException(string.Format("Não foi possível encontrar o ponto de extremidade com o nome \'{0}\'.", endpointConfiguration));
 }
Example #14
0
 private static System.ServiceModel.Channels.Binding GetBindingForEndpoint(EndpointConfiguration endpointConfiguration)
 {
     if ((endpointConfiguration == EndpointConfiguration.Pagos))
     {
         System.ServiceModel.Channels.CustomBinding result = new System.ServiceModel.Channels.CustomBinding();
         System.ServiceModel.Channels.TextMessageEncodingBindingElement textBindingElement = new System.ServiceModel.Channels.TextMessageEncodingBindingElement();
         textBindingElement.MessageVersion = System.ServiceModel.Channels.MessageVersion.CreateVersion(System.ServiceModel.EnvelopeVersion.Soap12, System.ServiceModel.Channels.AddressingVersion.None);
         result.Elements.Add(textBindingElement);
         System.ServiceModel.Channels.HttpTransportBindingElement httpBindingElement = new System.ServiceModel.Channels.HttpTransportBindingElement();
         httpBindingElement.AllowCookies           = true;
         httpBindingElement.MaxBufferSize          = int.MaxValue;
         httpBindingElement.MaxReceivedMessageSize = int.MaxValue;
         result.Elements.Add(httpBindingElement);
         return(result);
     }
     throw new System.InvalidOperationException(string.Format("No se pudo encontrar un punto de conexión con el nombre \"{0}\".", endpointConfiguration));
 }
Example #15
0
 private static System.ServiceModel.Channels.Binding GetBindingForEndpoint(EndpointConfiguration endpointConfiguration)
 {
     if ((endpointConfiguration == EndpointConfiguration.LDC_API_processPaymentOrder_v1_soap_ws_Port))
     {
         System.ServiceModel.Channels.CustomBinding result = new System.ServiceModel.Channels.CustomBinding();
         System.ServiceModel.Channels.TextMessageEncodingBindingElement textBindingElement = new System.ServiceModel.Channels.TextMessageEncodingBindingElement();
         textBindingElement.MessageVersion = System.ServiceModel.Channels.MessageVersion.CreateVersion(System.ServiceModel.EnvelopeVersion.Soap12, System.ServiceModel.Channels.AddressingVersion.None);
         result.Elements.Add(textBindingElement);
         System.ServiceModel.Channels.HttpsTransportBindingElement httpsBindingElement = new System.ServiceModel.Channels.HttpsTransportBindingElement();
         httpsBindingElement.AllowCookies           = true;
         httpsBindingElement.MaxBufferSize          = int.MaxValue;
         httpsBindingElement.MaxReceivedMessageSize = int.MaxValue;
         result.Elements.Add(httpsBindingElement);
         return(result);
     }
     throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration));
 }
Example #16
0
 private static System.ServiceModel.Channels.Binding GetBindingForEndpoint(EndpointConfiguration endpointConfiguration)
 {
     if ((endpointConfiguration == EndpointConfiguration.WSHttpBinding_IInsuranceInquiry))
     {
         System.ServiceModel.Channels.CustomBinding result = new System.ServiceModel.Channels.CustomBinding();
         System.ServiceModel.Channels.TransportSecurityBindingElement userNameOverTransportSecurityBindingElement = System.ServiceModel.Channels.SecurityBindingElement.CreateUserNameOverTransportBindingElement();
         userNameOverTransportSecurityBindingElement.MessageSecurityVersion = System.ServiceModel.MessageSecurityVersion.WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10;
         result.Elements.Add(userNameOverTransportSecurityBindingElement);
         System.ServiceModel.Channels.TextMessageEncodingBindingElement textBindingElement = new System.ServiceModel.Channels.TextMessageEncodingBindingElement();
         result.Elements.Add(textBindingElement);
         System.ServiceModel.Channels.HttpsTransportBindingElement httpsBindingElement = new System.ServiceModel.Channels.HttpsTransportBindingElement();
         httpsBindingElement.AllowCookies           = true;
         httpsBindingElement.MaxBufferSize          = int.MaxValue;
         httpsBindingElement.MaxReceivedMessageSize = int.MaxValue;
         result.Elements.Add(httpsBindingElement);
         return(result);
     }
     throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration));
 }
Example #17
0
        /// <summary>
        /// Cria um binding para comunicação.
        /// </summary>
        /// <param name="securityMode">Modo de segurança.</param>
        /// <param name="requireClientCertificates"></param>
        /// <returns></returns>
        public static System.ServiceModel.Channels.Binding CreateBinding(SecurityMode securityMode, bool requireClientCertificates)
        {
            WSHttpBinding binding = new WSHttpBinding(securityMode);

            binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
            binding.ReaderQuotas           = System.Xml.XmlDictionaryReaderQuotas.Max;
            binding.MaxReceivedMessageSize = System.Xml.XmlDictionaryReaderQuotas.Max.MaxStringContentLength;
            System.ServiceModel.Channels.Binding binding2 = binding;
            if ((securityMode == SecurityMode.Transport) && requireClientCertificates)
            {
                binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;
                System.ServiceModel.Channels.BindingElementCollection bindingElementsInTopDownChannelStackOrder = binding.CreateBindingElements();
                var item = new System.ServiceModel.Channels.TransportSecurityBindingElement();
                System.ServiceModel.Security.Tokens.X509SecurityTokenParameters parameters = new System.ServiceModel.Security.Tokens.X509SecurityTokenParameters();
                parameters.InclusionMode = System.ServiceModel.Security.Tokens.SecurityTokenInclusionMode.AlwaysToRecipient;
                item.EndpointSupportingTokenParameters.Endorsing.Add(parameters);
                bindingElementsInTopDownChannelStackOrder.Insert(bindingElementsInTopDownChannelStackOrder.Count - 1, item);
                binding2 = new System.ServiceModel.Channels.CustomBinding(bindingElementsInTopDownChannelStackOrder);
            }
            return(binding2);
        }
Example #18
0
 private static System.ServiceModel.Channels.Binding GetBindingForEndpoint(EndpointConfiguration endpointConfiguration)
 {
     if ((endpointConfiguration == EndpointConfiguration.NetHttpOrdered_WSReliableMessaging11_IWcfReliableService))
     {
         System.ServiceModel.Channels.CustomBinding result = new System.ServiceModel.Channels.CustomBinding();
         System.ServiceModel.Channels.ReliableSessionBindingElement reliableBindingElement = new System.ServiceModel.Channels.ReliableSessionBindingElement();
         reliableBindingElement.ReliableMessagingVersion = System.ServiceModel.ReliableMessagingVersion.WSReliableMessaging11;
         result.Elements.Add(reliableBindingElement);
         result.Elements.Add(new System.ServiceModel.Channels.BinaryMessageEncodingBindingElement());
         System.ServiceModel.Channels.HttpTransportBindingElement httpBindingElement = new System.ServiceModel.Channels.HttpTransportBindingElement();
         httpBindingElement.AllowCookies           = true;
         httpBindingElement.MaxBufferSize          = int.MaxValue;
         httpBindingElement.MaxReceivedMessageSize = int.MaxValue;
         result.Elements.Add(httpBindingElement);
         return(result);
     }
     if ((endpointConfiguration == EndpointConfiguration.NetHttpUnordered_WSReliableMessaging11_IWcfReliableService))
     {
         System.ServiceModel.Channels.CustomBinding result = new System.ServiceModel.Channels.CustomBinding();
         System.ServiceModel.Channels.ReliableSessionBindingElement reliableBindingElement = new System.ServiceModel.Channels.ReliableSessionBindingElement();
         reliableBindingElement.Ordered = false;
         reliableBindingElement.ReliableMessagingVersion = System.ServiceModel.ReliableMessagingVersion.WSReliableMessaging11;
         result.Elements.Add(reliableBindingElement);
         result.Elements.Add(new System.ServiceModel.Channels.BinaryMessageEncodingBindingElement());
         System.ServiceModel.Channels.HttpTransportBindingElement httpBindingElement = new System.ServiceModel.Channels.HttpTransportBindingElement();
         httpBindingElement.AllowCookies           = true;
         httpBindingElement.MaxBufferSize          = int.MaxValue;
         httpBindingElement.MaxReceivedMessageSize = int.MaxValue;
         result.Elements.Add(httpBindingElement);
         return(result);
     }
     if ((endpointConfiguration == EndpointConfiguration.NetHttpOrdered_WSReliableMessagingFebruary2005_IWcfReliableService))
     {
         System.ServiceModel.Channels.CustomBinding result = new System.ServiceModel.Channels.CustomBinding();
         System.ServiceModel.Channels.ReliableSessionBindingElement reliableBindingElement = new System.ServiceModel.Channels.ReliableSessionBindingElement();
         result.Elements.Add(reliableBindingElement);
         result.Elements.Add(new System.ServiceModel.Channels.BinaryMessageEncodingBindingElement());
         System.ServiceModel.Channels.HttpTransportBindingElement httpBindingElement = new System.ServiceModel.Channels.HttpTransportBindingElement();
         httpBindingElement.AllowCookies           = true;
         httpBindingElement.MaxBufferSize          = int.MaxValue;
         httpBindingElement.MaxReceivedMessageSize = int.MaxValue;
         result.Elements.Add(httpBindingElement);
         return(result);
     }
     if ((endpointConfiguration == EndpointConfiguration.NetHttpUnordered_WSReliableMessagingFebruary2005_IWcfReliableService))
     {
         System.ServiceModel.Channels.CustomBinding result = new System.ServiceModel.Channels.CustomBinding();
         System.ServiceModel.Channels.ReliableSessionBindingElement reliableBindingElement = new System.ServiceModel.Channels.ReliableSessionBindingElement();
         result.Elements.Add(reliableBindingElement);
         result.Elements.Add(new System.ServiceModel.Channels.BinaryMessageEncodingBindingElement());
         System.ServiceModel.Channels.HttpTransportBindingElement httpBindingElement = new System.ServiceModel.Channels.HttpTransportBindingElement();
         httpBindingElement.AllowCookies           = true;
         httpBindingElement.MaxBufferSize          = int.MaxValue;
         httpBindingElement.MaxReceivedMessageSize = int.MaxValue;
         result.Elements.Add(httpBindingElement);
         return(result);
     }
     if ((endpointConfiguration == EndpointConfiguration.NetTcpOrdered_WSReliableMessaging11_IWcfReliableService))
     {
         System.ServiceModel.Channels.CustomBinding result = new System.ServiceModel.Channels.CustomBinding();
         System.ServiceModel.Channels.ReliableSessionBindingElement reliableBindingElement = new System.ServiceModel.Channels.ReliableSessionBindingElement();
         reliableBindingElement.ReliableMessagingVersion = System.ServiceModel.ReliableMessagingVersion.WSReliableMessaging11;
         result.Elements.Add(reliableBindingElement);
         result.Elements.Add(new System.ServiceModel.Channels.BinaryMessageEncodingBindingElement());
         System.ServiceModel.Channels.TcpTransportBindingElement tcpBindingElement = new System.ServiceModel.Channels.TcpTransportBindingElement();
         tcpBindingElement.MaxBufferSize          = int.MaxValue;
         tcpBindingElement.MaxReceivedMessageSize = int.MaxValue;
         result.Elements.Add(tcpBindingElement);
         return(result);
     }
     if ((endpointConfiguration == EndpointConfiguration.NetTcpUnordered_WSReliableMessaging11_IWcfReliableService))
     {
         System.ServiceModel.Channels.CustomBinding result = new System.ServiceModel.Channels.CustomBinding();
         System.ServiceModel.Channels.ReliableSessionBindingElement reliableBindingElement = new System.ServiceModel.Channels.ReliableSessionBindingElement();
         reliableBindingElement.Ordered = false;
         reliableBindingElement.ReliableMessagingVersion = System.ServiceModel.ReliableMessagingVersion.WSReliableMessaging11;
         result.Elements.Add(reliableBindingElement);
         result.Elements.Add(new System.ServiceModel.Channels.BinaryMessageEncodingBindingElement());
         System.ServiceModel.Channels.TcpTransportBindingElement tcpBindingElement = new System.ServiceModel.Channels.TcpTransportBindingElement();
         tcpBindingElement.MaxBufferSize          = int.MaxValue;
         tcpBindingElement.MaxReceivedMessageSize = int.MaxValue;
         result.Elements.Add(tcpBindingElement);
         return(result);
     }
     if ((endpointConfiguration == EndpointConfiguration.NetTcpOrdered_WSReliableMessagingFebruary2005_IWcfReliableService))
     {
         System.ServiceModel.NetTcpBinding result = new System.ServiceModel.NetTcpBinding();
         result.MaxBufferSize           = int.MaxValue;
         result.ReaderQuotas            = System.Xml.XmlDictionaryReaderQuotas.Max;
         result.MaxReceivedMessageSize  = int.MaxValue;
         result.Security.Mode           = System.ServiceModel.SecurityMode.None;
         result.ReliableSession.Enabled = true;
         return(result);
     }
     if ((endpointConfiguration == EndpointConfiguration.NetTcpUnordered_WSReliableMessagingFebruary2005_IWcfReliableService))
     {
         System.ServiceModel.NetTcpBinding result = new System.ServiceModel.NetTcpBinding();
         result.MaxBufferSize           = int.MaxValue;
         result.ReaderQuotas            = System.Xml.XmlDictionaryReaderQuotas.Max;
         result.MaxReceivedMessageSize  = int.MaxValue;
         result.Security.Mode           = System.ServiceModel.SecurityMode.None;
         result.ReliableSession.Enabled = true;
         return(result);
     }
     if ((endpointConfiguration == EndpointConfiguration.WSHttpOrdered_WSReliableMessaging11_IWcfReliableService))
     {
         System.ServiceModel.Channels.CustomBinding result = new System.ServiceModel.Channels.CustomBinding();
         System.ServiceModel.Channels.ReliableSessionBindingElement reliableBindingElement = new System.ServiceModel.Channels.ReliableSessionBindingElement();
         reliableBindingElement.ReliableMessagingVersion = System.ServiceModel.ReliableMessagingVersion.WSReliableMessaging11;
         result.Elements.Add(reliableBindingElement);
         System.ServiceModel.Channels.TextMessageEncodingBindingElement textBindingElement = new System.ServiceModel.Channels.TextMessageEncodingBindingElement();
         result.Elements.Add(textBindingElement);
         System.ServiceModel.Channels.HttpTransportBindingElement httpBindingElement = new System.ServiceModel.Channels.HttpTransportBindingElement();
         httpBindingElement.AllowCookies           = true;
         httpBindingElement.MaxBufferSize          = int.MaxValue;
         httpBindingElement.MaxReceivedMessageSize = int.MaxValue;
         result.Elements.Add(httpBindingElement);
         return(result);
     }
     if ((endpointConfiguration == EndpointConfiguration.WSHttpUnordered_WSReliableMessaging11_IWcfReliableService))
     {
         System.ServiceModel.Channels.CustomBinding result = new System.ServiceModel.Channels.CustomBinding();
         System.ServiceModel.Channels.ReliableSessionBindingElement reliableBindingElement = new System.ServiceModel.Channels.ReliableSessionBindingElement();
         reliableBindingElement.Ordered = false;
         reliableBindingElement.ReliableMessagingVersion = System.ServiceModel.ReliableMessagingVersion.WSReliableMessaging11;
         result.Elements.Add(reliableBindingElement);
         System.ServiceModel.Channels.TextMessageEncodingBindingElement textBindingElement = new System.ServiceModel.Channels.TextMessageEncodingBindingElement();
         result.Elements.Add(textBindingElement);
         System.ServiceModel.Channels.HttpTransportBindingElement httpBindingElement = new System.ServiceModel.Channels.HttpTransportBindingElement();
         httpBindingElement.AllowCookies           = true;
         httpBindingElement.MaxBufferSize          = int.MaxValue;
         httpBindingElement.MaxReceivedMessageSize = int.MaxValue;
         result.Elements.Add(httpBindingElement);
         return(result);
     }
     if ((endpointConfiguration == EndpointConfiguration.WSHttpOrdered_WSReliableMessagingFebruary2005_IWcfReliableService))
     {
         System.ServiceModel.Channels.CustomBinding result = new System.ServiceModel.Channels.CustomBinding();
         System.ServiceModel.Channels.ReliableSessionBindingElement reliableBindingElement = new System.ServiceModel.Channels.ReliableSessionBindingElement();
         result.Elements.Add(reliableBindingElement);
         System.ServiceModel.Channels.TextMessageEncodingBindingElement textBindingElement = new System.ServiceModel.Channels.TextMessageEncodingBindingElement();
         result.Elements.Add(textBindingElement);
         System.ServiceModel.Channels.HttpTransportBindingElement httpBindingElement = new System.ServiceModel.Channels.HttpTransportBindingElement();
         httpBindingElement.AllowCookies           = true;
         httpBindingElement.MaxBufferSize          = int.MaxValue;
         httpBindingElement.MaxReceivedMessageSize = int.MaxValue;
         result.Elements.Add(httpBindingElement);
         return(result);
     }
     if ((endpointConfiguration == EndpointConfiguration.WSHttpUnordered_WSReliableMessagingFebruary2005_IWcfReliableService))
     {
         System.ServiceModel.Channels.CustomBinding result = new System.ServiceModel.Channels.CustomBinding();
         System.ServiceModel.Channels.ReliableSessionBindingElement reliableBindingElement = new System.ServiceModel.Channels.ReliableSessionBindingElement();
         result.Elements.Add(reliableBindingElement);
         System.ServiceModel.Channels.TextMessageEncodingBindingElement textBindingElement = new System.ServiceModel.Channels.TextMessageEncodingBindingElement();
         result.Elements.Add(textBindingElement);
         System.ServiceModel.Channels.HttpTransportBindingElement httpBindingElement = new System.ServiceModel.Channels.HttpTransportBindingElement();
         httpBindingElement.AllowCookies           = true;
         httpBindingElement.MaxBufferSize          = int.MaxValue;
         httpBindingElement.MaxReceivedMessageSize = int.MaxValue;
         result.Elements.Add(httpBindingElement);
         return(result);
     }
     throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration));
 }
Example #19
0
        private void StartService(string serverIP, string serverPort, string localPort)
        {
            if (!(NetworkingToolkit.ValidateIPAddress(serverIP) && NetworkingToolkit.ValidatePort(serverPort) && NetworkingToolkit.ValidatePort(localPort)))
            {
                throw new ArgumentException()
                      {
                          Source = "ListeningForm.StartService(string serverIP, string serverPort, string localPort)"
                      }
            }
            ;

            ////endereço do player
            Uri baseAddress = new Uri(String.Format("net.tcp://{0}:{1}/PlayerService/{2}", NetworkingToolkit.LocalIPAddress, localPort, Guid.NewGuid()));
            ////endpoint para onde as mensagens de announcement serão enviadas
            Uri announcementEndpointAddress = new Uri(String.Format("net.tcp://{0}:{1}/Announcement", serverIP, serverPort));

            //criar o host do serviço
            serviceHost = new ServiceHost(typeof(PlayerService), baseAddress);
            try
            {
                ////Adicionar um endpoint para o serviço
                //NetTcpBinding tcpBindingService = new NetTcpBinding();
                //tcpBindingService.Security.Mode = SecurityMode.None; //Alterar a autenticação para um modelo melhor
                ////tcpBindingService.Security.Transport.ProtectionLevel = System.Net.Security.ProtectionLevel.None;

                //tcpBindingService.MaxReceivedMessageSize = 10000000;
                //tcpBindingService.MaxBufferSize = 10000000;
                //tcpBindingService.MaxBufferPoolSize = 10000000;

                //ServiceEndpoint netTcpEndpoint = serviceHost.AddServiceEndpoint(typeof(IPlayer), tcpBindingService, string.Empty);

                //Criar um endpoint para o announcement server, que aponta para o DiscoveryProxy
                NetTcpBinding tcpBindingAnnouncement = new NetTcpBinding();
                tcpBindingAnnouncement.Security.Mode = SecurityMode.None; //Alterar a autenticação para um modelo melhor

                ////http://nerdwords.blogspot.pt/2008/01/wcf-error-socket-connection-was-aborted.html

                AnnouncementEndpoint announcementEndpoint = new AnnouncementEndpoint(tcpBindingAnnouncement, new EndpointAddress(announcementEndpointAddress));

                //Criar um DiscoveryBehaviour e adicionar o endpoint
                ServiceDiscoveryBehavior serviceDiscoveryBehavior = new ServiceDiscoveryBehavior();
                serviceDiscoveryBehavior.AnnouncementEndpoints.Add(announcementEndpoint);

#if EXPOSE_METADATA
                //Adicionar um endpoint MEX (Metadata EXchange) por TCP
                System.ServiceModel.Channels.BindingElement             bindingElement   = new System.ServiceModel.Channels.TcpTransportBindingElement();
                System.ServiceModel.Channels.CustomBinding              binding          = new System.ServiceModel.Channels.CustomBinding(bindingElement);
                System.ServiceModel.Description.ServiceMetadataBehavior metadataBehavior = serviceHost.Description.Behaviors.Find <System.ServiceModel.Description.ServiceMetadataBehavior>();

                if (metadataBehavior == null)
                {
                    metadataBehavior = new System.ServiceModel.Description.ServiceMetadataBehavior();
                    serviceHost.Description.Behaviors.Add(metadataBehavior);
                }

                serviceHost.AddServiceEndpoint(typeof(System.ServiceModel.Description.IMetadataExchange), binding, "MEX");
#endif
                //Adicionar o serviceDiscoveryBehavior ao host para poder ser descoberto
                serviceHost.Description.Behaviors.Add(serviceDiscoveryBehavior);

                serviceHost.Open();


                Clipboard.SetText(baseAddress.ToString());
            }
            catch (CommunicationException e)
            {
                Log(e);
            }
            catch (TimeoutException e)
            {
                Log(e);
            }
            catch (Exception ex)
            {
                Log(ex);
            }
        }

        void serviceHost_UnknownMessageReceived(object sender, UnknownMessageReceivedEventArgs e)
        {
            Log("Mensagem desconhecida recebida");
            Log(e.Message.ToString());
        }

        void serviceHost_RefreshState(object sender, EventArgs e)
        {
            this.RefreshState();
        }
Example #20
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            try
            {
                if (loaded)
                {
                    return;
                }
                #region 启动门禁监控
                NavigationWorkForm navigationForm = null;
                foreach (DockContent frm in this.dockPanel.Contents)
                {
                    if (frm is NavigationWorkForm)
                    {
                        frm.Activate();     //激活子窗体
                        return;
                    }
                }
                navigationForm          = ServiceLoader.LoadService <IMenJinControler>() as NavigationWorkForm;
                navigationForm.ShowHint = DockState.Document;
                navigationForm.Show(dockPanel);
                #endregion
                #region IReStartService
                var irestartservice = ServiceLoader.LoadService <IReStartService>();
                irestartservice.Start();
                #endregion ;
                #region hostZKService
                if (hostZKService == null)
                {
                    hostZKService = new ServiceHost(typeof(CardSystem_Service.ZKManage.ZKService));
                    System.ServiceModel.Channels.Binding binding = new NetTcpBinding(SecurityMode.None);
                    string strUrl = string.Format("net.tcp://{0}:{1}/ZK/ZKService", IPAddress.Any, SystemConfig.WcfServicePort);
                    //string strUrl = string.Format("net.tcp://{0}:{1}/ZK/ZKService", "192.168.0.170", SystemConfig.WcfServicePort);
                    hostZKService.AddServiceEndpoint(typeof(CardSystem_Service.ZKManage.IZKService), binding, strUrl);
                    if (hostZKService.Description.Behaviors.Find <System.ServiceModel.Description.ServiceMetadataBehavior>() == null)
                    {
                        System.ServiceModel.Channels.BindingElement elemnt = new System.ServiceModel.Channels.TcpTransportBindingElement();
                        System.ServiceModel.Channels.CustomBinding  bind   = new System.ServiceModel.Channels.CustomBinding(elemnt);
                        hostZKService.Description.Behaviors.Add(new System.ServiceModel.Description.ServiceMetadataBehavior());
                        hostZKService.AddServiceEndpoint(typeof(System.ServiceModel.Description.IMetadataExchange), bind, strUrl + "/Mex");
                    }
                    hostZKService.Faulted += Service_Faulted;
                }
                if (hostZKService.State != CommunicationState.Opened)
                {
                    hostZKService.Open();
                }
                #endregion ;
                #region menjincontrolerservice
                if (menjincontrolerservice == null)
                {
                    menjincontrolerservice = new ServiceHost(typeof(MenJinControlerService));
                    System.ServiceModel.Channels.Binding binding = new NetTcpBinding(SecurityMode.None)
                    {
                        MaxReceivedMessageSize = 2147483647
                    };
                    //string strUrl = string.Format("net.tcp://{0}:{1}/MenJinControlerService", "192.168.0.170", SystemConfig.WcfServicePort);
                    string strUrl = string.Format("net.tcp://{0}:{1}/MenJinControlerService", IPAddress.Any, SystemConfig.WcfServicePort);
                    menjincontrolerservice.AddServiceEndpoint(typeof(IMenJinControlerService), binding, strUrl);

                    if (menjincontrolerservice.Description.Behaviors.Find <System.ServiceModel.Description.ServiceMetadataBehavior>() == null)
                    {
                        System.ServiceModel.Channels.BindingElement elemnt = new System.ServiceModel.Channels.TcpTransportBindingElement();
                        System.ServiceModel.Channels.CustomBinding  bind   = new System.ServiceModel.Channels.CustomBinding(elemnt);
                        menjincontrolerservice.Description.Behaviors.Add(new System.ServiceModel.Description.ServiceMetadataBehavior());
                        menjincontrolerservice.AddServiceEndpoint(typeof(System.ServiceModel.Description.IMetadataExchange), bind, strUrl + "/Mex");
                    }
                    menjincontrolerservice.Faulted += Service_Faulted;
                }
                if (menjincontrolerservice.State != CommunicationState.Opened)
                {
                    menjincontrolerservice.Open();
                }
                #endregion
                #region UdpMsgService
                var udpmsgservice = ServiceLoader.LoadService <IUdpMsgService>();
                udpmsgservice.Start();
                #endregion ;
                #region UdpMsgTimerService
                var iudpmsgtimerservice = ServiceLoader.LoadService <IUdpMsgTimerService>();
                iudpmsgtimerservice.Start();
                #endregion ;
                loaded = true;
            }
            catch (Exception ex)
            {
                loaderror = true;
                Logger.Writer.Write(ex);
                Application.Restart();
            }
        }
Example #21
0
 static System.ServiceModel.Channels.Binding GetRestBinding()
 {
     var result = new System.ServiceModel.Channels.CustomBinding(new WebHttpBinding());
     var webMEBE = result.Elements.Find<System.ServiceModel.Channels.WebMessageEncodingBindingElement>();
     webMEBE.ContentTypeMapper = new RawWebContentTypeMapper();
     return result;
 }
Example #22
0
 private static System.ServiceModel.Channels.Binding GetBindingForEndpoint(EndpointConfiguration endpointConfiguration)
 {
     if ((endpointConfiguration == EndpointConfiguration.defaultEndpoint))
     {
         System.ServiceModel.Channels.CustomBinding result = new System.ServiceModel.Channels.CustomBinding();
         System.ServiceModel.Channels.TextMessageEncodingBindingElement textBindingElement = new System.ServiceModel.Channels.TextMessageEncodingBindingElement();
         result.Elements.Add(textBindingElement);
         System.ServiceModel.Channels.HttpTransportBindingElement httpBindingElement = new System.ServiceModel.Channels.HttpTransportBindingElement();
         httpBindingElement.AllowCookies           = true;
         httpBindingElement.MaxBufferSize          = int.MaxValue;
         httpBindingElement.MaxReceivedMessageSize = int.MaxValue;
         result.Elements.Add(httpBindingElement);
         return(result);
     }
     if ((endpointConfiguration == EndpointConfiguration.defaultBasic))
     {
         System.ServiceModel.BasicHttpBinding result = new System.ServiceModel.BasicHttpBinding();
         result.MaxBufferSize          = int.MaxValue;
         result.ReaderQuotas           = System.Xml.XmlDictionaryReaderQuotas.Max;
         result.MaxReceivedMessageSize = int.MaxValue;
         result.AllowCookies           = true;
         return(result);
     }
     if ((endpointConfiguration == EndpointConfiguration.basicHttpEndpoint))
     {
         System.ServiceModel.BasicHttpBinding result = new System.ServiceModel.BasicHttpBinding();
         result.MaxBufferSize          = int.MaxValue;
         result.ReaderQuotas           = System.Xml.XmlDictionaryReaderQuotas.Max;
         result.MaxReceivedMessageSize = int.MaxValue;
         result.AllowCookies           = true;
         return(result);
     }
     if ((endpointConfiguration == EndpointConfiguration.basicHttpsEndpoint))
     {
         System.ServiceModel.BasicHttpBinding result = new System.ServiceModel.BasicHttpBinding();
         result.MaxBufferSize          = int.MaxValue;
         result.ReaderQuotas           = System.Xml.XmlDictionaryReaderQuotas.Max;
         result.MaxReceivedMessageSize = int.MaxValue;
         result.AllowCookies           = true;
         result.Security.Mode          = System.ServiceModel.BasicHttpSecurityMode.Transport;
         return(result);
     }
     if ((endpointConfiguration == EndpointConfiguration.httpsoap11Endpoint))
     {
         System.ServiceModel.BasicHttpBinding result = new System.ServiceModel.BasicHttpBinding();
         result.MaxBufferSize          = int.MaxValue;
         result.ReaderQuotas           = System.Xml.XmlDictionaryReaderQuotas.Max;
         result.MaxReceivedMessageSize = int.MaxValue;
         result.AllowCookies           = true;
         return(result);
     }
     if ((endpointConfiguration == EndpointConfiguration.httpsoap12Endpoint))
     {
         System.ServiceModel.Channels.CustomBinding result = new System.ServiceModel.Channels.CustomBinding();
         System.ServiceModel.Channels.TextMessageEncodingBindingElement textBindingElement = new System.ServiceModel.Channels.TextMessageEncodingBindingElement();
         result.Elements.Add(textBindingElement);
         System.ServiceModel.Channels.HttpTransportBindingElement httpBindingElement = new System.ServiceModel.Channels.HttpTransportBindingElement();
         httpBindingElement.AllowCookies           = true;
         httpBindingElement.MaxBufferSize          = int.MaxValue;
         httpBindingElement.MaxReceivedMessageSize = int.MaxValue;
         result.Elements.Add(httpBindingElement);
         return(result);
     }
     if ((endpointConfiguration == EndpointConfiguration.httpbinaryEndpoint))
     {
         System.ServiceModel.Channels.CustomBinding result = new System.ServiceModel.Channels.CustomBinding();
         result.Elements.Add(new System.ServiceModel.Channels.BinaryMessageEncodingBindingElement());
         System.ServiceModel.Channels.HttpTransportBindingElement httpBindingElement = new System.ServiceModel.Channels.HttpTransportBindingElement();
         httpBindingElement.AllowCookies           = true;
         httpBindingElement.MaxBufferSize          = int.MaxValue;
         httpBindingElement.MaxReceivedMessageSize = int.MaxValue;
         result.Elements.Add(httpBindingElement);
         return(result);
     }
     if ((endpointConfiguration == EndpointConfiguration.httpssoap11Endpoint))
     {
         System.ServiceModel.BasicHttpBinding result = new System.ServiceModel.BasicHttpBinding();
         result.MaxBufferSize          = int.MaxValue;
         result.ReaderQuotas           = System.Xml.XmlDictionaryReaderQuotas.Max;
         result.MaxReceivedMessageSize = int.MaxValue;
         result.AllowCookies           = true;
         result.Security.Mode          = System.ServiceModel.BasicHttpSecurityMode.Transport;
         return(result);
     }
     if ((endpointConfiguration == EndpointConfiguration.httpssoap12Endpoint))
     {
         System.ServiceModel.Channels.CustomBinding result = new System.ServiceModel.Channels.CustomBinding();
         System.ServiceModel.Channels.TextMessageEncodingBindingElement textBindingElement = new System.ServiceModel.Channels.TextMessageEncodingBindingElement();
         result.Elements.Add(textBindingElement);
         System.ServiceModel.Channels.HttpsTransportBindingElement httpsBindingElement = new System.ServiceModel.Channels.HttpsTransportBindingElement();
         httpsBindingElement.AllowCookies           = true;
         httpsBindingElement.MaxBufferSize          = int.MaxValue;
         httpsBindingElement.MaxReceivedMessageSize = int.MaxValue;
         result.Elements.Add(httpsBindingElement);
         return(result);
     }
     if ((endpointConfiguration == EndpointConfiguration.nettcpdefaultBinding))
     {
         System.ServiceModel.NetTcpBinding result = new System.ServiceModel.NetTcpBinding();
         result.MaxBufferSize          = int.MaxValue;
         result.ReaderQuotas           = System.Xml.XmlDictionaryReaderQuotas.Max;
         result.MaxReceivedMessageSize = int.MaxValue;
         return(result);
     }
     if ((endpointConfiguration == EndpointConfiguration.nettcpdefaultBinding1))
     {
         System.ServiceModel.NetTcpBinding result = new System.ServiceModel.NetTcpBinding();
         result.MaxBufferSize          = int.MaxValue;
         result.ReaderQuotas           = System.Xml.XmlDictionaryReaderQuotas.Max;
         result.MaxReceivedMessageSize = int.MaxValue;
         result.Security.Mode          = System.ServiceModel.SecurityMode.None;
         return(result);
     }
     throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration));
 }
Example #23
0
        protected override System.ServiceModel.Channels.Binding AdjustBinding(System.ServiceModel.Channels.Binding binding)
        {
            System.ServiceModel.Channels.Binding result = binding;

            binding.SendTimeout = TimeSpan.MaxValue;
            binding.ReceiveTimeout = TimeSpan.MaxValue;

            // [XC-9600] - large byte buffers throw exceptions.
            #region Set timeouts and other binding class specific values

            // This is horrible, why couldn't these bindings all implement the same interface.
            //if (binding is System.ServiceModel.NetNamedPipeBinding)
            //{
            //    var polyBinding = (binding as System.ServiceModel.NetNamedPipeBinding);
            //}

            //if (binding is System.ServiceModel.NetPeerTcpBinding)
            //{
            //    var polyBinding = (binding as System.ServiceModel.NetPeerTcpBinding);
            //}

            if (binding is System.ServiceModel.NetTcpBinding)
            {
                var polyBinding = (binding as System.ServiceModel.NetTcpBinding);
                polyBinding.ReaderQuotas.MaxArrayLength = Int32.MaxValue;
                polyBinding.ReliableSession.Ordered = true;
                polyBinding.ReliableSession.InactivityTimeout = TimeSpan.MaxValue;
            }

            if (binding is System.ServiceModel.WSHttpBindingBase)
            {
                var polyBinding = (binding as System.ServiceModel.WSHttpBindingBase);
                polyBinding.ReliableSession.Ordered = true;
                polyBinding.ReliableSession.InactivityTimeout = TimeSpan.MaxValue;
            }

            if (binding is System.ServiceModel.WSDualHttpBinding)
            {
                var polyBinding = (binding as System.ServiceModel.WSDualHttpBinding);
                polyBinding.ReliableSession.Ordered = true;
                polyBinding.ReliableSession.InactivityTimeout = TimeSpan.MaxValue;
            }

            #endregion // Set timeouts and other binding class specific values

            // WCF - making things really complicated, one step at a time.

            // Ok, so unfortunately cannot access the transport directly in the binding.
            // So we have to use a "CustomBinding" wrapping it, which allows access to the TransportBindingElement element
            // (bit bizarre since BindingElementCollection is created dynamically on demand but CustomBinding bakes it at construction time)
            // which in turn allows access to the MaxReceivedMessageSize property, as specified in the exception message for reading too many bytes.
            System.ServiceModel.Channels.CustomBinding cb = new System.ServiceModel.Channels.CustomBinding(binding);
            System.ServiceModel.Channels.TransportBindingElement transport = cb.Elements.Find<System.ServiceModel.Channels.TransportBindingElement>();

            if (transport != null)
            {
                transport.MaxReceivedMessageSize = int.MaxValue;

            }

            // XML serialization may also get its knickers in a twist for which MaxReceivedMessageSize, it does nothing.
            // Changing MaxArrayLength in the encoding quotas on the other hand...
            System.ServiceModel.Channels.BinaryMessageEncodingBindingElement encoding = cb.Elements.Find<System.ServiceModel.Channels.BinaryMessageEncodingBindingElement>();

            if (encoding != null)
            {
                encoding.ReaderQuotas.MaxArrayLength = int.MaxValue;
            }

            result = cb;

            return result;
        }