Beispiel #1
0
        ChannelFactory <IDeveloperService> CreateFactory()
        {
            NetHttpBinding binding = new NetHttpBinding();

            //  binding.Security.Mode = BasicHttpSecurityMode.None;
            return(new ChannelFactory <IDeveloperService>(binding, new EndpointAddress(serviceUrl)));
        }
Beispiel #2
0
    public static void RequestResponseOverWebSocketManually_Echo_RoundTrips_Guid()
    {
        DuplexChannelFactory <IWcfDuplexService> factory = null;
        Guid guid = Guid.NewGuid();

        NetHttpBinding binding = new NetHttpBinding();

        binding.WebSocketSettings.TransportUsage = WebSocketTransportUsage.Always;

        WcfDuplexServiceCallback callbackService = new WcfDuplexServiceCallback();
        InstanceContext          context         = new InstanceContext(callbackService);

        try
        {
            factory = new DuplexChannelFactory <IWcfDuplexService>(context, binding, new EndpointAddress(Endpoints.NetHttpWebSocketTransport_Address));
            IWcfDuplexService duplexProxy = factory.CreateChannel();

            Task.Run(() => duplexProxy.Ping(guid));
            Guid returnedGuid = callbackService.CallbackGuid;

            Assert.True(guid == returnedGuid, string.Format("The sent GUID does not match the returned GUID. Sent '{0}', Received: '{1}'", guid, returnedGuid));
        }
        finally
        {
            if (factory != null && factory.State != CommunicationState.Closed)
            {
                factory.Abort();
            }
        }
    }
Beispiel #3
0
        ChannelFactory <IFileTransferService> CreateFileTransferServiceFactory()
        {
            NetHttpBinding binding = new NetHttpBinding();

            //  binding.Security.Mode = BasicHttpSecurityMode.None;
            return(new ChannelFactory <IFileTransferService>(binding, new EndpointAddress(fileTrasnferServicUrl)));
        }
        static void Main(string[] args)
        {
            var binding = new NetHttpBinding();

            binding.WebSocketSettings.TransportUsage = WebSocketTransportUsage.Always;
            ReactiveDuplexChannelFactory <IStockQuoteService, IStockQuoteServiceCallback> duplexChannel =
                new ReactiveDuplexChannelFactory <IStockQuoteService, IStockQuoteServiceCallback>(binding, "ws://localhost:3201/StockQuoteService.svc");


            duplexChannel.AsObservable <Quote>().Subscribe(quote => Console.WriteLine($"{quote.Code}-{quote.Price}"));
            var channel = duplexChannel.CreateChannel();



            channel.StartSendingQuotes();


            Console.ReadKey();


            channel.StopSendingQuotes();
            Thread.Sleep(4000);

            ((IClientChannel)channel).Close();
        }
        private static NetHttpBinding CreateNetHttpBinding()
        {
            var binding = new NetHttpBinding(BasicHttpSecurityMode.None);

            binding.BypassProxyOnLocal = true;
            binding.MessageEncoding    = NetHttpMessageEncoding.Binary;

            binding.ReaderQuotas.MaxBytesPerRead        = int.MaxValue;
            binding.ReaderQuotas.MaxDepth               = int.MaxValue;
            binding.ReaderQuotas.MaxArrayLength         = int.MaxValue;
            binding.ReaderQuotas.MaxStringContentLength = int.MaxValue;
            binding.ReaderQuotas.MaxNameTableCharCount  = int.MaxValue;

            binding.TransferMode = TransferMode.Streamed;

            binding.MaxBufferSize          = int.MaxValue;
            binding.MaxBufferPoolSize      = long.MaxValue;
            binding.MaxReceivedMessageSize = long.MaxValue;

            binding.OpenTimeout    = DefaultTimeout;
            binding.CloseTimeout   = DefaultTimeout;
            binding.SendTimeout    = TimeSpan.MaxValue;
            binding.ReceiveTimeout = TimeSpan.MaxValue;

            return(binding);
        }
