예제 #1
0
        //<snippet0>
        private void Run()
        {
            //<snippet1>
            WSHttpBinding b = new WSHttpBinding();

            b.Name = "HttpOrderedReliableSessionBinding";

            // Get a reference to the OptionalreliableSession object of the
            // binding and set its properties to new values.
            OptionalReliableSession myReliableSession = b.ReliableSession;

            myReliableSession.Enabled           = true;  // The default is false.
            myReliableSession.Ordered           = false; // The default is true.
            myReliableSession.InactivityTimeout =
                new TimeSpan(0, 15, 0);                  // The default is 10 minutes.
            //</snippet1>
            // Create a URI for the service's base address.
            Uri baseAddress = new Uri("http://localhost:8008/Calculator");

            // Create a service host.
            ServiceHost sh = new ServiceHost(typeof(Calculator), baseAddress);

            // Optional: Print out the binding information.
            PrintBindingInfo(b);
            // Create a URI for an endpoint, then add a service endpoint using the
            // binding with the latered OptionalReliableSession settings.
            sh.AddServiceEndpoint(typeof(ICalculator), b, "ReliableCalculator");
            sh.Open();

            Console.WriteLine("Listening...");
            Console.ReadLine();
            sh.Close();
        }
예제 #2
0
 public void InitializeFrom(OptionalReliableSession optionalReliableSession)
 {
     if (null == optionalReliableSession)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("optionalReliableSession");
     }
     base.InitializeFrom(optionalReliableSession);
     SetPropertyValueIfNotDefaultValue(ConfigurationStrings.Enabled, optionalReliableSession.Enabled);
 }
예제 #3
0
 public void ApplyConfiguration(OptionalReliableSession optionalReliableSession)
 {
     if (null == optionalReliableSession)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("optionalReliableSession");
     }
     base.ApplyConfiguration(optionalReliableSession);
     optionalReliableSession.Enabled = this.Enabled;
 }
예제 #4
0
 public void InitializeFrom(OptionalReliableSession optionalReliableSession)
 {
     if (optionalReliableSession == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("optionalReliableSession");
     }
     base.InitializeFrom(optionalReliableSession);
     this.Enabled = optionalReliableSession.Enabled;
 }
예제 #5
0
        public void Connect(User p)
        {
            OptionalReliableSession OptionalReliableSession = new OptionalReliableSession
            {
                Enabled           = true,
                InactivityTimeout = TimeSpan.MaxValue,
                Ordered           = true
            };

            NetTcpSecurity netTcpSecurity = new NetTcpSecurity
            {
                Mode = SecurityMode.None
            };

            XmlDictionaryReaderQuotas readerQuotas = new XmlDictionaryReaderQuotas
            {
                MaxDepth = 32 * 2,
                MaxStringContentLength = 8192 * 2,
                MaxArrayLength         = 16384 * 2,
                MaxBytesPerRead        = 4096 * 2,
                MaxNameTableCharCount  = 16384 * 2
            };

            NetTcpBinding netTcpBinding = new NetTcpBinding
            {
                Name                   = "DuplexBinding",
                ReceiveTimeout         = TimeSpan.FromMinutes(10 * 2),
                ReliableSession        = OptionalReliableSession,
                Security               = netTcpSecurity,
                CloseTimeout           = TimeSpan.FromMinutes(2),
                SendTimeout            = TimeSpan.FromMinutes(2),
                OpenTimeout            = TimeSpan.FromMinutes(2),
                ReaderQuotas           = readerQuotas,
                MaxBufferPoolSize      = 524288 * 2,
                MaxReceivedMessageSize = 65536 * 2,
                HostNameComparisonMode = HostNameComparisonMode.StrongWildcard,
                ListenBacklog          = 10 * 2,
                MaxBufferSize          = 65536 * 2,
                MaxConnections         = 48 * 2,
                TransactionFlow        = false,
                TransferMode           = TransferMode.Buffered,
                PortSharingEnabled     = false,
                Namespace              = "http://tempuri.org/"
            };

            InstanceContext site = new InstanceContext(this);

            proxy = new ChatProxy(site, netTcpBinding, new EndpointAddress(Uri));
            IAsyncResult iar = proxy.BeginJoin(p, new AsyncCallback(OnEndJoin), null);
        }
