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(); } } }
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()); }
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); } }
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); } }
public static void WebSocket_Http_RequestReply_BinaryStreamed() { 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 = NetHttpMessageEncoding.Binary; channelFactory = new ChannelFactory<IWSRequestReplyService>(binding, new EndpointAddress(Endpoints.WebSocketHttpRequestReplyBinaryStreamed_Address)); 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); } }
public static void TransportUsageAlways_WebSockets_Synchronous_Call() { DuplexClientBase<IWcfDuplexService> duplexService = null; Guid guid = Guid.NewGuid(); try { NetHttpBinding binding = new NetHttpBinding(); binding.WebSocketSettings.TransportUsage = WebSocketTransportUsage.Always; WcfDuplexServiceCallback callbackService = new WcfDuplexServiceCallback(); InstanceContext context = new InstanceContext(callbackService); var uri = new Uri(Endpoints.HttpBaseAddress_NetHttpWebSocket); UriBuilder builder = new UriBuilder(Endpoints.HttpBaseAddress_NetHttpWebSocket); switch (uri.Scheme.ToLowerInvariant()) { case "http": builder.Scheme = "ws"; break; case "https": builder.Scheme = "wss"; break; } duplexService = new MyDuplexClientBase<IWcfDuplexService>(context, binding, new EndpointAddress(builder.Uri)); IWcfDuplexService proxy = duplexService.ChannelFactory.CreateChannel(); // Ping on another thread. proxy.Ping(guid); //Task.Run(() => proxy.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)); ((ICommunicationObject)duplexService).Close(); } finally { if (duplexService != null && duplexService.State != CommunicationState.Closed) { duplexService.Abort(); } } }
public static Binding GetBinding(this BindingScheme scheme, ConnectionOptions options) { Binding binding = null; switch (scheme) { case BindingScheme.TCP: { binding = new NetTcpBinding(SecurityMode.None); var tcpBinding = ((NetTcpBinding)binding); tcpBinding.MaxBufferPoolSize = Constants.MAX_MSG_SIZE; tcpBinding.MaxReceivedMessageSize = Constants.MAX_MSG_SIZE; break; } case BindingScheme.NAMED_PIPE: { binding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None); var npBinding = ((NetNamedPipeBinding)binding); npBinding.MaxBufferPoolSize = Constants.MAX_MSG_SIZE; npBinding.MaxReceivedMessageSize = Constants.MAX_MSG_SIZE; break; } case BindingScheme.HTTP: { binding = new NetHttpBinding(BasicHttpSecurityMode.None); var httpBinding = ((NetHttpBinding)binding); httpBinding.MaxBufferPoolSize = Constants.MAX_MSG_SIZE; httpBinding.MaxReceivedMessageSize = Constants.MAX_MSG_SIZE; httpBinding.WebSocketSettings.TransportUsage = WebSocketTransportUsage.Always; httpBinding.MessageEncoding = NetHttpMessageEncoding.Text; break; } } if (binding != null) { binding.CloseTimeout = options.CloseTimeout; binding.OpenTimeout = options.OpenTimeout; binding.ReceiveTimeout = options.ReceiveTimeout; binding.SendTimeout = options.SendTimeout; } return binding; }
protected override void Load(ContainerBuilder builder) { builder.RegisterType<PluginService>(); builder.Register<IPluginServiceHost>(c => { var scope = c.Resolve<ILifetimeScope>(); var cfg = c.Resolve<IConfiguration>(); var uri = new Uri(string.Format(cfg.PluginUrlTemplate, "core")); var binding = new NetHttpBinding { HostNameComparisonMode = HostNameComparisonMode.Exact, MaxBufferPoolSize = 10485760, MaxReceivedMessageSize = 10485760, }; var host = new ServiceHost(typeof(PluginService)); host.AddServiceEndpoint(typeof(IPluginService), binding, uri); host.AddDependencyInjectionBehavior(typeof(PluginService), scope); return new PluginServiceHost(host); }); }
public static void WebSocket_Http_Duplex_BinaryStreamed() { NetHttpBinding binding = null; ClientReceiver clientReceiver = null; InstanceContext context = null; DuplexChannelFactory<IWSDuplexService> channelFactory = null; IWSDuplexService 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 = NetHttpMessageEncoding.Binary; clientReceiver = new ClientReceiver(); context = new InstanceContext(clientReceiver); channelFactory = new DuplexChannelFactory<IWSDuplexService>(context, binding, Endpoints.WebSocketHttpDuplexBinaryStreamed_Address); 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); client.StartPushingStream(); // Wait for the callback to get invoked before telling the service to stop streaming. // This ensures we can read from the stream on the callback while the NCL layer at the service // is still writing the bytes from the stream to the wire. // This will deadlock if the transfer mode is buffered because the callback will wait for the // stream, and the NCL layer will continue to buffer the stream until it reaches the end. Assert.True(clientReceiver.ReceiveStreamInvoked.WaitOne(ScenarioTestHelpers.TestTimeout), String.Format("Test case timeout was reached while waiting for the stream response from the Service. Timeout was: {0}", ScenarioTestHelpers.TestTimeout)); clientReceiver.ReceiveStreamInvoked.Reset(); // Upload the stream while we are downloading a different stream uploadStream = new FlowControlledStream(); uploadStream.ReadThrottle = TimeSpan.FromMilliseconds(500); uploadStream.StreamDuration = TimeSpan.FromSeconds(1); client.UploadStream(uploadStream); client.StopPushingStream(); // Waiting on ReceiveStreamCompleted from the ClientReceiver. Assert.True(clientReceiver.ReceiveStreamCompleted.WaitOne(ScenarioTestHelpers.TestTimeout), String.Format("Test case timeout was reached while waiting for the stream response from the Service to be completed. Timeout was: {0}", ScenarioTestHelpers.TestTimeout)); clientReceiver.ReceiveStreamCompleted.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); clientReceiver.Dispose(); } }
public static void WebSocket_WSScheme_WSTransportUsageAlways_DuplexCallback_GuidRoundtrip() { DuplexChannelFactory<IWcfDuplexService> factory = null; IWcfDuplexService proxy = 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); UriBuilder builder = new UriBuilder(Endpoints.NetHttpWebSocketTransport_Address); // Replacing "http" with "ws" as the uri scheme. builder.Scheme = "ws"; factory = new DuplexChannelFactory<IWcfDuplexService>(context, binding, new EndpointAddress(Endpoints.NetHttpWebSocketTransport_Address)); proxy = factory.CreateChannel(); // *** EXECUTE *** \\ Task.Run(() => proxy.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)proxy).Close(); } finally { // *** ENSURE CLEANUP *** \\ ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)proxy, factory); } }
public static void WebSocket_Http_WSTransportUsageDefault_DuplexCallback_GuidRoundtrip() { DuplexChannelFactory<IWcfDuplexService> factory = null; IWcfDuplexService duplexProxy = null; Guid guid = Guid.NewGuid(); try { // *** SETUP *** \\ NetHttpBinding binding = new NetHttpBinding(); // NetHttpBinding default value of WebSocketTransportSettings.WebSocketTransportUsage is "WhenDuplex" // Therefore using a Duplex Contract will trigger the use of the WCF implementation of WebSockets. WcfDuplexServiceCallback callbackService = new WcfDuplexServiceCallback(); InstanceContext context = new InstanceContext(callbackService); factory = new DuplexChannelFactory<IWcfDuplexService>(context, binding, new EndpointAddress(Endpoints.NetHttpDuplexWebSocket_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 *** \\ ((ICommunicationObject)duplexProxy).Close(); factory.Close(); } finally { // *** ENSURE CLEANUP *** \\ ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)duplexProxy, factory); } }
public static void WebSocket_Http_VerifyWebSocketsUsed() { #if FULLXUNIT_NOTSUPPORTED bool root_Certificate_Installed = Root_Certificate_Installed(); if (!root_Certificate_Installed) { Console.WriteLine("---- Test SKIPPED --------------"); Console.WriteLine("Attempting to run the test in ToF, a ConditionalFact evaluated as FALSE."); Console.WriteLine("Root_Certificate_Installed evaluated as {0}", root_Certificate_Installed); return; } #endif 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); } }
public static void WebSocket_Http_Duplex_BinaryBuffered() { #if FULLXUNIT_NOTSUPPORTED bool root_Certificate_Installed = Root_Certificate_Installed(); if (!root_Certificate_Installed) { Console.WriteLine("---- Test SKIPPED --------------"); Console.WriteLine("Attempting to run the test in ToF, a ConditionalFact evaluated as FALSE."); Console.WriteLine("Root_Certificate_Installed evaluated as {0}", root_Certificate_Installed); return; } #endif 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 = NetHttpMessageEncoding.Binary; clientReceiver = new ClientReceiver(); context = new InstanceContext(clientReceiver); channelFactory = new DuplexChannelFactory<IWSDuplexService>(context, binding, new EndpointAddress(Endpoints.WebSocketHttpDuplexBinaryBuffered_Address)); 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); } }
public static void IDuplexSessionChannel_Http_NetHttpBinding() { IChannelFactory<IDuplexSessionChannel> factory = null; IDuplexSessionChannel channel = null; Message replyMessage = null; try { // *** SETUP *** \\ NetHttpBinding binding = new NetHttpBinding(); // Create the channel factory factory = binding.BuildChannelFactory<IDuplexSessionChannel>(new BindingParameterCollection()); factory.Open(); // Create the channel. channel = factory.CreateChannel(new EndpointAddress(Endpoints.HttpBaseAddress_NetHttpWebSockets)); channel.Open(); // Create the Message object to send to the service. Message requestMessage = Message.CreateMessage( binding.MessageVersion, action, new CustomBodyWriter(clientMessage)); requestMessage.Headers.MessageId = new UniqueId(Guid.NewGuid()); // *** EXECUTE *** \\ // Send the Message and receive the Response. channel.Send(requestMessage); replyMessage = channel.Receive(TimeSpan.FromSeconds(5)); // *** VALIDATE *** \\ // If the incoming Message did not contain the same UniqueId used for the MessageId of the outgoing Message we would have received a Fault from the Service Assert.Equal(requestMessage.Headers.MessageId.ToString(), replyMessage.Headers.RelatesTo.ToString()); // Validate the Response var replyReader = replyMessage.GetReaderAtBodyContents(); string actualResponse = replyReader.ReadElementContentAsString(); string expectedResponse = "[client] This is my request.[service] Request received, this is my Reply."; Assert.Equal(expectedResponse, actualResponse); // *** CLEANUP *** \\ replyMessage.Close(); channel.Close(); factory.Close(); } finally { // *** ENSURE CLEANUP *** \\ ScenarioTestHelpers.CloseCommunicationObjects(channel, factory); } }
public static Binding GetNetHttpBinding(BasicHttpSecurityMode mode) { var binding = new NetHttpBinding(mode); Configure(binding); return binding; }
public static void WebSocketHttpDuplexBinaryStreamed() { NetHttpBinding binding = null; ClientReceiver clientReceiver = null; InstanceContext context = null; DuplexChannelFactory<IWSDuplexService> channelFactory = null; IWSDuplexService client = null; FlowControlledStream uploadStream = null; try { // *** SETUP *** \\ binding = new NetHttpBinding(); binding.WebSocketSettings.TransportUsage = WebSocketTransportUsage.Always; binding.MaxReceivedMessageSize = ScenarioTestHelpers.DefaultMaxReceivedMessageSize; binding.MaxBufferSize = ScenarioTestHelpers.DefaultMaxReceivedMessageSize; binding.TransferMode = TransferMode.Streamed; binding.MessageEncoding = NetHttpMessageEncoding.Binary; clientReceiver = new ClientReceiver(); context = new InstanceContext(clientReceiver); channelFactory = new DuplexChannelFactory<IWSDuplexService>(context, binding, Endpoints.WebSocketHttpDuplexBinaryStreamed_Address); 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); client.StartPushingStream(); // Wait for the callback to get invoked before telling the service to stop streaming. // This ensures we can read from the stream on the callback while the NCL layer at the service // is still writing the bytes from the stream to the wire. // This will deadlock if the transfer mode is buffered because the callback will wait for the // stream, and the NCL layer will continue to buffer the stream until it reaches the end. clientReceiver.ReceiveStreamInvoked.WaitOne(); clientReceiver.ReceiveStreamInvoked.Reset(); // Upload the stream while we are downloading a different stream uploadStream = new FlowControlledStream(); uploadStream.ReadThrottle = TimeSpan.FromMilliseconds(500); uploadStream.StreamDuration = TimeSpan.FromSeconds(1); client.UploadStream(uploadStream); client.StopPushingStream(); // Waiting on ReceiveStreamCompleted from the ClientReceiver. clientReceiver.ReceiveStreamCompleted.WaitOne(); clientReceiver.ReceiveStreamCompleted.Reset(); // *** VALIDATE *** \\ // Validation is based on no exceptions being thrown. // *** CLEANUP *** \\ ((ICommunicationObject)client).Close(); channelFactory.Close(); } finally { // *** ENSURE CLEANUP *** \\ ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)client, channelFactory); clientReceiver.Dispose(); } }
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); } }
public static void WebSocket_Http_RequestReply_BinaryBuffered_KeepAlive() { NetHttpBinding binding = null; ChannelFactory<IWSRequestReplyService> channelFactory = null; IWSRequestReplyService client = null; try { // *** SETUP *** \\ binding = new NetHttpBinding() { MaxReceivedMessageSize = ScenarioTestHelpers.SixtyFourMB, MaxBufferSize = ScenarioTestHelpers.SixtyFourMB, }; binding.WebSocketSettings.TransportUsage = WebSocketTransportUsage.Always; binding.MessageEncoding = NetHttpMessageEncoding.Binary; binding.WebSocketSettings.KeepAliveInterval = TimeSpan.FromSeconds(2); channelFactory = new ChannelFactory<IWSRequestReplyService>(binding, new EndpointAddress(Endpoints.WebSocketHttpRequestReplyBinaryBuffered_Address)); client = channelFactory.CreateChannel(); // *** EXECUTE *** \\ // Invoking DownloadData string result = client.DownloadData(); // Invoking UploadData client.UploadData(ScenarioTestHelpers.CreateInterestingString(123)); // *** 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); } }
internal static bool TryCreate(BindingElementCollection elements, out Binding binding) { binding = null; if (elements.Count > 4) { return(false); } SecurityBindingElement securityElement = null; MessageEncodingBindingElement encoding = null; HttpTransportBindingElement transport = null; foreach (BindingElement element in elements) { if (element is SecurityBindingElement) { securityElement = element as SecurityBindingElement; } else if (element is TransportBindingElement) { transport = element as HttpTransportBindingElement; } else if (element is MessageEncodingBindingElement) { encoding = element as MessageEncodingBindingElement; } else { return(false); } } if (transport == null || transport.WebSocketSettings.TransportUsage != WebSocketTransportUsage.Always) { return(false); } HttpsTransportBindingElement httpsTransport = transport as HttpsTransportBindingElement; if ((securityElement != null) && (httpsTransport != null) && (httpsTransport.RequireClientCertificate != TransportDefaults.RequireClientCertificate)) { return(false); } // process transport binding element UnifiedSecurityMode mode; HttpTransportSecurity transportSecurity = new HttpTransportSecurity(); if (!GetSecurityModeFromTransport(transport, transportSecurity, out mode)) { return(false); } if (encoding == null) { return(false); } if (!(encoding is TextMessageEncodingBindingElement || encoding is BinaryMessageEncodingBindingElement)) { return(false); } if (encoding.MessageVersion != MessageVersion.Soap12WSAddressing10) { return(false); } BasicHttpSecurity security; if (!TryCreateSecurity(securityElement, mode, transportSecurity, out security)) { return(false); } NetHttpBinding netHttpBinding = new NetHttpBinding(security); netHttpBinding.InitializeFrom(transport, encoding); // make sure all our defaults match if (!netHttpBinding.IsBindingElementsMatch(transport, encoding)) { return(false); } binding = netHttpBinding; return(true); }
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(Endpoints.HttpBaseAddress_NetHttp); DuplexChannelFactory<IWcfDuplexService> factory = new DuplexChannelFactory<IWcfDuplexService>(context, binding, endpoint); // Can't cast to IDuplexSessionChannel to IRequestChannel on http var exception = Assert.Throws<InvalidCastException>(() => { factory.CreateChannel(); }); Assert.True(exception.Message.Contains("IRequestChannel"), "InvalidCastException exception string should contain 'IRequestChannel'"); }
protected override Binding GetBinding() { var binding = new NetHttpBinding(); binding.WebSocketSettings.TransportUsage = WebSocketTransportUsage.Always; return binding; }
public static void WebSocket_Http_RequestReply_TextBuffered() { #if FULLXUNIT_NOTSUPPORTED bool root_Certificate_Installed = Root_Certificate_Installed(); if (!root_Certificate_Installed) { Console.WriteLine("---- Test SKIPPED --------------"); Console.WriteLine("Attempting to run the test in ToF, a ConditionalFact evaluated as FALSE."); Console.WriteLine("Root_Certificate_Installed evaluated as {0}", root_Certificate_Installed); return; } #endif NetHttpBinding binding = null; ChannelFactory<IWSRequestReplyService> channelFactory = null; IWSRequestReplyService client = null; try { // *** SETUP *** \\ binding = new NetHttpBinding() { MaxReceivedMessageSize = ScenarioTestHelpers.SixtyFourMB, MaxBufferSize = ScenarioTestHelpers.SixtyFourMB, }; binding.WebSocketSettings.TransportUsage = WebSocketTransportUsage.Always; binding.MessageEncoding = NetHttpMessageEncoding.Text; channelFactory = new ChannelFactory<IWSRequestReplyService>(binding, new EndpointAddress(Endpoints.WebSocketHttpRequestReplyTextBuffered_Address)); client = channelFactory.CreateChannel(); // *** EXECUTE *** \\ // Invoking DownloadData string result = client.DownloadData(); // Invoking UploadData client.UploadData(ScenarioTestHelpers.CreateInterestingString(123)); // *** 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); } }
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); // Can't cast to IDuplexSessionChannel to IRequestChannel on http var exception = Assert.Throws<InvalidCastException>(() => { factory.CreateChannel(); }); // Can't check that the InvalidCastException message as .NET Native only reports this message for all InvalidCastExceptions: // "System.InvalidCastException: Arg_InvalidCastException" }
public static void WebSocket_Http_Duplex_TextBuffered_KeepAlive() { 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 = NetHttpMessageEncoding.Text; binding.WebSocketSettings.KeepAliveInterval = TimeSpan.FromSeconds(2); clientReceiver = new ClientReceiver(); context = new InstanceContext(clientReceiver); channelFactory = new DuplexChannelFactory<IWSDuplexService>(context, binding, new EndpointAddress(Endpoints.WebSocketHttpDuplexTextBuffered_Address)); 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); } }
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(); }
public static Binding GetNetHttpBinding() { var binding = new NetHttpBinding(); Configure(binding); return binding; }