Beispiel #6
0
    public static void DefaultSettings_Echo_RoundTrips_String()
    {
        string        variationDetails = "Client:: NetHttpBinding/DefaultValues\nServer:: NetHttpBinding/DefaultValues";
        string        testString       = "Hello";
        StringBuilder errorBuilder     = new StringBuilder();
        bool          success          = false;

        NetHttpBinding binding = new NetHttpBinding();

        try
        {
            ChannelFactory <IWcfService> factory = new ChannelFactory <IWcfService>(binding, new EndpointAddress(Endpoints.HttpBaseAddress_NetHttp));
            IWcfService serviceProxy             = factory.CreateChannel();
            string      result = serviceProxy.Echo(testString);
            success = string.Equals(result, testString);

            if (!success)
            {
                errorBuilder.AppendLine(String.Format("    Error: expected response from service: '{0}' Actual was: '{1}'", testString, result));
            }
        }
        catch (Exception ex)
        {
            errorBuilder.AppendLine(String.Format("    Error: Unexpected exception was caught while doing the basic echo test for variation...\n'{0}'\nException: {1}", variationDetails, ex.ToString()));
        }

        Assert.True(errorBuilder.Length == 0, "Test case FAILED with errors: " + errorBuilder.ToString());
    }
Beispiel #7
0
        public static Binding CreateNetHttpBinding()
        {
            NetHttpBinding netHttp = new NetHttpBinding();

            netHttp.WebSocketSettings.TransportUsage = WebSocketTransportUsage.Always;
            return(SetupBindingTimeouts(netHttp));
        }
Beispiel #8
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(new string('a', 1024)));

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

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

            Console.WriteLine(service.Echo(new string('b', 1024)));
            Console.WriteLine("called service successfully using binding from config. Press enter to exit...");

            Console.ReadLine();
        }
Beispiel #9
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(new string('a', 1024)));

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

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

            Console.WriteLine(service.Echo(new string('b', 1024)));
            Console.WriteLine("called service successfully using binding from config. Press enter to exit...");

            Console.ReadLine();
        }
Beispiel #10
0
    public static async Task EchoCall(ReliableMessagingVersion rmVersion, bool ordered, string endpointSuffix)
    {
        string testString = "Hello";
        ChannelFactory <IWcfReliableService> factory = null;
        IWcfReliableService serviceProxy             = null;
        NetHttpBinding      binding = null;

        try
        {
            // *** SETUP *** \\
            binding = new NetHttpBinding(BasicHttpSecurityMode.None, true);
            binding.ReliableSession.Ordered = ordered;
            var customBinding = new CustomBinding(binding);
            var reliableSessionBindingElement = customBinding.Elements.Find <ReliableSessionBindingElement>();
            reliableSessionBindingElement.ReliableMessagingVersion = rmVersion;
            factory      = new ChannelFactory <IWcfReliableService>(customBinding, new EndpointAddress(Endpoints.ReliableSession_NetHttp + endpointSuffix));
            serviceProxy = factory.CreateChannel();
            // *** EXECUTE *** \\
            ((IClientChannel)serviceProxy).Open(); // This will establish a reliable session
            var result = await serviceProxy.EchoAsync(testString);

            // *** VALIDATE *** \\
            Assert.Equal(testString, result);

            // *** CLEANUP *** \\
            ((IClientChannel)serviceProxy).Close();
            factory.Close();
            ((ICommunicationObject)serviceProxy).Close();
        }
        finally
        {
            // *** ENSURE CLEANUP *** \\
            ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)serviceProxy, factory);
        }
    }
 public override Binding Configure(
     NetHttpBinding binding)
 {
     // inherently session-full binding
     IncompatibleBinding(binding);
     return(binding);
 }
Beispiel #12
0
            protected override Channels.Binding GetServerBinding()
            {
                var binding = new NetHttpBinding(Channels.BasicHttpSecurityMode.None);

                binding.MessageEncoding = NetHttpMessageEncoding.Binary;
                return(binding);
            }
    public static void DefaultSettings_Echo_RoundTrips_String()
    {
        string testString = "Hello";
        ChannelFactory <IWcfService> factory = null;
        IWcfService serviceProxy             = null;

        try
        {
            // *** SETUP *** \\
            NetHttpBinding binding = new NetHttpBinding();
            factory      = new ChannelFactory <IWcfService>(binding, new EndpointAddress(Endpoints.HttpBaseAddress_NetHttp));
            serviceProxy = factory.CreateChannel();

            // *** EXECUTE *** \\
            string result = serviceProxy.Echo(testString);

            // *** VALIDATE *** \\
            Assert.NotNull(result);
            Assert.Equal(testString, result);

            // *** CLEANUP *** \\
            factory.Close();
            ((ICommunicationObject)serviceProxy).Close();
        }
        finally
        {
            // *** ENSURE CLEANUP *** \\
            ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)serviceProxy, factory);
        }
    }