예제 #6
0
        private void Initialize()
        {
            WSHttpBinding wSHttpBinding = new WSHttpBinding();

            this.httpTransport   = new HttpRelayTransportBindingElement();
            this.httpsTransport  = new HttpsRelayTransportBindingElement();
            this.messageEncoding = wSHttpBinding.MessageEncoding;
            this.session         = new System.ServiceModel.Channels.ReliableSessionBindingElement(true);
            this.textEncoding    = new TextMessageEncodingBindingElement()
            {
                MessageVersion = System.ServiceModel.Channels.MessageVersion.Soap12WSAddressing10
            };
            this.mtomEncoding = new MtomMessageEncodingBindingElement()
            {
                MessageVersion = System.ServiceModel.Channels.MessageVersion.Soap12WSAddressing10
            };
            this.reliableSession = new OptionalReliableSession(this.session);
        }
예제 #7
0
        public bool Initialize(IService1Callback callbackHandler)
        {
            try
            {
                this.callbackHandler = callbackHandler;
                InstanceContext instanceContext = new InstanceContext(callbackHandler);
                EndpointAddress address         = new EndpointAddress(new Uri(Properties.Settings.Default.RemoteIP));

                NetTcpBinding tcpBinding = new NetTcpBinding(SecurityMode.None);
                ReliableSessionBindingElement reliableBe = new ReliableSessionBindingElement();
                reliableBe.Ordered                = true;
                tcpBinding.OpenTimeout            = new TimeSpan(24, 20, 31, 23);
                tcpBinding.CloseTimeout           = new TimeSpan(24, 20, 31, 23);
                tcpBinding.ReceiveTimeout         = new TimeSpan(24, 20, 31, 23);
                tcpBinding.SendTimeout            = new TimeSpan(24, 20, 31, 23);
                tcpBinding.MaxBufferSize          = 2147483647;
                tcpBinding.MaxReceivedMessageSize = 2147483647;

                OptionalReliableSession reliableSession = new OptionalReliableSession(reliableBe);
                tcpBinding.ReliableSession = reliableSession;
                tcpBinding.ReceiveTimeout  = new TimeSpan(24, 20, 31, 23);

                dupFactory = new DuplexChannelFactory <IService1>(instanceContext, tcpBinding, address);
                dupFactory.Open();

                wcfService = dupFactory.CreateChannel();
                wcfService.RegisterCallback();

                Thread workerThread = new Thread(DoWork);
                _shouldStop = true;
                workerThread.Start();
            }
            catch (Exception)
            {
                return(false);
            }

            return(true);
        }
