Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            // allow server certificate that doesn't match the host in the endpoint address
            ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(IgnoreSubjectNameMismatch);

            string uri = "https://" + Environment.MachineName + ":8443/TestService/BinaryEncoderOverHTTPS";

            if (args.Length > 0)
            {
                uri = args[0];
            }
            EndpointAddress address = new EndpointAddress(uri);
            NetHttpBinding  binding = new NetHttpBinding();
            ChannelFactory <IEchoService> factory = new ChannelFactory <IEchoService>(binding, address);

            factory.Open();
            IEchoService service = factory.CreateChannel();

            Console.WriteLine(service.Echo("'Test string passed for calling service using code'"));

            Console.WriteLine("called service successfully using binding in code");

            factory = new ChannelFactory <IEchoService>("EchoServer");
            factory.Open();
            service = factory.CreateChannel();

            Console.WriteLine(service.Echo("'Test string passed for calling service using code'"));
            Console.WriteLine("called service successfully using binding from config. Press enter to exit...");

            Console.ReadLine();
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            NetHttpBinding httpsBinding = new NetHttpBinding();
            NetHttpBinding httpBinding  = new NetHttpBinding(NetHttpSecurityMode.TransportCredentialOnly);
            ServiceHost    serviceHost  = new ServiceHost(typeof(EchoService), GetBaseAddress("http", 8000), GetBaseAddress("https", 8443));

            serviceHost.AddServiceEndpoint(typeof(IEchoService), httpBinding, "BinaryEncoderOverHTTP");
            serviceHost.AddServiceEndpoint(typeof(IEchoService), httpsBinding, "BinaryEncoderOverHTTPS");
            serviceHost.Open();

            Console.WriteLine("Service started at: " + serviceHost.ChannelDispatchers[0].Listener.Uri.AbsoluteUri);
            Console.WriteLine("Service started at: " + serviceHost.ChannelDispatchers[1].Listener.Uri.AbsoluteUri);
            Console.WriteLine("Press enter to exit...");
            Console.ReadLine();
        }
        protected override void InitializeFrom(Binding binding)
        {
            base.InitializeFrom(binding);
            NetHttpBinding netHttpBinding = ((NetHttpBinding)(binding));

            this.BypassProxyOnLocal     = netHttpBinding.BypassProxyOnLocal;
            this.HostNameComparisonMode = netHttpBinding.HostNameComparisonMode;
            this.MaxBufferSize          = netHttpBinding.MaxBufferSize;
            this.MaxBufferPoolSize      = netHttpBinding.MaxBufferPoolSize;
            this.MaxReceivedMessageSize = netHttpBinding.MaxReceivedMessageSize;
            this.ProxyAddress           = netHttpBinding.ProxyAddress;
            this.SecurityMode           = netHttpBinding.SecurityMode;
            this.TransferMode           = netHttpBinding.TransferMode;
            this.UseDefaultWebProxy     = netHttpBinding.UseDefaultWebProxy;
            this.ReaderQuotas           = netHttpBinding.ReaderQuotas;
        }
        protected override void OnApplyConfiguration(Binding binding)
        {
            if ((binding == null))
            {
                throw new System.ArgumentNullException("binding");
            }
            if ((binding.GetType() != typeof(NetHttpBinding)))
            {
                throw new System.ArgumentException(string.Format(CultureInfo.CurrentCulture, "Invalid type for binding. Expected type: {0}. Type passed in: {1}.", typeof(NetHttpBinding).AssemblyQualifiedName, binding.GetType().AssemblyQualifiedName));
            }
            NetHttpBinding netHttpBinding = ((NetHttpBinding)(binding));

            netHttpBinding.BypassProxyOnLocal     = this.BypassProxyOnLocal;
            netHttpBinding.HostNameComparisonMode = this.HostNameComparisonMode;
            netHttpBinding.MaxBufferSize          = this.MaxBufferSize;
            netHttpBinding.MaxBufferPoolSize      = this.MaxBufferPoolSize;
            netHttpBinding.MaxReceivedMessageSize = this.MaxReceivedMessageSize;
            netHttpBinding.ProxyAddress           = this.ProxyAddress;
            netHttpBinding.SecurityMode           = this.SecurityMode;
            netHttpBinding.TransferMode           = this.TransferMode;
            netHttpBinding.UseDefaultWebProxy     = this.UseDefaultWebProxy;
            netHttpBinding.ReaderQuotas           = this.ReaderQuotas;
        }