Beispiel #14
0
    public static void WebSocket_Http_VerifyWebSocketsUsed()
    {
        NetHttpBinding binding = null;
        ChannelFactory <IVerifyWebSockets> channelFactory = null;
        IVerifyWebSockets client = null;

        try
        {
            // *** SETUP *** \\
            binding = new NetHttpBinding();
            binding.WebSocketSettings.TransportUsage = WebSocketTransportUsage.Always;

            channelFactory = new ChannelFactory <IVerifyWebSockets>(binding, new EndpointAddress(Endpoints.WebSocketHttpVerifyWebSocketsUsed_Address));
            client         = channelFactory.CreateChannel();

            // *** EXECUTE *** \\
            ((ICommunicationObject)client).Open();

            // *** VALIDATE *** \\
            bool responseFromService = client.ValidateWebSocketsUsed();
            Assert.True(responseFromService, String.Format("Response from the service was not expected. Expected: 'True' but got {0}", responseFromService));

            // *** CLEANUP *** \\
            ((ICommunicationObject)client).Close();
            channelFactory.Close();
        }
        finally
        {
            // *** ENSURE CLEANUP *** \\
            ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)client, channelFactory);
        }
    }
Beispiel #15
0
        protected override Binding GetBinding()
        {
            NetHttpBinding binding = new NetHttpBinding();

            binding.WebSocketSettings.TransportUsage = WebSocketTransportUsage.Always;
            return(binding);
        }
Beispiel #16
0
    public static void WebSocket_Http_Duplex_Buffered(NetHttpMessageEncoding messageEncoding)
    {
        EndpointAddress endpointAddress;
        NetHttpBinding  binding        = null;
        ClientReceiver  clientReceiver = null;
        InstanceContext context        = null;
        DuplexChannelFactory <IWSDuplexService> channelFactory = null;
        IWSDuplexService client = null;

        try
        {
            // *** SETUP *** \\
            binding = new NetHttpBinding()
            {
                MaxReceivedMessageSize = ScenarioTestHelpers.SixtyFourMB,
                MaxBufferSize          = ScenarioTestHelpers.SixtyFourMB,
            };
            binding.WebSocketSettings.TransportUsage = WebSocketTransportUsage.Always;
            binding.MessageEncoding = messageEncoding;

            clientReceiver  = new ClientReceiver();
            context         = new InstanceContext(clientReceiver);
            endpointAddress = new EndpointAddress(Endpoints.WebSocketHttpDuplexBuffered_Address + Enum.GetName(typeof(NetHttpMessageEncoding), messageEncoding));
            channelFactory  = new DuplexChannelFactory <IWSDuplexService>(context, binding, endpointAddress);
            client          = channelFactory.CreateChannel();

            // *** EXECUTE *** \\
            // Invoking UploadData
            client.UploadData(ScenarioTestHelpers.CreateInterestingString(123));

            // Invoking StartPushingData
            client.StartPushingData();
            Assert.True(clientReceiver.ReceiveDataInvoked.WaitOne(ScenarioTestHelpers.TestTimeout),
                        String.Format("Test case timeout was reached while waiting for the buffered response from the Service. Timeout was: {0}", ScenarioTestHelpers.TestTimeout));
            clientReceiver.ReceiveDataInvoked.Reset();
            // Invoking StopPushingData
            client.StopPushingData();
            Assert.True(clientReceiver.ReceiveDataCompleted.WaitOne(ScenarioTestHelpers.TestTimeout),
                        String.Format("Test case timeout was reached while waiting for the buffered response from the Service to be completed. Timeout was: {0}", ScenarioTestHelpers.TestTimeout));
            clientReceiver.ReceiveDataCompleted.Reset();

            // Getting results from server via callback.
            client.GetLog();
            Assert.True(clientReceiver.LogReceived.WaitOne(ScenarioTestHelpers.TestTimeout),
                        String.Format("Test case timeout was reached while waiting for the Logging from the Service to be received. Timeout was: {0}", ScenarioTestHelpers.TestTimeout));

            // *** VALIDATE *** \\
            Assert.True(clientReceiver.ServerLog.Count > 0,
                        "The logging done by the Server was not returned via the Callback.");

            // *** CLEANUP *** \\
            ((ICommunicationObject)client).Close();
            channelFactory.Close();
        }
        finally
        {
            // *** ENSURE CLEANUP *** \\
            ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)client, channelFactory);
        }
    }
Beispiel #17
0
        public static Binding GetNetHttpBinding(BasicHttpSecurityMode mode)
        {
            var binding = new NetHttpBinding(mode);

            Configure(binding);
            return(binding);
        }