예제 #8
0
        private void TcpTransportCert()
        {
            // This string uses a function to prepend the computer name at run time.
            string addressTCP = String.Format(
                "net.tcp://{0}:8036/NetTcpSecurity/Transport/Certificate",
                System.Net.Dns.GetHostEntry("").HostName);

            // <Snippet1>
            NetTcpBinding binding = new NetTcpBinding();

            binding.Security.Mode = SecurityMode.Transport;
            binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Certificate;
            // </Snippet1>

            // <Snippet3>
            NetTcpBinding bSecurity = new NetTcpBinding(SecurityMode.Transport);
            // </Snippet3>

            // <Snippet4>
            NetTcpBinding bConfigurationName = new NetTcpBinding("MyConfiguration");
            // </Snippet4>

            // <Snippet5>
            NetTcpBinding bSecurityReliable = new NetTcpBinding(SecurityMode.Transport, true);
            // </Snippet5>

            // <Snippet6>
            EnvelopeVersion envelopeVersion = binding.EnvelopeVersion;
            // </Snippet6>

            // <Snippet7>
            HostNameComparisonMode hostNameComparisonMode = binding.HostNameComparisonMode;
            // </Snippet7>

            // <Snippet8>
            int listenBacklog = binding.ListenBacklog;
            // </Snippet8>

            // <Snippet9>
            long maxBufferPoolsize = binding.MaxBufferPoolSize;
            // </Snippet9>

            // <Snippet10>
            int maxBufferSize = binding.MaxBufferSize;
            // </Snippet10>

            // <Snippet11>
            int maxConnections = binding.MaxConnections;
            // </Snippet11>

            // <Snippet12>
            long MaxReceivedMessageSize = binding.MaxReceivedMessageSize;
            // </Snippet12>

            // <Snippet13>
            bool portSharingEnabled = binding.PortSharingEnabled;
            // </Snippet13>

            // <Snippet14>
            XmlDictionaryReaderQuotas xmlDictionaryReaderQuotas =
                binding.ReaderQuotas;
            // </Snippet14>

            // <Snippet15>
            OptionalReliableSession reliableSession =
                binding.ReliableSession;
            // </Snippet15>

            // <Snippet16>
            string scheme = binding.Scheme;
            // </Snippet16>

            // <Snippet17>
            NetTcpSecurity security = binding.Security;
            // </Snippet17>

            // <Snippet18>
            bool transactionFlow = binding.TransactionFlow;
            // </Snippet18>

            // <Snippet19>
            TransactionProtocol transactionProtocol =
                binding.TransactionProtocol;
            // </Snippet19>

            // <Snippet20>
            BindingElementCollection elementCollection =
                binding.CreateBindingElements();
            // </Snippet20>

            // <Snippet21>
            // P:System.ServiceModel.NetTcpBinding.System.ServiceModel.Channels.
            // IBindingRuntimePreferences.ReceiveSynchronously
            // Private, no example needed
            // </Snippet21>

            // <Snippet22>
            TransferMode transferMode = binding.TransferMode;
            // </Snippet22>



            // You must create an array of URI objects to have a base address.
            Uri a = new Uri(addressTCP);

            Uri[] baseAddresses = new Uri[] { a };

            // Create the ServiceHost. The service type (Calculator) is not
            // shown here.
            ServiceHost sh = new ServiceHost(typeof(Calculator), baseAddresses);

            // Add an endpoint to the service. Insert the thumbprint of an X.509
            // certificate found on your computer.
            Type c = typeof(ICalculator);

            //sh.AddServiceEndpoint(c, b, "Aloha");
            sh.Credentials.ServiceCertificate.SetCertificate(
                StoreLocation.LocalMachine,
                StoreName.My,
                X509FindType.FindByThumbprint,
                "af1f51b25cd413ed9cd00c315bbb6dc1c08da5e6");

            // This next line is optional. It specifies that the client's certificate
            // does not have to be issued by a trusted authority, but can be issued
            // by a peer if it is in the Trusted People store. Do not use this setting
            // for production code.
            // sh.Credentials.ClientCertificate.Authentication.CertificateValidationMode =
            //X509CertificateValidationMode.PeerOrChainTrust;
            sh.Open();

            string address = sh.Description.Endpoints[0].ListenUri.AbsoluteUri;

            Console.WriteLine("Listening @ {0}", address);
            Console.WriteLine("Press enter to close the service");
            Console.ReadLine();
        }