Beispiel #18
0
        public static Binding GetNetHttpBinding()
        {
            var binding = new NetHttpBinding();

            Configure(binding);
            return(binding);
        }
Beispiel #19
0
    public static void RequestResponseOverWebSocketManually_Echo_RoundTrips_Guid()
    {
        DuplexChannelFactory <IWcfDuplexService> factory = null;
        IWcfDuplexService duplexProxy = null;
        Guid guid = Guid.NewGuid();

        try
        {
            // *** SETUP *** \\
            NetHttpBinding binding = new NetHttpBinding();
            binding.WebSocketSettings.TransportUsage = WebSocketTransportUsage.Always;

            WcfDuplexServiceCallback callbackService = new WcfDuplexServiceCallback();
            InstanceContext          context         = new InstanceContext(callbackService);

            factory     = new DuplexChannelFactory <IWcfDuplexService>(context, binding, new EndpointAddress(Endpoints.NetHttpWebSocketTransport_Address));
            duplexProxy = factory.CreateChannel();

            // *** EXECUTE *** \\
            Task.Run(() => duplexProxy.Ping(guid));
            Guid returnedGuid = callbackService.CallbackGuid;

            // *** VALIDATE *** \\
            Assert.True(guid == returnedGuid, string.Format("The sent GUID does not match the returned GUID. Sent '{0}', Received: '{1}'", guid, returnedGuid));

            // *** CLEANUP *** \\
            factory.Close();
            ((ICommunicationObject)duplexProxy).Close();
        }
        finally
        {
            // *** ENSURE CLEANUP *** \\
            ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)duplexProxy, factory);
        }
    }
        void IWsdlImportExtension.ImportEndpoint(WsdlImporter importer, WsdlEndpointConversionContext endpointContext)
        {
            if (endpointContext == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("endpointContext");
            }

#pragma warning suppress 56506 // [....], endpointContext.Endpoint is never null
            if (endpointContext.Endpoint.Binding == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("endpointContext.Binding");
            }

            if (endpointContext.Endpoint.Binding is CustomBinding)
            {
                BindingElementCollection elements = ((CustomBinding)endpointContext.Endpoint.Binding).Elements;

                Binding binding;
                TransportBindingElement transport = elements.Find <TransportBindingElement>();

                if (transport is HttpTransportBindingElement)
                {
                    if (WSHttpBindingBase.TryCreate(elements, out binding))
                    {
                        SetBinding(endpointContext.Endpoint, binding);
                    }
                    else if (WSDualHttpBinding.TryCreate(elements, out binding))
                    {
                        SetBinding(endpointContext.Endpoint, binding);
                    }
                    else if (BasicHttpBinding.TryCreate(elements, out binding))
                    {
                        SetBinding(endpointContext.Endpoint, binding);
                    }
                    else if (NetHttpBinding.TryCreate(elements, out binding))
                    {
                        SetBinding(endpointContext.Endpoint, binding);
                    }
                }
                else if (transport is MsmqTransportBindingElement && NetMsmqBinding.TryCreate(elements, out binding))
                {
                    SetBinding(endpointContext.Endpoint, binding);
                }
                else if (transport is NamedPipeTransportBindingElement && NetNamedPipeBinding.TryCreate(elements, out binding))
                {
                    SetBinding(endpointContext.Endpoint, binding);
                }
#pragma warning disable 0618
                else if (transport is PeerTransportBindingElement && NetPeerTcpBinding.TryCreate(elements, out binding))
                {
                    SetBinding(endpointContext.Endpoint, binding);
                }
#pragma warning restore 0618
                else if (transport is TcpTransportBindingElement && NetTcpBinding.TryCreate(elements, out binding))
                {
                    SetBinding(endpointContext.Endpoint, binding);
                }
            }
        }
Beispiel #21
0
        private Binding GetNetHttpBinding(NetHttpMessageEncoding encoding)
        {
            var binding = new NetHttpBinding();

            binding.MessageEncoding = encoding;
            binding.Name            = Enum.GetName(typeof(NetHttpMessageEncoding), encoding);
            return(binding);
        }
Beispiel #22
0
        private static IDeveloperService CreateDeveloperService()
        {
            const string serviceUrl     = "http://localhost:1578/Service/DeveloperService.svc/~/Service/Developer.svc";
            var          binding        = new NetHttpBinding();
            var          channelFactory = new ChannelFactory <IDeveloperService>(binding, new EndpointAddress(serviceUrl));

            return(channelFactory.CreateChannel());
        }
Beispiel #23
0
        public static NetHttpBinding GetBufferedModeWebSocketBinding()
        {
            var binding = new NetHttpBinding();

            binding.WebSocketSettings.TransportUsage = WebSocketTransportUsage.Always;
            ApplyDebugTimeouts(binding);
            return(binding);
        }
Beispiel #24
0
    public static void WebSocket_Http_RequestReply_Streamed(NetHttpMessageEncoding messageEncoding)
    {
        EndpointAddress endpointAddress;
        NetHttpBinding  binding = null;
        ChannelFactory <IWSRequestReplyService> channelFactory = null;
        IWSRequestReplyService client       = null;
        FlowControlledStream   uploadStream = null;

        try
        {
            // *** SETUP *** \\
            binding = new NetHttpBinding()
            {
                MaxReceivedMessageSize = ScenarioTestHelpers.SixtyFourMB,
                MaxBufferSize          = ScenarioTestHelpers.SixtyFourMB,
            };
            binding.WebSocketSettings.TransportUsage = WebSocketTransportUsage.Always;
            binding.TransferMode    = TransferMode.Streamed;
            binding.MessageEncoding = messageEncoding;
            endpointAddress         = new EndpointAddress(Endpoints.WebSocketHttpRequestReplyStreamed_Address + Enum.GetName(typeof(NetHttpMessageEncoding), messageEncoding));
            channelFactory          = new ChannelFactory <IWSRequestReplyService>(binding, endpointAddress);
            client = channelFactory.CreateChannel();

            // *** EXECUTE *** \\
            using (Stream stream = client.DownloadStream())
            {
                int readResult;
                // Read from the stream, 1000 bytes at a time.
                byte[] buffer = new byte[1000];

                do
                {
                    readResult = stream.Read(buffer, 0, buffer.Length);
                }while (readResult != 0);
            }

            uploadStream = new FlowControlledStream();
            uploadStream.ReadThrottle   = TimeSpan.FromMilliseconds(500);
            uploadStream.StreamDuration = TimeSpan.FromSeconds(1);
            client.UploadStream(uploadStream);

            // *** VALIDATE *** \\
            foreach (string serverLogItem in client.GetLog())
            {
                //Assert.True(serverLogItem != ScenarioTestHelpers.RemoteEndpointMessagePropertyFailure, ScenarioTestHelpers.RemoteEndpointMessagePropertyFailure);
                Assert.True(!ScenarioTestHelpers.IsLocalHost() || !serverLogItem.Contains(ScenarioTestHelpers.RemoteEndpointMessagePropertyFailure), serverLogItem);
            }

            // *** CLEANUP *** \\
            ((ICommunicationObject)client).Close();
            channelFactory.Close();
        }
        finally
        {
            // *** ENSURE CLEANUP *** \\
            ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)client, channelFactory);
        }
    }
Beispiel #25
0
        private IUserService CreateUserService()
        {
            string         serviceUrl = ServerUri.GetUserWcfServiceUri().OriginalString;
            NetHttpBinding binding    = new NetHttpBinding();

            binding.MaxReceivedMessageSize = 500 * 1024;
            _channelFactory = new ChannelFactory <IUserService>(binding, new EndpointAddress(serviceUrl));
            return(_channelFactory.CreateChannel());
        }
Beispiel #26
0
        public static Binding CreateNetHttpStreamingBinding(int maxStreamSize)
        {
            var binding = new NetHttpBinding();

            binding.MaxReceivedMessageSize           = maxStreamSize * 2;
            binding.TransferMode                     = TransferMode.Streamed;
            binding.WebSocketSettings.TransportUsage = WebSocketTransportUsage.Always;
            return(SetupBindingTimeouts(binding));
        }
        protected override Binding GetBinding()
        {
            NetHttpBinding binding = new NetHttpBinding();

            binding.WebSocketSettings.TransportUsage = WebSocketTransportUsage.Always;
            // This setting lights up the code path that calls the operation attributed with ConnectionOpenedAction
            binding.WebSocketSettings.CreateNotificationOnConnection = true;
            return(binding);
        }