예제 #9
0
        // Create and configure bindings within this EXE console application.
        public static void Main()
        {
            // Create a WSHttpBinding
            // <Snippet3>
            // <Snippet1>
            WSHttpBinding binding1 = new WSHttpBinding();

            // </Snippet1>

            binding1.BypassProxyOnLocal = true;
            // </Snippet3>

            // <Snippet4>
            EnvelopeVersion envelopeVersion =
                binding1.EnvelopeVersion;
            // </Snippet4>

            // <Snippet5>
            HostNameComparisonMode hostnameComparisonMode =
                binding1.HostNameComparisonMode;
            // </Snippet5>

            // <Snippet6>
            long maxBufferPoolSize =
                binding1.MaxBufferPoolSize;
            // </Snippet6>


            // <Snippet7>
            long maxReceivedMessageSize =
                binding1.MaxReceivedMessageSize;
            // </Snippet7>

            // <Snippet8>
            WSMessageEncoding messageEncoding =
                binding1.MessageEncoding;
            // </Snippet8>

            // <Snippet9>
            Uri proxyAddress =
                binding1.ProxyAddress;
            // </Snippet9>

            // <Snippet10>
            XmlDictionaryReaderQuotas readerQuotas =
                binding1.ReaderQuotas;
            // </Snippet10>

            // <Snippet11>
            OptionalReliableSession reliableSession =
                binding1.ReliableSession;
            // </Snippet11>

            // <Snippet12>
            string scheme = binding1.Scheme;
            // </Snippet12>

            // <Snippet13>
            Encoding textEncoding =
                binding1.TextEncoding;
            // </Snippet13>

            // <Snippet14>
            bool transactionFlow =
                binding1.TransactionFlow;
            // </Snippet14>

            // <Snippet15>
            bool useDefaultWebProxy =
                binding1.UseDefaultWebProxy;
            // </Snippet15>

            // <Snippet16>
            BindingElementCollection bindingElements =
                binding1.CreateBindingElements();

            // </Snippet16>



            // Set WSHttpBinding binding property values
            binding1.Name = "Binding1";
            binding1.HostNameComparisonMode =
                HostNameComparisonMode.StrongWildcard;
            binding1.Security.Mode           = SecurityMode.Message;
            binding1.ReliableSession.Enabled = false;
            binding1.TransactionFlow         = false;
            // binding1.Security.Message.DefaultProtectionLevel = System.Net.Security.ProtectionLevel.EncryptAndSign;

            // Enumerate properties of the binding1.
            Console.WriteLine("WSHttpBinding binding1 properties:");
            Console.WriteLine("      - name:\t\t\t{0}", binding1.Name);
            Console.WriteLine("      - hostname comparison:\t{0}", binding1.HostNameComparisonMode);
            Console.WriteLine("      - security mode:\t\t{0}", binding1.Security.Mode);
            Console.WriteLine("      - RM enabled:\t\t{0}", binding1.ReliableSession.Enabled);
            Console.WriteLine("      - transaction flow:\t{0}", binding1.TransactionFlow);
            //Console.WriteLine("      - message security:\t{0}", binding1.Security.Message.DefaultProtectionLevel);
            Console.WriteLine("      - transport scheme:\t{0}", binding1.Scheme);
            Console.WriteLine("      - max message size:\t{0}", binding1.MaxReceivedMessageSize);
            Console.WriteLine("      - default text encoding:\t{0}", binding1.TextEncoding);
            Console.WriteLine();

            // Create a WSFederationBinding with a message security mode
            // and with a reliable session enabled.
            WSFederationHttpBinding binding3 = new WSFederationHttpBinding(WSFederationHttpSecurityMode.Message, true);

            // Enumerate properties of the binding2.
            Console.WriteLine("WSFederationBinding binding3 properties:");
            Console.WriteLine("      - security mode:\t\t{0}", binding3.Security.Mode);
            Console.WriteLine("      - RM enabled:\t\t{0}", binding3.ReliableSession.Enabled);
            Console.WriteLine();
            Console.WriteLine("Press <ENTER> to terminate.");
            Console.ReadLine();
        }
        // Methods

        public void ApplyConfiguration(OptionalReliableSession s)
        {
            base.ApplyConfiguration(s);
            s.Enabled = this.Enabled;
        }
예제 #11
0
 private void Initialize()
 {
     this.session         = new ReliableSessionBindingElement();
     this.reliableSession = new OptionalReliableSession(this.session);
 }
예제 #12
0
        // Methods

        public void ApplyConfiguration(OptionalReliableSession optionalReliableSession)
        {
            base.ApplyConfiguration(optionalReliableSession);
            optionalReliableSession.Enabled = this.Enabled;
        }
예제 #13
0
        public static List <WSHttpBinding> GetWsHttpBindings(string exeConfigPath)
        {
            if (string.IsNullOrWhiteSpace(exeConfigPath))
            {
                return(null);
            }

            var svcSection = Read.Config.ExeConfig.GetServiceModelSection(exeConfigPath);

            var configs = new List <WSHttpBinding>();

            foreach (
                var section in
                svcSection.Bindings.WSHttpBinding.ConfiguredBindings
                .Cast <WSHttpBindingElement>())
            {
                var df      = new WSHttpBinding();
                var binding = new WSHttpBinding
                {
                    Name = section.Name,

                    MaxBufferPoolSize      = section.MaxBufferPoolSize > 0 ? section.MaxBufferPoolSize : df.MaxBufferPoolSize,
                    MaxReceivedMessageSize = section.MaxReceivedMessageSize > 0 ? section.MaxReceivedMessageSize : df.MaxReceivedMessageSize,
                    CloseTimeout           = section.CloseTimeout != TimeSpan.Zero ? section.CloseTimeout : df.CloseTimeout,
                    OpenTimeout            = section.OpenTimeout != TimeSpan.Zero ? section.OpenTimeout : df.OpenTimeout,
                    SendTimeout            = section.SendTimeout != TimeSpan.Zero ? section.SendTimeout : df.SendTimeout,
                    ReceiveTimeout         =
                        section.ReceiveTimeout != TimeSpan.Zero ? section.ReceiveTimeout : df.ReceiveTimeout,

                    TextEncoding = section.TextEncoding ?? df.TextEncoding,

                    MessageEncoding        = section.MessageEncoding,
                    AllowCookies           = section.AllowCookies,
                    BypassProxyOnLocal     = section.BypassProxyOnLocal,
                    TransactionFlow        = section.TransactionFlow,
                    HostNameComparisonMode = section.HostNameComparisonMode,
                    UseDefaultWebProxy     = section.UseDefaultWebProxy,
                };

                var readerQuotasSection = section.ReaderQuotas;
                var readerQuotas        = new System.Xml.XmlDictionaryReaderQuotas();
                if (readerQuotasSection != null && readerQuotasSection.MaxDepth > 0)
                {
                    readerQuotas.MaxDepth = readerQuotasSection.MaxDepth;
                    readerQuotas.MaxStringContentLength = readerQuotasSection.MaxStringContentLength;
                    readerQuotas.MaxArrayLength         = readerQuotasSection.MaxArrayLength;
                    readerQuotas.MaxBytesPerRead        = readerQuotasSection.MaxBytesPerRead;
                    readerQuotas.MaxNameTableCharCount  = readerQuotasSection.MaxNameTableCharCount;
                }
                else
                {
                    readerQuotas = null;
                }

                var reliableSessionSection = section.ReliableSession;
                var dfRss           = new OptionalReliableSession();
                var reliableSession = new OptionalReliableSession
                {
                    Enabled           = reliableSessionSection.Enabled,
                    Ordered           = reliableSessionSection.Ordered,
                    InactivityTimeout =
                        reliableSessionSection.InactivityTimeout != TimeSpan.Zero
                            ? reliableSessionSection.InactivityTimeout
                            : dfRss.InactivityTimeout,
                };

                var messageSection = section.Security.Message;
                var message        = new NonDualMessageSecurityOverHttp
                {
                    EstablishSecurityContext   = messageSection.EstablishSecurityContext,
                    ClientCredentialType       = messageSection.ClientCredentialType,
                    NegotiateServiceCredential = messageSection.NegotiateServiceCredential,
                    AlgorithmSuite             = messageSection.AlgorithmSuite
                };

                var transportSection = section.Security.Transport;
                var transport        = new HttpTransportSecurity
                {
                    ClientCredentialType = transportSection.ClientCredentialType,
                    ProxyCredentialType  = transportSection.ProxyCredentialType
                };

                var wsHttpSecuritySection = section.Security;
                var wsHttpSecurity        = new WSHttpSecurity
                {
                    Mode      = wsHttpSecuritySection.Mode,
                    Transport = transport,
                    Message   = message
                };
                ;
                binding.Security = wsHttpSecurity;
                if (readerQuotas != null)
                {
                    binding.ReaderQuotas = readerQuotas;
                }
                binding.ReliableSession = reliableSession;

                configs.Add(binding);
            }
            return(configs);
        }