Beispiel #28
0
        public static void Main(string[] args)
        {
            ConfigurationManager.AppSettings["aspnet:UseTaskFriendlySynchronizationContext"] = "true";

            var mapping = new ProtocolMappingElementCollection();

            mapping.Add(
                element: new ProtocolMappingElement(
                    schemeType: "http",
                    binding: "netHttpBinding",
                    bindingConfiguration: "default"));
            mapping.Add(
                element: new ProtocolMappingElement(
                    schemeType: "https",
                    binding: "netHttpsBinding",
                    bindingConfiguration: "default"));

            ServiceHost serviceHost = null;

            try
            {
                string addressStr = "http://localhost:8012/HelloService";

                var binding = new NetHttpBinding(
                    securityMode: BasicHttpSecurityMode.None,
                    reliableSessionEnabled: true);

                var addressUri = new Uri(uriString: addressStr);

                serviceHost = new ServiceHost(
                    serviceType: typeof(HelloService),
                    baseAddresses: addressUri);

                //var endpoint = serviceHost.AddServiceEndpoint(
                //  implementedContract: typeof(IHelloService),
                //  binding: binding,
                //  address: addressUri);

                serviceHost.Open();

                Console.WriteLine(
                    "WebSocketsServiceValues service is running, press any key to close...");
                Console.ReadKey();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            finally
            {
                if (serviceHost != null)
                {
                    serviceHost.Close();
                }
            }
        }
Beispiel #29
0
        private static bool IsBindingSupported(Binding binding)
        {
            s_bindingValidationErrors.Clear();

            if (!(binding is BasicHttpBinding || binding is NetHttpBinding || binding is WSHttpBinding || binding is NetTcpBinding || binding is CustomBinding))
            {
                s_bindingValidationErrors.Add(string.Format(SR.BindingTypeNotSupportedFormat, binding.GetType().FullName,
                                                            typeof(BasicHttpBinding).FullName, typeof(NetHttpBinding).FullName, typeof(WSHttpBinding).FullName, typeof(NetTcpBinding).FullName, typeof(CustomBinding).FullName));
            }
            else
            {
                WSHttpBinding wsHttpBinding = binding as WSHttpBinding;
                if (wsHttpBinding != null)
                {
                    if (wsHttpBinding.ReliableSession.Enabled)
                    {
                        s_bindingValidationErrors.Add(SR.BindingReliableSessionNotSupported);
                    }
                    if (wsHttpBinding.TransactionFlow)
                    {
                        s_bindingValidationErrors.Add(SR.BindingTransactionFlowNotSupported);
                    }
                    if (wsHttpBinding.MessageEncoding != WSMessageEncoding.Text)
                    {
                        s_bindingValidationErrors.Add(string.Format(SR.BindingMessageEncodingNotSupportedFormat, wsHttpBinding.MessageEncoding, WSMessageEncoding.Text));
                    }
                }
                else
                {
                    NetTcpBinding netTcpBinding = binding as NetTcpBinding;
                    if (netTcpBinding != null)
                    {
                        if (netTcpBinding.ReliableSession.Enabled)
                        {
                            s_bindingValidationErrors.Add(SR.BindingReliableSessionNotSupported);
                        }
                        if (netTcpBinding.TransactionFlow)
                        {
                            s_bindingValidationErrors.Add(SR.BindingTransactionFlowNotSupported);
                        }
                    }
                    else
                    {
                        NetHttpBinding netHttpBinding = binding as NetHttpBinding;
                        if (netHttpBinding != null && netHttpBinding.ReliableSession.Enabled)
                        {
                            s_bindingValidationErrors.Add(SR.BindingReliableSessionNotSupported);
                        }
                    }
                }

                ValidateBindingElements(binding);
            }

            return(s_bindingValidationErrors.Count == 0);
        }
    public static void CreateChannel_Using_Http_NoSecurity()
    {
        WcfDuplexServiceCallback callback = new WcfDuplexServiceCallback();
        InstanceContext          context  = new InstanceContext(callback);
        Binding         binding           = new NetHttpBinding(BasicHttpSecurityMode.None);
        EndpointAddress endpoint          = new EndpointAddress(FakeAddress.HttpAddress);
        DuplexChannelFactory <IWcfDuplexService> factory = new DuplexChannelFactory <IWcfDuplexService>(context, binding, endpoint);

        factory.CreateChannel();
    }
Beispiel #31
0
        /// <summary>
        /// Configures the specified binding.
        /// </summary>
        /// <param name="binding">The binding.</param>
        /// <returns>Binding.</returns>
        public virtual Binding Configure(
            NetHttpBinding binding)
        {
            if (binding == null)
            {
                throw new ArgumentNullException(nameof(binding));
            }

            return(ConfigureDefault(binding));
        }
Beispiel #32
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();
        }